Reputation: 16315
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?)
Upvotes: 5
Views: 4248
Reputation: 28525
I would suggest using NULL
for the addr
argument and giving the implementation the complete freedom to place your mmaped
region( cos the address you specify might go awry with respect to the process' address space) until there's a serious reason not to do otherwise.
Upvotes: 0
Reputation: 399743
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.
Upvotes: 2