summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2022-05-24 13:39:00 +0200
committerJan Janssen <medhefgo@web.de>2022-05-31 15:15:01 +0200
commitbbc1f2eac582cc9a95da8836e84b03a67100dcd5 (patch)
treefbfd519d3692bcece392b0e55d15912fa77e29cc /src
parentf7967716e3da6c2df0673ba9edbf84ae78233429 (diff)
downloadsystemd-bbc1f2eac582cc9a95da8836e84b03a67100dcd5.tar.gz
boot: Use memcmp/memcpy/memset
Diffstat (limited to 'src')
-rw-r--r--src/boot/efi/boot.c8
-rw-r--r--src/boot/efi/cpio.c12
-rw-r--r--src/boot/efi/devicetree.c4
-rw-r--r--src/boot/efi/initrd.c2
-rw-r--r--src/boot/efi/linux.c4
-rw-r--r--src/boot/efi/linux_x86.c4
-rw-r--r--src/boot/efi/measure.c4
-rw-r--r--src/boot/efi/pe.c6
-rw-r--r--src/boot/efi/random-seed.c2
-rw-r--r--src/boot/efi/stub.c10
-rw-r--r--src/boot/efi/util.c6
-rw-r--r--src/boot/efi/xbootldr.c14
-rw-r--r--src/fundamental/macro-fundamental.h1
-rw-r--r--src/fundamental/sha256.c6
-rw-r--r--src/fundamental/string-util-fundamental.h1
15 files changed, 42 insertions, 42 deletions
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
index b75e4261a4..e3964033c2 100644
--- a/src/boot/efi/boot.c
+++ b/src/boot/efi/boot.c
@@ -162,7 +162,7 @@ static BOOLEAN line_edit(
UINTN cursor_color = TEXT_ATTR_SWAP(COLOR_EDIT);
j = MIN(len - first, x_max);
- CopyMem(print, line + first, j * sizeof(CHAR16));
+ memcpy(print, line + first, j * sizeof(CHAR16));
while (clear > 0 && j < x_max) {
clear--;
print[j++] = ' ';
@@ -1866,7 +1866,7 @@ static BOOLEAN is_sd_boot(EFI_FILE *root_dir, const CHAR16 *loader_path) {
if (EFI_ERROR(err) || size != read)
return FALSE;
- return CompareMem(content, magic, sizeof(magic)) == 0;
+ return memcmp(content, magic, sizeof(magic)) == 0;
}
static ConfigEntry *config_entry_add_loader_auto(
@@ -1986,7 +1986,7 @@ static EFI_STATUS boot_windows_bitlocker(void) {
if (EFI_ERROR(err))
continue;
- if (CompareMem(buf + 3, "-FVE-FS-", STRLEN("-FVE-FS-")) == 0) {
+ if (memcmp(buf + 3, "-FVE-FS-", STRLEN("-FVE-FS-")) == 0) {
found = TRUE;
break;
}
@@ -2434,7 +2434,7 @@ static void config_write_entries_to_variable(Config *config) {
UINTN l;
l = strsize16(config->entries[i]->id);
- CopyMem(p, config->entries[i]->id, l);
+ memcpy(p, config->entries[i]->id, l);
p += l;
}
diff --git a/src/boot/efi/cpio.c b/src/boot/efi/cpio.c
index 5f8489635f..8345f957f7 100644
--- a/src/boot/efi/cpio.c
+++ b/src/boot/efi/cpio.c
@@ -116,7 +116,7 @@ static EFI_STATUS pack_cpio_one(
*cpio_buffer = a;
a = (CHAR8*) *cpio_buffer + *cpio_buffer_size;
- CopyMem(a, "070701", 6); /* magic ID */
+ memcpy(a, "070701", 6); /* magic ID */
a += 6;
a = write_cpio_word(a, (*inode_counter)++); /* inode */
@@ -139,7 +139,7 @@ static EFI_STATUS pack_cpio_one(
a = write_cpio_word(a, target_dir_prefix_size + fname_size + 2); /* fname size */
a = write_cpio_word(a, 0); /* "crc" */
- CopyMem(a, target_dir_prefix, target_dir_prefix_size);
+ memcpy(a, target_dir_prefix, target_dir_prefix_size);
a += target_dir_prefix_size;
*(a++) = '/';
a = mangle_filename(a, fname);
@@ -147,7 +147,7 @@ static EFI_STATUS pack_cpio_one(
/* Pad to next multiple of 4 */
a = pad4(a, *cpio_buffer);
- CopyMem(a, contents, contents_size);
+ memcpy(a, contents, contents_size);
a += contents_size;
/* Pad to next multiple of 4 */
@@ -198,7 +198,7 @@ static EFI_STATUS pack_cpio_dir(
*cpio_buffer = a = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + l);
a = (CHAR8*) *cpio_buffer + *cpio_buffer_size;
- CopyMem(a, "070701", 6); /* magic ID */
+ memcpy(a, "070701", 6); /* magic ID */
a += 6;
a = write_cpio_word(a, (*inode_counter)++); /* inode */
@@ -215,7 +215,7 @@ static EFI_STATUS pack_cpio_dir(
a = write_cpio_word(a, path_size + 1); /* fname size */
a = write_cpio_word(a, 0); /* "crc" */
- CopyMem(a, path, path_size + 1);
+ memcpy(a, path, path_size + 1);
a += path_size + 1;
/* Pad to next multiple of 4 */
@@ -298,7 +298,7 @@ static EFI_STATUS pack_cpio_trailer(
assert_cc(sizeof(trailer) % 4 == 0);
*cpio_buffer = xreallocate_pool(*cpio_buffer, *cpio_buffer_size, *cpio_buffer_size + sizeof(trailer));
- CopyMem((UINT8*) *cpio_buffer + *cpio_buffer_size, trailer, sizeof(trailer));
+ memcpy((UINT8*) *cpio_buffer + *cpio_buffer_size, trailer, sizeof(trailer));
*cpio_buffer_size += sizeof(trailer);
return EFI_SUCCESS;
diff --git a/src/boot/efi/devicetree.c b/src/boot/efi/devicetree.c
index b8ba52a523..81c6e60ca6 100644
--- a/src/boot/efi/devicetree.c
+++ b/src/boot/efi/devicetree.c
@@ -51,7 +51,7 @@ static EFI_STATUS devicetree_fixup(struct devicetree_state *state, UINTN len) {
if (EFI_ERROR(err))
return err;
- CopyMem(PHYSICAL_ADDRESS_TO_POINTER(state->addr), oldptr, len);
+ memcpy(PHYSICAL_ADDRESS_TO_POINTER(state->addr), oldptr, len);
err = BS->FreePages(oldaddr, oldpages);
if (EFI_ERROR(err))
return err;
@@ -122,7 +122,7 @@ EFI_STATUS devicetree_install_from_memory(struct devicetree_state *state,
if (EFI_ERROR(err))
return err;
- CopyMem(PHYSICAL_ADDRESS_TO_POINTER(state->addr), dtb_buffer, dtb_length);
+ memcpy(PHYSICAL_ADDRESS_TO_POINTER(state->addr), dtb_buffer, dtb_length);
err = devicetree_fixup(state, dtb_length);
if (EFI_ERROR(err))
diff --git a/src/boot/efi/initrd.c b/src/boot/efi/initrd.c
index 3136d3b8fa..2d0984990b 100644
--- a/src/boot/efi/initrd.c
+++ b/src/boot/efi/initrd.c
@@ -61,7 +61,7 @@ EFIAPI EFI_STATUS initrd_load_file(
return EFI_BUFFER_TOO_SMALL;
}
- CopyMem(buffer, loader->address, loader->length);
+ memcpy(buffer, loader->address, loader->length);
*buffer_size = loader->length;
return EFI_SUCCESS;
}
diff --git a/src/boot/efi/linux.c b/src/boot/efi/linux.c
index 31413ed3a4..dcffea15c0 100644
--- a/src/boot/efi/linux.c
+++ b/src/boot/efi/linux.c
@@ -145,9 +145,9 @@ EFI_STATUS linux_exec(
if (EFI_ERROR(err))
return EFI_OUT_OF_RESOURCES;
new_buffer = PHYSICAL_ADDRESS_TO_POINTER(ALIGN_TO(kernel.addr, kernel_alignment));
- CopyMem(new_buffer, linux_buffer, linux_length);
+ memcpy(new_buffer, linux_buffer, linux_length);
/* zero out rest of memory (probably not needed, but BSS section should be 0) */
- SetMem((UINT8 *)new_buffer + linux_length, kernel_size_of_image - linux_length, 0);
+ memset((UINT8 *)new_buffer + linux_length, 0, kernel_size_of_image - linux_length);
/* get the entry point inside the relocated kernel */
kernel_entry = (EFI_IMAGE_ENTRY_POINT) ((const UINT8 *)new_buffer + kernel_entry_address);
diff --git a/src/boot/efi/linux_x86.c b/src/boot/efi/linux_x86.c
index 15052bdff6..a6c1f06939 100644
--- a/src/boot/efi/linux_x86.c
+++ b/src/boot/efi/linux_x86.c
@@ -159,7 +159,7 @@ EFI_STATUS linux_exec(
return err;
boot_params = (struct boot_params *) PHYSICAL_ADDRESS_TO_POINTER(addr);
- ZeroMem(boot_params, 0x4000);
+ memset(boot_params, 0, 0x4000);
boot_params->hdr = image_params->hdr;
boot_params->hdr.type_of_loader = 0xff;
setup_sectors = image_params->hdr.setup_sects > 0 ? image_params->hdr.setup_sects : 4;
@@ -176,7 +176,7 @@ EFI_STATUS linux_exec(
if (EFI_ERROR(err))
return err;
- CopyMem(PHYSICAL_ADDRESS_TO_POINTER(addr), cmdline, cmdline_len);
+ memcpy(PHYSICAL_ADDRESS_TO_POINTER(addr), cmdline, cmdline_len);
((CHAR8 *) PHYSICAL_ADDRESS_TO_POINTER(addr))[cmdline_len] = 0;
boot_params->hdr.cmd_line_ptr = (UINT32) addr;
}
diff --git a/src/boot/efi/measure.c b/src/boot/efi/measure.c
index 7579b756c5..c9ce8f19e0 100644
--- a/src/boot/efi/measure.c
+++ b/src/boot/efi/measure.c
@@ -32,7 +32,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log(
.PCRIndex = pcrindex,
.EventType = EV_IPL,
};
- CopyMem(tcg_event->Event, description, desc_len);
+ memcpy(tcg_event->Event, description, desc_len);
return tcg->HashLogExtendEvent(
(EFI_TCG *) tcg,
@@ -66,7 +66,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log(
.Header.EventType = EV_IPL,
};
- CopyMem(tcg_event->Event, description, desc_len);
+ memcpy(tcg_event->Event, description, desc_len);
return tcg->HashLogExtendEvent(
tcg,
diff --git a/src/boot/efi/pe.c b/src/boot/efi/pe.c
index daa7638862..f9bd57f0ce 100644
--- a/src/boot/efi/pe.c
+++ b/src/boot/efi/pe.c
@@ -119,12 +119,12 @@ struct PeSectionHeader {
static inline BOOLEAN verify_dos(const struct DosFileHeader *dos) {
assert(dos);
- return CompareMem(dos->Magic, DOS_FILE_MAGIC, STRLEN(DOS_FILE_MAGIC)) == 0;
+ return memcmp(dos->Magic, DOS_FILE_MAGIC, STRLEN(DOS_FILE_MAGIC)) == 0;
}
static inline BOOLEAN verify_pe(const struct PeFileHeader *pe, BOOLEAN allow_compatibility) {
assert(pe);
- return CompareMem(pe->Magic, PE_FILE_MAGIC, STRLEN(PE_FILE_MAGIC)) == 0 &&
+ return memcmp(pe->Magic, PE_FILE_MAGIC, STRLEN(PE_FILE_MAGIC)) == 0 &&
(pe->FileHeader.Machine == TARGET_MACHINE_TYPE ||
(allow_compatibility && pe->FileHeader.Machine == TARGET_MACHINE_TYPE_COMPATIBILITY)) &&
pe->FileHeader.NumberOfSections > 0 &&
@@ -154,7 +154,7 @@ static void locate_sections(
const struct PeSectionHeader *sect = section_table + i;
for (UINTN j = 0; sections[j]; j++) {
- if (CompareMem(sect->Name, sections[j], strlen8((const char *) sections[j])) != 0)
+ if (memcmp(sect->Name, sections[j], strlen8((const char *) sections[j])) != 0)
continue;
if (addrs)
diff --git a/src/boot/efi/random-seed.c b/src/boot/efi/random-seed.c
index 2ff8299fa6..a9ee273673 100644
--- a/src/boot/efi/random-seed.c
+++ b/src/boot/efi/random-seed.c
@@ -223,7 +223,7 @@ static void validate_sha256(void) {
sha256_process_bytes(array[i].string, strlen8(array[i].string), &hash);
sha256_finish_ctx(&hash, result);
- assert(CompareMem(result, array[i].hash, HASH_VALUE_SIZE) == 0);
+ assert(memcmp(result, array[i].hash, HASH_VALUE_SIZE) == 0);
}
#endif
diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c
index 40f615b2b3..36becafa08 100644
--- a/src/boot/efi/stub.c
+++ b/src/boot/efi/stub.c
@@ -68,28 +68,28 @@ static EFI_STATUS combine_initrd(
/* Order matters, the real initrd must come first, since it might include microcode updates
* which the kernel only looks for in the first cpio archive */
- CopyMem(p, PHYSICAL_ADDRESS_TO_POINTER(initrd_base), initrd_size);
+ memcpy(p, PHYSICAL_ADDRESS_TO_POINTER(initrd_base), initrd_size);
p += initrd_size;
pad = ALIGN_TO(initrd_size, 4) - initrd_size;
if (pad > 0) {
- ZeroMem(p, pad);
+ memset(p, 0, pad);
p += pad;
}
}
if (credential_initrd) {
- CopyMem(p, credential_initrd, credential_initrd_size);
+ memcpy(p, credential_initrd, credential_initrd_size);
p += credential_initrd_size;
}
if (global_credential_initrd) {
- CopyMem(p, global_credential_initrd, global_credential_initrd_size);
+ memcpy(p, global_credential_initrd, global_credential_initrd_size);
p += global_credential_initrd_size;
}
if (sysext_initrd) {
- CopyMem(p, sysext_initrd, sysext_initrd_size);
+ memcpy(p, sysext_initrd, sysext_initrd_size);
p += sysext_initrd_size;
}
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c
index 2827dae8ff..83e03fa835 100644
--- a/src/boot/efi/util.c
+++ b/src/boot/efi/util.c
@@ -117,7 +117,7 @@ EFI_STATUS efivar_get(const EFI_GUID *vendor, const CHAR16 *name, CHAR16 **value
/* Make sure a terminating NUL is available at the end */
val = xallocate_pool(size + sizeof(CHAR16));
- CopyMem(val, buf, size);
+ memcpy(val, buf, size);
val[size / sizeof(CHAR16) - 1] = 0; /* NUL terminate */
*value = val;
@@ -397,7 +397,7 @@ EFI_STATUS file_read(EFI_FILE *dir, const CHAR16 *name, UINTN off, UINTN size, C
return err;
/* Note that handle->Read() changes size to reflect the actually bytes read. */
- ZeroMem(buf + size, extra);
+ memset(buf + size, 0, extra);
*ret = TAKE_PTR(buf);
if (ret_size)
@@ -566,7 +566,7 @@ CHAR8 *xstrndup8(const CHAR8 *p, UINTN sz) {
n = xallocate_pool(sz + 1);
if (sz > 0)
- CopyMem(n, p, sz);
+ memcpy(n, p, sz);
n[sz] = 0;
return n;
diff --git a/src/boot/efi/xbootldr.c b/src/boot/efi/xbootldr.c
index f73b5eeb20..bc82768715 100644
--- a/src/boot/efi/xbootldr.c
+++ b/src/boot/efi/xbootldr.c
@@ -19,7 +19,7 @@ static EFI_DEVICE_PATH *path_chop(EFI_DEVICE_PATH *path, EFI_DEVICE_PATH *node)
UINTN len = (UINT8 *) node - (UINT8 *) path;
EFI_DEVICE_PATH *chopped = xallocate_pool(len + END_DEVICE_PATH_LENGTH);
- CopyMem(chopped, path, len);
+ memcpy(chopped, path, len);
SetDevicePathEndNode((EFI_DEVICE_PATH *) ((UINT8 *) chopped + len));
return chopped;
@@ -35,7 +35,7 @@ static BOOLEAN verify_gpt(union GptHeaderBuffer *gpt_header_buffer, EFI_LBA lba_
h = &gpt_header_buffer->gpt_header;
/* Some superficial validation of the GPT header */
- if (CompareMem(&h->Header.Signature, "EFI PART", sizeof(h->Header.Signature)) != 0)
+ if (memcmp(&h->Header.Signature, "EFI PART", sizeof(h->Header.Signature)) != 0)
return FALSE;
if (h->Header.HeaderSize < 92 || h->Header.HeaderSize > 512)
@@ -123,12 +123,12 @@ static EFI_STATUS try_gpt(
entry = (EFI_PARTITION_ENTRY*) ((UINT8*) entries + gpt.gpt_header.SizeOfPartitionEntry * i);
- if (CompareMem(&entry->PartitionTypeGUID, XBOOTLDR_GUID, sizeof(entry->PartitionTypeGUID)) != 0)
+ if (memcmp(&entry->PartitionTypeGUID, XBOOTLDR_GUID, sizeof(entry->PartitionTypeGUID)) != 0)
continue;
/* Let's use memcpy(), in case the structs are not aligned (they really should be though) */
- CopyMem(&start, &entry->StartingLBA, sizeof(start));
- CopyMem(&end, &entry->EndingLBA, sizeof(end));
+ memcpy(&start, &entry->StartingLBA, sizeof(start));
+ memcpy(&end, &entry->EndingLBA, sizeof(end));
if (end < start) /* Bogus? */
continue;
@@ -138,7 +138,7 @@ static EFI_STATUS try_gpt(
ret_hd->PartitionSize = end - start + 1;
ret_hd->MBRType = MBR_TYPE_EFI_PARTITION_TABLE_HEADER;
ret_hd->SignatureType = SIGNATURE_TYPE_GUID;
- CopyMem(ret_hd->Signature, &entry->UniquePartitionGUID, sizeof(ret_hd->Signature));
+ memcpy(ret_hd->Signature, &entry->UniquePartitionGUID, sizeof(ret_hd->Signature));
return EFI_SUCCESS;
}
@@ -227,7 +227,7 @@ static EFI_STATUS find_device(EFI_HANDLE *device, EFI_DEVICE_PATH **ret_device_p
/* Patch in the data we found */
EFI_DEVICE_PATH *xboot_path = ASSERT_SE_PTR(DuplicateDevicePath(partition_path));
- CopyMem((UINT8 *) xboot_path + ((UINT8 *) part_node - (UINT8 *) partition_path), &hd, sizeof(hd));
+ memcpy((UINT8 *) xboot_path + ((UINT8 *) part_node - (UINT8 *) partition_path), &hd, sizeof(hd));
*ret_device_path = xboot_path;
return EFI_SUCCESS;
}
diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h
index 59d63e8e5d..bb9e779dd2 100644
--- a/src/fundamental/macro-fundamental.h
+++ b/src/fundamental/macro-fundamental.h
@@ -77,7 +77,6 @@
#define static_assert _Static_assert
#define assert_se(expr) ({ _likely_(expr) ? VOID_0 : efi_assert(#expr, __FILE__, __LINE__, __PRETTY_FUNCTION__); })
- #define memcpy(a, b, c) CopyMem((a), (b), (c))
#define free(a) FreePool(a)
#endif
diff --git a/src/fundamental/sha256.c b/src/fundamental/sha256.c
index 0577a24920..6fcb37a7d9 100644
--- a/src/fundamental/sha256.c
+++ b/src/fundamental/sha256.c
@@ -23,8 +23,10 @@
/* Written by Ulrich Drepper <drepper@redhat.com>, 2007. */
-#ifndef SD_BOOT
-#include <string.h>
+#ifdef SD_BOOT
+# include "efi-string.h"
+#else
+# include <string.h>
#endif
#include "macro-fundamental.h"
diff --git a/src/fundamental/string-util-fundamental.h b/src/fundamental/string-util-fundamental.h
index d7a67356ab..8048a07f73 100644
--- a/src/fundamental/string-util-fundamental.h
+++ b/src/fundamental/string-util-fundamental.h
@@ -18,7 +18,6 @@
# define strcasecmp strcasecmp16
# define strncasecmp strncasecmp16
# define STR_C(str) (L ## str)
-# define memcmp(a, b, n) CompareMem(a, b, n)
#else
# define STR_C(str) (str)
#endif