diff options
| author | 2023-07-02 17:38:14 -0400 | |
|---|---|---|
| committer | 2023-07-02 17:38:14 -0400 | |
| commit | daaf03942fb7a3d484941f8b5a09a6349be4b0c0 (patch) | |
| tree | 4a35aff5a9cfa9896762b609720bdc30a0af4785 /src/core/hle/kernel/svc | |
| parent | Merge pull request #10949 from t895/memory-requirements (diff) | |
| parent | kernel: Synchronize (diff) | |
| download | yuzu-daaf03942fb7a3d484941f8b5a09a6349be4b0c0.tar.gz yuzu-daaf03942fb7a3d484941f8b5a09a6349be4b0c0.tar.xz yuzu-daaf03942fb7a3d484941f8b5a09a6349be4b0c0.zip | |
Merge pull request #10969 from Morph1984/k-synchronize
kernel: Synchronize
Diffstat (limited to 'src/core/hle/kernel/svc')
| -rw-r--r-- | src/core/hle/kernel/svc/svc_ipc.cpp | 37 | ||||
| -rw-r--r-- | src/core/hle/kernel/svc/svc_synchronization.cpp | 41 |
2 files changed, 42 insertions, 36 deletions
diff --git a/src/core/hle/kernel/svc/svc_ipc.cpp b/src/core/hle/kernel/svc/svc_ipc.cpp index 60247df2e..bb94f6934 100644 --- a/src/core/hle/kernel/svc/svc_ipc.cpp +++ b/src/core/hle/kernel/svc/svc_ipc.cpp | |||
| @@ -38,22 +38,31 @@ Result SendAsyncRequestWithUserBuffer(Core::System& system, Handle* out_event_ha | |||
| 38 | 38 | ||
| 39 | Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_addr, s32 num_handles, | 39 | Result ReplyAndReceive(Core::System& system, s32* out_index, uint64_t handles_addr, s32 num_handles, |
| 40 | Handle reply_target, s64 timeout_ns) { | 40 | Handle reply_target, s64 timeout_ns) { |
| 41 | // Ensure number of handles is valid. | ||
| 42 | R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange); | ||
| 43 | |||
| 44 | // Get the synchronization context. | ||
| 41 | auto& kernel = system.Kernel(); | 45 | auto& kernel = system.Kernel(); |
| 42 | auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); | 46 | auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); |
| 43 | 47 | auto objs = GetCurrentThread(kernel).GetSynchronizationObjectBuffer(); | |
| 44 | R_UNLESS(0 <= num_handles && num_handles <= ArgumentHandleCountMax, ResultOutOfRange); | 48 | auto handles = GetCurrentThread(kernel).GetHandleBuffer(); |
| 45 | R_UNLESS(GetCurrentMemory(kernel).IsValidVirtualAddressRange( | 49 | |
| 46 | handles_addr, static_cast<u64>(sizeof(Handle) * num_handles)), | 50 | // Copy user handles. |
| 47 | ResultInvalidPointer); | 51 | if (num_handles > 0) { |
| 48 | 52 | // Ensure we can try to get the handles. | |
| 49 | std::array<Handle, Svc::ArgumentHandleCountMax> handles; | 53 | R_UNLESS(GetCurrentMemory(kernel).IsValidVirtualAddressRange( |
| 50 | GetCurrentMemory(kernel).ReadBlock(handles_addr, handles.data(), sizeof(Handle) * num_handles); | 54 | handles_addr, static_cast<u64>(sizeof(Handle) * num_handles)), |
| 51 | 55 | ResultInvalidPointer); | |
| 52 | // Convert handle list to object table. | 56 | |
| 53 | std::array<KSynchronizationObject*, Svc::ArgumentHandleCountMax> objs; | 57 | // Get the handles. |
| 54 | R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(objs.data(), handles.data(), | 58 | GetCurrentMemory(kernel).ReadBlock(handles_addr, handles.data(), |
| 55 | num_handles), | 59 | sizeof(Handle) * num_handles); |
| 56 | ResultInvalidHandle); | 60 | |
| 61 | // Convert the handles to objects. | ||
| 62 | R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>( | ||
| 63 | objs.data(), handles.data(), num_handles), | ||
| 64 | ResultInvalidHandle); | ||
| 65 | } | ||
| 57 | 66 | ||
| 58 | // Ensure handles are closed when we're done. | 67 | // Ensure handles are closed when we're done. |
| 59 | SCOPE_EXIT({ | 68 | SCOPE_EXIT({ |
diff --git a/src/core/hle/kernel/svc/svc_synchronization.cpp b/src/core/hle/kernel/svc/svc_synchronization.cpp index 53df5bcd8..f02d03f30 100644 --- a/src/core/hle/kernel/svc/svc_synchronization.cpp +++ b/src/core/hle/kernel/svc/svc_synchronization.cpp | |||
| @@ -47,21 +47,35 @@ Result ResetSignal(Core::System& system, Handle handle) { | |||
| 47 | R_THROW(ResultInvalidHandle); | 47 | R_THROW(ResultInvalidHandle); |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | static Result WaitSynchronization(Core::System& system, int32_t* out_index, const Handle* handles, | 50 | /// Wait for the given handles to synchronize, timeout after the specified nanoseconds |
| 51 | int32_t num_handles, int64_t timeout_ns) { | 51 | Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_handles, |
| 52 | int32_t num_handles, int64_t timeout_ns) { | ||
| 53 | LOG_TRACE(Kernel_SVC, "called user_handles={:#x}, num_handles={}, timeout_ns={}", user_handles, | ||
| 54 | num_handles, timeout_ns); | ||
| 55 | |||
| 52 | // Ensure number of handles is valid. | 56 | // Ensure number of handles is valid. |
| 53 | R_UNLESS(0 <= num_handles && num_handles <= Svc::ArgumentHandleCountMax, ResultOutOfRange); | 57 | R_UNLESS(0 <= num_handles && num_handles <= Svc::ArgumentHandleCountMax, ResultOutOfRange); |
| 54 | 58 | ||
| 55 | // Get the synchronization context. | 59 | // Get the synchronization context. |
| 56 | auto& kernel = system.Kernel(); | 60 | auto& kernel = system.Kernel(); |
| 57 | auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); | 61 | auto& handle_table = GetCurrentProcess(kernel).GetHandleTable(); |
| 58 | std::array<KSynchronizationObject*, Svc::ArgumentHandleCountMax> objs; | 62 | auto objs = GetCurrentThread(kernel).GetSynchronizationObjectBuffer(); |
| 63 | auto handles = GetCurrentThread(kernel).GetHandleBuffer(); | ||
| 59 | 64 | ||
| 60 | // Copy user handles. | 65 | // Copy user handles. |
| 61 | if (num_handles > 0) { | 66 | if (num_handles > 0) { |
| 67 | // Ensure we can try to get the handles. | ||
| 68 | R_UNLESS(GetCurrentMemory(kernel).IsValidVirtualAddressRange( | ||
| 69 | user_handles, static_cast<u64>(sizeof(Handle) * num_handles)), | ||
| 70 | ResultInvalidPointer); | ||
| 71 | |||
| 72 | // Get the handles. | ||
| 73 | GetCurrentMemory(kernel).ReadBlock(user_handles, handles.data(), | ||
| 74 | sizeof(Handle) * num_handles); | ||
| 75 | |||
| 62 | // Convert the handles to objects. | 76 | // Convert the handles to objects. |
| 63 | R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>(objs.data(), handles, | 77 | R_UNLESS(handle_table.GetMultipleObjects<KSynchronizationObject>( |
| 64 | num_handles), | 78 | objs.data(), handles.data(), num_handles), |
| 65 | ResultInvalidHandle); | 79 | ResultInvalidHandle); |
| 66 | } | 80 | } |
| 67 | 81 | ||
| @@ -80,23 +94,6 @@ static Result WaitSynchronization(Core::System& system, int32_t* out_index, cons | |||
| 80 | R_RETURN(res); | 94 | R_RETURN(res); |
| 81 | } | 95 | } |
| 82 | 96 | ||
| 83 | /// Wait for the given handles to synchronize, timeout after the specified nanoseconds | ||
| 84 | Result WaitSynchronization(Core::System& system, int32_t* out_index, u64 user_handles, | ||
| 85 | int32_t num_handles, int64_t timeout_ns) { | ||
| 86 | LOG_TRACE(Kernel_SVC, "called user_handles={:#x}, num_handles={}, timeout_ns={}", user_handles, | ||
| 87 | num_handles, timeout_ns); | ||
| 88 | |||
| 89 | // Ensure number of handles is valid. | ||
| 90 | R_UNLESS(0 <= num_handles && num_handles <= Svc::ArgumentHandleCountMax, ResultOutOfRange); | ||
| 91 | std::array<Handle, Svc::ArgumentHandleCountMax> handles; | ||
| 92 | if (num_handles > 0) { | ||
| 93 | GetCurrentMemory(system.Kernel()) | ||
| 94 | .ReadBlock(user_handles, handles.data(), num_handles * sizeof(Handle)); | ||
| 95 | } | ||
| 96 | |||
| 97 | R_RETURN(WaitSynchronization(system, out_index, handles.data(), num_handles, timeout_ns)); | ||
| 98 | } | ||
| 99 | |||
| 100 | /// Resumes a thread waiting on WaitSynchronization | 97 | /// Resumes a thread waiting on WaitSynchronization |
| 101 | Result CancelSynchronization(Core::System& system, Handle handle) { | 98 | Result CancelSynchronization(Core::System& system, Handle handle) { |
| 102 | LOG_TRACE(Kernel_SVC, "called handle=0x{:X}", handle); | 99 | LOG_TRACE(Kernel_SVC, "called handle=0x{:X}", handle); |