我无法让mmap功能工作。它返回EINVAL错误代码。
void* mapped =
mmap((void*)(map_addr + slide),
map_size,
PROT_WRITE | PROT_READ,
MAP_PRIVATE | MAP_ANON,
bprm->file,
map_offset);
我已经在我的平台 ( Darwin ) 上检查了此功能的文档,似乎没有任何问题。mmap 的手册页提供了四种情况下会返回 EINVAL。
[EINVAL] MAP_FIXED was specified and the addr argument was not page
aligned, or part of the desired address space resides out of the
valid address space for a user process.
MAP_FIXED 未指定,所以不是这个。
[EINVAL] flags does not include either MAP_PRIVATE or MAP_SHARED.
存在 MAP_PRIVATE。
[EINVAL] The len argument was negative.
调用时的 len (map_size) 参数是 8192。
[EINVAL] The offset argument was not page-aligned based on the page size as
returned by getpagesize(3).
偏移量参数 (map_offset) 为 0,因此它必须是页面对齐的。(也许我错了?)