Commit graph

63 commits

Author SHA1 Message Date
Nekotekina b49a1f27eb Warning fixes 2022-09-17 16:35:02 +03:00
Nekotekina b6608ad31d vm_native: rewrite win7 workaround 2022-08-15 12:26:17 +03:00
Nekotekina 7bb2d94e53 vm: use sparse files to emulate overcommit memory
Fix shm::map_critical page flags.
2022-08-12 13:59:03 +03:00
sguo35 9e57efe82c spu: implement assembly functions for arm64 2022-07-15 12:37:33 +03:00
sguo35 086e12c6ca mac: mmap calls should initialize with r/w page perms
Mac/Arm64 pages should be R/W by default due to 16k page
incompatibility. Without this there will be segfaults due to invalid
permissions.
2022-07-15 12:37:33 +03:00
Eladash 219e3d61f8 Minor fix in shm::map_critical 2022-07-10 14:19:59 +03:00
Nekotekina 4b787b22c8 Implement FN (lambda shortener)
Useful for some higher order functions.
Allows to make short lambdas even shorter.
2022-07-08 14:47:41 +03:00
Elad Ashkenazi fcd297ffb2
Savestates Support For PS3 Emulation (#10478) 2022-07-04 16:02:17 +03:00
Jeff Guo cefc37a553
PPU LLVM arm64+macOS port (#12115)
* BufferUtils: use naive function pointer on Apple arm64

Use naive function pointer on Apple arm64 because ASLR breaks asmjit.
See BufferUtils.cpp comment for explanation on why this happens and how
to fix if you want to use asmjit.

* build-macos: fix source maps for Mac

Tell Qt not to strip debug symbols when we're in debug or relwithdebinfo
modes.

* LLVM PPU: fix aarch64 on macOS

Force MachO on macOS to fix LLVM being unable to patch relocations
during codegen. Adds Aarch64 NEON intrinsics for x86 intrinsics used by
PPUTranslator/Recompiler.

* virtual memory: use 16k pages on aarch64 macOS

Temporary hack to get things working by using 16k pages instead of 4k
pages in VM emulation.

* PPU/SPU: fix NEON intrinsics and compilation for arm64 macOS

Fixes some intrinsics usage and patches usages of asmjit to properly
emit absolute jmps so ASLR doesn't cause out of bounds rel jumps. Also
patches the SPU recompiler to properly work on arm64 by telling LLVM to
target arm64.

* virtual memory: fix W^X toggles on macOS aarch64

Fixes W^X on macOS aarch64 by setting all JIT mmap'd regions to default
to RW mode. For both SPU and PPU execution threads, when initialization
finishes we toggle to RX mode. This exploits Apple's per-thread setting
for RW/RX to let us be technically compliant with the OS's W^X
    enforcement while not needing to actually separate the memory
    allocated for code/data.

* PPU: implement aarch64 specific functions

Implements ppu_gateway for arm64 and patches LLVM initialization to use
the correct triple. Adds some fixes for macOS W^X JIT restrictions when
entering/exiting JITed code.

* PPU: Mark rpcs3 calls as non-tail

Strictly speaking, rpcs3 JIT -> C++ calls are not tail calls. If you
call a function inside e.g. an L2 syscall, it will clobber LR on arm64
and subtly break returns in emulated code. Only JIT -> JIT "calls"
should be tail.

* macOS/arm64: compatibility fixes

* vm: patch virtual memory for arm64 macOS

Tag mmap calls with MAP_JIT to allow W^X on macOS. Fix mmap calls to
existing mmap'd addresses that were tagged with MAP_JIT on macOS. Fix
memory unmapping on 16K page machines with a hack to mark "unmapped"
pages as RW.

* PPU: remove wrong comment

* PPU: fix a merge regression

* vm: remove 16k page hacks

* PPU: formatting fixes

* PPU: fix arm64 null function assembly

* ppu: clean up arch-specific instructions
2022-06-14 15:28:38 +03:00
Elad Ashkenazi 1738b38536
vm_native.cpp: Use Windows 10 memory mapping API (the correct API) 2022-06-10 14:27:02 +03:00
Nekotekina b0ccd2a8a0 Implement utils::c_page_size (unused)
Query platform memory page size.
2022-06-02 12:56:49 +03:00
Nekotekina dba2baba9c Implement utils::memory_map_fd (partial)
Improve JIT profiling dump format (data + name, mmap)
Improve objdump interception util (better speed, fix bugs)
Rename spu_ubertrampoline to __ub+number
2022-01-26 15:46:16 +03:00
Nekotekina 580bd2b25e Initial Linux Aarch64 support
* Update asmjit dependency (aarch64 branch)
* Disable USE_DISCORD_RPC by default
* Dump some JIT objects in rpcs3 cache dir
* Add SIGILL handler for all platforms
* Fix resetting zeroing denormals in thread pool
* Refactor most v128:: utils into global gv_** functions
* Refactor PPU interpreter (incomplete), remove "precise"
* - Instruction specializations with multiple accuracy flags
* - Adjust calling convention for speed
* - Removed precise/fast setting, replaced with static
* - Started refactoring interpreters for building at runtime JIT
*   (I got tired of poor compiler optimizations)
* - Expose some accuracy settings (SAT, NJ, VNAN, FPCC)
* - Add exec_bytes PPU thread variable (akin to cycle count)
* PPU LLVM: fix VCTUXS+VCTSXS instruction NaN results
* SPU interpreter: remove "precise" for now (extremely non-portable)
* - As with PPU, settings changed to static/dynamic for interpreters.
* - Precise options will be implemented later
* Fix termination after fatal error dialog
2022-01-15 06:48:04 +03:00
Eladash c6641748ce
vm_native.cpp: Fix DeviceIoControl usage (#11029) 2021-10-19 12:53:08 +03:00
Jan Beich 7a24642c56 vm_native: simplify vm.overcommit sysctl
dragonfly$ sysctl vm.overcommit
sysctl: unknown oid 'vm.overcommit'

freebsd$ rg VM_OVERCOMMIT /usr/include
/usr/include/vm/vm_param.h
89:#define VM_OVERCOMMIT                12      /* vm.overcommit */
2021-10-12 02:11:58 +03:00
Jan Beich 1a90adfb5e vm_native: unbreak runtime on FreeBSD after 63104af8e9
shm_open() returns a file descriptor on success, not zero. As SHM_ANON
only exists on FreeBSD which also has memfd_create use the same code
as on Linux.

$ rpcs3
[...]
Verification failed (in file rpcs3/util/vm_native.cpp:478[:4], in function shm) (errno=2)
Segmentation fault
2021-10-12 02:11:58 +03:00
RipleyTom 1e108d97b2 Removes need for sys/sysctl.h on linux 2021-08-31 12:30:22 +03:00
Nekotekina 63104af8e9 vm_native: detect overcommit support on FreeBSD and other OS
Used in sparse memory initialization code.
2021-08-30 14:42:16 +03:00
Jan Beich 3a6399aaaa vm_native: add workaround for FreeBSD 12
rpcs3/util/vm_native.cpp:302:16: error: no member named 'memfd_create' in the global namespace
                                m_file = ::memfd_create_("2M", c_mfd_huge_2mb);
                                         ~~^
rpcs3/util/vm_native.cpp:34:23: note: expanded from macro 'memfd_create_'
 #define memfd_create_ memfd_create
                       ^
rpcs3/util/vm_native.cpp:308:15: error: no member named 'memfd_create' in the global namespace
                        m_file = ::memfd_create_("", 0);
                                 ~~^
rpcs3/util/vm_native.cpp:34:23: note: expanded from macro 'memfd_create_'
 #define memfd_create_ memfd_create
                       ^
2021-07-29 20:48:10 +03:00
Jan Beich de6f3b5653 vm_native: enable memfd_create on FreeBSD 2021-07-29 20:48:10 +03:00
Nekotekina 6f874be41b vm_native: bypass rpcs3_vm creation if overcommit is enabled (Linux)
Unfortunately, different systems need different approach here.
2021-06-12 19:12:59 +03:00
Nekotekina dfbd63df94 vm_native.cpp: change rpcs3_vm name/location priority (Win32)
Prefer temp directory, rename to rpcs3_vm_sparse.tmp
Try to remove archive attribute (doesn't work well).
2021-06-11 19:15:21 +03:00
Nekotekina 7311c161f6 vm_native: fix Linux/Posix sparse file check
Fix fast path condition (xnor is not ==, facepalm).
Increase probe size.
Should fix #10334
Closes #10335

Co-authored-by: Jan Beich <jbeich@FreeBSD.org>
2021-05-25 09:55:43 +03:00
Nekotekina 5db38c0127 vm_native: improve sparse file check (Linux/BSD)
Use lseek(FIND_DATA) to check for sparse file support.
2021-05-24 18:21:52 +03:00
Nekotekina 191cb92300 vm_native: improve sparse file implementation (Win32)
Fix sparse attribute set/check, improve logic.
Implement actual check of file data.
Ask to restart RPCS3 first time (Win7 bug).
2021-05-24 18:21:52 +03:00
Nekotekina 160b131de3 types.hpp: implement smin, smax, amin, amax
Rewritten the following global utility constants:
`umax` returns max number, restricted to unsigned.
`smax` returns max signed number, restricted to integrals.
`smin` returns min signed number, restricted to signed.
`amin` returns smin or zero, less restricted.
`amax` returns smax or umax, less restricted.

Fix operators == and <=> for synthesized rel-ops.
2021-05-22 12:10:57 +03:00
Nekotekina 613777afde vm_native: try to workaround another bug (Win32)
Resize sparse file gradually.
2021-05-22 08:16:54 +03:00
Nekotekina 16620f6835 vm_native: sparse file fixup (Win32)
Clear file if it occupies blocks.
Makes it more fool-proof and fixes possible bug.
2021-05-19 22:41:16 +03:00
Nekotekina 6e497ae372 vm: disable sparse files on win7 2021-05-18 13:31:46 +03:00
Nekotekina 2a26bc6668 Fix page mapping rights to file mapping 2021-05-13 13:49:24 +03:00
Nekotekina 126141cdce vm_native: improve sparse file handling
Don't specify O_TRUNC every time.
Add portable support test (Linux/Unix).
Use PAGE_WRITECOPY (Windows).
2021-05-13 10:23:33 +03:00
Nekotekina 0bd64a0e72 Don't fatal on sparse file initialization failure
Also try two different locations (Win32).
2021-05-10 00:39:28 +03:00
Nekotekina 1b0b2fe21e vm: add "hook" memory (32G)
Implement overcommit emulation for shm.
2021-05-04 18:02:52 +03:00
Nekotekina e327d47169 vm_native: add cow flag to map functions
CoW is copy-on-write mapping type.
2021-05-04 09:53:19 +03:00
Nekotekina 7a9561b966 vm_native: document some unmap_critical behaviour (posix) 2021-04-18 13:13:15 +03:00
Nekotekina c061991c43 vm_native: supply only one madvise flag at a time 2021-04-18 13:13:15 +03:00
David Carlier 266c4209c4 VM: FreeBSD c_madv_no_dump/dump constants support. 2021-04-17 20:47:36 +03:00
Megamouse a16d8ba3ea More random changes 2021-04-11 14:01:51 +03:00
Nekotekina ad1027455a Fix minor inconsistency in utils::memory_reset (Linux) 2021-02-22 13:00:01 +03:00
Nekotekina 8e6e57de86 Enable -Wunused-function warning 2021-02-15 14:39:53 +03:00
Nekotekina caa83d20f7 vm_native.cpp: implement shm::try_map
Treats addr as a hint, emulating windows behaviour.
2021-01-25 16:55:19 +03:00
kd-11 ead180aa60 win32: Be a bit more optimistic with allocated ranges; we get contiguous ranges more often than not 2021-01-24 14:24:55 +03:00
Nekotekina 0ac68def49 vm_native.cpp: minor compilation fix 2021-01-17 15:14:11 +03:00
Nekotekina 4ed76a15ff Use different approach in shm::unmap_critical (Linux)
For now, set protection to PROT_NONE.
Attempt to address #9609
2021-01-15 20:11:09 +03:00
Nekotekina b5837d1271 Memory: use MADV_DONTDUMP if available (Linux)
Also refactor other madvise() usage
2021-01-15 19:54:41 +03:00
Nekotekina ea916fd7e1 Memory: fix critical bug in shm::unmap_critical (Linux)
It was leaving holes in reserved areas.
Windows is unaffected.
2021-01-14 18:04:29 +03:00
Eladash 923fcc3b3d utils::shm: Hotfix after #9578 2021-01-12 23:57:36 +03:00
Eladash c50b9bc4b4
utils::shm: Make map_self() atomic (#9578) 2021-01-12 19:53:18 +03:00
Nekotekina db8e6fe7a7 Enable -Wunused-variable 2021-01-12 14:34:14 +03:00
Nekotekina e3dec420a2 vm_native.cpp: conditionally define c_madv_free 2020-12-27 12:19:50 +03:00