summaryrefslogtreecommitdiff
path: root/src/user/lib/tce/syscall.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/lib/tce/syscall.c')
-rw-r--r--src/user/lib/tce/syscall.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/user/lib/tce/syscall.c b/src/user/lib/tce/syscall.c
index ae58e73..f9243b0 100644
--- a/src/user/lib/tce/syscall.c
+++ b/src/user/lib/tce/syscall.c
@@ -1,8 +1,9 @@
#include <tce/syscall.h>
-#include <tce/mem.h>
+#include <stdlib.h>
+#include <sched.h>
-static int call(unsigned a, unsigned b, unsigned c, unsigned d, unsigned e, unsigned f) {
- unsigned ret;
+static size_t call(size_t a, size_t b, size_t c, size_t d, size_t e, size_t f) {
+ size_t ret;
asm volatile("int $64" : "=a"(ret) : "a"(a), "b"(b), "c"(c), "d"(d), "S"(e), "D"(f));
return ret;
}
@@ -33,11 +34,17 @@ struct thread_start_data {
void *data;
void *stack;
};
+void *_stack_to_free = 0;
+uint32_t _stack_freeing_mutex = MUTEX_UNLOCKED;
+
void thread_start(void *data) {
struct thread_start_data *tsd = data;
tsd->entry(tsd->data);
- free(tsd->stack);
- thread_exit();
+ mutex_lock(&_stack_freeing_mutex);
+ if (_stack_to_free != 0) free(_stack_to_free);
+ _stack_to_free = tsd->stack;
+ asm volatile("movl %0, (_stack_freeing_mutex); int $64;" ::
+ "a"(0), "r"(MUTEX_UNLOCKED));
}
void thread_new(void (*entry)(void*), void *data) {
struct thread_start_data *tsd = malloc(sizeof(struct thread_start_data));
@@ -55,14 +62,10 @@ int proc_priv() {
return call(7, 0, 0, 0, 0, 0);
}
-int proc_setheap(size_t start, size_t end) {
- return call(8, start, end, 0, 0, 0);
-}
-
-int shm_create(size_t offset, size_t length) {
- return call(9, offset, length, 0, 0, 0);
+void* sbrk(size_t s) {
+ return (void*)call(8, s, 0, 0, 0, 0);
}
-int shm_delete(size_t offset) {
- return call(10, offset, 0, 0, 0, 0);
+void brk(void* ptr) {
+ return call (9, ptr, 0, 0, 0, 0);
}