From d763a3829ac503eb180e332f5e2687fba2864945 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Tue, 6 Jan 2026 19:40:23 -0500 Subject: [PATCH] semaphore.h: Add SEM_VALUE_MAX. It's specified in POSIX, and FreeBSD puts it in this file. Distinguish it from _POSIX_SEM_VALUE_MAX (which is really a "minimum value this can have" as specified in POSIX.) --- headers/posix/semaphore.h | 3 ++- headers/private/system/posix/realtime_sem_defs.h | 1 - src/system/kernel/posix/realtime_sem.cpp | 2 +- src/system/libroot/posix/unistd/conf.cpp | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/headers/posix/semaphore.h b/headers/posix/semaphore.h index 67216c7a1c..7ec774102f 100644 --- a/headers/posix/semaphore.h +++ b/headers/posix/semaphore.h @@ -21,7 +21,8 @@ typedef struct _sem_t { int32_t padding[2]; } sem_t; -#define SEM_FAILED ((sem_t*)(long)-1) +#define SEM_FAILED ((sem_t*)(long)-1) +#define SEM_VALUE_MAX INT_MAX __BEGIN_DECLS diff --git a/headers/private/system/posix/realtime_sem_defs.h b/headers/private/system/posix/realtime_sem_defs.h index 80b625887c..29f4e2a2d3 100644 --- a/headers/private/system/posix/realtime_sem_defs.h +++ b/headers/private/system/posix/realtime_sem_defs.h @@ -11,7 +11,6 @@ #define MAX_POSIX_SEMS_PER_TEAM _POSIX_SEM_NSEMS_MAX #define MAX_POSIX_SEMS 1024 -#define MAX_POSIX_SEM_VALUE _POSIX_SEM_VALUE_MAX #endif // SYSTEM_REALTIME_SEM_H diff --git a/src/system/kernel/posix/realtime_sem.cpp b/src/system/kernel/posix/realtime_sem.cpp index d78d1b0b34..de53445b82 100644 --- a/src/system/kernel/posix/realtime_sem.cpp +++ b/src/system/kernel/posix/realtime_sem.cpp @@ -679,7 +679,7 @@ _user_realtime_sem_open(const char* userName, int openFlagsOrShared, if (context == NULL) return B_NO_MEMORY; - if (semCount > MAX_POSIX_SEM_VALUE) + if (semCount > SEM_VALUE_MAX) return B_BAD_VALUE; // userSem must always be given diff --git a/src/system/libroot/posix/unistd/conf.cpp b/src/system/libroot/posix/unistd/conf.cpp index e72f470ee2..f13b8b4361 100644 --- a/src/system/libroot/posix/unistd/conf.cpp +++ b/src/system/libroot/posix/unistd/conf.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -96,7 +97,7 @@ __sysconf(int name) // unlimited, instead of _POSIX_SEM_NSEMS_MAX return -1; case _SC_SEM_VALUE_MAX: - return _POSIX_SEM_VALUE_MAX; + return SEM_VALUE_MAX; case _SC_IOV_MAX: return IOV_MAX; case _SC_NPROCESSORS_CONF: