lib: c: pthread: implement pthread_self
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
.code64
|
.code64
|
||||||
|
|
||||||
.global pthread_self
|
.global __pthread_self
|
||||||
.type pthread_self, @function
|
.type __pthread_self, @function
|
||||||
|
|
||||||
pthread_self:
|
__pthread_self:
|
||||||
push %rbp
|
push %rbp
|
||||||
mov %rsp, %rbp
|
mov %rsp, %rbp
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ struct __pthread {
|
|||||||
void *thr_result;
|
void *thr_result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern struct __pthread *__pthread_self(void);
|
||||||
extern void __pthread_unmap_exit(
|
extern void __pthread_unmap_exit(
|
||||||
kern_handle_t address_space,
|
kern_handle_t address_space,
|
||||||
void *unmap_base,
|
void *unmap_base,
|
||||||
|
|||||||
@@ -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