aboutsummaryrefslogtreecommitdiff
path: root/lib/mlibc/sysdeps/lyre/generic/thread.cpp
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:52 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 18:24:51 -0500
commitf5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 (patch)
tree93b156621dc0303816b37f60ba88051b702d92f6 /lib/mlibc/sysdeps/lyre/generic/thread.cpp
parentbd5969fc876a10b18613302db7087ef3c40f18e1 (diff)
build: Build mlibc + add distclean target
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/sysdeps/lyre/generic/thread.cpp')
-rw-r--r--lib/mlibc/sysdeps/lyre/generic/thread.cpp58
1 files changed, 0 insertions, 58 deletions
diff --git a/lib/mlibc/sysdeps/lyre/generic/thread.cpp b/lib/mlibc/sysdeps/lyre/generic/thread.cpp
deleted file mode 100644
index 5186e1f..0000000
--- a/lib/mlibc/sysdeps/lyre/generic/thread.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-#include <sys/mman.h>
-#include <mlibc/debug.hpp>
-#include <errno.h>
-#include <mlibc/all-sysdeps.hpp>
-#include <bits/ensure.h>
-#include <mlibc/tcb.hpp>
-
-extern "C" void __mlibc_thread_trampoline(void *(*fn)(void *), Tcb *tcb, void *arg) {
- if (mlibc::sys_tcb_set(tcb)) {
- __ensure(!"failed to set tcb for new thread");
- }
-
- while (__atomic_load_n(&tcb->tid, __ATOMIC_RELAXED) == 0) {
- mlibc::sys_futex_wait(&tcb->tid, 0, nullptr);
- }
-
- tcb->invokeThreadFunc(reinterpret_cast<void *>(fn), arg);
-
- __atomic_store_n(&tcb->didExit, 1, __ATOMIC_RELEASE);
- mlibc::sys_futex_wake(&tcb->didExit);
-
- mlibc::sys_thread_exit();
-}
-
-#define DEFAULT_STACK 0x400000
-
-namespace mlibc {
- int sys_prepare_stack(void **stack, void *entry, void *arg, void *tcb, size_t *stack_size, size_t *guard_size, void **stack_base) {
- // TODO guard
-
- mlibc::infoLogger() << "mlibc: sys_prepare_stack() does not setup a guard!" << frg::endlog;
-
- *guard_size = 0;
-
- *stack_size = *stack_size ? *stack_size : DEFAULT_STACK;
-
- if (!*stack) {
- *stack_base = mmap(NULL, *stack_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
- if (*stack_base == MAP_FAILED) {
- return errno;
- }
- } else {
- *stack_base = *stack;
- }
-
- *stack = (void *)((char *)*stack_base + *stack_size);
-
- void **stack_it = (void **)*stack;
-
- *--stack_it = arg;
- *--stack_it = tcb;
- *--stack_it = entry;
-
- *stack = (void *)stack_it;
-
- return 0;
- }
-}