I cannot get the mmap function to work. It returns an EINVAL error code.
void* mapped =
mmap((void*)(map_addr + slide),
map_size,
PROT_WRITE | PROT_READ,
MAP_PRIVATE | MAP_ANON,
bprm->file,
map_offset);
I checked the documentation for this feature on my platform ( Darwin ), and there seems to be something wrong. The man page for mmap presents four cases in which EINVAL will be returned.
[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 is not specified, so it is not.
[EINVAL] flags does not include either MAP_PRIVATE or MAP_SHARED.
MAP_PRIVATE is present.
[EINVAL] The len argument was negative.
The argument len (map_size) during the call is 8192.
[EINVAL] The offset argument was not page-aligned based on the page size as
returned by getpagesize(3).
The offset (map_offset) argument is 0, so it should be page aligned. (maybe I'm wrong?)
source
share