aboutsummaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/svc.cpp
AgeCommit message (Collapse)Author
2018-12-29Merge pull request #1847 from ogniK5377/backtrace-breakbunnei
Print backtrace on svcBreak
2018-12-27kernel: Rename 'default' CPU core to 'ideal' coreLioncash
This makes the naming more closely match its meaning. It's just a preferred core, not a required default core. This also makes the usages of this term consistent across the thread and process implementations.
2018-12-27kernel/process: Remove most allocation functions from Process' interfaceLioncash
In all cases that these functions are needed, the VMManager can just be retrieved and used instead of providing the same functions in Process' interface. This also makes it a little nicer dependency-wise, since it gets rid of cases where the VMManager interface was being used, and then switched over to using the interface for a Process instance. Instead, it makes all accesses uniform and uses the VMManager instance for all necessary tasks. All the basic memory mapping functions did was forward to the Process' VMManager instance anyways.
2018-12-26Merge pull request #1849 from encounter/svcSetThreadActivitybunnei
svc: Implement SetThreadActivity (thread suspension)
2018-12-21Merge pull request #1925 from lioncash/pidbunnei
kernel/{process, thread}: Amend behavior related to IDs
2018-12-19kernel/svc: Handle thread handles within GetProcessIdLioncash
If a thread handle is passed to svcGetProcessId, the kernel attempts to access the process ID via the thread's instance's owning process. Technically, this function should also be handling the kernel debug objects as well, however we currently don't handle those kernel objects yet, so I've left a note via a comment about it to remind myself when implementing it in the future.
2018-12-19svc: Implement svcSetMemoryAttributeLioncash
With all the basic backing functionality implemented, we can now unstub svcSetMemoryAttribute.
2018-12-18kernel/svc: Correct output parameter for svcGetThreadIdLioncash
The service call uses a 64-bit value, just like svcGetProcessId. This amends the function signature accordingly.
2018-12-18kernel/svc: Correct output parameter for svcGetProcessIdLioncash
svcGetProcessId's out parameter is a pointer to a 64-bit value, not a 32-bit one.
2018-12-19Moved backtrace to ArmInterfaceDavid Marcec
2018-12-15Merge pull request #1732 from DarkLordZach/yield-typesbunnei
svc: Implement yield types 0 and -1
2018-12-14Merge pull request #1899 from lioncash/statebunnei
vm_manager/svc: Modify MemoryState enum, and correct error handling for svcQueryMemory
2018-12-12svc: Enable svcQueryProcessMemoryLioncash
svcQueryProcessMemory is trivial to implement, given all the behavior necessary for it is present, it just needs a handler for it.
2018-12-12svc: Write out the complete MemoryInfo structure in QueryProcessMemoryLioncash
In the previous change, the memory writing was moved into the service function itself, however it still had a problem, in that the entire MemoryInfo structure wasn't being written out, only the first 32 bytes of it were being written out. We still need to write out the trailing two reference count members and zero out the padding bits. Not doing this can result in wrong behavior in userland code in the following scenario: MemoryInfo info; // Put on the stack, not quaranteed to be zeroed out. svcQueryMemory(&info, ...); if (info.device_refcount == ...) // Whoops, uninitialized read. This can also cause the wrong thing to happen if the user code uses std::memcmp to compare the struct, with another one (questionable, but allowed), as the padding bits are not guaranteed to be a deterministic value. Note that the kernel itself also fully zeroes out the structure before writing it out including the padding bits.
2018-12-12svc: Handle memory writing explicitly within QueryProcessMemoryLioncash
Moves the memory writes directly into QueryProcessMemory instead of letting the wrapper function do it. It would be inaccurate to allow the handler to do it because there's cases where memory shouldn't even be written to. For example, if the given process handle is invalid. HOWEVER, if the memory writing is within the wrapper, then we have no control over if these memory writes occur, meaning in an error case, 68 bytes of memory randomly get trashed with zeroes, 64 of those being written to wherever the memory info address points to, and the remaining 4 being written wherever the page info address points to. One solution in this case would be to just conditionally check within the handler itself, but this is kind of smelly, given the handler shouldn't be performing conditional behavior itself, it's a behavior of the managed function. In other words, if you remove the handler from the equation entirely, does the function still retain its proper behavior? In this case, no. Now, we don't potentially trash memory from this function if an invalid query is performed.
2018-12-12vm_manager: Migrate memory querying to the VMManager interfaceLioncash
Gets rid of the need to directly access the managed VMAs outside of the memory manager itself just for querying memory.
2018-12-12vm_manager: Amend MemoryState enum membersLioncash
Amends the MemoryState enum to use the same values like the actual kernel does. Also provides the necessary operators to operate on them. This will be necessary in the future for implementing svcSetMemoryAttribute, as memory block state is checked before applying the attribute.
2018-12-12Fix Process object leak on emulation stopJens Schmer
The Process object kept itself alive indefinitely because its handle_table contains a SharedMemory object which owns a reference to the same Process object, creating a circular ownership scenario. Break that up by storing only a non-owning pointer in the SharedMemory object.
2018-12-10Merge pull request #1876 from lioncash/vmabunnei
vm_manager: Make vma_map private
2018-12-06vm_manager: Make vma_map privateLioncash
This was only ever public so that code could check whether or not a handle was valid or not. Instead of exposing the object directly and allowing external code to potentially mess with the map contents, we just provide a member function that allows checking whether or not a handle is valid. This makes all member variables of the VMManager class private except for the page table.
2018-12-04svc: Avoid incorrect fast yield conditionZach Hilman
2018-12-04kernel/svc: Correct behavior of svcResetSignal()Lioncash
While partially correct, this service call allows the retrieved event to be null, as it also uses the same handle to check if it was referring to a Process instance. The previous two changes put the necessary machinery in place to allow for this, so we can simply call those member functions here and be done with it.
2018-12-04kernel/svc: Remove unused header inclusionLioncash
2018-12-04kernel/svc: Implement svcSignalEvent()Lioncash
This function simply does a handle table lookup for a writable event instance identified by the given handle value. If a writable event cannot be found for the given handle, then an invalid handle error is returned. If a writable event is found, then it simply signals the event, as one would expect.
2018-12-04kernel/svc: Implement svcCreateEvent()Lioncash
svcCreateEvent operates by creating both a readable and writable event and then attempts to add both to the current process' handle table. If adding either of the events to the handle table fails, then the relevant error from the handle table is returned. If adding the readable event after the writable event to the table fails, then the writable event is removed from the handle table and the relevant error from the handle table is returned. Note that since we do not currently test resource limits, we don't check the resource limit table yet.
2018-12-04Merge pull request #1853 from lioncash/eventbunnei
kernel/object: Amend handle types to distinguish between readable and writable events
2018-12-04kernel/object: Amend handle types to distinguish between readable and ↵Lioncash
writable events Two kernel object should absolutely never have the same handle ID type. This can cause incorrect behavior when it comes to retrieving object types from the handle table. In this case it allows converting a WritableEvent into a ReadableEvent and vice-versa, which is undefined behavior, since the object types are not the same. This also corrects ClearEvent() to check both kernel types like the kernel itself does.
2018-12-04kernel/svc: Implement the resource limit svcGetInfo optionLioncash
Allows a process to register the resource limit as part of its handle table.
2018-12-04svc: Implement SetThreadActivity (thread suspension)Luke Street
2018-12-04[Kernel::CreateThread] Match format specifiers to LOG_TRACE's argumentsV.Kalyuzhny
2018-12-03scheduler: Avoid manual Reschedule callZach Hilman
This will automatically occur anyway when PrepareReschedule is called
2018-12-03Merge pull request #1840 from lioncash/infobunnei
svc: Reorganize svcGetInfo, handle more error cases for existing implemented info categories
2018-12-03scheduler: Only work steal higher priority threads from other coresZach Hilman
2018-12-03Merge pull request #1803 from DarkLordZach/k-able-eventbunnei
kernel: Divide Event into ReadableEvent and WritableEvent
2018-12-03Print backtrace on svcBreakDavid Marcec
When we get an svcBreak we get a backtrace now
2018-12-02svc: Use the current process' handle table for retrieving the process ↵Lioncash
instance to act upon The kernel uses the handle table of the current process to retrieve the process that should be used to retrieve certain information. To someone not familiar with the kernel, this might raise the question of "Ok, sounds nice, but doesn't this make it impossible to retrieve information about the current process?". No, it doesn't, because HandleTable instances in the kernel have the notion of a "pseudo-handle", where certain values allow the kernel to lookup objects outside of a given handle table. Currently, there's only a pseudo-handle for the current process (0xFFFF8001) and a pseudo-handle for the current thread (0xFFFF8000), so to retrieve the current process, one would just pass 0xFFFF8001 into svcGetInfo. The lookup itself in the handle table would be something like: template <typename T> T* Lookup(Handle handle) { if (handle == PSEUDO_HANDLE_CURRENT_PROCESS) { return CurrentProcess(); } if (handle == PSUEDO_HANDLE_CURRENT_THREAD) { return CurrentThread(); } return static_cast<T*>(&objects[handle]); } which, as is shown, allows accessing the current process or current thread, even if those two objects aren't actually within the HandleTable instance.
2018-12-02svc: Reorganize svcGetInfo, handle more error cases for existing implemented ↵Lioncash
info categories Our implementation of svcGetInfo was slightly incorrect in that we weren't doing proper error checking everywhere. Instead, reorganize it to be similar to how the kernel seems to do it.
2018-12-02svc: Avoid performance-degrading unnecessary rescheduleZach Hilman
2018-12-01Fix debug buildLioncash
A non-existent parameter was left in some formatting calls (the logging macro for which only does anything meaningful on debug builds)
2018-11-29kernel/event: Reference ReadableEvent from WritableEventZach Hilman
2018-11-29core: Port all current usages of Event to Readable/WritableEventZach Hilman
2018-11-29Merge pull request #1801 from ogniK5377/log-before-executebunnei
Changed logging to be "Log before execution", Added more error logging, all services/svc should now log on some level
2018-11-26svc: Implement svcSetResourceLimitLimitValue()Lioncash
The opposite of the getter functions, this function sets the limit value for a particular ResourceLimit resource category, with the restriction that the new limit value must be equal to or greater than the current resource value. If this is violated, then ERR_INVALID_STATE is returned. e.g. Assume: current[Events] = 10; limit[Events] = 20; a call to this service function lowering the limit value to 10 would be fine, however, attempting to lower it to 9 in this case would cause an invalid state error.
2018-11-26svc: Implement svcGetResourceLimitCurrentValue()Lioncash
This kernel service function is essentially the exact same as svcGetResourceLimitLimitValue(), with the only difference being that it retrieves the current value for a given resource category using the provided resource limit handle, rather than retrieving the limiting value of that resource limit instance. Given these are exactly the same and only differ on returned values, we can extract the existing code for svcGetResourceLimitLimitValue() to handle both values.
2018-11-26svc: Implement svcGetResourceLimitLimitValue()Lioncash
This kernel service function retrieves the maximum allowable value for a provided resource category for a given resource limit instance. Given we already have the functionality added to the resource limit instance itself, it's sufficient to just hook it up. The error scenarios for this are: 1. If an invalid resource category type is provided, then ERR_INVALID_ENUM is returned. 2. If an invalid handle is provided, then ERR_INVALID_HANDLE is returned (bad thing goes in, bad thing goes out, as one would expect). If neither of the above error cases occur, then the out parameter is provided with the maximum limit value for the given category and success is returned.
2018-11-26svc: Implement svcCreateResourceLimit()Lioncash
This function simply creates a ResourceLimit instance and attempts to create a handle for it within the current process' handle table. If the kernal fails to either create the ResourceLimit instance or create a handle for the ResourceLimit instance, it returns a failure code (OUT_OF_RESOURCE, and HANDLE_TABLE_FULL respectively). Finally, it exits by providing the output parameter with the handle value for the ResourceLimit instance and returning that it was successful. Note: We do not return OUT_OF_RESOURCE because, if yuzu runs out of available memory, then new will currently throw. We *could* allocate the kernel instance with std::nothrow, however this would be inconsistent with how all other kernel objects are currently allocated.
2018-11-27Added comment on Main memory size for more clarityDavid Marcec
2018-11-27Made svcSetHeapSize and svcCreateSharedMemory more readableDavid Marcec
2018-11-27Reworked svcs slightly, improved error messages in AM and fsp_srvDavid Marcec
2018-11-26Improved error messages for SVCsDavid Marcec