Commit graph

291 commits

Author SHA1 Message Date
bunnei
203b812a83 Merge pull request #8157 from lat9nq/kernel-races
kernel: Fix some data races
2022-04-11 21:13:01 -07:00
Merry
de61c0897c core/hle: Replace lock_guard with scoped_lock 2022-04-07 19:44:07 +01:00
lat9nq
53d3082dd4 kernel: Fix current_process race
TSan reported a race at :258 and :803, so make current_process an atomic
pointer.
2022-04-03 21:47:57 -04:00
bunnei
60f2fe3b48 hle: kernel: Create a default thread for services that do not need their own host thread. 2022-04-02 01:24:30 -04:00
ameerj
22e01068e1 core: Reduce unused includes 2022-03-19 02:23:32 -04:00
bunnei
8b109f8a69 core: hle: kernel: Allocate dummy threads on host thread storage.
- Fixes a crash where on subsequent boots, long-lived host threads would have their dummy threads freed.
2022-03-14 18:14:54 -07:00
bunnei
18baef2ec9 core: hle: kernel: Downgrade dangling objects warning to debug.
- It is not impossible to leak kernel objects, so this is not really any issue anymore (albeit, still interesting).
2022-03-14 18:14:54 -07:00
bunnei
58b39c8ad8 core: hle: kernel: Make object list container global and ensure it is reset on each emulation session. 2022-03-14 18:14:54 -07:00
bunnei
29924a999e core: hle: kernel: Remove server session tracking.
- These are now allocated/managed by emulated memory, so we do not need to track and free them on shutdown.
2022-03-14 18:14:54 -07:00
bunnei
4b022badf0 core: hle: kernel: Update init_slab_heap, use device memory, and add KThreadLocalPage and KPageBuffer.
- Refreshes our slab initialization code to latest known behavior.
- Moves all guest kernel slabs into emulated device memory.
- Adds KThreadLocalPage and KPageBuffer, which we will use for accurate TLS management.
2022-03-14 18:14:54 -07:00
bunnei
82ca8230ad hle: kernel: Re-create memory layout at initialization.
- As this can only be derived once.
2022-02-27 18:00:09 -08:00
bunnei
41c9c93736 hle: kernel: Remove unused pool locals. 2022-02-27 18:00:09 -08:00
bunnei
939707cf75 hle: kernel: k_memory_manager: Rework for latest kernel behavior.
- Updates the KMemoryManager implementation against latest documentation.
- Reworks KMemoryLayout to be accessed throughout the kernel.
- Fixes an issue with pool sizes being incorrectly reported.
2022-02-27 18:00:09 -08:00
bunnei
f2cc07cc2c core: hle: kernel: Remove resource limit hack for PhysicalMemory.
- With prior changes, we now report the correct amount of physical memory available to the emulated process.
2022-02-21 12:41:31 -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
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
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
b6bf119a43 core: hle: kernel: Instantiate a kernel instance of KWorkerTaskManager. 2022-01-14 16:44:14 -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
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
ameerj
1fff9ea35e kernel: Manually destroy the current process during shut down
Avoids a memory leak.
2021-12-19 01:38:25 -05:00
FernandoS27
8a38790bd3 hle: kernel: fix timing on thread preemption 2021-12-06 16:39:18 -08:00
bunnei
58da4d5a6e hle: kernel: Add a flag for indicating that the kernel is currently shutting down. 2021-12-06 16:39:17 -08:00
bunnei
51a7f04b81 core: hle: kernel: DisableDispatch on suspend threads. 2021-12-06 16:39:16 -08:00
bunnei
3a83c9c027 core: hle: kernel: Use CurrentPhysicalCoreIndex as appropriate. 2021-12-06 16:39:16 -08:00
bunnei
fa26f905c8 core: hle: kernel: Ensure idle threads are closed before destroying scheduler. 2021-12-06 16:39:16 -08:00
bunnei
cae0bef7ec core: hle: kernel: Reflect non-emulated threads as core 3. 2021-12-06 16:39:16 -08:00
Adam Heinermann
fc017ead67 Fix crash on exit due to static scoped dummy threads 2021-11-17 15:29:25 -08:00
ameerj
d27abf5546 core: Remove unused includes 2021-11-03 21:42:57 -04:00
Feng Chen
60df1f9030 Fix dangling kernel objects when exiting 2021-10-27 09:06:30 +08:00
Feng Chen
301d0ac5e0 Revert PR7009 2021-10-27 09:06:30 +08:00
Feng Chen
c13d1e0b0f Fix memory leak 2021-10-27 09:06:22 +08:00
bunnei
5e600cba3a Revert "kernel: Various improvements to scheduler" 2021-08-25 20:59:28 -07:00
Ameer J
b53a87b6b4 Merge pull request #6878 from BreadFish64/optimize-GetHostThreadID
kernel: Optimize GetHostThreadID
2021-08-24 00:01:13 -04:00
BreadFish64
8c4f818e77 kernel: Optimize GetHostThreadID 2021-08-16 07:30:23 -05:00
bunnei
0cd7bf70a3 core: hle: kernel: DisableDispatch on suspend threads. 2021-08-07 12:18:47 -07:00
bunnei
347e4d6ab8 core: hle: kernel: Use CurrentPhysicalCoreIndex as appropriate. 2021-08-07 12:18:47 -07:00
bunnei
43fcb97ef3 core: hle: kernel: Ensure idle threads are closed before destroying scheduler. 2021-08-07 12:18:47 -07:00
bunnei
951143ba57 core: hle: kernel: Reflect non-emulated threads as core 3. 2021-08-07 12:18:47 -07:00
bunnei
beeed68944 hle: kernel: Track and release server sessions, and protect methods with locks. 2021-07-20 18:54:56 -07:00
bunnei
81d111fd1b hle: kernel: Ensure current running process is closed. 2021-07-20 18:54:56 -07:00
bunnei
88350871df hle: kernel: Ensure global handle table is finalized before closing. 2021-07-20 18:54:56 -07:00
bunnei
2c96cc5343 hle: kernel: Ensure global handle table is initialized. 2021-07-20 18:54:55 -07:00
bunnei
a4b3202b65 hle: kernel: Provide methods for tracking dangling kernel objects. 2021-07-20 18:54:55 -07:00
Wunkolo
722f9c3cb5 common: Replace common_sizes into user-literals
Removes common_sizes.h in favor of having `_KiB`, `_MiB`, `_GiB`, etc
user-literals within literals.h.

To keep the global namespace clean, users will have to use:

```
using namespace Common::Literals;
```

to access these literals.
2021-06-24 09:27:40 -07:00
bunnei
a3de201dcf hle: kernel: Remove service thread manager and use weak_ptr.
- We no longer need to queue up service threads to be destroyed.
- Fixes a race condition where a thread could be destroyed too early, which caused a crash in Pokemon Sword/Shield.
2021-06-07 21:10:51 -07:00
bunnei
fb86819b39 Merge pull request #6373 from bunnei/use-slabheap-tls
hle: kernel: KSlabHeap: Allow host or guest allocations.
2021-05-29 00:17:24 -07:00
Markus Wick
9f92beed0a Fix two GCC 11 warnings: Unneeded copies.
std::move created an unneeded copy.
iterating without reference also created copies.
2021-05-29 08:57:44 +02:00
bunnei
639baf88f7 hle: kernel: KSlabHeap: Allow host or guest allocations.
- Use host allocations for kernel memory, as this is not properly emulated yet.
- Use guest allocations for TLS, as this needs to be backed by DeviceMemory.
2021-05-28 17:42:41 -07:00