cassemblyx86-64system-callsmmap

Looking for mmap flag values


I was wondering where I could find mmap flag values on os x. The manpages for mmap say to use MAP_PRIVATE, MAP_... and such, but if you are dealing with assembly you have to know the actual values to make the syscall. I tried looking for the header files that defined these constants but I could not find it. Could someone link it possibly?


Solution

  • Using the -E option with gcc allows you to see the output of a source file after the preprocessor. Using gcc -E test.c on the following source file

    #include <sys/mman.h>
    
    int main() {
            return MAP_PRIVATE;
    }
    

    outputs

    ...
    # 2 "asdf.c" 2
    
    int main() {
    
     return 0x02;
    }
    

    which shows that MAP_PRIVATE is equal to 0x02 on my system. This may not be true on all systems, however.