Skip to content

Commit 33cbb24

Browse files
authored
Transform pthread allow list to deny list. NFC. (#14172)
Since that is easier to maintain and allows us to quickly identify which functions could be supported in the future.
1 parent ad438df commit 33cbb24

File tree

1 file changed

+60
-67
lines changed

1 file changed

+60
-67
lines changed

tools/system_libs.py

Lines changed: 60 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def get_files(self):
678678

679679
# musl modules
680680
ignore = [
681-
'ipc', 'passwd', 'thread', 'signal', 'sched', 'ipc', 'time', 'linux',
681+
'ipc', 'passwd', 'signal', 'sched', 'ipc', 'time', 'linux',
682682
'aio', 'exit', 'legacy', 'mq', 'search', 'setjmp', 'env',
683683
'ldso'
684684
]
@@ -713,6 +713,65 @@ def get_files(self):
713713
shared.path_from_root('system', 'lib', 'libc', 'emscripten_asan_fcntl.c'),
714714
]
715715

716+
if self.is_mt:
717+
ignore += [
718+
'clone.c', '__lock.c',
719+
'pthread_cleanup_push.c', 'pthread_create.c',
720+
'pthread_kill.c', 'pthread_sigmask.c',
721+
'__set_thread_area.c', 'synccall.c',
722+
'__syscall_cp.c', '__tls_get_addr.c',
723+
'__unmapself.c',
724+
# Empty files, simply ignore them.
725+
'syscall_cp.c', 'tls.c',
726+
# TODO: Comment out (or support) within upcoming musl upgrade. See #12216.
727+
# 'pthread_setname_np.c',
728+
# TODO: No longer exists in the latest musl version.
729+
'__futex.c',
730+
# TODO: Could be supported in the upcoming musl upgrade
731+
'lock_ptc.c', 'pthread_getattr_np.c',
732+
# 'pthread_setattr_default_np.c',
733+
# TODO: These could be moved away from JS in the upcoming musl upgrade.
734+
'pthread_cancel.c', 'pthread_detach.c',
735+
'pthread_join.c', 'pthread_testcancel.c',
736+
# TODO: Support C11 condition variable and mutex library functions.
737+
'cnd_broadcast.c',
738+
'cnd_destroy.c',
739+
'cnd_init.c',
740+
'cnd_signal.c',
741+
'cnd_timedwait.c',
742+
'cnd_wait.c',
743+
'mtx_destroy.c',
744+
'mtx_init.c',
745+
'mtx_lock.c',
746+
'mtx_timedlock.c',
747+
'mtx_trylock.c',
748+
'mtx_unlock.c',
749+
]
750+
libc_files += files_in_path(
751+
path_components=['system', 'lib', 'pthread'],
752+
filenames=[
753+
'library_pthread.c',
754+
'emscripten_thread_state.s',
755+
])
756+
else:
757+
ignore += ['thread']
758+
libc_files += files_in_path(
759+
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
760+
filenames=[
761+
'pthread_self.c',
762+
# C11 thread library functions
763+
'thrd_create.c',
764+
'thrd_exit.c',
765+
'thrd_join.c',
766+
'thrd_sleep.c',
767+
'thrd_yield.c',
768+
'call_once.c',
769+
'tss_create.c',
770+
'tss_delete.c',
771+
'tss_set.c',
772+
])
773+
libc_files += [shared.path_from_root('system', 'lib', 'pthread', 'library_pthread_stub.c')]
774+
716775
# These are included in wasm_libc_rt instead
717776
ignore += [os.path.basename(f) for f in get_wasm_libc_rt_files()]
718777

@@ -765,74 +824,8 @@ def get_files(self):
765824
path_components=['system', 'lib', 'pthread'],
766825
filenames=['emscripten_atomic.c'])
767826

768-
libc_files += files_in_path(
769-
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
770-
filenames=[
771-
'pthread_self.c',
772-
# C11 thread library functions
773-
'thrd_create.c',
774-
'thrd_exit.c',
775-
'thrd_join.c',
776-
'thrd_sleep.c',
777-
'thrd_yield.c',
778-
'call_once.c',
779-
'tss_create.c',
780-
'tss_delete.c',
781-
'tss_set.c',
782-
])
783-
784827
libc_files += glob_in_path(['system', 'lib', 'libc', 'compat'], '*.c')
785828

786-
if self.is_mt:
787-
libc_files += files_in_path(
788-
path_components=['system', 'lib', 'libc', 'musl', 'src', 'thread'],
789-
filenames=[
790-
'pthread_attr_destroy.c', 'pthread_condattr_setpshared.c',
791-
'pthread_mutex_lock.c', 'pthread_spin_destroy.c', 'pthread_attr_get.c',
792-
'pthread_cond_broadcast.c', 'pthread_mutex_setprioceiling.c',
793-
'pthread_spin_init.c', 'pthread_attr_init.c', 'pthread_cond_destroy.c',
794-
'pthread_mutex_timedlock.c', 'pthread_spin_lock.c',
795-
'pthread_attr_setdetachstate.c', 'pthread_cond_init.c',
796-
'pthread_mutex_trylock.c', 'pthread_spin_trylock.c',
797-
'pthread_attr_setguardsize.c', 'pthread_cond_signal.c',
798-
'pthread_mutex_unlock.c', 'pthread_spin_unlock.c',
799-
'pthread_attr_setinheritsched.c', 'pthread_cond_timedwait.c',
800-
'pthread_once.c', 'sem_destroy.c', 'pthread_attr_setschedparam.c',
801-
'pthread_cond_wait.c', 'pthread_rwlockattr_destroy.c', 'sem_getvalue.c',
802-
'pthread_attr_setschedpolicy.c', 'pthread_equal.c', 'pthread_rwlockattr_init.c',
803-
'sem_init.c', 'pthread_attr_setscope.c', 'pthread_getspecific.c',
804-
'pthread_rwlockattr_setpshared.c', 'sem_open.c', 'pthread_attr_setstack.c',
805-
'pthread_key_create.c', 'pthread_rwlock_destroy.c', 'sem_post.c',
806-
'pthread_attr_setstacksize.c', 'pthread_mutexattr_destroy.c',
807-
'pthread_rwlock_init.c', 'sem_timedwait.c', 'pthread_barrierattr_destroy.c',
808-
'pthread_mutexattr_init.c', 'pthread_rwlock_rdlock.c', 'sem_trywait.c',
809-
'pthread_barrierattr_init.c', 'pthread_mutexattr_setprotocol.c',
810-
'pthread_rwlock_timedrdlock.c', 'sem_unlink.c',
811-
'pthread_barrierattr_setpshared.c', 'pthread_mutexattr_setpshared.c',
812-
'pthread_rwlock_timedwrlock.c', 'sem_wait.c', 'pthread_barrier_destroy.c',
813-
'pthread_mutexattr_setrobust.c', 'pthread_rwlock_tryrdlock.c',
814-
'__timedwait.c', 'pthread_barrier_init.c', 'pthread_mutexattr_settype.c',
815-
'pthread_rwlock_trywrlock.c', 'vmlock.c', 'pthread_barrier_wait.c',
816-
'pthread_mutex_consistent.c', 'pthread_rwlock_unlock.c', '__wait.c',
817-
'pthread_condattr_destroy.c', 'pthread_mutex_destroy.c',
818-
'pthread_rwlock_wrlock.c', 'pthread_condattr_init.c',
819-
'pthread_mutex_getprioceiling.c', 'pthread_setcanceltype.c',
820-
'pthread_condattr_setclock.c', 'pthread_mutex_init.c',
821-
'pthread_setspecific.c', 'pthread_setcancelstate.c',
822-
'pthread_getconcurrency.c', 'pthread_setconcurrency.c',
823-
'pthread_getschedparam.c', 'pthread_setschedparam.c',
824-
'pthread_setschedprio.c', 'pthread_atfork.c',
825-
'pthread_getcpuclockid.c',
826-
])
827-
libc_files += files_in_path(
828-
path_components=['system', 'lib', 'pthread'],
829-
filenames=[
830-
'library_pthread.c',
831-
'emscripten_thread_state.s',
832-
])
833-
else:
834-
libc_files += [shared.path_from_root('system', 'lib', 'pthread', 'library_pthread_stub.c')]
835-
836829
return libc_files
837830

838831

0 commit comments

Comments
 (0)