boot: Use memcmp/memcpy/memset
This commit is contained in:
+4
-4
@@ -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;
|
||||
}
|
||||
|
||||
+6
-6
@@ -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;
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
+5
-5
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user