2018-02-25 11:14:43 +03:00
|
|
|
/* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
2018-05-01 11:12:56 +03:00
|
|
|
* Copyright (C) 2012-2018 K. Lange
|
2018-02-25 11:14:43 +03:00
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <syscall.h>
|
|
|
|
#include <signal.h>
|
2018-05-09 15:26:45 +03:00
|
|
|
#include <pthread.h>
|
2018-07-18 04:45:42 +03:00
|
|
|
#include <errno.h>
|
2018-02-25 11:14:43 +03:00
|
|
|
|
|
|
|
#define PTHREAD_STACK_SIZE 0x100000
|
|
|
|
|
|
|
|
int clone(uintptr_t a,uintptr_t b,void* c) {
|
2018-07-18 04:45:42 +03:00
|
|
|
__sets_errno(syscall_clone(a,b,c));
|
2018-02-25 11:14:43 +03:00
|
|
|
}
|
|
|
|
int gettid() {
|
2018-07-18 04:45:42 +03:00
|
|
|
return syscall_gettid(); /* never fails */
|
2018-02-25 11:14:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg) {
|
|
|
|
char * stack = malloc(PTHREAD_STACK_SIZE);
|
|
|
|
uintptr_t stack_top = (uintptr_t)stack + PTHREAD_STACK_SIZE;
|
|
|
|
thread->stack = stack;
|
|
|
|
thread->id = clone(stack_top, (uintptr_t)start_routine, arg);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pthread_kill(pthread_t thread, int sig) {
|
2018-07-18 04:45:42 +03:00
|
|
|
__sets_errno(kill(thread.id, sig));
|
2018-02-25 11:14:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void pthread_exit(void * value) {
|
|
|
|
/* Perform nice cleanup */
|
|
|
|
#if 0
|
|
|
|
/* XXX: LOCK */
|
|
|
|
free(stack);
|
|
|
|
/* XXX: Return value!? */
|
|
|
|
#endif
|
|
|
|
uintptr_t magic_exit_target = 0xFFFFB00F;
|
|
|
|
void (*magic_exit_func)(void) = (void *)magic_exit_target;
|
|
|
|
magic_exit_func();
|
|
|
|
}
|