0

I'm in an identity-mapped memory context (UEFI on x86_64 platform) and I want to dump some contiguous memory content into a structure. Say my structure has this shape:

typedef struct _mystr {
    char char_arr[7];
    uint32_t u_d;
    uint8_t u_b;
} __attribute__((packed)) mystr;

Supposing I have in mem_ptr the address to the requested memory's offset 0, what's the best way to copy its content into a mystr instance? Is there a way to do that without iterating through memory with a loop (which seems super boring)?


EDIT: Nicolas Jean suggested the use of memcpy but unfortunately in an EFI developing context the use of a C standard library makes little sense. However, efilib.h from gnu-efi has CopyMem(IN VOID * dst, IN CONST VOID * src, IN UINTN len) which carries out the same task.

4

3 回答 3

2

正如您正确识别的那样,memcpy 在 UEFI 环境中并不真正存在,但如果将 CopyMem 用于编译到固件映像中的某些内容,则效果很好。

对于驱动程序或应用程序,您最好使用 gBS->CopyMem() 引导服务。

于 2016-09-09T23:18:47.997 回答
2

使用 memcpy 复制内存内容可能是您正在寻找的。

mystr mystr_instance;
memcpy(&mystr_instance, mem_ptr, sizeof(mystr_instance));
于 2016-09-09T09:16:26.760 回答
1

假设内存格式正确,您可以将指针转换为地址或将数据 memcpy 到您的结构中

于 2016-09-09T09:06:10.623 回答