lib: c: pthread: implement pthread_self
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
#include "pthread.h"
|
||||
|
||||
#include <mango/task.h>
|
||||
#include <mango/types.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
static struct __pthread main_thread = {0};
|
||||
|
||||
struct __pthread *pthread_self(void)
|
||||
{
|
||||
static int init = 0;
|
||||
if (!init) {
|
||||
kern_handle_t self_handle = KERN_HANDLE_INVALID;
|
||||
kern_status_t status = thread_self(&self_handle);
|
||||
if (status != KERN_OK) {
|
||||
/* TODO set an errno value in a way that doesn't result
|
||||
* in a recursive call to pthread_self */
|
||||
return NULL;
|
||||
}
|
||||
struct __pthread *self = &main_thread;
|
||||
self->thr_self = self;
|
||||
self->thr_handle = self_handle;
|
||||
self->thr_map_base = self;
|
||||
self->thr_map_size = sizeof *self;
|
||||
thread_config_set(
|
||||
self_handle,
|
||||
THREAD_CFG_GSBASE,
|
||||
&self,
|
||||
sizeof(void *));
|
||||
init = 1;
|
||||
return self;
|
||||
}
|
||||
|
||||
return __pthread_self();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user