Commit graph

521 commits

Author SHA1 Message Date
Sebastian Valle
93742ec510
Merge pull request #3088 from Subv/clientsession_closing
Kernel/Sessions: Wake up any threads waiting on a ServerSession when its client is closed
2017-11-15 09:15:34 -05:00
Subv
c9c1ba0952 Kernel/IPC: Implement StaticBuffer translation for HLE services that use the HLERequestContext architecture.
The real kernel requires services to set up their static buffer targets ahead of time. This implementation does not require that and will simply create the storage for the buffers as they are processed in the incoming IPC request.

Static buffers are kept in an unordered_map keyed by their buffer id, and are written into the already-setup area of the request thread when responding an IPC request.

This fixes a regression (crash) introduced in #2992.

This PR introduces more warnings due to the [[deprecated]] attribute being added to void PushStaticBuffer(VAddr buffer_vaddr, size_t size, u8 buffer_id); and VAddr PopStaticBuffer(size_t* data_size);
2017-11-12 11:00:00 -05:00
Subv
c68adb787b Kernel/Arbiters: When doing ArbitrateAddress(Signal), always pick the highest priority thread, using the first one that was put to sleep if more than one thread with the same highest priority exists.
This is consistent with hardware behavior as shown by this test https://gist.github.com/ds84182/40e46129bd38b46a5100f15f96ba5eaf
2017-11-08 18:47:08 -05:00
Subv
06a2e0b591 Kernel/Sessions: Wake up any threads waiting on a ServerSession when its client is closed
The error code 0xC920181A will be returned by svcReplyAndReceive when the wakeup callback runs.
This lets LLE services be properly notified of clients closing the connection so they can end their handler threads instead of letting them linger indefinitely, taking up connection slots in their parent port.
2017-11-06 23:07:08 -05:00
Subv
2d9e295e07 Kernel/IPC: Handle the StaticBuffer descriptor in LLE command requests.
This descriptor requires the target process to set up a "receive buffer" beforehand, where the input data will be written to when the descriptor is processed.
2017-11-06 13:30:31 -05:00
Subv
980df62397 Kernel/Thread: Run the main thread in the CPU specified by the process' exheader.
System services usually have Core1 in this field, but citra was running them in Core0 regardless.
2017-11-06 13:14:31 -05:00
Sebastian Valle
d55a13c35d
Merge pull request #2981 from Subv/replyreceive
Kernel/SVC: Implement LLE command buffer translation in ReplyAndReceive
2017-11-06 13:02:30 -05:00
Subv
23deae4785 Debugging: Implement GetName for Kernel::ServerSession.
Fixes the "[UNKNOWN KERNEL OBJECT]" message in the wait tree when inspecting a server session.
2017-11-06 10:47:06 -05:00
Subv
8f108367c9 Kernel/IPC: Put a thread to sleep when performing an LLE IPC request.
It will be awoken when the server replies to the request via svcReplyAndReceive.
2017-11-06 10:46:19 -05:00
Subv
33c5982f6d Kernel/Threads: Added a new thread status to identify threads waiting for an IPC reply from svcSendSyncRequest. 2017-11-06 10:46:19 -05:00
Subv
8e2d9f48f5 Kernel/IPC: Remove dead buffer translation code.
This is all implemented elsewhere, HLERequestContext for HLE requests, and svcReplyAndReceive for LLE requests.
2017-11-06 10:46:18 -05:00
Subv
7cf7999e02 Kernel/IPC: Added a function to translate the IPC command buffer from one process to another.
Currently only CopyHandle, MoveHandle and CallingPid descriptors are implemented.
2017-11-06 10:46:12 -05:00
wwylele
4fdc877626 remove trailing spaces 2017-11-06 13:57:06 +02:00
Sebastian Valle
ff17773c28
Kernel/Mutex: Add a missing return in Mutex::Release
Fixes a regression in #3042.
Closes #3079
2017-11-05 21:31:22 -05:00
Weiyi Wang
4fc0448093
Merge pull request #3064 from wwylele/printf-warnings
Clean all format warnings
2017-11-05 10:32:46 +02:00
Subv
68dba11805 Kernel/SVC: Don't let svcReleaseMutex release a mutex owned by another thread.
This behavior was reverse engineered from the 3DS kernel.
2017-11-04 10:05:18 -05:00
wwylele
499508389c core: clear format warnings 2017-11-01 12:35:32 +02:00
bunnei
15c7641bef Merge pull request #2977 from Subv/shmem_create
SharedMemory: Don't take over and unmap the source memory block when creating a shared memory, just reference it
2017-10-03 16:21:49 -04:00
Subv
b18589ecf7 Kernel/SharedMemory: Don't take over and unmap the source memory block when creating a shared memory, just reference it.
Also reference the right offset into the backing block for the requested address.
2017-10-02 15:16:16 -05:00
Sebastian Valle
30fabc41c6 Merge pull request #2971 from Subv/per_process_memops
Memory: Add overloads for ReadBlock and WriteBlock that operate on a specific process.
2017-10-01 14:44:06 -05:00
Subv
8217ed7acb Kernel/Thread: Added a helper function to get a thread's command buffer VAddr. 2017-10-01 14:18:35 -05:00
Subv
0a308e224c Kernel/Threads: Add a new thread status that will allow using a Kernel::Event to put a guest thread to sleep inside an HLE handler until said event is signaled. 2017-09-30 11:16:49 -05:00
Sebastian Valle
db752b52e8 Merge pull request #2967 from Subv/thread_wakeup_callbacks
Kernel/Threads: When putting a thread to wait, specify a function to execute when it is awoken
2017-09-30 09:12:18 -05:00
Huw Pascoe
a13ab958cb Fixed type conversion ambiguity 2017-09-30 09:34:35 +01:00
Subv
8432749db7 Kernel/Threads: When putting a thread to wait, specify a function to execute when it is awoken.
This change makes for a clearer (less confusing) path of execution in the scheduler, now the code to execute when a thread awakes is closer to the code that puts the thread to sleep (WaitSynch1, WaitSynchN). It also allows us to implement the special wake up behavior of ReplyAndReceive without hacking up WaitObject::WakeupAllWaitingThreads.

If savestates are desired in the future, we can change this implementation to one similar to the CoreTiming event system, where we first register the callback functions at startup and assign their identifiers to the Thread callback variable instead of directly assigning a lambda to the wake up callback variable.
2017-09-28 11:53:32 -05:00
Subv
3165466b66 Kernel/Thread: Allow specifying which process a thread belongs to when creating it.
Don't automatically assume that Thread::Create will only be called when the parent process is currently scheduled. This assumption will be broken when applets or system modules are loaded.
2017-09-26 17:40:49 -05:00
MerryMage
c02bbb7030 memory: Add GetCurrentPageTable/SetCurrentPageTable
Don't expose Memory::current_page_table as a global.
2017-09-24 22:42:42 +01:00
B3n30
813837c5cf Merge pull request #2842 from Subv/switchable_page_table
Kernel/Memory: Give each process its own page table and allow switching the current page table upon reschedule
2017-09-15 22:41:45 +02:00
Subv
b178089251 Kernel/Threads: Don't clear the CPU instruction cache when performing a context switch from an idle thread into a thread in the same process.
We were unnecessarily clearing the cache when going from Process A -> Idle -> Process A, this caused extreme performance regressions.
2017-09-15 14:26:15 -05:00
Subv
214150f00c Kernel/Memory: Changed GetPhysicalPointer so that it doesn't go through the current process' page table to obtain a pointer. 2017-09-15 14:26:13 -05:00
Subv
c34ec5e77c Kernel/Memory: Switch the current page table when a new process is scheduled. 2017-09-10 15:14:31 -05:00
Subv
6d2734a074 Kernel/Memory: Give each Process its own page table.
The loader is in charge of setting the newly created process's page table as the main one during the loading process.
2017-09-10 15:13:41 -05:00
James Rowe
61442d6afb Merge pull request #2839 from Subv/global_kernel_lock
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).
2017-08-23 18:17:44 -06:00
bunnei
2bbff9fa96 Merge pull request #2893 from Subv/not_schedule_main_thread
Kernel/Threads: Don't immediately switch to the new main thread when loading a new process.
2017-08-22 17:45:47 -04:00
Subv
bca8916cea 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
Subv
fa228ca637 Kernel/Threads: Don't immediately switch to the new main thread when loading a new process.
This is necessary for loading multiple processes at the same time.
The main thread will be automatically scheduled when necessary once the scheduler runs.
2017-08-21 20:54:29 -05:00
Subv
65f19b51c4 Warnings: Add UNREACHABLE macros to switches that contemplate all possible values. 2017-08-21 08:34:28 -05:00
Weiyi Wang
045d0b5bbd Merge pull request #2799 from yuriks/virtual-cached-range-flush
Add address conversion functions returning optional, Add function to flush virtual region from rasterizer cache
2017-07-22 10:15:52 +03:00
Sebastian Valle
56d718b2a1 Merge pull request #2793 from Subv/replyandreceive
Kernel/SVC: Partially implemented svcReplyAndReceive
2017-06-29 17:05:22 -05:00
Subv
b53fa9514f Kernel/SVC: Pass the current thread as a parameter to ClientSession::SendSyncRequest. 2017-06-29 12:30:34 -05:00
Subv
c3c9175a1c Kernel/Sessions: Clean up the list of pending request threads of a session when the client endpoint is closed. 2017-06-25 23:38:29 -05:00
Subv
8feeb81af2 Kernel/ServerSession: Keep track of which threads have issued sync requests. 2017-06-25 14:47:25 -05:00
Yuri Kunde Schlesner
e192d417ec Kernel: Implement AcceptSession SVC 2017-06-23 11:26:37 -07:00
Yuri Kunde Schlesner
326e7c7020 Memory: Make PhysicalToVirtualAddress return a boost::optional
And fix a few places in the code to take advantage of that.
2017-06-21 22:55:17 -07:00
Yuri Kunde Schlesner
f64d0b3f26 Kernel/IPC: Support translation of null handles
Missed this in my first implementation. Thanks to @wwylele for pointing
out that this was missing.
2017-06-21 14:27:03 -07:00
Weiyi Wang
c4f0927a62 Merge pull request #2789 from yuriks/misc-kernel
Trivial no-op additions
2017-06-21 20:34:12 +03:00
Yuri Kunde Schlesner
b21dfbb295 Merge pull request #2790 from yuriks/remove-movefrom
Remove ResultVal::MoveFrom
2017-06-20 22:04:09 -07:00
Yuri Kunde Schlesner
723dc644fa ResultVal: Remove MoveFrom()
Replace it with std::move(result_val).Unwrap(), or Foo().Unwrap() in
case you already have an rvalue.
2017-06-18 19:03:15 -07:00
Yuri Kunde Schlesner
90b8d4dd36 Kernel: Add comment about the extended linear heap area 2017-06-18 18:38:40 -07:00
Yuri Kunde Schlesner
0dfafdbe59 Kernel/IPC: Make HLERequestContext usable from outside kernel 2017-06-18 16:05:12 -07:00
Yuri Kunde Schlesner
d8f6000f54 Kernel/IPC: Use boost::small_vector for HLE context objects 2017-06-11 16:34:13 -07:00
Yuri Kunde Schlesner
92ca422088 Kernel: Allow clearing request_objects to re-use buffer space
Reduces the necessary allocation to max(in_handles, out_handles) rather
than (in_handles + out_handles).
2017-06-11 13:10:21 -07:00
Yuri Kunde Schlesner
8cb65fe65a Kernel: Basic support for IPC translation for HLE services 2017-06-11 13:10:21 -07:00
Yuri Kunde Schlesner
05fee70211 Kernel: Add methods in HLERequestContext abstracting handle creation 2017-06-11 13:07:33 -07:00
Yuri Kunde Schlesner
20e5abb308 ServiceFramework: Use separate copy of command buffer
Copy the IPC command buffer to/from the request context before/after the
handler is invoked. This is part of a move away from using global data
for handling IPC requests.
2017-06-11 13:07:33 -07:00
Yuri Kunde Schlesner
78398d0978 Merge pull request #2756 from yuriks/service-framework
New service framework
2017-06-08 21:03:03 -07:00
Yuri Kunde Schlesner
838faf147e Session: Remove/add some forward declarations 2017-06-08 00:33:57 -07:00
Yuri Kunde Schlesner
d666e01cdf Kernel: Ensure objects are kept alive during ClientSession disconnection
Fixes #2760
2017-06-08 00:33:24 -07:00
Yuri Kunde Schlesner
84c497292a Service: Add new ServiceFramework framework for writing HLE services
The old "Interface" class had a few problems such as using free
functions (Which didn't allow you to write the service handler as if it
were a regular class.) which weren't very extensible. (Only received one
parameter with a pointer to the Interface object.)

The new ServiceFramework aims to solve these problems by working with
member functions and passing a generic context struct as parameter. This
struct can be extended in the future without having to update all
existing service implementations.
2017-06-08 00:11:37 -07:00
Yuri Kunde Schlesner
6dc133c24a Kernel: Remove some unnecessary namespace qualifications 2017-06-06 14:51:42 -07:00
Yuri Kunde Schlesner
6354d08359 Kernel: Add a dedicated SetHleHandler method to ServerPort/ServerSession
This allows attaching a HLE handle to a ServerPort at any point after it
is created, allowing port/session creation to be generic between HLE and
regular services.
2017-06-06 02:56:32 -07:00
Yuri Kunde Schlesner
e626a520ca HLE: Move SessionRequestHandler from Service:: to Kernel::
Most of the code that works with this is or will be in the kernel, so
it's a more appropriate place for it to be.
2017-06-05 23:40:11 -07:00
Yuri Kunde Schlesner
be031989ee Kernel: Move HandleTable to a separate file 2017-05-29 17:34:39 -07:00
Yuri Kunde Schlesner
64ecf81a3c 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
9453223075 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
b17754f998 Kernel: Extract dynamic Object pointer cast into its own function 2017-05-29 14:42:27 -07:00
Yuri Kunde Schlesner
2cdb40d709 Kernel: Centralize error definitions in errors.h 2017-05-24 21:06:00 -07:00
Yuri Kunde Schlesner
cc566dadd8 Merge pull request #2406 from Subv/session_disconnect
Kernel: Properly update port counters on session disconnection.
2017-05-21 17:18:16 -07:00
Subv
37347bfa38 Kernel/Sessions: Remove the ClientSession::Create function.
It is not meant to be used by anything other than CreateSessionPair.
2017-05-21 18:52:42 -05:00
Subv
ce5bc477ca Kernel: Remove a now unused enum and variable regarding a session's status. 2017-05-15 11:22:16 -05:00
Subv
ddfabf3133 Kernel: Use a Session object to keep track of the status of a Client/Server session pair.
Reduce the associated port's connection count when a ServerSession is destroyed.
2017-05-15 11:22:15 -05:00
Yuri Kunde Schlesner
f18d454eb6 Kernel: Map special regions according to ExHeader
This replaces the hardcoded VRAM/DSP mappings with ones made based on
the ExHeader ARM11 Kernel caps list. While this has no visible effect
for most applications (since they use a standard set of mappings) it
does improve support for system modules and n3DS exclusives.
2017-05-09 21:44:00 -07:00
Yuri Kunde Schlesner
b4a93cfdde DSP: Create backing memory for entire DSP RAM
Also move address space mapping out of video_core.
2017-05-09 21:44:00 -07:00
wwylele
85ba60d5ec Timer: restore missing signaled=true from #2421 2017-02-27 22:49:46 +02:00
B3n30
dcf115778a Fix log entry in timer::signal (#2600) 2017-02-27 11:04:03 -05:00
Mat M
0cb52ee74a Doxygen: Amend minor issues (#2593)
Corrects a few issues with regards to Doxygen documentation, for example:

- Incorrect parameter referencing.
- Missing @param tags.
- Typos in @param tags.

and a few minor other issues.
2017-02-26 17:58:51 -08:00
Yuri Kunde Schlesner
b250ce21b9 Merge pull request #2587 from yuriks/status-bar
Replace built-in Profiler with indicators in status bar
2017-02-26 17:51:15 -08:00
Yuri Kunde Schlesner
441f8b5a4b Core: Remove unnecessary include in thread.h 2017-02-26 17:22:01 -08:00
Subv
029a11030e Timers: Immediately signal the timer if it was started with an initial value of 0. 2017-02-21 20:51:54 -05:00
Subv
1ddff14511 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
f2f2572fed Thread: Added priority range checking to svcSetThreadPriority and removed priority clamping code from Thread::SetPriority. 2017-01-11 16:38:04 -05:00
bunnei
84d72fd92f Merge pull request #2397 from Subv/pulse
Kernel: Implemented Pulse event and timers.
2017-01-10 10:45:00 -05:00
bunnei
b5eac78b43 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
bunnei
59f4f1d7ff Merge pull request #2396 from Subv/sema_acquire
Kernel/Semaphore: Fixed a regression in semaphore waits.
2017-01-06 22:00:12 -05:00
bunnei
1c792389e6 Merge pull request #2408 from Subv/priority_boosting
Kernel: Removed the priority boost code for starved threads.
2017-01-06 00:40:39 -05:00
Subv
fc2266130b 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
5e2a8ebabf Kernel: Remove some unused functions. 2017-01-05 13:17:06 -05:00
Subv
933df2606a Kernel: Removed the priority boost code for starved threads.
After hwtesting and reverse engineering the kernel, it was found that the CTROS scheduler performs no priority boosting for threads like this, although some other forms of scheduling priority-starved threads might take place.

For example, it was found that hardware interrupts might cause low-priority threads to run if the CPU is preempted in the middle of an SVC handler that deschedules the current (high priority) thread before scheduling it again.
2017-01-05 13:12:39 -05:00
Subv
e52ca85711 Kernel: Implemented Pulse event and timers.
Closes #1904
2017-01-05 13:06:17 -05:00
Subv
4251eb26ec Kernel/Semaphore: Fixed a regression in semaphore waits.
The regression was caused by a missing check in #2260.

The new behavior is consistent with the real kernel.
2017-01-05 13:00:05 -05:00
Subv
dda4ec93be Kernel: Add some asserts to enforce the invariants in the scheduler. 2017-01-05 09:40:18 -05:00
Subv
7f1dca8cd2 Kernel: Remove a thread from all of its waiting objects' waiting_threads list when it is awoken.
This fixes a potential bug where threads would not get removed from said list if they awoke after waiting with WaitSynchronizationN with wait_all = false
2017-01-05 09:40:15 -05:00
Subv
fd95b6ee26 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
cef5f45de2 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
d3ff5b91e1 Kernel/Mutex: Propagate thread priority changes to other threads inheriting the priority via mutexes 2017-01-04 15:58:48 -05:00
Subv
b6a0355568 Kernel/Mutex: Update a mutex priority when a thread stops waiting on it. 2017-01-04 15:58:47 -05:00
Subv
7abf185390 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
e6a7723f2f 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
38a90882a4 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
8b1e269e58 ThreadContext: Move from "core" to "arm_interface". 2016-12-22 00:27:49 -05:00