mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 16:21:29 +00:00
LibPthread: Move the pthread and semaphore implementation to LibC
This additionally adds some compatibility code to redirect linking attempts for LibPthread to LibC instead.
This commit is contained in:
parent
e156f79f53
commit
2f3b9c49a5
Notes:
sideshowbarker
2024-07-17 22:41:14 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/2f3b9c49a5 Pull-request: https://github.com/SerenityOS/serenity/pull/14453 Reviewed-by: https://github.com/linusg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
|
@ -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);
|
||||
}
|
|
@ -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)")
|
||||
|
|
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue