Commit graph

1990 commits

Author SHA1 Message Date
Lioncash
2c2e08df02 general: Move deleted copy/move constructor/assignment operators to public interface
This allows for better compiler errors, where the compiler will state a
copy or move couldn't occur due to the relevant function being deleted.

Previously a compiler would warn about the relevant function not being
accessible (which, while true, isn't as informative as it could be).
2022-02-02 12:17:08 -05:00
bunnei
1552c524ad hle: kernel: KPageTable: Migrate locks to KScopedLightLock.
- More accurately reflects real kernel behavior by using guest locks.
2022-02-01 19:34:24 -08:00
Narr the Reg
33594225c7 svc: Add 32 bit SynchronizePreemptionState
Used by Espgaluda II
2022-01-31 19:02:41 -06:00
bunnei
1b8ed3a76d hle: kernel: KScheduler: Fix deadlock with core waiting for a thread lock that has migrated.
- Previously, it was possible for a thread migration to occur from core A to core B.
- Next, core B waits on a guest lock that must be released by a thread queued for core A.
- Meanwhile, core A is still waiting on the core B's current thread lock - resulting in a deadlock.
- Fix this by try-locking the thread lock.
- Fixes softlocks in FF8 and Pokemon Legends Arceus.
2022-01-27 12:17:14 -08:00
bunnei
f73ced739a Merge pull request #7762 from bunnei/un-map-improve
Kernel Memory Updates (Part 4): Improve Un/MapPages, and more.
2022-01-26 17:54:20 -08:00
Morph
c2fd2c56e9 Merge pull request #7771 from lioncash/assert
kernel/k_affinity_mask: Remove duplicated assert
2022-01-25 16:15:18 -05:00
Lioncash
1e57fbe71d kernel/k_affinity_mask: Remove duplicated assert
This is already checked inside GetCoreBit()
2022-01-24 10:35:22 -05:00
bunnei
a2731424a6 hle: kernel: KThread: Improve Increment/Decrement RunningThreadCount.
- Previously implementation was incorrect, and would occasionally underflow.
2022-01-22 21:09:45 -08:00
bunnei
912b6b9ef4 core: hle: kernel: KPageTable: Various improvements to MapPages and UnmapPages. 2022-01-22 20:51:34 -08:00
bunnei
c46f07a62a core: hle: kernel: KPageTable: MapProcessCode: Various cleanup. 2022-01-22 20:51:34 -08:00
bunnei
4f848b6f68 core: hle: kernel: KPageTable: ReserveTransferMemory: Various cleanup. 2022-01-22 20:51:34 -08:00
bunnei
bf904afa0f core: hle: kernel: KPageTable: ResetTransferMemory: Various cleanup. 2022-01-22 20:51:34 -08:00
bunnei
1b3dd42de4 core: hle: kernel: KPageTable: SetMemoryAttribute: Various cleanup. 2022-01-22 20:51:34 -08:00
bunnei
05918a20c3 core: hle: kernel: KPageTable: Assert valid address on GetPhysicalAddr. 2022-01-22 01:33:26 -08:00
bunnei
a8476d9db0 core: hle: kernel: KPageTable: Operate: Assert lock ownership. 2022-01-22 01:33:26 -08:00
bunnei
8f3c7cb89b core: hle: kernel: KPageTable: SetHeapSize: Cleanup & take physical memory lock. 2022-01-22 01:33:26 -08:00
bunnei
24efadee60 core: hle: kernel: Refactor Un/MapPhysicalMemory to remove unnecessary methods. 2022-01-22 01:33:26 -08:00
bunnei
ebb9ec197e core: hle: kernel: Rename Un/Map to Un/MapMeory. 2022-01-22 01:33:26 -08:00
bunnei
b3f8d2491d hle: kernel: KThread: Ensure host (dummy) threads block on locking.
- But do not enter the priority queue, as otherwise they will be scheduled.
- Allows dummy threads to use guest synchronization primitives.
2022-01-21 17:12:06 -08:00
bunnei
8f2630de0a hle: kernel: Remove redundant tracking of dummy threads.
- These are already tracked by kernel's registered_objects member.
2022-01-20 17:08:00 -08:00
bunnei
f2e870d6b6 hle: kernel: KThread: DummyThread can be waited, ensure wait_queue is not nullptr. 2022-01-20 17:08:00 -08:00
bunnei
668af26696 hle: kernel: KThread: Decrease DummyThread priority to ensure it is never scheduled. 2022-01-20 17:08:00 -08:00
bunnei
db3c11506b hle: kernel: service_thread: Ensure dummy thread is closed & destroyed on thread exit. 2022-01-20 17:08:00 -08:00
bunnei
e885b0ab0d hle: kernel: KServerSession: Remove hack for CompleteSyncRequest.
- This does not appear to be necessary anymore.
2022-01-20 17:08:00 -08:00
bunnei
af11abed3f hle: kernel: KServerSession: Simplify CompleteSyncRequest EndWait.
- Considering is_thread_waiting is never set, so we can remove IsThreadWaiting.
- KThread::EndWait will take the scheduler lock, so we can remove the redundant lock.
2022-01-20 17:08:00 -08:00
bunnei
247a7e2205 hle: kernel: KThread: Ensure dummy threads never call EndWait.
- These are only used by host threads for locking and will never have a wait_queue.
2022-01-20 17:08:00 -08:00
bunnei
f1e06f984d hle: kernel: KScheduler: Ensure dummy threads are never scheduled.
- These are only used by host threads for locking.
2022-01-20 17:08:00 -08:00
bunnei
cc4cbff1ca hle: kernel: KThread: Rename thread_type_for_debugging -> thread_type.
- This will be used to ensure that we do not schedule dummy threads.
2022-01-20 17:08:00 -08:00
bunnei
70b2b91f71 Merge pull request #7701 from bunnei/clear-mem-pages
Kernel Memory Updates (Part 3): Clear KMemoryManager pages & other fixes
2022-01-18 21:20:42 -08:00
bunnei
74407b1348 Merge pull request #7712 from bunnei/fix-thread-exit
Accurately implement thread exit
2022-01-17 18:08:24 -08:00
Valeri
01852ee857 hle: remove no-op code
Found by static analysis with PVS-Studio. Nobody seems to really know what was it doing there.
2022-01-17 13:51:12 +03:00
bunnei
4148fde355 hle: kernel: k_memory_manager: Clear pages on allocation & free.
- Heap pages should be zero'd.
- Also explicitly passed along heap allocation option.
2022-01-14 21:16:33 -08:00
bunnei
b52516263d core: hle: kernel: KThread: Integrate with KWorkerTask and implement DoWorkerTaskImpl.
- This is used to terminate a thread asynchronously after it has been exited.
- This fixes a crash that can occur in Pokemon Sword/Shield because a thread is incorrectly closed on svcExitThread, then, the thread is destroyed on svcCloseHandle while it is still scheduled.
- Instead, we now wait for the thread to no longer be scheduled on all cores before destroying it from KWorkerTaskManager, which is accurate to HOS behavior.
2022-01-14 16:44:14 -08:00
bunnei
18969b5d8e core: hle: kernel: KProcess: Integrate with KWorkerTask and add unimplemented DoWorkerTaskImpl. 2022-01-14 16:44:14 -08:00
bunnei
914431487b core: hle: kernel: KThread: Replace Suspend with UpdateState & various updates.
- This makes our implementations of these more closely match HOS.
2022-01-14 16:44:14 -08:00
bunnei
b6bf119a43 core: hle: kernel: Instantiate a kernel instance of KWorkerTaskManager. 2022-01-14 16:44:14 -08:00
bunnei
b722faaf7a core: hle: kernel: Add KWorkerTask and KWorkerTaskManager.
- These primitives are used to dispatch asynchronous kernel tasks from KThread and KProcess.
2022-01-14 16:43:59 -08:00
bunnei
fbab3dc017 hle: kernel: Fix service_threads access to be thread safe V2.
- PR #7699 attempted to fix CreateServiceThread and ReleaseServiceThread to be thread safe, but inadvertently introduced a possible dead-lock.
- With this PR, we use a worker thread to manage the service thread list, allowing it only to be accessed by a single thread, and guaranteeing threads will not destroy themselves.
- Fixes a rare crash in Pokemon Sword/Shield, I've now run this game for ~12 hours non-stop and am quite confident this is a good solution for this issue.
2022-01-14 16:02:57 -08:00
Mai M
8fb335ff3f Merge pull request #7699 from bunnei/fix-service-thread-race
hle: kernel: Fix service_threads access to be thread safe.
2022-01-14 00:46:16 -05:00
bunnei
ef9186172f hle: kernel: Fix service_threads access to be thread safe.
- CreateServiceThread and ReleaseServiceThread can be accessed by different threads, uses a lock to make this thread safe.
- Fixes a rare crash in Pokemon Sword/Shield that can occur when a new service thread is being created while an old one is being destroyed.
2022-01-13 21:26:10 -08:00
bunnei
d45b65b4d9 hle: kernel: k_page_table: Update SetProcessMemoryPermission. 2022-01-11 16:28:11 -08:00
bunnei
84a61db25b hle: kernel: k_page_table: ReadAndWrite -> UserReadWrite. 2022-01-11 16:28:11 -08:00
bunnei
0942533d2f hle: kernel: k_page_table: Rename *ProcessCodeMemory -> *CodeMemory. 2022-01-11 16:28:11 -08:00
bunnei
b227426ae5 core: hle: kernel: svc: Updates to SetMemoryAttribute and SetMemoryPermission. 2022-01-08 12:18:14 -08:00
bunnei
090f1c400e core: hle: kernel: k_page_table: Update CheckMemoryState. 2022-01-08 03:20:57 -08:00
bunnei
b12695ddc4 core: hle: kernel: Implement thread pinning.
- We largely had the mechanics in place for thread pinning, this change hooks these up.
- Validated with tests https://github.com/Atmosphere-NX/Atmosphere/blob/master/tests/TestSvc/source/test_thread_pinning.cpp.
2021-12-30 15:50:45 -08:00
bunnei
714dcea191 core: hle: kernel: Updated implementation of svcSetHeapSize.
- Updates our svcSetHeapSize with latest HOS, furthermore allowing heap size to properly be extended/shrunk.
- Validated with tests https://github.com/Atmosphere-NX/Atmosphere/blob/master/tests/TestSvc/source/test_set_heap_size.cpp.
2021-12-28 01:25:20 -08:00
bunnei
5217285536 Merge pull request #7621 from bunnei/set-mem-perm
core: hle: kernel: Implement SetMemoryPermission.
2021-12-27 23:33:11 -08:00
bunnei
555481005d core: hle: kernel: Implement SetMemoryPermission.
- Not seen in any games yet, but validated with kernel tests.
2021-12-23 01:10:36 -08:00
bunnei
bc45d0fc1a core: hle: kernel: KThread: X18 should be a cryptographically random number.
- This was added with firmware 11.0.0 (https://switchbrew.org/wiki/11.0.0).
    - X18 is OR'd by kernel with 1, to make sure it is odd.
2021-12-23 00:03:39 -08:00