I can't get the mmap function to work. It returns the 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've checked the documentation for this function on my platform (Darwin) and there doesn't seem to be anything wrong. The man page for mmap presents four cases under which EINVAL would 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 isn't specified so it isn't this.
[EINVAL] flags does not include either MAP_PRIVATE or MAP_SHARED.
MAP_PRIVATE is present.
[EINVAL] The len argument was negative.
The len (map_size) argument at the time of the call is 8192.
[EINVAL] The offset argument was not page-aligned based on the page size as
returned by getpagesize(3).
The offset argument (map_offset) is 0 so it must be page aligned. (maybe I'm wrong?)
Are you sure about your reading of the first description? It could also be read as describing two disjoint cases:
if read like this, the actual value of the the map_addr + slide
expression becomes interesting.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With