diff options
author | Tim Schumacher <timschumi@gmx.de> | 2022-06-12 20:16:06 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-19 11:00:35 +0100 |
commit | 2f3b9c49a5fa4e867b77b40191c4221db17f0a16 (patch) | |
tree | 3ed0bad36c2816eadd800a96bab38ca7ebb31e31 /Userland | |
parent | e156f79f53d9cfbe238fdb4813609bfb5141c114 (diff) | |
download | serenity-2f3b9c49a5fa4e867b77b40191c4221db17f0a16.zip |
LibPthread: Move the pthread and semaphore implementation to LibC
This additionally adds some compatibility code to redirect linking
attempts for LibPthread to LibC instead.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/DynamicLoader/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibC/CMakeLists.txt | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibC/bits/pthread_forward.h | 29 | ||||
-rw-r--r-- | Userland/Libraries/LibC/pthread.cpp (renamed from Userland/Libraries/LibPthread/pthread.cpp) | 0 | ||||
-rw-r--r-- | Userland/Libraries/LibC/pthread.h (renamed from Userland/Libraries/LibPthread/pthread.h) | 0 | ||||
-rw-r--r-- | Userland/Libraries/LibC/pthread_cond.cpp (renamed from Userland/Libraries/LibPthread/pthread_cond.cpp) | 0 | ||||
-rw-r--r-- | Userland/Libraries/LibC/pthread_forward.cpp | 87 | ||||
-rw-r--r-- | Userland/Libraries/LibC/pthread_once.cpp (renamed from Userland/Libraries/LibPthread/pthread_once.cpp) | 0 | ||||
-rw-r--r-- | Userland/Libraries/LibC/semaphore.cpp (renamed from Userland/Libraries/LibPthread/semaphore.cpp) | 0 | ||||
-rw-r--r-- | Userland/Libraries/LibC/semaphore.h (renamed from Userland/Libraries/LibPthread/semaphore.h) | 0 | ||||
-rw-r--r-- | Userland/Libraries/LibPthread/CMakeLists.txt | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibPthread/forward.cpp | 31 |
12 files changed, 11 insertions, 159 deletions
diff --git a/Userland/DynamicLoader/CMakeLists.txt b/Userland/DynamicLoader/CMakeLists.txt index 55c86fc19e..4b2c9aadc2 100644 --- a/Userland/DynamicLoader/CMakeLists.txt +++ b/Userland/DynamicLoader/CMakeLists.txt @@ -25,6 +25,9 @@ if (ENABLE_UNDEFINED_SANITIZER) set(LOADER_SOURCES ${LOADER_SOURCES} ../Libraries/LibSanitizer/UBSanitizer.cpp) endif() +# pthread requires thread local storage, which DynamicLoader does not have. +list(FILTER LIBC_SOURCES1 EXCLUDE REGEX ".*/LibC/pthread\\.cpp") + add_definitions(-D_DYNAMIC_LOADER) set(SOURCES ${LOADER_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${LIBC_SOURCES1} ${LIBC_SOURCES2} ${LIBC_SOURCES3} ${LIBSYSTEM_SOURCES}) diff --git a/Userland/Libraries/LibC/CMakeLists.txt b/Userland/Libraries/LibC/CMakeLists.txt index aa5c40d116..2319a241e1 100644 --- a/Userland/Libraries/LibC/CMakeLists.txt +++ b/Userland/Libraries/LibC/CMakeLists.txt @@ -27,8 +27,10 @@ set(LIBC_SOURCES netdb.cpp poll.cpp priority.cpp - pthread_forward.cpp + pthread.cpp + pthread_cond.cpp pthread_integration.cpp + pthread_once.cpp pthread_tls.cpp pty.cpp pwd.cpp @@ -38,6 +40,7 @@ set(LIBC_SOURCES scanf.cpp sched.cpp search.cpp + semaphore.cpp serenity.cpp shadow.cpp signal.cpp diff --git a/Userland/Libraries/LibC/bits/pthread_forward.h b/Userland/Libraries/LibC/bits/pthread_forward.h deleted file mode 100644 index 849220a967..0000000000 --- a/Userland/Libraries/LibC/bits/pthread_forward.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021, Gunnar Beutner <gunnar@beutner.name> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include <pthread.h> - -struct PthreadFunctions { - int (*pthread_mutex_trylock)(pthread_mutex_t* mutex); - int (*pthread_mutex_destroy)(pthread_mutex_t*); - - int (*pthread_mutexattr_init)(pthread_mutexattr_t*); - int (*pthread_mutexattr_settype)(pthread_mutexattr_t*, int); - int (*pthread_mutexattr_destroy)(pthread_mutexattr_t*); - - int (*pthread_once)(pthread_once_t*, void (*)(void)); - - int (*pthread_cond_broadcast)(pthread_cond_t*); - int (*pthread_cond_init)(pthread_cond_t*, pthread_condattr_t const*); - int (*pthread_cond_signal)(pthread_cond_t*); - int (*pthread_cond_wait)(pthread_cond_t*, pthread_mutex_t*); - int (*pthread_cond_destroy)(pthread_cond_t*); - int (*pthread_cond_timedwait)(pthread_cond_t*, pthread_mutex_t*, const struct timespec*); -}; - -void __init_pthread_forward(PthreadFunctions); diff --git a/Userland/Libraries/LibPthread/pthread.cpp b/Userland/Libraries/LibC/pthread.cpp index e09f6a6850..e09f6a6850 100644 --- a/Userland/Libraries/LibPthread/pthread.cpp +++ b/Userland/Libraries/LibC/pthread.cpp diff --git a/Userland/Libraries/LibPthread/pthread.h b/Userland/Libraries/LibC/pthread.h index 6260cd5454..6260cd5454 100644 --- a/Userland/Libraries/LibPthread/pthread.h +++ b/Userland/Libraries/LibC/pthread.h diff --git a/Userland/Libraries/LibPthread/pthread_cond.cpp b/Userland/Libraries/LibC/pthread_cond.cpp index 5ba15c368e..5ba15c368e 100644 --- a/Userland/Libraries/LibPthread/pthread_cond.cpp +++ b/Userland/Libraries/LibC/pthread_cond.cpp diff --git a/Userland/Libraries/LibC/pthread_forward.cpp b/Userland/Libraries/LibC/pthread_forward.cpp deleted file mode 100644 index 32fcd015e7..0000000000 --- a/Userland/Libraries/LibC/pthread_forward.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (c) 2021, Gunnar Beutner <gunnar@beutner.name> - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <AK/Assertions.h> -#include <LibC/bits/pthread_forward.h> - -static PthreadFunctions s_pthread_functions; - -void __init_pthread_forward(PthreadFunctions funcs) -{ - s_pthread_functions = funcs; -} - -int pthread_mutex_trylock(pthread_mutex_t* mutex) -{ - VERIFY(s_pthread_functions.pthread_mutex_trylock); - return s_pthread_functions.pthread_mutex_trylock(mutex); -} - -int pthread_mutex_destroy(pthread_mutex_t* mutex) -{ - VERIFY(s_pthread_functions.pthread_mutex_destroy); - return s_pthread_functions.pthread_mutex_destroy(mutex); -} - -int pthread_mutexattr_init(pthread_mutexattr_t* attr) -{ - VERIFY(s_pthread_functions.pthread_mutexattr_init); - return s_pthread_functions.pthread_mutexattr_init(attr); -} - -int pthread_mutexattr_settype(pthread_mutexattr_t* attr, int type) -{ - VERIFY(s_pthread_functions.pthread_mutexattr_settype); - return s_pthread_functions.pthread_mutexattr_settype(attr, type); -} - -int pthread_mutexattr_destroy(pthread_mutexattr_t* attr) -{ - VERIFY(s_pthread_functions.pthread_mutexattr_destroy); - return s_pthread_functions.pthread_mutexattr_destroy(attr); -} - -int pthread_once(pthread_once_t* self, void (*callback)(void)) -{ - VERIFY(s_pthread_functions.pthread_once); - return s_pthread_functions.pthread_once(self, callback); -} - -int pthread_cond_broadcast(pthread_cond_t* cond) -{ - VERIFY(s_pthread_functions.pthread_cond_broadcast); - return s_pthread_functions.pthread_cond_broadcast(cond); -} - -int pthread_cond_init(pthread_cond_t* cond, pthread_condattr_t const* attr) -{ - VERIFY(s_pthread_functions.pthread_cond_init); - return s_pthread_functions.pthread_cond_init(cond, attr); -} - -int pthread_cond_signal(pthread_cond_t* cond) -{ - VERIFY(s_pthread_functions.pthread_cond_signal); - return s_pthread_functions.pthread_cond_signal(cond); -} - -int pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) -{ - VERIFY(s_pthread_functions.pthread_cond_wait); - return s_pthread_functions.pthread_cond_wait(cond, mutex); -} - -int pthread_cond_destroy(pthread_cond_t* cond) -{ - VERIFY(s_pthread_functions.pthread_cond_destroy); - return s_pthread_functions.pthread_cond_destroy(cond); -} - -int pthread_cond_timedwait(pthread_cond_t* cond, pthread_mutex_t* mutex, const struct timespec* abstime) -{ - VERIFY(s_pthread_functions.pthread_cond_timedwait); - return s_pthread_functions.pthread_cond_timedwait(cond, mutex, abstime); -} diff --git a/Userland/Libraries/LibPthread/pthread_once.cpp b/Userland/Libraries/LibC/pthread_once.cpp index ab435d4639..ab435d4639 100644 --- a/Userland/Libraries/LibPthread/pthread_once.cpp +++ b/Userland/Libraries/LibC/pthread_once.cpp diff --git a/Userland/Libraries/LibPthread/semaphore.cpp b/Userland/Libraries/LibC/semaphore.cpp index d60d43fc1e..d60d43fc1e 100644 --- a/Userland/Libraries/LibPthread/semaphore.cpp +++ b/Userland/Libraries/LibC/semaphore.cpp diff --git a/Userland/Libraries/LibPthread/semaphore.h b/Userland/Libraries/LibC/semaphore.h index d04c22943e..d04c22943e 100644 --- a/Userland/Libraries/LibPthread/semaphore.h +++ b/Userland/Libraries/LibC/semaphore.h diff --git a/Userland/Libraries/LibPthread/CMakeLists.txt b/Userland/Libraries/LibPthread/CMakeLists.txt index bb6c95319b..ba5fc79edb 100644 --- a/Userland/Libraries/LibPthread/CMakeLists.txt +++ b/Userland/Libraries/LibPthread/CMakeLists.txt @@ -1,11 +1,4 @@ -set(SOURCES - forward.cpp - pthread.cpp - pthread_cond.cpp - pthread_once.cpp - semaphore.cpp -) - -serenity_libc(LibPthread pthread) -target_link_libraries(LibPthread LibC LibSystem) -target_include_directories(LibPthread PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +# Provide a dummy target and a linker script that tells everything to link against LibC instead. +add_library(LibPthread INTERFACE) +target_link_libraries(LibPthread INTERFACE LibC) +file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libpthread.so" "INPUT(libc.so)") diff --git a/Userland/Libraries/LibPthread/forward.cpp b/Userland/Libraries/LibPthread/forward.cpp deleted file mode 100644 index f8a964c580..0000000000 --- a/Userland/Libraries/LibPthread/forward.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2021, Gunnar Beutner <gunnar@beutner.name> - * Copyright (c) 2022, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include <LibC/bits/pthread_forward.h> - -static constexpr PthreadFunctions s_functions = { - .pthread_mutex_trylock = pthread_mutex_trylock, - .pthread_mutex_destroy = pthread_mutex_destroy, - - .pthread_mutexattr_init = pthread_mutexattr_init, - .pthread_mutexattr_settype = pthread_mutexattr_settype, - .pthread_mutexattr_destroy = pthread_mutexattr_destroy, - - .pthread_once = pthread_once, - - .pthread_cond_broadcast = pthread_cond_broadcast, - .pthread_cond_init = pthread_cond_init, - .pthread_cond_signal = pthread_cond_signal, - .pthread_cond_wait = pthread_cond_wait, - .pthread_cond_destroy = pthread_cond_destroy, - .pthread_cond_timedwait = pthread_cond_timedwait, -}; - -[[gnu::constructor]] static void forward_pthread_functions() -{ - __init_pthread_forward(s_functions); -} |