xenia-project / xenia

Xbox 360 Emulator Research Project
https://xenia.jp
Other
7.87k stars 1.11k forks source link

[LINUX/BASE] Fixed mmap usage and (re)-implemented most parts of memory_posix.cc #2230

Open guccigang420 opened 9 months ago

guccigang420 commented 9 months ago

As the title says. Previously the MapFileView function did not take into account the handle argument, as it used the MAP_ANONYMOUS and the MAP_PRIVATE flags.

Additionally, AllocFixed used mmap and DeallocFixed used munmap always, with the MAP_FIXED flag. This was not ideal for several reasons:

  1. Invoking mmap the way it was invoked silently unmaps the range from the file it was previously mapped to.
  2. MAP_FIXED was used even with a nullptr base_address.
  3. Mapped file memory should not be unmapped in DeallocFixed.

For more information regarding mmap, see: https://man7.org/linux/man-pages/man2/mmap.2.html

guccigang420 commented 9 months ago

So I did implement some of these recommendations. I also added a mutex to avoid race conditions in multi-threaded scenarios.