* Introduce Jit32 and JitCore32 objects
* Initialize JIT when launching 32bit executables
* Introduce kernel objects for 32bit processes
This commit introduces two new kernel thread types, `KNceThread` and `Jit32Thread`.
`KNceThread`s behave like the previous kernel thread object by setting up thread state and jumping into guest code.
`KJit32Thread`s need to run guest code on a `JitCore32` object, so they perform the necessary state setup and then they also setup the jit core for executing guest code. A loop was introduced because jit execution might return when halted, either for an SVC or for preemption. In those cases the thread needs to wait to be scheduled before executing again.
The process object has also been updated to be able to create 32bit threads when running 32bit processes.
Additionally NCE's ThreadContext has been removed from DeviceState, since a thread is not an NCE thread only anymore, and IPC code has been changed to retrieve the tls region from the thread object.
* Introduce a preemption handler for scheduling with JIT
Scheduler initialization has been delayed until process information is available, as it needs to differentiate between 32bit and 64bit processes.
* Support initializing VMM for 32bit address spaces
* Implement GetThreadContext3 SVC for 32bit processes
* Introduce a thread local pointer to the current guest thread
This also gives easier access to the current guest process structure via the thread structure, just like any kernel does for their internal structures.
* Add a signal handler for JIT threads
* Implement coprocessor 15 accesses
* Implement exclusive memory writes and exclusive monitor
* Enable JIT fastmem
* Enable more JIT optimizations and log exceptions
* Fix incorrect logging call in QueryMemory
* Translate guest virtual addresses on direct accesses from SVCs
* Perform TLS page address translation for direct accesses
This allows the IPC code to work without modifications since `KThread::tlsRegion` now stores a host address that can be accessed directly.
* Add Dynarmic as a submodule
* Revert "Perform TLS page address translation for direct accesses"
This reverts commit 2e25b3f7e4f0687b038fa949648c74e3393da006.
* Revert "Translate guest virtual addresses on direct accesses from SVCs"
This reverts commit 7bec4e0902e6dbb6f06a2efac53a1e2127f44068.
* add an option to change cpu backend
* Fix
---------
Co-authored-by: lynxnb <niccolo.betto@gmail.com>
* Add support for multiple search locations
Co-authored-by: hacobotdev <hacobotdev>
* SearchLocationHelper: Use mutableListOf<Uri> and change the return value of the ``getSearchLocations`` function to List<Uri>
* MainViewModel: Modify load rom and check rom hash to accept List uri instead of array uri
* Use SearchLocationHelper when initialising search location first time
* fix search location app bar title
The memory manager has been reworked to handle addresses in the guest address space, and applying an offset to get the address on the host whenever memory needs to be mapped/unmapped/reprotected.
The memory manager was incorrectly inserting chunks when the new chunk was being inserted at the beginning of the chunks map (no previous chunk available). The existing chunk was resized to an empty chunk (correctly), but the new chunk was never inserted because of `std::map::insert` skipping insertion on an already existing key.
This resulted in an empty chunk being left at the beginning of the map, causing infinite loops for code that worked by scanning the chunks map.
Usages of `std::map::operator[]` have also been replaced with the safer `insert_or_assign`.
dynsym is not hardcoded to handle Elf64_Sym only anymore, and a templated ResolveSymbol function has been introduced to easily support Elf32_Sym lookup in the future.
dynsym is not hardcoded to handle Elf64_Sym only anymore, and a templated ResolveSymbol function has been introduced to easily support Elf32_Sym lookup in the future.
Starting from version 26+, the NDK is based on LLVM 17 and comes with Clang 17 featuring full language and library C++20 support.
This means we can get rid of the massive LLVM submodule in the repo, which will be done in a following commit.
Co-authored-by: nickbeth <nickbeth>
It was effectively unused, and only caused issues for users, even after proper implementation that enabled it on signed builds only.
Co-authored-by: nickbeth <nickbeth@gmail.com>
Since the latest Android updates, which most users received in the form of August 2023 security patches, the Android runtime seems to rely on handling SIGSEGV via sigchain while performing JNI calls. We were hooking libc directly to inject our own signal handlers, so that they could run and restore the host TLS since the signal might have been generated in guest code. However, due to how we dispatched signals, the ART handlers were never called and the app crashed whenever a JNI call was made after installing our handlers.
This commit reworks signal handling to remove per-thread handlers. We now make a distinction between guest signals and host signals, and two new functions to set signal handlers have been introduced: `SetGuestSignalHandler` and `SetHostSignalHandler`. This greatly simplifies our signal handling code and allows us to get rid of some thread-local state.
Because of the above distinction, we install a "guest-safe" signal handler only when a guest signal is set. The guest-safe signal handler calls guest handlers only for guest signals, or falls back to the host handler if that's not the case.
Once a guest handler exists for a particular signal, we query libc sigaction as well as the sigchain-hooked sigaction and compare the results, and in case they differ we call sigchain's sigaction so that the host handler is correctly chained, ensuring no host handler can accidentally override the sigchain handler.
CommandScheduler and PresentationEngine both constructed the consumer threads before their CircularQueues, this resulted in a data race that would lead to a segfault if the threads were scheduled for execution quickly enough, as they would read uninitialized memory.