diff --git a/ChangeLog.md b/ChangeLog.md index 8daa90cefc3bf..5dcde5de6332c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -36,6 +36,8 @@ See docs/process.md for more on how version tagging works. explicitly allow for returning EINTR when the wait is interrupted by an async operation. All callers of emscripten_futux_wait are advised to use a loop to handle these types of spurious wakeups / interruptions. (#26659, #26735) +- Attempting to use PTHREAD_PROCESS_SHARED when creating pthread primitives such + as locks and condvars will now fail with ENOTSUP. (#26743) 5.0.6 - 04/14/26 ---------------- diff --git a/system/lib/libc/musl/include/unistd.h b/system/lib/libc/musl/include/unistd.h index 73a075c24dd47..d98a7460db4d3 100644 --- a/system/lib/libc/musl/include/unistd.h +++ b/system/lib/libc/musl/include/unistd.h @@ -263,7 +263,11 @@ pid_t gettid(void); #else #define _POSIX_THREADS _POSIX_VERSION #endif +#ifndef __EMSCRIPTEN__ #define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION +#else +#define _POSIX_THREAD_PROCESS_SHARED -1 +#endif #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION diff --git a/system/lib/libc/musl/src/thread/pthread_condattr_setpshared.c b/system/lib/libc/musl/src/thread/pthread_condattr_setpshared.c index 51453e0480a82..809cc68d20a51 100644 --- a/system/lib/libc/musl/src/thread/pthread_condattr_setpshared.c +++ b/system/lib/libc/musl/src/thread/pthread_condattr_setpshared.c @@ -3,6 +3,9 @@ int pthread_condattr_setpshared(pthread_condattr_t *a, int pshared) { if (pshared > 1U) return EINVAL; +#ifdef __EMSCRIPTEN__ + if (pshared) return ENOTSUP; +#endif a->__attr &= 0x7fffffff; a->__attr |= (unsigned)pshared<<31; return 0; diff --git a/system/lib/libc/musl/src/thread/pthread_mutexattr_setpshared.c b/system/lib/libc/musl/src/thread/pthread_mutexattr_setpshared.c index 100f6ff203f1b..e2f0d3cb859e8 100644 --- a/system/lib/libc/musl/src/thread/pthread_mutexattr_setpshared.c +++ b/system/lib/libc/musl/src/thread/pthread_mutexattr_setpshared.c @@ -3,6 +3,9 @@ int pthread_mutexattr_setpshared(pthread_mutexattr_t *a, int pshared) { if (pshared > 1U) return EINVAL; +#ifdef __EMSCRIPTEN__ + if (pshared) return ENOTSUP; +#endif a->__attr &= ~128U; a->__attr |= pshared<<7; return 0; diff --git a/system/lib/libc/musl/src/thread/pthread_rwlockattr_setpshared.c b/system/lib/libc/musl/src/thread/pthread_rwlockattr_setpshared.c index e7061973d6d6b..33f9466a60ddb 100644 --- a/system/lib/libc/musl/src/thread/pthread_rwlockattr_setpshared.c +++ b/system/lib/libc/musl/src/thread/pthread_rwlockattr_setpshared.c @@ -3,6 +3,9 @@ int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *a, int pshared) { if (pshared > 1U) return EINVAL; +#ifdef __EMSCRIPTEN__ + if (pshared) return ENOTSUP; +#endif a->__attr[0] = pshared; return 0; } diff --git a/system/lib/libc/musl/src/thread/sem_init.c b/system/lib/libc/musl/src/thread/sem_init.c index 55092434386f8..f9b851778f2c8 100644 --- a/system/lib/libc/musl/src/thread/sem_init.c +++ b/system/lib/libc/musl/src/thread/sem_init.c @@ -8,6 +8,9 @@ int sem_init(sem_t *sem, int pshared, unsigned value) errno = EINVAL; return -1; } +#ifdef __EMSCRIPTEN__ + if (pshared) return ENOTSUP; +#endif sem->__val[0] = value; sem->__val[1] = 0; sem->__val[2] = pshared ? 0 : 128; diff --git a/system/lib/pthread/library_pthread_stub.c b/system/lib/pthread/library_pthread_stub.c index e4e0416915337..e5badfbbd3a2a 100644 --- a/system/lib/pthread/library_pthread_stub.c +++ b/system/lib/pthread/library_pthread_stub.c @@ -268,43 +268,6 @@ int pthread_kill(pthread_t thread, int sig) { return 0; } -int pthread_mutexattr_init(pthread_mutexattr_t *attr) { - return 0; -} - -int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int protocol) { - return 0; -} - -int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) { - return 0; -} - -int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) { - return 0; -} - -int pthread_mutexattr_setpshared(pthread_mutexattr_t *attr, int pshared) { - // XXX implement if/when getpshared is required - return 0; -} - -int pthread_condattr_init(pthread_condattr_t * attr) { - return 0; -} - -int pthread_condattr_destroy(pthread_condattr_t *attr) { - return 0; -} - -int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clk) { - return 0; -} - -int pthread_condattr_setpshared(pthread_condattr_t *attr, int shared) { - return 0; -} - int pthread_setcancelstate(int state, int* oldstate) { return 0; } @@ -349,42 +312,6 @@ int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) { return 0; } -int pthread_rwlockattr_init(pthread_rwlockattr_t *attr) { - return 0; -} - -int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) { - return 0; -} - -int pthread_rwlockattr_setpshared(pthread_rwlockattr_t* attr, int pshared) { - return 0; -} - -int pthread_spin_init(pthread_spinlock_t *lock, int pshared) { - return 0; -} - -int pthread_spin_destroy(pthread_spinlock_t *lock) { - return 0; -} - -int pthread_spin_lock(pthread_spinlock_t *lock) { - return 0; -} - -int pthread_spin_trylock(pthread_spinlock_t *lock) { - return 0; -} - -int pthread_spin_unlock(pthread_spinlock_t *lock) { - return 0; -} - -int sem_init(sem_t *sem, int pshared, unsigned int value) { - return 0; -} - int sem_post(sem_t *sem) { return 0; } @@ -397,10 +324,6 @@ int sem_trywait(sem_t *sem) { return 0; } -int sem_destroy(sem_t *sem) { - return 0; -} - // When pthreads is not enabled, we can't use the Atomics futex api to do // proper sleeps, so simulate a busy spin wait loop instead. void emscripten_thread_sleep(double msecs) { diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index 60713bafd1b45..ad210ca19d8b0 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -1,10 +1,10 @@ { "a.out.js": 7023, "a.out.js.gz": 3310, - "a.out.nodebug.wasm": 172710, - "a.out.nodebug.wasm.gz": 63307, - "total": 179733, - "total_gz": 66617, + "a.out.nodebug.wasm": 172741, + "a.out.nodebug.wasm.gz": 63318, + "total": 179764, + "total_gz": 66628, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_files_wasmfs.json b/test/codesize/test_codesize_files_wasmfs.json index 327251e75f6b3..c089d1d20731a 100644 --- a/test/codesize/test_codesize_files_wasmfs.json +++ b/test/codesize/test_codesize_files_wasmfs.json @@ -1,10 +1,10 @@ { "a.out.js": 5465, "a.out.js.gz": 2575, - "a.out.nodebug.wasm": 58418, - "a.out.nodebug.wasm.gz": 18067, - "total": 63883, - "total_gz": 20642, + "a.out.nodebug.wasm": 58426, + "a.out.nodebug.wasm.gz": 18182, + "total": 63891, + "total_gz": 20757, "sent": [ "a (emscripten_date_now)", "b (emscripten_err)", @@ -113,6 +113,7 @@ "$std::__2::basic_string\\2c\\20std::__2::allocator>&\\20std::__2::basic_string\\2c\\20std::__2::allocator>::__assign_no_alias\\28char\\20const*\\2c\\20unsigned\\20long\\29", "$std::__2::basic_string\\2c\\20std::__2::allocator>::__grow_by_and_replace\\28unsigned\\20long\\2c\\20unsigned\\20long\\2c\\20unsigned\\20long\\2c\\20unsigned\\20long\\2c\\20unsigned\\20long\\2c\\20unsigned\\20long\\2c\\20char\\20const*\\29", "$std::__2::basic_string\\2c\\20std::__2::allocator>::__init_copy_ctor_external\\28char\\20const*\\2c\\20unsigned\\20long\\29", + "$std::__2::recursive_mutex::recursive_mutex\\28\\29", "$std::__2::shared_ptr\\20std::__2::make_shared\\5babi:nn210108\\5d\\28\\29", "$std::__2::vector>::__append\\28unsigned\\20long\\29", "$std::__2::vector>::erase\\5babi:nn210108\\5d\\28std::__2::__wrap_iter\\29", diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index d792bdbee9775..26ef6e22e06cb 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { "a.out.js": 244416, - "a.out.nodebug.wasm": 577672, - "total": 822088, + "a.out.nodebug.wasm": 578085, + "total": 822501, "sent": [ "IMG_Init", "IMG_Load", @@ -4620,6 +4620,9 @@ "$pthread_barrierattr_getpshared", "$pthread_condattr_getclock", "$pthread_condattr_getpshared", + "$pthread_condattr_init", + "$pthread_condattr_setclock", + "$pthread_condattr_setpshared", "$pthread_equal", "$pthread_getattr_np", "$pthread_getcpuclockid", @@ -4629,8 +4632,16 @@ "$pthread_mutexattr_getpshared", "$pthread_mutexattr_getrobust", "$pthread_mutexattr_gettype", + "$pthread_mutexattr_setprotocol", + "$pthread_mutexattr_setpshared", + "$pthread_mutexattr_settype", + "$pthread_rwlockattr_init", + "$pthread_rwlockattr_setpshared", "$pthread_setspecific", "$pthread_sigmask", + "$pthread_spin_init", + "$pthread_spin_lock", + "$pthread_spin_trylock", "$ptsname", "$putc_unlocked", "$putchar", @@ -4697,6 +4708,7 @@ "$seed48", "$seekdir", "$select", + "$sem_init", "$send", "$sendmmsg", "$sendmsg", @@ -4736,7 +4748,6 @@ "$sigaltstack", "$sigandset", "$sigdelset", - "$sigemptyset", "$sigfillset", "$siginterrupt", "$sigisemptyset", diff --git a/test/test_posixtest.py b/test/test_posixtest.py index b8424d8715c13..6e338df94eb04 100644 --- a/test/test_posixtest.py +++ b/test/test_posixtest.py @@ -70,6 +70,13 @@ def get_tests(): } unsupported = { + 'test_pthread_cond_init_4_2': 'PTHREAD_PROCESS_SHARED not supported', + 'test_pthread_condattr_getpshared_1_2': 'PTHREAD_PROCESS_SHARED not supported', + 'test_pthread_mutexattr_setpshared_1_1': 'PTHREAD_PROCESS_SHARED not supported', + 'test_pthread_rwlockattr_setpshared_1_1': 'PTHREAD_PROCESS_SHARED not supported', + 'test_pthread_condattr_setpshared_1_2': 'PTHREAD_PROCESS_SHARED not supported', + 'test_pthread_mutexattr_getpshared_1_2': 'PTHREAD_PROCESS_SHARED not supported', + 'test_pthread_mutexattr_setpshared_2_2': 'PTHREAD_PROCESS_SHARED not supported', 'test_pthread_exit_6_1': 'fork() and multiple processes are not supported', 'test_pthread_atfork_1_1': 'fork() and multiple processes are not supported', 'test_pthread_atfork_1_2': 'fork() and multiple processes are not supported', diff --git a/tools/system_libs.py b/tools/system_libs.py index 53dab461c77fc..5aae13b11c326 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -1269,10 +1269,27 @@ def get_files(self): 'pthread_attr_setscope.c', 'pthread_attr_setstack.c', 'pthread_attr_setstacksize.c', + 'pthread_condattr_destroy.c', + 'pthread_condattr_init.c', + 'pthread_condattr_setpshared.c', + 'pthread_condattr_setclock.c', + 'pthread_mutexattr_destroy.c', + 'pthread_mutexattr_init.c', + 'pthread_mutexattr_setprotocol.c', + 'pthread_mutexattr_settype.c', + 'pthread_mutexattr_setpshared.c', + 'pthread_rwlockattr_destroy.c', + 'pthread_rwlockattr_init.c', + 'pthread_rwlockattr_setpshared.c', 'pthread_getattr_np.c', 'pthread_getconcurrency.c', 'pthread_getcpuclockid.c', 'pthread_getschedparam.c', + 'pthread_spin_destroy.c', + 'pthread_spin_init.c', + 'pthread_spin_lock.c', + 'pthread_spin_trylock.c', + 'pthread_spin_unlock.c', 'pthread_setschedprio.c', 'pthread_setconcurrency.c', 'default_attr.c', @@ -1293,6 +1310,8 @@ def get_files(self): 'mtx_timedlock.c', 'mtx_trylock.c', 'mtx_unlock.c', + 'sem_destroy.c', + 'sem_init.c', 'thrd_create.c', 'thrd_exit.c', 'thrd_join.c',