From 21f69bfa573ccb78d8b7ef07f25680970cd1a5fc Mon Sep 17 00:00:00 2001 From: fincs Date: Sat, 15 Dec 2018 18:11:35 +0100 Subject: [PATCH] Add, document, and use MAX_WAIT_OBJECTS --- nx/include/switch/kernel/svc.h | 4 ++++ nx/include/switch/kernel/wait.h | 4 ++-- nx/source/kernel/wait.c | 4 +--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/nx/include/switch/kernel/svc.h b/nx/include/switch/kernel/svc.h index 932d474b..f3b0823f 100644 --- a/nx/include/switch/kernel/svc.h +++ b/nx/include/switch/kernel/svc.h @@ -13,6 +13,9 @@ /// Pseudo handle for the current thread. #define CUR_THREAD_HANDLE 0xFFFF8000 +/// Maximum number of objects that can be waited on by \ref svcWaitSynchronization (Horizon kernel limitation). +#define MAX_WAIT_OBJECTS 0x40 + /// Memory type enumeration (lower 8 bits of \ref MemoryState) typedef enum { MemType_Unmapped=0x00, ///< Unmapped memory. @@ -362,6 +365,7 @@ Result svcResetSignal(Handle handle); * @brief Waits on one or more synchronization objects, optionally with a timeout. * @return Result code. * @note Syscall number 0x18. + * @note \p handleCount must not be greater than \ref MAX_WAIT_OBJECTS. This is a Horizon kernel limitation. * @note Please use \ref waitMultiHandle instead. That function handles sporadical interrupts caused by usermode synchronization primitives. */ Result svcWaitSynchronization(s32* index, const Handle* handles, s32 handleCount, u64 timeout); diff --git a/nx/include/switch/kernel/wait.h b/nx/include/switch/kernel/wait.h index 1b8f34e5..42d17d9c 100644 --- a/nx/include/switch/kernel/wait.h +++ b/nx/include/switch/kernel/wait.h @@ -58,7 +58,7 @@ Result waitNHandle(s32* idx_out, Handle* handles, size_t num_handles, u64 timeou * @brief Waits for an arbitrary number of waiters. This is a macro that uses var-args. * @param[out] idx_out The index of the signalled waiter. * @param[in] timeout Timeout (in nanoseconds). - * @note The number of waiters must be less than 64. This is a Horizon kernel limitation. + * @note The number of objects must not be greater than \ref MAX_WAIT_OBJECTS. This is a Horizon kernel limitation. */ #define waitMulti(idx_out, timeout, ...) \ waitN((idx_out), (Waiter[]) { __VA_ARGS__ }, sizeof((Waiter[]) { __VA_ARGS__ }) / sizeof(Waiter), (timeout)) @@ -67,7 +67,7 @@ Result waitNHandle(s32* idx_out, Handle* handles, size_t num_handles, u64 timeou * @brief Waits for an arbitrary number of handles. This is a macro that uses var-args. * @param[out] idx_out The index of the signalled handle. * @param[in] timeout Timeout (in nanoseconds). - * @note The number of handles must be less than 64. This is a Horizon kernel limitation. + * @note The number of objects must not be greater than \ref MAX_WAIT_OBJECTS. This is a Horizon kernel limitation. */ #define waitMultiHandle(idx_out, timeout, ...) \ waitNHandle((idx_out), (Handle[]) { __VA_ARGS__ }, sizeof((Handle[]) { __VA_ARGS__ }) / sizeof(Handle), (timeout)) diff --git a/nx/source/kernel/wait.c b/nx/source/kernel/wait.c index b6beee62..46210d40 100644 --- a/nx/source/kernel/wait.c +++ b/nx/source/kernel/wait.c @@ -8,13 +8,11 @@ #include "wait.h" #include "../internal.h" -#define MAX_WAIT 0x40 - typedef Result (*WaitImplFunc)(s32* idx_out, void* objects, size_t num_objects, u64 timeout); static Result waitImpl(s32* idx_out, Waiter* objects, size_t num_objects, u64 timeout) { - if (num_objects > MAX_WAIT) + if (num_objects > MAX_WAIT_OBJECTS) return KERNELRESULT(OutOfRange); // same error returned by kernel Handle own_thread_handle = getThreadVars()->handle;