Commit graph

204 commits

Author SHA1 Message Date
danzel
e16c96d587 Use recursive_mutex instead of mutex to fix #2902 2017-08-29 20:39:55 +12:00
Subv
9cf64ca2cf Kernel/HLE: Use a mutex to synchronize access to the HLE kernel state between the cpu thread and any other possible threads that might touch the kernel (network thread, etc).
This mutex is acquired in SVC::CallSVC, ie, as soon as the guest application enters the HLE kernel, and should be acquired by the aforementioned threads before modifying kernel structures.
2017-08-22 09:30:55 -05:00
Sebastian Valle
4f7e8c6f1e Merge pull request #2793 from Subv/replyandreceive
Kernel/SVC: Partially implemented svcReplyAndReceive
2017-06-29 17:05:22 -05:00
Subv
4a8de6bb00 Kernel/SVC: Pass the current thread as a parameter to ClientSession::SendSyncRequest. 2017-06-29 12:30:34 -05:00
Subv
820509103c Kernel/SVC: Partially implemented svcReplyAndReceive.
It behaves mostly as WaitSynchronizationN with wait_all = false, except for IPC buffer translation.

The target thread of an IPC response will now wake up when responding.
IPC buffer translation is currently not implemented.
Error passing back to svcSendSyncRequest is currently not implemented.
2017-06-25 23:38:28 -05:00
Yuri Kunde Schlesner
afa851d0a4 Kernel: Implement AcceptSession SVC 2017-06-23 11:26:37 -07:00
Yuri Kunde Schlesner
cf12983372 Kernel: Implement CreateSessionToPort SVC 2017-06-23 11:22:02 -07:00
Yuri Kunde Schlesner
364ef24f77 Kernel: Implement CreateSession SVC 2017-06-22 00:39:27 -07:00
Yuri Kunde Schlesner
ecfda5317e Kernel: Move HandleTable to a separate file 2017-05-29 17:34:39 -07:00
Yuri Kunde Schlesner
6f662625d3 Kernel: Move WaitObject to a separate file
Now that HandleTable doesn't directly depend on WaitObject anymore, this
can be separated from the main kernel.h header.
2017-05-29 16:16:46 -07:00
Yuri Kunde Schlesner
ddbf9cec1b Kernel: Removed HandleTable::GetWaitObject
This isn't necessary anymore since plain Get works correctly for
WaitObjects.
2017-05-29 15:10:06 -07:00
Yuri Kunde Schlesner
467545ed48 Kernel: Centralize error definitions in errors.h 2017-05-24 21:06:00 -07:00
Yuri Kunde Schlesner
88fddcbce4 Remove ability to load symbol maps
This was now mostly unused except by thread creation, which used a
symbol of the entrypoint, if available, to name the thread.
2017-05-07 15:33:07 -07:00
Michael Theall
775ae0634e Fix OutputDebugString syscall 2017-04-01 04:09:39 -05:00
Fernando Sahmkow
b302e3e34d Refined thread launch on syscore error messages 2017-03-09 08:18:18 -05:00
Subv
be2b4057e5 Timers: Return an error when calling SetTimer with negative timeouts. 2017-02-21 20:51:56 -05:00
Subv
a81290ffb4 Threads: Check the process' resource limit for the max allowed priority when creating a thread and remove the priority clamping code. 2017-01-11 16:38:05 -05:00
Subv
fbe090645c Thread: Added priority range checking to svcSetThreadPriority and removed priority clamping code from Thread::SetPriority. 2017-01-11 16:38:04 -05:00
bunnei
961bb24cf9 Merge pull request #2410 from Subv/sleepthread
Don't yield execution in SleepThread(0) if there are no available threads to run
2017-01-06 22:01:33 -05:00
Hyper
82ed89eec2 Kernel: Fix SharedMemory objects always returning error when addr = 0 (#2404)
Closes #2400
2017-01-06 08:21:22 -05:00
Subv
6c6117868a Kernel: Don't attempt to yield execution in SleepThread(0) if there are no available threads to run.
With this we avoid an useless temporary deschedule of the current thread.
2017-01-05 19:11:34 -05:00
Subv
3ce2c24665 Kernel: Remove Thread::wait_objects_index and use wait_objects to hold all the objects that a thread is waiting on. 2017-01-05 09:40:14 -05:00
Subv
bcad1d6f12 Kernel: Use different thread statuses when a thread calls WaitSynchronization1 and WaitSynchronizationN with wait_all = true.
This commit removes the overly general THREADSTATUS_WAIT_SYNCH and replaces it with two more granular statuses:

THREADSTATUS_WAIT_SYNCH_ANY when a thread waits on objects via WaitSynchronization1 or WaitSynchronizationN with wait_all = false.

THREADSTATUS_WAIT_SYNCH_ALL when a thread waits on objects via WaitSynchronizationN with wait_all = true.
2017-01-04 15:58:50 -05:00
Subv
8503e56689 Kernel/Mutex: Propagate thread priority changes to other threads inheriting the priority via mutexes 2017-01-04 15:58:48 -05:00
Subv
d33885b60b Kernel/Mutex: Update a mutex priority when a thread stops waiting on it. 2017-01-04 15:58:47 -05:00
Subv
4e6369d41d Kernel/Mutex: Implemented priority inheritance.
The implementation is based on reverse engineering of the 3DS's kernel.

A mutex holder's priority will be temporarily boosted to the best priority among any threads that want to acquire any of its held mutexes.
When the holder releases the mutex, it's priority will be boosted to the best priority among the threads that want to acquire any of its remaining held mutexes.
2017-01-04 15:58:46 -05:00
Subv
90570c153b Kernel: Object ShouldWait and Acquire calls now take a thread as a parameter.
This will be useful when implementing mutex priority inheritance.
2017-01-04 15:58:45 -05:00
Subv
a1718862e3 Kernel/Synch: Do not attempt a reschedule on every syscall.
Not all syscalls should cause reschedules, this commit attempts to remedy that, however, it still does not cover all cases.
2017-01-04 15:58:44 -05:00
bunnei
8cfd0762fd core: Replace "AppCore" nomenclature with just "CPU". 2016-12-22 00:27:46 -05:00
bunnei
1fd7cfb69e Address clang-format issues. 2016-12-21 23:48:14 -05:00
bunnei
5d22844f3e core: Remove HLE module, consolidate code & various cleanups. 2016-12-21 23:48:13 -05:00
bunnei
d504f6cf08 core: Consolidate core and system state, remove system module & cleanups. 2016-12-21 23:29:13 -05:00
wwylele
c62bc4e616 Thread: remove the thread from the thread list when exiting 2016-12-17 19:23:52 +02:00
bunnei
034651fa7f Merge pull request #2260 from Subv/scheduling
Threading: Reworked the way our scheduler works.
2016-12-16 00:41:22 -05:00
Subv
3e80a1a1c1 Fixed the codestyle to match our clang-format rules. 2016-12-14 12:45:36 -05:00
Subv
00decc1180 Fixed the codestyle to match our clang-format rules. 2016-12-14 12:35:01 -05:00
Subv
7066deff78 Properly remove a thread from its wait_objects' waitlist when it is awoken by a timeout. 2016-12-10 13:29:31 -05:00
Subv
d4815e828d WaitSynch: Removed unused variables and reduced SharedPtr copies.
Define a variable with the value of the sync timeout error code.

Use a boost::flat_map instead of an unordered_map to hold the equivalence of objects and wait indices in a WaitSynchN call.
2016-12-09 12:23:09 -05:00
Subv
021e732815 Use std::move where appropriate. 2016-12-08 11:06:19 -05:00
Subv
06b2b80d31 Return an error code when connecting to a saturated port.
The error code was taken from the 3DS kernel.
2016-12-05 13:59:57 -05:00
Subv
977039e722 KServerPorts now have an HLE handler "template", which is inherited by all ServerSessions created from it. 2016-12-05 11:02:08 -05:00
Subv
44c59feca6 Threading: Added some utility functions and const correctness. 2016-12-04 09:58:36 -05:00
Subv
5bc10a74f6 Threading: Reworked the way our scheduler works.
Threads will now be awakened when the objects they're waiting on are signaled, instead of repeating the WaitSynchronization call every now and then.

The scheduler is now called once after every SVC call, and once after a thread is awakened from sleep by its timeout callback.

This new implementation is based off reverse-engineering of the real kernel.

See https://gist.github.com/Subv/02f29bd9f1e5deb7aceea1e8f019c8f4 for a more detailed description of how the real kernel handles rescheduling.
2016-12-03 22:38:14 -05:00
Subv
811d684274 Threads do not wait for the server endpoint to call AcceptSession before returning from a ConnectToPort or GetServiceHandle call. 2016-12-01 10:47:06 -05:00
Subv
4f2326c8a9 A bit of a redesign.
Sessions and Ports are now detached from each other.
HLE services are handled by means of a SessionRequestHandler class, Interface now inherits from this class.
The File and Directory classes are no longer kernel objects, but SessionRequestHandlers instead, bound to a ServerSession when requested.
File::OpenLinkFile now creates a new session pair and binds the File instance to it.
2016-11-30 23:12:35 -05:00
Subv
302ef594a6 Kernel/IPC: Use Ports and Sessions as the fundamental building block of Inter Process Communication.
All handles obtained via srv::GetServiceHandle or svcConnectToPort are references to ClientSessions.
Service modules will wait on the counterpart of those ClientSessions (Called ServerSessions) using svcReplyAndReceive or svcWaitSynchronization[1|N], and will be awoken when a SyncRequest is performed.

HLE Interfaces are now ClientPorts which override the HandleSyncRequest virtual member function to perform command handling immediately.
2016-11-30 23:02:05 -05:00
wwylele
d1d4b24f76 name objects 2016-09-22 13:52:52 +08:00
Emmanuel Gil Peyrot
1138ec0d49 Remove empty newlines in #include blocks.
This makes clang-format useful on those.

Also add a bunch of forgotten transitive includes, which otherwise
prevented compilation.
2016-09-21 11:15:47 +09:00
Emmanuel Gil Peyrot
628ed4376a Sources: Run clang-format on everything. 2016-09-18 09:38:01 +09:00
Subv
a350b5274f Kernel/SVC: Implemented svcCreatePort. 2016-06-11 08:37:37 -05:00