summaryrefslogtreecommitdiff
path: root/kernel/source/syscall.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/source/syscall.cpp')
-rw-r--r--kernel/source/syscall.cpp78
1 files changed, 73 insertions, 5 deletions
diff --git a/kernel/source/syscall.cpp b/kernel/source/syscall.cpp
index f2a6801..c631df1 100644
--- a/kernel/source/syscall.cpp
+++ b/kernel/source/syscall.cpp
@@ -183,7 +183,7 @@ namespace hilbert::kernel::syscall {
.waiting_to_read = utility::queue<application::thread *>(),
.is_other_side_open = true, .other_process = p2, .other_end = 0 };
se2_out = new application::socket_stream_end {
- .the_socket = s, .read_queue = s->queue_2, .write_queue = s->queue_2,
+ .the_socket = s, .read_queue = s->queue_2, .write_queue = s->queue_1,
.waiting_to_read = utility::queue<application::thread *>(),
.is_other_side_open = true, .other_process = p1, .other_end = se1_out };
se1_out->other_end = se2_out;
@@ -494,8 +494,12 @@ namespace hilbert::kernel::syscall {
rax = (uint64_t)application::stream_result::other_end_closed;
return;
}
- for (uint64_t i = 0; i < count; ++i)
+ auto &wtr_queue = ss->other_end->waiting_to_read;
+ for (uint64_t i = 0; i < count; ++i) {
ss->write_queue.insert(buffer[i]);
+ if (wtr_queue.count > 0)
+ application::paused_threads->insert(wtr_queue.take());
+ }
rax = (uint64_t)application::stream_result::success;
}
@@ -617,7 +621,8 @@ namespace hilbert::kernel::syscall {
break;
}
- application::process *p = new application::process(memory);
+ application::process *p =
+ new application::process(memory, file.dir_entry.name);
for (uint64_t i = 0; i < psi->env_var_count; ++i)
p->add_environment_variable(
@@ -735,6 +740,66 @@ namespace hilbert::kernel::syscall {
}
+ void get_environment_variable_length_syscall(
+ uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) {
+
+ const char *name = (const char *)rdi;
+ uint64_t name_len = rsi;
+ set_zero(rax, rdi, rsi, rdx);
+
+ auto *app = application::running_thread->owner;
+
+ if (!app->memory->valid_to_read(name, name + name_len, false))
+ return;
+
+ utility::string name_string(name, name_len);
+ utility::string *value = app->get_environment_variable(name_string);
+ rax = value == 0 ? (uint64_t)-1 : value->count;
+
+ }
+
+ void get_environment_variable_value_syscall(
+ uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) {
+
+ const char *name = (const char *)rdi;
+ uint64_t name_len = rsi;
+ char *buffer = (char *)rdx;
+ set_zero(rax, rdi, rsi, rdx);
+
+ auto *app = application::running_thread->owner;
+
+ if (!app->memory->valid_to_read(name, name + name_len, false))
+ return;
+
+ utility::string name_string(name, name_len);
+ utility::string *value = app->get_environment_variable(name_string);
+ if (value == 0)
+ return;
+
+ if (!app->memory->valid_to_read(buffer, buffer + value->count, true))
+ return;
+
+ for (unsigned i = 0; i < value->count; ++i)
+ buffer[i] = value->buffer[i];
+
+ }
+
+ void set_thread_name_syscall(
+ uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) {
+
+ const char *name = (const char *)rdi;
+ uint64_t name_len = rsi;
+ set_zero(rax, rdi, rsi, rdx);
+
+ auto *t = application::running_thread;
+
+ if (!t->owner->memory->valid_to_read(name, name + name_len, false))
+ return;
+
+ t->name = utility::string(name, name_len);
+
+ }
+
void (*handlers[])(
uint64_t &rax, uint64_t &rdi, uint64_t &rsi, uint64_t &rdx) = {
@@ -759,11 +824,14 @@ namespace hilbert::kernel::syscall {
&set_stream_length_syscall,
&get_other_end_process_handle_syscall,
&start_thread_syscall,
- &clear_socket_read_queue_syscall
+ &clear_socket_read_queue_syscall,
+ &get_environment_variable_length_syscall,
+ &get_environment_variable_value_syscall,
+ &set_thread_name_syscall
};
- static constexpr int max_syscall_number = 20;
+ static constexpr int max_syscall_number = 24;
}