FEX-Emu / FEX

A fast usermode x86 and x86-64 emulator for Arm64 Linux
https://fex-emu.com
MIT License
2.31k stars 122 forks source link

SMC/Mtrack: Add shm, mremap, madvise support #1638

Open skmp opened 2 years ago

skmp commented 2 years ago

shmat, mremap are not tracked for smc.

Tests: https://github.com/FEX-Emu/fex-assorted-tests-bins/blob/main/src/smc-2.cpp

Looks like the shm size would have to be queried on map / unmap, similar to the tracking the 32-bit allocator does.

skmp commented 2 years ago

Quick note here, mmap + MAP_GROWSDOWN and mprotect + PROT_GROWSDOWN, mprotect + PROT_GROWSUP need to be also investigated w/ test cases

skmp commented 2 years ago

(also, is there a MAP_GROWSUP?)

skmp commented 2 years ago

As per the kernel source (5.17) MAP_GROWSUP is only defined for ia64, though it is ignored there.

VM_GROWSUP exists, and seems mostly implemented in mmap/mprotect, but no code maps MAP_GROWSUP to VM_GORWSUP.

VM_GROWSUP seems only implemented in ia64 fault handling.

As such, PROT_GROWSUP can never work.

Verified PROT_GROWSDOWN behaves as expected, it only changes protection downwards to the prev vma range.

skmp commented 2 years ago

Added the tests to https://github.com/FEX-Emu/fex-assorted-tests-bins/blob/main/src/prot-growsdown.cpp.

skmp commented 2 years ago

Another edge case is madvise w/ MADV_DONTNEED, MADV_REMOVE, MADV_DONTFORK+MADV_DOFORK, MADV_HWPOISON, MADV_FREE, MADV_WIPEONFORK + MADV_KEEPONFORK.

It seems like MADV_FREE is impossible to be correctly implemented.

skmp commented 2 years ago

1558 now implements mremap, shmat, shmdt. Will update description once finalized and merged with the unsupported cases.