我无法获取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,因此它必须页对齐。 (也许我错了?)