options/posix: implement pthread_self

This commit is contained in:
Kacper Słomiński 2020-02-23 19:13:25 +01:00
parent 0d801ae176
commit d164dd13f8
4 changed files with 28 additions and 2 deletions

View file

@ -135,6 +135,7 @@ internal_sources = [
'options/internal/gcc/initfini.cpp',
'options/internal/gcc-extra/cxxabi.cpp',
'options/internal/x86_64/setjmp.S',
'options/internal/x86_64/thread.cpp',
]
if not static

View file

@ -0,0 +1,10 @@
#ifndef MLIBC_THREAD_HPP
#define MLIBC_THREAD_HPP
namespace mlibc {
void *get_current_tcb();
}
#endif // MLIBC_THREAD_HPP

View file

@ -0,0 +1,13 @@
#include <mlibc/thread.hpp>
#include <stdint.h>
namespace mlibc {
void *get_current_tcb() {
uintptr_t ptr;
asm ("movq %%fs:0, %0" : "=r"(ptr));
return reinterpret_cast<void *>(ptr);
}
}

View file

@ -10,6 +10,7 @@
#include <mlibc/allocator.hpp>
#include <mlibc/debug.hpp>
#include <mlibc/sysdeps.hpp>
#include <mlibc/thread.hpp>
static bool enableTrace = false;
@ -100,10 +101,11 @@ int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict,
__ensure(!"Not implemented");
__builtin_unreachable();
}
pthread_t pthread_self(void) {
__ensure(!"Not implemented");
__builtin_unreachable();
return reinterpret_cast<pthread_t>(mlibc::get_current_tcb());
}
int pthread_equal(pthread_t, pthread_t) {
__ensure(!"Not implemented");
__builtin_unreachable();