Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------
Expand Down
4 changes: 4 additions & 0 deletions system/lib/libc/musl/include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions system/lib/libc/musl/src/thread/pthread_condattr_setpshared.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 3 additions & 0 deletions system/lib/libc/musl/src/thread/sem_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
77 changes: 0 additions & 77 deletions system/lib/pthread/library_pthread_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions test/codesize/test_codesize_cxx_wasmfs.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 5 additions & 4 deletions test/codesize/test_codesize_files_wasmfs.json
Original file line number Diff line number Diff line change
@@ -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)",
Expand Down Expand Up @@ -113,6 +113,7 @@
"$std::__2::basic_string<char\\2c\\20std::__2::char_traits<char>\\2c\\20std::__2::allocator<char>>&\\20std::__2::basic_string<char\\2c\\20std::__2::char_traits<char>\\2c\\20std::__2::allocator<char>>::__assign_no_alias<true>\\28char\\20const*\\2c\\20unsigned\\20long\\29",
"$std::__2::basic_string<char\\2c\\20std::__2::char_traits<char>\\2c\\20std::__2::allocator<char>>::__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<char\\2c\\20std::__2::char_traits<char>\\2c\\20std::__2::allocator<char>>::__init_copy_ctor_external\\28char\\20const*\\2c\\20unsigned\\20long\\29",
"$std::__2::recursive_mutex::recursive_mutex\\28\\29",
"$std::__2::shared_ptr<wasmfs::SpecialFiles::\\28anonymous\\20namespace\\29::RandomFile>\\20std::__2::make_shared\\5babi:nn210108\\5d<wasmfs::SpecialFiles::\\28anonymous\\20namespace\\29::RandomFile\\2c\\200>\\28\\29",
"$std::__2::vector<unsigned\\20char\\2c\\20std::__2::allocator<unsigned\\20char>>::__append\\28unsigned\\20long\\29",
"$std::__2::vector<wasmfs::MemoryDirectory::ChildEntry\\2c\\20std::__2::allocator<wasmfs::MemoryDirectory::ChildEntry>>::erase\\5babi:nn210108\\5d\\28std::__2::__wrap_iter<wasmfs::MemoryDirectory::ChildEntry\\20const*>\\29",
Expand Down
17 changes: 14 additions & 3 deletions test/codesize/test_codesize_hello_dylink_all.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -4697,6 +4708,7 @@
"$seed48",
"$seekdir",
"$select",
"$sem_init",
"$send",
"$sendmmsg",
"$sendmsg",
Expand Down Expand Up @@ -4736,7 +4748,6 @@
"$sigaltstack",
"$sigandset",
"$sigdelset",
"$sigemptyset",
"$sigfillset",
"$siginterrupt",
"$sigisemptyset",
Expand Down
7 changes: 7 additions & 0 deletions test/test_posixtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
19 changes: 19 additions & 0 deletions tools/system_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
Loading