From 353baa92518fb3b7993ad04012de62c9797de39d Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Sat, 25 Apr 2020 15:59:22 +0200 Subject: [PATCH] libc: add pthread alias functions with underscore The libc calls pthread functions with underscore internally. Issue #725 --- repos/libports/src/lib/libc/pthread.cc | 85 +++++++++++++++++++ repos/libports/src/lib/libc/pthread_create.cc | 3 + repos/libports/src/lib/libc/rwlock.cc | 27 ++++++ 3 files changed, 115 insertions(+) diff --git a/repos/libports/src/lib/libc/pthread.cc b/repos/libports/src/lib/libc/pthread.cc index 92a227a38a..9589d6b170 100644 --- a/repos/libports/src/lib/libc/pthread.cc +++ b/repos/libports/src/lib/libc/pthread.cc @@ -519,6 +519,9 @@ extern "C" { return 0; } + typeof(pthread_join) _pthread_join + __attribute__((alias("pthread_join"))); + int pthread_attr_init(pthread_attr_t *attr) { @@ -531,6 +534,9 @@ extern "C" { return 0; } + typeof(pthread_attr_init) _pthread_attr_init + __attribute__((alias("pthread_attr_init"))); + int pthread_attr_destroy(pthread_attr_t *attr) { @@ -544,6 +550,9 @@ extern "C" { return 0; } + typeof(pthread_attr_destroy) _pthread_attr_destroy + __attribute__((alias("pthread_attr_destroy"))); + int pthread_cancel(pthread_t thread) { @@ -558,6 +567,9 @@ extern "C" { sleep_forever(); } + typeof(pthread_exit) _pthread_exit + __attribute__((alias("pthread_exit"))); + /* special non-POSIX function (for example used in libresolv) */ int _pthread_main_np(void) @@ -598,6 +610,9 @@ extern "C" { return unmanaged_singleton(*Thread::myself()); } + typeof(pthread_self) _pthread_self + __attribute__((alias("pthread_self"))); + pthread_t thr_self(void) { return pthread_self(); } @@ -624,6 +639,9 @@ extern "C" { return 0; } + typeof(pthread_attr_setstacksize) _pthread_attr_setstacksize + __attribute__((alias("pthread_attr_setstacksize"))); + int pthread_attr_getstack(const pthread_attr_t *attr, void **stackaddr, @@ -645,6 +663,9 @@ extern "C" { return pthread_attr_getstack(attr, stackaddr, &stacksize); } + typeof(pthread_attr_getstackaddr) _pthread_attr_getstackaddr + __attribute__((alias("pthread_attr_getstackaddr"))); + int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize) { @@ -652,6 +673,9 @@ extern "C" { return pthread_attr_getstack(attr, &stackaddr, stacksize); } + typeof(pthread_attr_getstacksize) _pthread_attr_getstacksize + __attribute__((alias("pthread_attr_getstacksize"))); + int pthread_attr_get_np(pthread_t pthread, pthread_attr_t *attr) { @@ -670,6 +694,9 @@ extern "C" { return (t1 == t2); } + typeof(pthread_equal) _pthread_equal + __attribute__((alias("pthread_equal"))); + void __pthread_cleanup_push_imp(void (*routine)(void*), void *arg, struct _pthread_cleanup_info *) @@ -698,6 +725,9 @@ extern "C" { return 0; } + typeof(pthread_mutexattr_init) _pthread_mutexattr_init + __attribute__((alias("pthread_mutexattr_init"))); + int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) { @@ -711,6 +741,9 @@ extern "C" { return 0; } + typeof(pthread_mutexattr_destroy) _pthread_mutexattr_destroy + __attribute__((alias("pthread_mutexattr_destroy"))); + int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) { @@ -722,6 +755,9 @@ extern "C" { return 0; } + typeof(pthread_mutexattr_settype) _pthread_mutexattr_settype + __attribute__((alias("pthread_mutexattr_settype"))); + int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t const *attr) @@ -747,6 +783,9 @@ extern "C" { return 0; } + typeof(pthread_mutex_init) _pthread_mutex_init + __attribute__((alias("pthread_mutex_init"))); + int pthread_mutex_destroy(pthread_mutex_t *mutex) { @@ -760,6 +799,9 @@ extern "C" { return 0; } + typeof(pthread_mutex_destroy) _pthread_mutex_destroy + __attribute__((alias("pthread_mutex_destroy"))); + int pthread_mutex_lock(pthread_mutex_t *mutex) { @@ -772,6 +814,9 @@ extern "C" { return (*mutex)->lock(); } + typeof(pthread_mutex_lock) _pthread_mutex_lock + __attribute__((alias("pthread_mutex_lock"))); + int pthread_mutex_trylock(pthread_mutex_t *mutex) { @@ -784,6 +829,9 @@ extern "C" { return (*mutex)->trylock(); } + typeof(pthread_mutex_trylock) _pthread_mutex_trylock + __attribute__((alias("pthread_mutex_trylock"))); + int pthread_mutex_timedlock(pthread_mutex_t *mutex, struct timespec const *abstimeout) @@ -810,6 +858,9 @@ extern "C" { return (*mutex)->unlock(); } + typeof(pthread_mutex_unlock) _pthread_mutex_unlock + __attribute__((alias("pthread_mutex_unlock"))); + /* Condition variable */ @@ -900,6 +951,9 @@ extern "C" { return cond_init(cond, attr); } + typeof(pthread_cond_init) _pthread_cond_init + __attribute__((alias("pthread_cond_init"))); + int pthread_cond_destroy(pthread_cond_t *cond) { @@ -916,6 +970,9 @@ extern "C" { return 0; } + typeof(pthread_cond_destroy) _pthread_cond_destroy + __attribute__((alias("pthread_cond_destroy"))); + int pthread_cond_timedwait(pthread_cond_t *__restrict cond, pthread_mutex_t *__restrict mutex, @@ -960,6 +1017,9 @@ extern "C" { return result; } + typeof(pthread_cond_timedwait) _pthread_cond_timedwait + __attribute__((alias("pthread_cond_timedwait"))); + int pthread_cond_wait(pthread_cond_t *__restrict cond, pthread_mutex_t *__restrict mutex) @@ -967,6 +1027,9 @@ extern "C" { return pthread_cond_timedwait(cond, mutex, nullptr); } + typeof(pthread_cond_wait) _pthread_cond_wait + __attribute__((alias("pthread_cond_wait"))); + int pthread_cond_signal(pthread_cond_t *cond) { @@ -990,6 +1053,9 @@ extern "C" { return 0; } + typeof(pthread_cond_signal) _pthread_cond_signal + __attribute__((alias("pthread_cond_signal"))); + int pthread_cond_broadcast(pthread_cond_t *cond) { @@ -1016,6 +1082,10 @@ extern "C" { return 0; } + typeof(pthread_cond_broadcast) _pthread_cond_broadcast + __attribute__((alias("pthread_cond_broadcast"))); + + /* TLS */ @@ -1074,6 +1144,9 @@ extern "C" { return EAGAIN; } + typeof(pthread_key_create) _pthread_key_create + __attribute__((alias("pthread_key_create"))); + int pthread_key_delete(pthread_key_t key) { @@ -1091,6 +1164,9 @@ extern "C" { return 0; } + typeof(pthread_key_delete) _pthread_key_delete + __attribute__((alias("pthread_key_delete"))); + int pthread_setspecific(pthread_key_t key, const void *value) { @@ -1115,6 +1191,9 @@ extern "C" { return 0; } + typeof(pthread_setspecific) _pthread_setspecific + __attribute__((alias("pthread_setspecific"))); + void *pthread_getspecific(pthread_key_t key) { @@ -1133,6 +1212,9 @@ extern "C" { return 0; } + typeof(pthread_getspecific) _pthread_getspecific + __attribute__((alias("pthread_getspecific"))); + int pthread_once(pthread_once_t *once, void (*init_once)(void)) { @@ -1177,4 +1259,7 @@ extern "C" { return 0; } + + typeof(pthread_once) _pthread_once + __attribute__((alias("pthread_once"))); } diff --git a/repos/libports/src/lib/libc/pthread_create.cc b/repos/libports/src/lib/libc/pthread_create.cc index a15252ac9a..8ba2643c5c 100644 --- a/repos/libports/src/lib/libc/pthread_create.cc +++ b/repos/libports/src/lib/libc/pthread_create.cc @@ -145,4 +145,7 @@ extern "C" pthread_name.string(), _cpu_session, location); } + + typeof(pthread_create) _pthread_create + __attribute__((alias("pthread_create"))); } diff --git a/repos/libports/src/lib/libc/rwlock.cc b/repos/libports/src/lib/libc/rwlock.cc index 8bcc499844..f078b94a6b 100644 --- a/repos/libports/src/lib/libc/rwlock.cc +++ b/repos/libports/src/lib/libc/rwlock.cc @@ -93,10 +93,12 @@ extern "C" { } }; + struct pthread_rwlockattr { }; + static int rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) { static Mutex rwlock_init_mutex { }; @@ -112,11 +114,16 @@ extern "C" { } catch (...) { return ENOMEM; } } + int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) { return rwlock_init(rwlock, attr); } + typeof(pthread_rwlock_init) _pthread_rwlock_init + __attribute__((alias("pthread_rwlock_init"))); + + int pthread_rwlock_destroy(pthread_rwlock_t *rwlock) { Libc::Allocator alloc { }; @@ -124,6 +131,10 @@ extern "C" { return 0; } + typeof(pthread_rwlock_destroy) _pthread_rwlock_destroy + __attribute__((alias("pthread_rwlock_destroy"))); + + int pthread_rwlock_rdlock(pthread_rwlock_t * rwlock) { if (!rwlock) @@ -137,6 +148,10 @@ extern "C" { return 0; } + typeof(pthread_rwlock_rdlock) _pthread_rwlock_rdlock + __attribute__((alias("pthread_rwlock_rdlock"))); + + int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) { if (!rwlock) @@ -150,11 +165,19 @@ extern "C" { return 0; } + typeof(pthread_rwlock_wrlock) _pthread_rwlock_wrlock + __attribute__((alias("pthread_rwlock_wrlock"))); + + int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) { return (*rwlock)->unlock(); } + typeof(pthread_rwlock_unlock) _pthread_rwlock_unlock + __attribute__((alias("pthread_rwlock_unlock"))); + + int pthread_rwlockattr_init(pthread_rwlockattr_t *attr) { Libc::Allocator alloc { }; @@ -162,12 +185,14 @@ extern "C" { return 0; } + int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *attr, int *pshared) { *pshared = PTHREAD_PROCESS_PRIVATE; return 0; } + int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *attr, int pshared) { if (pshared != PTHREAD_PROCESS_PRIVATE) { @@ -177,6 +202,7 @@ extern "C" { return 0; } + int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) { Libc::Allocator alloc { }; @@ -184,6 +210,7 @@ extern "C" { return 0; } + /* * Unimplemented functions: * int pthread_rwlock_timedrdlock(pthread_rwlock_t *, const struct timespec *);