Framework for exporting system header to user space (#59)
[lunaix-os.git] / lunaix-os / usr / libc / src / pthread.c
index 08c82e0e538f37d0a9b78537888d882fe48a08bf..5a51b1c7ef4b821b6f48caf14b078cfbf28376aa 100644 (file)
@@ -1,66 +1,50 @@
-#include <lunaix/syscall.h>
+#include <syscall.h>
 #include <pthread.h>
 
-static void*
-__pthread_routine_wrapper(void *(*start_routine)(void*), void* arg)
-{
-    void* ret = start_routine(arg);
-
-    do_lunaix_syscall(__SYSCALL_th_exit, ret);
-
-    return ret; // should not reach
-}
-
 int 
 pthread_create(pthread_t* thread,
                 const pthread_attr_t* attr,
                 void *(*start_routine)(void*), void* arg)
 {
     // FIXME attr currently not used
+    int ret;
+    struct uthread_param th_param;
 
-    struct uthread_info th_info;
-    int ret = do_lunaix_syscall(__SYSCALL_th_create, thread, &th_info, __pthread_routine_wrapper, NULL);
-
-    if (ret) {
-        return ret;
-    }
-
-    // FIXME we should encapsulate these parameter into struct
-    //       and pass it as a single thread param.
-
-    void** th_stack = (void**) th_info.th_stack_top; 
-    th_stack[1] = (void*)start_routine;
-    th_stack[2] = arg;
+    th_param.th_handler = start_routine;
+    th_param.arg1 = arg;
 
+    extern void th_trampoline();
+    ret = do_lunaix_syscall(__NR__lxsys_th_create, thread, 
+                            &th_param, th_trampoline);
     return ret;
 }
 
 int 
 pthread_detach(pthread_t thread)
 {
-    return do_lunaix_syscall(__SYSCALL_th_detach, thread);
+    return do_lunaix_syscall(__NR__lxsys_th_detach, thread);
 }
 
 void 
 pthread_exit(void *value_ptr)
 {
-    do_lunaix_syscall(__SYSCALL_th_exit, value_ptr);
+    do_lunaix_syscall(__NR__lxsys_th_exit, value_ptr);
 }
 
 int 
 pthread_join(pthread_t thread, void **value_ptr)
 {
-    return do_lunaix_syscall(__SYSCALL_th_join, thread, value_ptr);
+    return do_lunaix_syscall(__NR__lxsys_th_join, thread, value_ptr);
 }
 
 int 
 pthread_kill(pthread_t thread, int sig)
 {
-    return do_lunaix_syscall(__SYSCALL_th_kill, thread, sig);
+    return do_lunaix_syscall(__NR__lxsys_th_kill, thread, sig);
 }
 
 pthread_t 
 pthread_self(void)
 {
-    return do_lunaix_syscall(__SYSCALL_th_self);
+    return do_lunaix_syscall(__NR__lxsys_th_self);
 }