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