diff options
author | Benji Dial <benji@benjidial.net> | 2024-07-27 16:57:39 -0400 |
---|---|---|
committer | Benji Dial <benji@benjidial.net> | 2024-07-27 16:57:39 -0400 |
commit | fbfc078e9f44c1c1e95c9c484f1d5650bcf631b7 (patch) | |
tree | cab539c8cbbac81d895b6f8be695f3f53bf8f4d5 /kernel/source/syscall.cpp | |
parent | 9af5588c30c4126a2800aae1afcb0de2c373dc6c (diff) | |
download | hilbert-os-fbfc078e9f44c1c1e95c9c484f1d5650bcf631b7.tar.gz |
lots and lots of userspace stuff
Diffstat (limited to 'kernel/source/syscall.cpp')
-rw-r--r-- | kernel/source/syscall.cpp | 47 |
1 files changed, 42 insertions, 5 deletions
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; } |