2012-04-13 07:42:24 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
2012-09-05 07:27:49 +04:00
|
|
|
#include <syscall.h>
|
2014-04-22 06:46:38 +04:00
|
|
|
#include <signal.h>
|
2012-04-13 07:42:24 +04:00
|
|
|
#include "pthread.h"
|
|
|
|
|
2014-04-21 00:19:52 +04:00
|
|
|
#define PTHREAD_STACK_SIZE 0x100000
|
2012-04-13 07:42:24 +04:00
|
|
|
|
2012-09-05 07:27:49 +04:00
|
|
|
int clone(uintptr_t a,uintptr_t b,void* c) {
|
2012-09-13 10:14:01 +04:00
|
|
|
return syscall_clone(a,b,c);
|
2012-09-05 07:27:49 +04:00
|
|
|
}
|
|
|
|
int gettid() {
|
2012-09-13 10:14:01 +04:00
|
|
|
return syscall_gettid();
|
2012-09-05 07:27:49 +04:00
|
|
|
}
|
2012-04-13 07:42:24 +04: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;
|
|
|
|
}
|
|
|
|
|
2014-04-22 06:46:38 +04:00
|
|
|
int pthread_kill(pthread_t thread, int sig) {
|
|
|
|
return kill(thread.id, sig);
|
|
|
|
}
|
|
|
|
|
2012-04-13 07:42:24 +04:00
|
|
|
void pthread_exit(void * value) {
|
|
|
|
/* Perform nice cleanup */
|
|
|
|
#if 0
|
|
|
|
/* XXX: LOCK */
|
|
|
|
free(stack);
|
|
|
|
/* XXX: Return value!? */
|
|
|
|
#endif
|
|
|
|
__asm__ ("jmp 0xFFFFB00F"); /* Force thread exit */
|
|
|
|
}
|