Non riesco a ottenere la funzione mmap per funzionare. Restituisce il codice di errore EINVAL.mmap() restituisce EINVAL
void* mapped =
mmap((void*)(map_addr + slide),
map_size,
PROT_WRITE | PROT_READ,
MAP_PRIVATE | MAP_ANON,
bprm->file,
map_offset);
Ho controllato la documentazione per questa funzione sulla mia piattaforma (Darwin) e non sembra essere nulla di male. La pagina man per mmap presenta quattro casi in cui EINVAL verrebbe restituito.
[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 non è specificato, quindi non è questo.
[EINVAL] flags does not include either MAP_PRIVATE or MAP_SHARED.
MAP_PRIVATE è presente.
[EINVAL] The len argument was negative.
Il len (map_size) tesi al momento della chiamata è 8192.
[EINVAL] The offset argument was not page-aligned based on the page size as
returned by getpagesize(3).
L'argomento offset (map_offset) è 0, quindi deve essere allineata pagina. (forse mi sbaglio?)
Con MAP_ANON, alcune implementazioni richiedono che fd sia -1. Può valere la pena controllare. –
** @ Simon Elliott ** Sì, hai ragione. Grazie. –