aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Kernel
AgeCommit message (Collapse)Author
2022-08-18Removed unused usings. (#3593)1.1.223Nicholas Rodine
* Removed unused usings. * Added back using, now that it's used. * Removed extra whitespace.
2022-06-24Fix ThreadingLock deadlock on invalid access and TerminateProcess (#3407)1.1.155gdkchan
2022-06-22Rewrite kernel memory allocator (#3316)1.1.152gdkchan
* Rewrite kernel memory allocator * Remove unused using * Adjust private static field naming * Change UlongBitSize to UInt64BitSize * Fix unused argument, change argument order to be inline with official code and disable random allocation
2022-06-11Allow concurrent BSD EventFd read/write (#3385)1.1.145gdkchan
2022-05-31Rewrite SVC handler using source generators rather than IL emit (#3371)1.1.135gdkchan
* Implement syscall handlers using a source generator * Copy FlushProcessDataCache implementation to Syscall since it was only implemented on Syscall32 * Fix wrong argument order in some syscalls * Delete old Reflection.Emit based syscall handling code * Improvements to the code generation * ControlCodeMemory address and size is always 64-bit
2022-05-31Refactor CPU interface to allow the implementation of other CPU emulators ↵1.1.134gdkchan
(#3362) * Refactor CPU interface * Use IExecutionContext interface on SVC handler, change how CPU interrupts invokes the handlers * Make CpuEngine take a ITickSource rather than returning one The previous implementation had the scenario where the CPU engine had to implement the tick source in mind, like for example, when we have a hypervisor and the game can read CNTPCT on the host directly. However given that we need to do conversion due to different frequencies anyway, it's not worth it. It's better to just let the user pass the tick source and redirect any reads to CNTPCT to the user tick source * XML docs for the public interfaces * PPTC invalidation due to NativeInterface function name changes * Fix build of the CPU tests * PR feedback
2022-05-03Implement PM GetProcessInfo atmosphere extension (partially) (#2966)1.1.112gdkchan
2022-05-03Implement code memory syscalls (#2958)1.1.111gdkchan
* Implement code memory syscalls * Remove owner process validation * Add 32-bit code memory syscalls * Remove unused field
2022-05-02Support memory aliasing (#2954)1.1.110gdkchan
* Back to the origins: Make memory manager take guest PA rather than host address once again * Direct mapping with alias support on Windows * Fixes and remove more of the emulated shared memory * Linux support * Make shared and transfer memory not depend on SharedMemoryStorage * More efficient view mapping on Windows (no more restricted to 4KB pages at a time) * Handle potential access violations caused by partial unmap * Implement host mapping using shared memory on Linux * Add new GetPhysicalAddressChecked method, used to ensure the virtual address is mapped before address translation Also align GetRef behaviour with software memory manager * We don't need a mirrorable memory block for software memory manager mode * Disable memory aliasing tests while we don't have shared memory support on Mac * Shared memory & SIGBUS handler for macOS * Fix typo + nits + re-enable memory tests * Set MAP_JIT_DARWIN on x86 Mac too * Add back the address space mirror * Only set MAP_JIT_DARWIN if we are mapping as executable * Disable aliasing tests again (still fails on Mac) * Fix UnmapView4KB (by not casting size to int) * Use ref counting on memory blocks to delay closing the shared memory handle until all blocks using it are disposed * Address PR feedback * Make RO hold a reference to the guest process memory manager to avoid early disposal Co-authored-by: nastys <nastys@users.noreply.github.com>
2022-03-12Fix GetUserDisableCount NRE (#3187)1.1.67gdkchan
2022-03-11KThread: Fix GetPsr mask (#3180)1.1.65merry
* ExecutionContext: GetPstate / SetPstate * Put it in NativeContext * KThread: Fix GetPsr mask * ExecutionContext: Turn methods into Pstate property * Address nit
2022-02-18Enable CPU JIT cache invalidation (#2965)1.1.44gdkchan
* Enable CPU JIT cache invalidation * Invalidate cache on IC IVAU
2022-02-18Use BitOperations methods and delete now unused BitUtils methods (#3134)1.1.42Berkan Diler
Replaces BitUtils.CountTrailingZeros/CountLeadingZeros/IsPowerOfTwo with BitOperations methods
2022-02-18Move kernel syscall logs to new trace log level (#3137)1.1.41gdkchan
2022-02-17Added trace log level (#3096)1.1.38mlgatto
* added trace log level * use trace log level instead of debug ( #1547) * alignment #1547 * moved trace logs toggle at the bottom #1547 * bumped config file version #3096 * added migration step #3096 * setting moved to the dev section #1547 * performance warning displayed when trace is enabled #1547
2022-02-13Use Enum and Delegate.CreateDelegate generic overloads (#3111)1.1.27Berkan Diler
* Use Enum generic overloads * Remove EnumExtensions.cs * Use Delegate.CreateDelegate generic overloads
2022-02-09misc: Make PID unsigned long instead of long (#3043)1.1.22Mary
2022-01-29kernel: A bit of refactoring and fix GetThreadContext3 correctness (#3042)1.1.12Mary
* Start refactoring kernel a bit and import some changes from kernel decoupling PR * kernel: Put output always at the start in Syscall functions * kernel: Rewrite GetThreadContext3 to use a structure and to be accurate * kernel: make KernelTransfer use generic types and simplify * Fix some warning and do not use getters on MemoryInfo * Address gdkchan's comment * GetThreadContext3: use correct pause flag
2022-01-16kernel: Fix deadlock when pinning in interrupt handler (#2999)Mary
* kernel: Fix deadlock when pinning in interrupt handler This fix a deadlock on DoDonPachi Resurrection when starting a new game * Address gdkchan's comment
2021-12-30kernel: Implement thread pinning support (#2840)Mary
* kernel: Implement Thread pinning support This commit adds support for 8.x thread pinning changes and implement SynchronizePreemptionState syscall. Based on kernel 13.x reverse. * Address gdkchan's comment * kernel: fix missing critical section leave in SetActivity Fix Unity games * Implement missing bits on the interrupt handler and inline update pinning function as it cannot be generic * Fix some bugs in SetActivity and SetCoreAndAffinityMask * Address gdkchan's comments
2021-12-23Remove PortRemoteClosed warning (#2928)gdkchan
2021-12-04kernel: Improve GetInfo readability and update to 13.0.0 (#2900)Mary
* kernel: Define InfoTYpe and make it less obscure when reading GetInfo Also map ThreadTickCount to 25 instead of 0xF0000002 like 13.x kernel. * kernel: Implement GetInfo IsApplication * kernel: Implement GetInfo FreeThreadCount
2021-11-28kernel: Fix sleep timing accuracy (#2828)Mary
* kernel: Fix sleep timing accuracy This commit corrects some mistake while comparing reversing of kernel 13.x with our own. WaitAndCheckScheduledObjects timing accuracy was also improved. * Make KTimeManager.WaitAndCheckScheduledObjects spin wait for sub milliseconds Fix performance regression on Pokemon Let's Go games and possibly others. * Address rip's comment * kernel: Fix issues with timeout of -1 (0xFFFFFFFF) Fixes possible hang on Pokemon DP and possibly others
2021-11-28kernel: Add support for CFI (#2839)Mary
Add basic support for the CFI value being passed in X18 since 11.0.0 by the official kernel. We do not implement any random generator atm in the kernel and as such the KSystemControl.GenerateRandom function is stubbed
2021-10-24kernel: Fix inverted condition on permission check of SetMemoryPermission ↵Mary
syscall (#2777) * kernel: Fix inverted condition on permission check of SetMemoryPermission syscall * Fix condition for real..
2021-10-24kernel: Clear pages allocated with SetHeapSize (#2776)Mary
* kernel: Clear pages allocated with SetHeapSize Before this commit, all new pages allocated by SetHeapSize were not cleared by the kernel. This would cause undefined data to be pass to the userland and possibly resulting in weird memory corruption. This commit also add support for custom fill heap and ipc value (that is also supported by the official kernel) * Remove dots at the end of KPageTableBase.MapPages new documentation * Remove unused _stackFillValue
2021-10-24kernel: Add resource limit related syscalls (#2773)Mary
* kernel: Add resource limit related syscalls This commit implements all resource limit related syscalls. * Fix register mapping being wrong for SetResourceLimitLimitValue * Address gdkchan's comment
2021-10-24kernel: Implement SetMemoryPermission syscall (#2772)Mary
* kernel: Implement SetMemoryPermission syscall This commit implement the SetMemoryPermission syscall accurately. This also fix KMemoryPermission not being an unsigned 32 bits type and add the "DontCare" bit (used by shared memory, currently unused in Ryujinx) * Update MemoryPermission mask * Address gdkchan's comments * Fix a nit * Address gdkchan's comment
2021-10-24kernel: Add missing address space check in SetMemoryAttribute syscall (#2771)Mary
2021-09-11Implement a "Pause Emulation" option & hotkey (#2428)mpnico
* Add a "Pause Emulation" option and hotkey Closes Ryujinx#1604 * Refactoring how pause is handled * Applied suggested changes from review * Applied suggested fixes * Pass correct suspend type to threads for suspend/resume * Fix NRE after stoping emulation * Removing SimulateWakeUpMessage call after resuming emulation * Skip suspending non game process * Pause the tickCounter in the ExecutionContext * Refactoring tickCounter pause/resume as suggested * Fix Config migration to add pause hotkey * Fixed pausing only application threads * Fix exiting emulator while paused * Avoid pause/resume while already paused/resumed * Cleanup unused code * Avoid restarting audio if stopping emulation while in pause. * Added suggested changes * Fix ConfigurationState
2021-08-04Update TamperMachine and disable write-to-code prevention (#2506)Caian Benedicto
* Enable write to memory and improve logging * Update tamper machine opcodes and improve reporting * Add Else support * Add missing private statement
2021-07-11Fix virtual memory allocation being out of range (#2464)gdkchan
2021-06-29Initial support for separate GPU address spaces (#2394)gdkchan
* Make GPU memory manager a member of GPU channel * Move physical memory instance to the memory manager, and the caches to the physical memory * PR feedback
2021-06-23kernel: Implement MapTransferMemory and UnmapTransferMemory (#2386)Mary
Based on my reversing of kernel 12.0.0
2021-05-30Fix guest stack trace inexistent function names (#2326)gdkchan
2021-05-30Fix inverted low/high mask value on GetThreadCoreMask32 syscall (#2325)gdkchan
2021-05-29Add multi-level function table (#2228)FICTURE7
* Add AddressTable<T> * Use AddressTable<T> for dispatch * Remove JumpTable & co. * Add fallback for out of range addresses * Add PPTC support * Add documentation to `AddressTable<T>` * Make AddressTable<T> configurable * Fix table walk * Fix IsMapped check * Remove CountTableCapacity * Add PPTC support for fast path * Rename IsMapped to IsValid * Remove stale comment * Change format of address in exception message * Add TranslatorStubs * Split DispatchStub Avoids recompilation of stubs during tests. * Add hint for 64bit or 32bit * Add documentation to `Symbol` * Add documentation to `TranslatorStubs` Make `TranslatorStubs` disposable as well. * Add documentation to `SymbolType` * Add `AddressTableEventSource` to monitor function table size Add an EventSource which measures the amount of unmanaged bytes allocated by AddressTable<T> instances. dotnet-counters monitor -n Ryujinx --counters ARMeilleure * Add `AllowLcqInFunctionTable` optimization toggle This is to reduce the impact this change has on the test duration. Before everytime a test was ran, the FunctionTable would be initialized and populated so that the newly compiled test would get registered to it. * Implement unmanaged dispatcher Uses the DispatchStub to dispatch into the next translation, which allows execution to stay in unmanaged for longer and skips a ConcurrentDictionary look up when the target translation has been registered to the FunctionTable. * Remove redundant null check * Tune levels of FunctionTable Uses 5 levels instead of 4 and change unit of AddressTableEventSource from KB to MB. * Use 64-bit function table Improves codegen for direct branches: mov qword [rax+0x408],0x10603560 - mov rcx,sub_10603560_OFFSET - mov ecx,[rcx] - mov ecx,ecx - mov rdx,JIT_CACHE_BASE - add rdx,rcx + mov rcx,sub_10603560 + mov rdx,[rcx] mov rcx,rax Improves codegen for dispatch stub: and rax,byte +0x1f - mov eax,[rcx+rax*4] - mov eax,eax - mov rcx,JIT_CACHE_BASE - lea rax,[rcx+rax] + mov rax,[rcx+rax*8] mov rcx,rbx * Remove `JitCacheSymbol` & `JitCache.Offset` * Turn `Translator.Translate` into an instance method We do not have to add more parameter to this method and related ones as new structures are added & needed for translation. * Add symbol only when PTC is enabled Address LDj3SNuD's feedback * Change `NativeContext.Running` to a 32-bit integer * Fix PageTable symbol for host mapped
2021-05-24POWER - Performance Optimizations With Extensive Ramifications (#2286)riperiperi
* Refactoring of KMemoryManager class * Replace some trivial uses of DRAM address with VA * Get rid of GetDramAddressFromVa * Abstracting more operations on derived page table class * Run auto-format on KPageTableBase * Managed to make TryConvertVaToPa private, few uses remains now * Implement guest physical pages ref counting, remove manual freeing * Make DoMmuOperation private and call new abstract methods only from the base class * Pass pages count rather than size on Map/UnmapMemory * Change memory managers to take host pointers * Fix a guest memory leak and simplify KPageTable * Expose new methods for host range query and mapping * Some refactoring of MapPagesFromClientProcess to allow proper page ref counting and mapping without KPageLists * Remove more uses of AddVaRangeToPageList, now only one remains (shared memory page checking) * Add a SharedMemoryStorage class, will be useful for host mapping * Sayonara AddVaRangeToPageList, you served us well * Start to implement host memory mapping (WIP) * Support memory tracking through host exception handling * Fix some access violations from HLE service guest memory access and CPU * Fix memory tracking * Fix mapping list bugs, including a race and a error adding mapping ranges * Simple page table for memory tracking * Simple "volatile" region handle mode * Update UBOs directly (experimental, rough) * Fix the overlap check * Only set non-modified buffers as volatile * Fix some memory tracking issues * Fix possible race in MapBufferFromClientProcess (block list updates were not locked) * Write uniform update to memory immediately, only defer the buffer set. * Fix some memory tracking issues * Pass correct pages count on shared memory unmap * Armeilleure Signal Handler v1 + Unix changes Unix currently behaves like windows, rather than remapping physical * Actually check if the host platform is unix * Fix decommit on linux. * Implement windows 10 placeholder shared memory, fix a buffer issue. * Make PTC version something that will never match with master * Remove testing variable for block count * Add reference count for memory manager, fix dispose Can still deadlock with OpenAL * Add address validation, use page table for mapped check, add docs Might clean up the page table traversing routines. * Implement batched mapping/tracking. * Move documentation, fix tests. * Cleanup uniform buffer update stuff. * Remove unnecessary assignment. * Add unsafe host mapped memory switch On by default. Would be good to turn this off for untrusted code (homebrew, exefs mods) and give the user the option to turn it on manually, though that requires some UI work. * Remove C# exception handlers They have issues due to current .NET limitations, so the meilleure one fully replaces them for now. * Fix MapPhysicalMemory on the software MemoryManager. * Null check for GetHostAddress, docs * Add configuration for setting memory manager mode (not in UI yet) * Add config to UI * Fix type mismatch on Unix signal handler code emit * Fix 6GB DRAM mode. The size can be greater than `uint.MaxValue` when the DRAM is >4GB. * Address some feedback. * More detailed error if backing memory cannot be mapped. * SetLastError on all OS functions for consistency * Force pages dirty with UBO update instead of setting them directly. Seems to be much faster across a few games. Need retesting. * Rebase, configuration rework, fix mem tracking regression * Fix race in FreePages * Set memory managers null after decrementing ref count * Remove readonly keyword, as this is now modified. * Use a local variable for the signal handler rather than a register. * Fix bug with buffer resize, and index/uniform buffer binding. Should fix flickering in games. * Add InvalidAccessHandler to MemoryTracking Doesn't do anything yet * Call invalid access handler on unmapped read/write. Same rules as the regular memory manager. * Make unsafe mapped memory its own MemoryManagerType * Move FlushUboDirty into UpdateState. * Buffer dirty cache, rather than ubo cache Much cleaner, may be reusable for Inline2Memory updates. * This doesn't return anything anymore. * Add sigaction remove methods, correct a few function signatures. * Return empty list of physical regions for size 0. * Also on AddressSpaceManager Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2021-05-21Extend info printed when guest crashes/breaks execution (#1845)Somebody Whoisbored
* Add CPU register printout when guest crashes/breaks execution * Print out registers when undefined instruction is hit * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * Fixes after rebase * Address gdkchan's comments Co-authored-by: Ac_K <Acoustik666@gmail.com> Co-authored-by: Mary <me@thog.eu>
2021-05-11Fix a specific core migration bug on the scheduler (#2271)gdkchan
2021-04-24HLE: Fix integer sign inconcistency accross the codebase (#2222)Mary
* Make all title id instances unsigned * Replace address and size with ulong instead of signed types Long overdue change. Also change some logics here and there to optimize with the new memory manager. * Address Ac_K's comments * Remove uneeded cast all around * Fixes some others misalignment
2021-04-04Allow DRAM size to be increased from 4GB to 6GB (#2174)gdkchan
* Allow DRAM size to be increased from 4GB to 6GB * Add option on the UI
2021-03-27Add the TamperMachine module for runtime mods and cheats (#1928)Caian Benedicto
* Add initial implementation of the Tamper Machine * Implement Atmosphere opcodes 0, 4 and 9 * Add missing TamperCompilationException class * Implement Atmosphere conditional and loop opcodes 1, 2 and 3 * Inplement input conditional opcode 8 * Add register store opcode A * Implement extended pause/resume opcodes FF0 and FF1 * Implement extended log opcode FFF * Implement extended register conditional opcode C0 * Refactor TamperProgram to an interface * Moved Atmosphere classes to a separate subdirectory * Fix OpProcCtrl class not setting process * Implement extended register save/restore opcodes C1, C2 and C3 * Refactor code emitters to separate classes * Supress memory access errors from the Tamper Machine * Add debug information to tamper register and memory writes * Add block stack check to Atmosphere Cheat compiler * Add handheld input support to Tamper Machine * Fix code styling * Fix build id and cheat case mismatch * Fix invalid immediate size selection * Print build ids of the title * Prevent Tamper Machine from change code regions * Remove Atmosphere namespace * Remove empty cheats from the list * Prevent code modification without disabling the tampering * Fix missing addressing mode in LoadRegisterWithMemory * Fix wrong addressing in RegisterConditional * Add name to the tamper machine thread * Fix code styling
2021-02-08Fix inter-process data copy on non-contiguous physical regions (#1988)gdkchan
2021-01-01Update KAddressArbiter implementation to 11.x kernel (#1851)gdkchan
* Update KAddressArbiter implementation to 11.x kernel * InsertSortedByPriority is no longer needed
2020-12-13Correct type of executable sizes (#1802)gdkchan
2020-12-09Rewrite scheduler context switch code (#1786)gdkchan
* Rewrite scheduler context switch code * Fix race in UnmapIpcRestorePermission * Fix thread exit issue that could leave the scheduler in a invalid state * Change context switch method to not wait on guest thread, remove spin wait, use SignalAndWait to pass control * Remove multi-core setting (it is always on now) * Re-enable assert * Remove multicore from default config and schema * Fix race in KTimeManager
2020-12-07Signal memory tracking before/after mapping into another process (#1785)riperiperi
* Signal memory tracking before/after mapping into another process * Wording. * Add missing method.
2020-12-02IPC refactor part 2: Use ReplyAndReceive on HLE services and remove special ↵gdkchan
handling from kernel (#1458) * IPC refactor part 2: Use ReplyAndReceive on HLE services and remove special handling from kernel * Fix for applet transfer memory + some nits * Keep handles if possible to avoid server handle table exhaustion * Fix IPC ZeroFill bug * am: Correctly implement CreateManagedDisplayLayer and implement CreateManagedDisplaySeparableLayer CreateManagedDisplaySeparableLayer is requires since 10.x+ when appletResourceUserId != 0 * Make it exit properly * Make ServiceNotImplementedException show the full message again * Allow yielding execution to avoid starving other threads * Only wait if active * Merge IVirtualMemoryManager and IAddressSpaceManager * Fix Ro loading data from the wrong process Co-authored-by: Thog <me@thog.eu>
2020-09-22IPC refactor part 1: Use explicit separate threads to process requests (#1447)gdkchan
* Changes to allow explicit management of service threads * Remove now unused code * Remove ThreadCounter, its no longer needed * Allow and use separate server per service, also fix exit issues * New policy change: PTC version now uses PR number