Closed free1ze closed 2 years ago
Note that mmap
is a quite tricky system call, and one of the goals of this project is to help you get more familiar with it.
A little detour from your question, you may want to check both your addr
and len
fed to mmap
, because it want your required address to be page-aligned.
Your direct question comes from your output line DEBUG_PRINT(("addr: %d\n", addr));
, where void*
has a length of 8, while %d
tries to interpret its upper 4 bytes. Remember the lecture when the teacher told you why having two weak definitions is a bad thing, because it could interpret int
as a double
and vice versa?
According to the man page of mmap, mmap
will return -1
on failure, so you should think of other reasons when you see such an odd, unfriendly negative value.
You should turn to the man page to find out how to map the second segment, and that should not be discussed here.
I wonder if it is because the wrong argument as indicated, or some other reasons like the defacts of VMWare virtual environment.
Also, we are not doing something quite sophisticated or hacking here, so do not blame the VM unless you are very very sure:)
I get it. I did not align the offset to the page size, which will cause "Invalid argument" error using mmap(). APPRECIATE🌹
environment: VMWare20, Ubuntu 16
enconter "Invalid argument" error using mmap(), printed by perror(). I was iteraing through the Program Headers, trying to map some space for PT_LOAD type segments. I always get this error the second time I call mmap(). My code here:
and I get output like this
I wonder if it is because the wrong argument as indicated, or some other reasons like the defacts of VMWare virtual environment.