When will you use mmap map_fixed

I look at different flags for the mmap function, namely MAP_FIXED, MAP_SHARED, MAP_PRIVATE. Can someone explain the purpose of MAP_FIXED to me? There is no guarantee that the address space will be used in the first place.

+4
source share
2 answers

MAP_FIXEDis dup2for memory mappings and is useful in the same situations when it dup2is useful for file descriptors: when you want to perform a replacement operation that atomically reassigns a resource identifier (memory range in case MAP_FIXED, or fd in case dup2) to refer to a new resource without race capability, where it can be reassigned to something else if you first released an old resource and then tried to return it to a new resource.

( ). , , : read + exec-only , ( , ) ( .bss). , . , ( ) MAP_FIXED, , MAP_FIXED , .

, , MAP_FIXED . MAP_FIXED - , mmap MAP_FIXED, - , . dup2; dup2, fd .

+9

, , , , , . .

  • , , .

  • .

  • , , , , ( ).

MAP_FIXED .

+2

All Articles