From fbfc078e9f44c1c1e95c9c484f1d5650bcf631b7 Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sat, 27 Jul 2024 16:57:39 -0400 Subject: lots and lots of userspace stuff --- kernel/source/syscall.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'kernel/source/syscall.cpp') diff --git a/kernel/source/syscall.cpp b/kernel/source/syscall.cpp index 6b0f13f..f2a6801 100644 --- a/kernel/source/syscall.cpp +++ b/kernel/source/syscall.cpp @@ -700,10 +700,44 @@ namespace hilbert::kernel::syscall { } - typedef void (*syscall_handler)( - uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx); + void start_thread_syscall( + uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) { + + uint64_t entry_point = rdi; + uint64_t argument = rsi; + set_zero(rax, rdi, rsi, rdx); + + auto *p = application::running_thread->owner; + auto *t = new application::thread(p, entry_point); + t->saved_state.rdi = argument; + p->add_thread(t); + application::paused_threads->insert(t); + + } + + void clear_socket_read_queue_syscall( + uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) { + + unsigned handle = (unsigned)rdi; + set_zero(rax, rdi, rsi, rdx); + + auto stream = application::running_thread->owner->get_stream(handle); + + if (stream.is_null() || !stream.is_socket) { + rax = 0; + return; + } + + auto &queue = stream.as_socket_stream->read_queue; + + rax = queue.count; + queue.clear(); + + } + + void (*handlers[])( + uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) = { - syscall_handler handlers[] = { &encode_color_syscall, &get_framebuffer_syscall, &open_file_syscall, @@ -723,10 +757,13 @@ namespace hilbert::kernel::syscall { &start_process_syscall, &end_this_process_syscall, &set_stream_length_syscall, - &get_other_end_process_handle_syscall + &get_other_end_process_handle_syscall, + &start_thread_syscall, + &clear_socket_read_queue_syscall + }; - static constexpr int max_syscall_number = 19; + static constexpr int max_syscall_number = 20; } -- cgit v1.2.3