Commit graph

1978 commits

Author SHA1 Message Date
bunnei 3f8eb44e7d hle: kernel: k_light_condition_variable: Revert unnecessary license comment changes. 2021-12-06 16:39:18 -08:00
bunnei 2e8d737a96 hle: kernel: k_condition_variable: Revert unnecessary style changes. 2021-12-06 16:39:18 -08:00
bunnei 0d1bdfc1d4 hle: kernel: Remove unnecessary virtual specifier on CancelWait. 2021-12-06 16:39:18 -08:00
bunnei d7f6d516ce hle: kernel: service_thread: Force stop threads on destruction. 2021-12-06 16:39:18 -08:00
bunnei e596fac6ee hle: kernel: k_light_lock: Implement CancelWait.
- Fixes a crash in Megadimension Neptunia VII.
2021-12-06 16:39:18 -08:00
bunnei efb5de1c5f hle: kernel: service_thread: Use std::jthread.
- Fixes a potential deadlock on service thread shutdown.
2021-12-06 16:39:18 -08:00
bunnei a2384a18fa hle: kernel: k_thread: Skip reschedule on DisableDispatch with SC. 2021-12-06 16:39:18 -08:00
bunnei 42697527ba hle: kernel: k_thread: Rename sleeping_queue -> wait_queue. 2021-12-06 16:39:18 -08:00
bunnei e3d156ab0e hle: kernel: svc: Fix deadlock that can occur with single core. 2021-12-06 16:39:18 -08:00
bunnei 0d9afdedc4 hle: kernel: k_thread: Treat dummy threads as a special type. 2021-12-06 16:39:18 -08:00
FernandoS27 894ed14ebc hle: kernel: fix timing on thread preemption 2021-12-06 16:39:18 -08:00
FernandoS27 3c2a451f47 hle: kernel: fix scheduling ops from HLE host thread. 2021-12-06 16:39:17 -08:00
bunnei abbea575cf hle: kernel: Add a flag for indicating that the kernel is currently shutting down. 2021-12-06 16:39:17 -08:00
bunnei 2c49a65d2b hle: kernel: KSynchronizationObject: Fix variable shadowing. 2021-12-06 16:39:17 -08:00
bunnei 8f4ff06c4c hle: kernel: Cleanup to match coding style. 2021-12-06 16:39:17 -08:00
bunnei 316a2dd22a hle: kernel: KProcess: Improvements for thread pinning. 2021-12-06 16:39:17 -08:00
bunnei 4c74761155 hle: kernel: KThreadQueue: Remove deprecated code. 2021-12-06 16:39:17 -08:00
bunnei f3d6e31e78 hle: kernel: KConditionVariable: Various updates & simplifications. 2021-12-06 16:39:17 -08:00
bunnei f62c7091a2 hle: kernel: KThread: Migrate to updated KThreadQueue (part 2). 2021-12-06 16:39:17 -08:00
bunnei b0671c7cfa hle: kernel: KThread: Migrate to updated KThreadQueue (part 1). 2021-12-06 16:39:17 -08:00
bunnei beb55cb90e hle: kernel: KConditionVariable: Migrate to updated KThreadQueue. 2021-12-06 16:39:17 -08:00
bunnei e942d97540 hle: kernel: KServerSession: Migrate to updated KThreadQueue. 2021-12-06 16:39:17 -08:00
bunnei 5dff28290f hle: kernel: KLightConditionVariable: Migrate to updated KThreadQueue. 2021-12-06 16:39:17 -08:00
bunnei 423acf53b7 hle: kernel: KLightLock: Migrate to updated KThreadQueue. 2021-12-06 16:39:17 -08:00
bunnei 15c721b909 hle: kernel: KAddressArbiter: Migrate to updated KThreadQueue. 2021-12-06 16:39:17 -08:00
bunnei 2f89456041 hle: kernel: KThread: Remove tracking of sync object from threads. 2021-12-06 16:39:17 -08:00
bunnei bc1399204b hle: kernel: Update KThreadQueue and migrate KSynchronizationObject. 2021-12-06 16:39:17 -08:00
bunnei 3dc803a430 core: hle: kernel: Disable dispatch count tracking on single core.
- This would have limited value, and would be a mess to handle properly.
2021-12-06 16:39:17 -08:00
bunnei d14b8fc747 core: hle: kernel: k_thread: Mark KScopedDisableDispatch as nodiscard. 2021-12-06 16:39:17 -08:00
bunnei 07690572f7 core: hle: kernel: k_auto_object: Add GetName method.
- Useful purely for debugging.
2021-12-06 16:39:16 -08:00
bunnei 3239442de6 core: hle: kernel: DisableDispatch on suspend threads. 2021-12-06 16:39:16 -08:00
bunnei 284015dfd7 core: hle: kernel: k_scheduler: Improve DisableScheduling and EnableScheduling. 2021-12-06 16:39:16 -08:00
bunnei 178584e56f core: hle: kernel: Use CurrentPhysicalCoreIndex as appropriate. 2021-12-06 16:39:16 -08:00
bunnei 629f9274ac core: hle: kernel: k_scheduler: Remove unnecessary MakeCurrentProcess. 2021-12-06 16:39:16 -08:00
bunnei 13c82d042f core: hle: kernel: k_scheduler: Improve ScheduleImpl. 2021-12-06 16:39:16 -08:00
bunnei f412d2027a core: hle: kernel: k_scheduler: Improve Unload. 2021-12-06 16:39:16 -08:00
bunnei f13fce3953 core: hle: kernel: k_process: DisableDispatch on main thread. 2021-12-06 16:39:16 -08:00
bunnei 4c18a207a4 core: hle: kernel: k_handle_table: Use KScopedDisableDispatch as necessary. 2021-12-06 16:39:16 -08:00
bunnei 04daefa488 core: hle: kernel: k_thread: Add KScopedDisableDispatch. 2021-12-06 16:39:16 -08:00
bunnei 3bd5d4b6f8 core: hle: kernel: Ensure idle threads are closed before destroying scheduler. 2021-12-06 16:39:16 -08:00
bunnei 669a2d2c67 core: hle: kernel: Reflect non-emulated threads as core 3. 2021-12-06 16:39:16 -08:00
itsmeft24 8ed2748820
fix formatting 2021-12-06 11:02:33 -05:00
itsmeft24 e10903cab9
move private members below public members 2021-12-06 10:37:13 -05:00
itsmeft24 4bdacdedc1
fix formatting 2021-12-06 10:37:09 -05:00
itsmeft24 32854a2992
fix formatting
Co-authored-by: Mai M. <mathew1800@gmail.com>
2021-12-06 07:58:28 -05:00
itsmeft24 14c03b9748 fix formatting 2021-12-05 19:00:29 -05:00
itsmeft24 8254f238b9 Remove unnecessary includes 2021-12-05 18:49:40 -05:00
itsmeft24 b7d80c127f Add copyright notice 2021-12-05 16:49:52 -05:00
itsmeft24 8aef8f39d8 kernel: svc: Implement Map/UnmapProcessMemory and Create/ControlCodeMemory
Used by Skyline modding framework
2021-12-05 15:04:08 -05:00
bunnei daecbd3a7f
Merge pull request #7394 from Morph1984/svc-SetMemoryPermission
kernel: svc: Implement SetProcessMemoryPermission
2021-11-22 14:06:09 -08:00
Morph 5cf93c1346 kernel: svc: Move all IsValid functions to an anonymous namespace 2021-11-20 22:49:13 -05:00
Morph 2726d705f8 kernel: svc: Implement SetProcessMemoryPermission
- Used by Skyline modding framework
2021-11-20 22:18:56 -05:00
Morph 281437c811 kernel: KPageTable: Rename SetCodeMemoryPermission to SetProcessMemoryPermission 2021-11-20 22:18:56 -05:00
Adam Heinermann d8a783a368 Fix crash on exit due to static scoped dummy threads 2021-11-17 15:29:25 -08:00
Morph 64275dfbf4 general: Rename GetTitleID to GetProgramID 2021-11-04 16:57:16 -04:00
ameerj b275f2e475 core: Fix transitive include build errors 2021-11-03 21:42:58 -04:00
ameerj 7c4b6aab2e core: Remove unused includes 2021-11-03 21:42:57 -04:00
Morph b871388a31 svc: Correct WaitSynchronization num_handles param type
num_handles is a s32
2021-11-02 22:31:04 -04:00
Morph cb09ea0f01 general: Remove MakeResult helpers
This is made obsolete by the presence of implicit constructors.
2021-11-02 17:23:19 -04:00
bunnei b118fa8698
Merge pull request #7227 from vonchenplus/fix_memory_leak_v2
Fix memory leak v2
2021-11-01 20:11:30 -07:00
Feng Chen dd29285e35 Fix dangling kernel objects when exiting 2021-10-27 09:06:30 +08:00
Feng Chen 052017e189 Revert PR7009 2021-10-27 09:06:30 +08:00
Feng Chen a8b0104923 Fix memory leak 2021-10-27 09:06:22 +08:00
Morph 63ed7d9af7
Merge pull request #7193 from FernandoS27/idle
SVC: Implement svcInfo:IdleTickCount
2021-10-25 09:17:49 -04:00
Fernando Sahmkow da6673e79a SVC: Implement svcInfo:IdleTickCount
Used by the Witcher 3
2021-10-16 20:33:44 +02:00
Morph 50384e2619 KPageTable: Perform ranged invalidation when unmapping code memory
Co-Authored-By: Fernando S. <1731197+FernandoS27@users.noreply.github.com>
2021-10-13 14:27:11 -04:00
Morph bea7824bd1 kernel: hle_ipc: Foward declare KAutoObject 2021-10-07 13:32:36 -04:00
bunnei 5b2fa8dd41
Merge pull request #7115 from ameerj/log-compile
common/logging: Reduce dependent header include overhead
2021-10-05 10:05:46 -07:00
Ameer J 01f79d638f
Merge pull request #7091 from vonchenplus/fix_memroy_leak
core: Fix memory leak
2021-10-04 00:09:08 -04:00
ameerj 5daf3abe65 common/logging: Move Log::Entry declaration to a separate header
This reduces the load of requiring to include std::chrono in all files which include log.h
2021-10-01 20:48:49 -04:00
Morph e29f3b87f1 style: Remove extra space preceding the :: operator 2021-09-29 01:26:01 -04:00
Feng Chen 5fbfc4c19e Fix KShareMemory object leak 2021-09-29 09:51:20 +08:00
Feng Chen 7cd43b139a Fix KScopedAutoObject object leak when SendSyncRequest 2021-09-25 22:16:21 +08:00
ameerj 73666fb262 general: Update style to clang-format-12 2021-09-24 15:52:05 -04:00
Morph 6f307f1521 kernel: Add missing <functional> include 2021-09-11 17:19:15 -04:00
bunnei 0c8594b225
Revert "kernel: Various improvements to scheduler" 2021-08-25 20:59:28 -07:00
Ameer J bed0c3c92a
Merge pull request #6878 from BreadFish64/optimize-GetHostThreadID
kernel: Optimize GetHostThreadID
2021-08-24 00:01:13 -04:00
Valeri 0b3d12be40
Fix check is thread current in GetThreadContext
Misplaced break made it only check for the first core.
2021-08-19 16:46:30 +03:00
BreadFish64 14e93f133a kernel: Optimize GetHostThreadID 2021-08-16 07:30:23 -05:00
bunnei aef0ca6f0d core: hle: kernel: Disable dispatch count tracking on single core.
- This would have limited value, and would be a mess to handle properly.
2021-08-14 02:14:19 -07:00
bunnei 5060a97210 core: hle: kernel: k_thread: Mark KScopedDisableDispatch as nodiscard. 2021-08-07 12:33:31 -07:00
bunnei 48a3496b93 core: hle: kernel: k_auto_object: Add GetName method.
- Useful purely for debugging.
2021-08-07 12:18:48 -07:00
bunnei 5051d3c415 core: hle: kernel: DisableDispatch on suspend threads. 2021-08-07 12:18:47 -07:00
bunnei 1798c3b6b0 core: hle: kernel: k_scheduler: Improve DisableScheduling and EnableScheduling. 2021-08-07 12:18:47 -07:00
bunnei 2dfb07388a core: hle: kernel: Use CurrentPhysicalCoreIndex as appropriate. 2021-08-07 12:18:47 -07:00
bunnei d1c502720d core: hle: kernel: k_scheduler: Remove unnecessary MakeCurrentProcess. 2021-08-07 12:18:47 -07:00
bunnei 77ad64b97d core: hle: kernel: k_scheduler: Improve ScheduleImpl. 2021-08-07 12:18:47 -07:00
bunnei bedcf19710 core: hle: kernel: k_scheduler: Improve Unload. 2021-08-07 12:18:47 -07:00
bunnei 7569d6774d core: hle: kernel: k_process: DisableDispatch on main thread. 2021-08-07 12:18:47 -07:00
bunnei f2b0d28983 core: hle: kernel: k_handle_table: Use KScopedDisableDispatch as necessary. 2021-08-07 12:18:47 -07:00
bunnei 01af2f4162 core: hle: kernel: k_thread: Add KScopedDisableDispatch. 2021-08-07 12:18:47 -07:00
bunnei 2b9560428b core: hle: kernel: Ensure idle threads are closed before destroying scheduler. 2021-08-07 12:18:47 -07:00
bunnei 68eee94875 core: hle: kernel: Reflect non-emulated threads as core 3. 2021-08-07 12:18:47 -07:00
bunnei f3db3dcc8d hle: kernel: svc: Remove part of ExitProcess.
- ExitProcess is not actually implemented either way, and this needs more work before we implement.
2021-07-20 18:54:56 -07:00
bunnei 52caa52cc2 hle: kernel: Track and release server sessions, and protect methods with locks. 2021-07-20 18:54:56 -07:00
bunnei 8d755147d8 hle: kernel: KProcess: Change process termination assert to a warning.
- Since we do not implement multiprocess right now, this should not be a crashing assert.
2021-07-20 18:54:56 -07:00
bunnei 854c7a3c28 hle: kernel: Ensure current running process is closed. 2021-07-20 18:54:56 -07:00
bunnei ecf3653444 hle: kernel: Ensure global handle table is finalized before closing. 2021-07-20 18:54:56 -07:00
bunnei 24540e0ad9 kernel: svc: ConnectToNamedPort: Close extra reference to port. 2021-07-20 18:54:56 -07:00
bunnei b119363fc2 hle: kernel: k_process: Close the handle table on shutdown. 2021-07-20 18:54:55 -07:00
bunnei 6020723e77 hle: kernel: k_process: Close main thread reference after it is inserted into handle table. 2021-07-20 18:54:55 -07:00
bunnei fe402d3506 hle: kernel: Ensure global handle table is initialized. 2021-07-20 18:54:55 -07:00
bunnei 929994132a hle: kernel: Provide methods for tracking dangling kernel objects. 2021-07-20 18:54:55 -07:00
Wunkolo 4569f39c7c 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
Morph 1a5eceeb9c kernel: Fix missing peak set in KResourceLimit::SetLimitValue 2021-06-18 07:27:48 -04:00
Morph ebd38d66db kernel: Unconditionally set thread state when appropriate 2021-06-11 00:58:04 -04:00
Morph aa79ca7a7a kernel: KLightConditionVariable: Update implementation to 12.x
Updates the implementation of KLightConditionVariable to FW 12.x
2021-06-11 00:58:04 -04:00
bunnei b259e95c09 hle: kernel: KClientPort: Add an assert for session count.
- Prevents us from over decrementing num_sessions.
2021-06-09 22:36:42 -07:00
bunnei ec5674a6ad hle: service: sm: Fix GetService setup of session & port. 2021-06-09 22:29:18 -07:00
bunnei b2971b48ed hle: kernel: KServerSession: Fix client disconnected.
- Prevents a cloned session's handler from being overwritten by another disconnected session.
- Fixes session handler nullptr asserts with Pokemon Sword & Shield.
2021-06-09 21:37:11 -07:00
bunnei c63ea608aa kernel: svc: Add missing error check to CancelSynchronization.
- Avoids a potential crash if the handle is invalid, and also makes this code accurate to real kernel behavior.
2021-06-09 15:24:46 -07:00
bunnei b8fb9b3f11 hle: kernel: KServerSession: Work-around scenario where session is closed too early. 2021-06-08 13:39:20 -07:00
bunnei 08d798b6fe hle: kernel: hle_ipc: Ensure SessionRequestHandler is valid. 2021-06-07 21:55:37 -07:00
bunnei a493ab2678 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 9db569b2d9 hle: kernel: KServerSession: Use ASSERT_MSG where appropriate. 2021-06-06 22:09:25 -07:00
bunnei ada4242c01 hle: kernel: k_server_session: Return service thread by strong pointer. 2021-06-06 17:54:06 -07:00
bunnei 93f93cb8bc hle: kernel: k_server_session: Ensure service thread is valid before dereference. 2021-06-06 17:03:36 -07:00
bunnei 384cbe3829 hle: kernel: hle_ipc: Use default destructor for SessionRequestManager. 2021-06-06 15:41:16 -07:00
bunnei 6119836795 hle: kernel: KAutoObjectWithListContainer: Use boost::instrusive::rbtree.
- Fixes some crashes introduced by our common intrusive red/black tree impl.
2021-06-06 15:39:11 -07:00
bunnei 27ce97fd42 hle: kernel: Refactor to allocate a ServiceThread per service handler.
- Previously, we would allocate a thread per session, which adds new threads on CloneCurrentObject.
- This results in race conditions with N sessions queuing requests to the same service interface.
- Fixes Pokken Tournament DX crashes/softlocks, which were regressed by #6347.
2021-06-04 19:26:48 -07:00
Morph a0e4c2e1fc general: Replace RESULT_UNKNOWN with ResultUnknown
Transition to PascalCase for result names.
2021-06-02 00:39:27 -04:00
Morph 12c1766997 general: Replace RESULT_SUCCESS with ResultSuccess
Transition to PascalCase for result names.
2021-06-02 00:39:27 -04:00
bunnei a6cfc73cb2
Merge pull request #6387 from lioncash/class-token
k_class_token: Use variable templates where applicable
2021-05-29 23:55:17 -07:00
Lioncash 646622ccd4 k_class_token: Use variable templates where applicable
Same behavior, less code.
2021-05-29 05:25:34 -04:00
bunnei c7c4ef9d43
Merge pull request #6384 from lioncash/virtual
kernel: Add missing override specifiers
2021-05-29 02:11:40 -07:00
bunnei cdabc9064b
Merge pull request #6382 from lioncash/null
k_thread: Move dereference after null check in Initialize()
2021-05-29 01:17:28 -07:00
bunnei 5388e6db84
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
Lioncash 7b2917b4e1 kernel: Add missing override specifiers
Over the course of the kernel refactoring a tiny bit of missing
overrides slipped through review, so we can add these.

While we're at it, we can remove redundant virtual keywords where
applicable as well.
2021-05-29 02:58:32 -04:00
Markus Wick 5a8cd1b118 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
Lioncash 16ff0161b3 k_thread: Move dereference after null check in Initialize()
Prevents a -Wnonnull warning on GCC.
2021-05-29 00:31:38 -04:00
bunnei ee099b2697 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
Markus Wick 3d2e80daed core/arm_interface: Call SVC after end of dynarmic block.
So we can modify all of dynarmic states within SVC without ExceptionalExit.

Especially as the ExceptionalExit hack is dropped on upstream dynarmic.
2021-05-27 23:23:23 +02:00
Morph ec28d3c439 kernel: process_capability: Add MapRegion capability
- Used by nx-hbloader
2021-05-25 01:44:46 -04:00
bunnei 6418a42884 hle: kernel: service_thread: Take reference to KServerSession on service request. 2021-05-20 22:39:44 -07:00
bunnei e33ffdc555 hle: kernel: k_port: Use AcceptSession to ensure SessionList state is correct.
- Fixes a use-after-free, work-around until we fixup session/port management.
2021-05-20 21:41:52 -07:00
bunnei b4fc2e52a2 hle: kernel: Use host memory allocations for KSlabMemory.
- There are some issues with the current workaround, we will just use host memory until we have a complete kernel memory implementation.
2021-05-20 21:41:52 -07:00
bunnei 7331bb9d8d Revert "WORKAROUND: Do not use slab heap while we track down issues with resource management."
This reverts commit f2c26443f8.
2021-05-20 21:41:52 -07:00
bunnei f4fe71c1c9 hle: kernel: hle_ipc: Simplify incoming/outgoing move/copy/domain objects. 2021-05-20 21:41:52 -07:00
bunnei 7361eac10f hle: kernel: Implement CloneCurrentObject and improve session management. 2021-05-20 21:41:49 -07:00
bunnei c40e7593f5 Revert "WORKAROUND: temp. disable session resource limits while we work out issues"
This reverts commit fc086f93b2.
2021-05-20 21:40:30 -07:00
bunnei ea4e4b05e4
Merge pull request #6320 from Morph1984/get-pid
hle_ipc: Add a getter for PID
2021-05-20 21:40:03 -07:00
Morph 7f78b17e20 KTransferMemory: Return size instead of size * PageSize in GetSize()
size is already the size in bytes. We do not need to multiply it by the page size
2021-05-18 13:14:28 -04:00
Morph 049769a0c9 hle_ipc: unsigned -> u32
This is more concise and consistent with the rest of the codebase.
2021-05-16 04:11:00 -04:00
Morph 81a5ecdb18 hle_ipc: Add a getter for PID 2021-05-16 04:10:42 -04:00
Lioncash 9a07ed53eb core: Make variable shadowing a compile-time error
Now that we have most of core free of shadowing, we can enable the
warning as an error to catch anything that may be remaining and also
eliminate this class of logic bug entirely.
2021-05-16 03:43:16 -04:00
bunnei 12d569e483 hle: kernel: hle_ipc: Fix outgoing IPC response size calculation. 2021-05-11 12:27:43 -07:00
bunnei fc086f93b2 WORKAROUND: temp. disable session resource limits while we work out issues 2021-05-11 10:51:39 -07:00
bunnei f2c26443f8 WORKAROUND: Do not use slab heap while we track down issues with resource management. 2021-05-11 10:27:18 -07:00
bunnei 913971417e hle: kernel: hle_ipc: Improve IPC code and add initial support for TIPC.
- Fixes our move handles implementation to actually move objects.
- Simplifies the traditional IPC path.
2021-05-10 20:34:38 -07:00
bunnei da25a59866 hle: service: Implement IPC::CommandType::Close.
- This was not actually closing sessions before.
2021-05-10 20:34:38 -07:00