Skip to content

Commit

Permalink
Kernel: Disable __thread and TLS on x86_64 for now
Browse files Browse the repository at this point in the history
They're not yet properly supported.
  • Loading branch information
gunnarbeutner authored and awesomekling committed Jun 30, 2021
1 parent c0bd2c0 commit fe2716d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if("${SERENITY_ARCH}" STREQUAL "x86_64")
# FIXME: Implement TLS support and get rid of this
add_compile_definitions(NO_TLS X86_64_NO_TLS)
endif()

add_compile_options(-Wno-literal-suffix)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fconcepts)
Expand Down
2 changes: 1 addition & 1 deletion Kernel/Syscalls/mmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ KResultOr<FlatPtr> Process::sys$allocate_tls(Userspace<const char*> initial_data
tls_descriptor.set_base(main_thread->thread_specific_data());
tls_descriptor.set_limit(main_thread->thread_specific_region_size());
#else
TODO();
dbgln("FIXME: Not setting FS_BASE for process.");
#endif

return m_master_tls_region.unsafe_ptr()->vaddr().get();
Expand Down
5 changes: 4 additions & 1 deletion Userland/Libraries/LibC/pthread_tls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ struct SpecificTable {

static KeyTable s_keys;

__thread SpecificTable t_specifics;
# ifndef X86_64_NO_TLS
__thread
# endif
SpecificTable t_specifics;

int __pthread_key_create(pthread_key_t* key, KeyDestructor destructor)
{
Expand Down
12 changes: 10 additions & 2 deletions Userland/Libraries/LibDl/dlfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
#include <string.h>

// FIXME: use thread_local and a String once TLS works
__thread char* s_dlerror_text = NULL;
__thread bool s_dlerror_retrieved = false;
#ifndef X86_64_NO_TLS
__thread
#endif
char* s_dlerror_text
= NULL;
#ifndef X86_64_NO_TLS
__thread
#endif
bool s_dlerror_retrieved
= false;

static void store_error(const String& error)
{
Expand Down
10 changes: 8 additions & 2 deletions Userland/Libraries/LibPthread/pthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ static constexpr size_t required_stack_alignment = 4 * MiB;
static constexpr size_t highest_reasonable_guard_size = 32 * PAGE_SIZE;
static constexpr size_t highest_reasonable_stack_size = 8 * MiB; // That's the default in Ubuntu?

__thread void* s_stack_location;
__thread size_t s_stack_size;
#ifndef X86_64_NO_TLS
__thread
#endif
void* s_stack_location;
#ifndef X86_64_NO_TLS
__thread
#endif
size_t s_stack_size;

#define __RETURN_PTHREAD_ERROR(rc) \
return ((rc) < 0 ? -(rc) : 0)
Expand Down

0 comments on commit fe2716d

Please sign in to comment.