options/posix: implement pthread_self
This commit is contained in:
parent
0d801ae176
commit
d164dd13f8
|
@ -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
|
||||
|
|
10
options/internal/include/mlibc/thread.hpp
Normal file
10
options/internal/include/mlibc/thread.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef MLIBC_THREAD_HPP
|
||||
#define MLIBC_THREAD_HPP
|
||||
|
||||
namespace mlibc {
|
||||
|
||||
void *get_current_tcb();
|
||||
|
||||
}
|
||||
|
||||
#endif // MLIBC_THREAD_HPP
|
13
options/internal/x86_64/thread.cpp
Normal file
13
options/internal/x86_64/thread.cpp
Normal 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue