summaryrefslogtreecommitdiff
path: root/kernel/source
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/source')
-rw-r--r--kernel/source/application.cpp15
-rw-r--r--kernel/source/entry.cpp3
-rw-r--r--kernel/source/interrupts.cpp5
-rw-r--r--kernel/source/syscall.cpp78
4 files changed, 92 insertions, 9 deletions
diff --git a/kernel/source/application.cpp b/kernel/source/application.cpp
index 8070019..6df49cd 100644
--- a/kernel/source/application.cpp
+++ b/kernel/source/application.cpp
@@ -83,7 +83,8 @@ namespace hilbert::kernel::application {
resume_thread(t->saved_state);
}
- process::process(app_memory *memory) : memory(memory) {}
+ process::process(app_memory *memory, const utility::string &name)
+ : name(name), memory(memory) {}
process::~process() {
delete memory; //:p
@@ -94,6 +95,14 @@ namespace hilbert::kernel::application {
environment_variables.insert_end({.a = name, .b = value});
}
+ utility::string *process::get_environment_variable(
+ const utility::string &name) {
+ for (auto *i = environment_variables.first; i; i = i->next)
+ if (i->value.a == name)
+ return &i->value.b;
+ return 0;
+ }
+
void process::add_thread(thread *t) {
threads.insert_end(t);
}
@@ -197,8 +206,8 @@ namespace hilbert::kernel::application {
thread::thread(process *owner, uint64_t entry)
: stack_top(owner->memory->map_new_stack()), waiting_for_socket_stream(0),
- waiting_to_accept_from(0), waiting_to_connect_to(0),
- waiting_for_input(false), owner(owner) {
+ waiting_to_accept_from(0), waiting_to_connect_to(0), waiting_for_input(false),
+ name(utility::string("main", 4)), owner(owner) {
saved_state.rax = 0;
saved_state.rbx = 0;
diff --git a/kernel/source/entry.cpp b/kernel/source/entry.cpp
index 2389bb1..efa70fd 100644
--- a/kernel/source/entry.cpp
+++ b/kernel/source/entry.cpp
@@ -214,7 +214,8 @@ extern "C" [[noreturn]] void entry() {
if (load_init_result != load_app_result::success)
panic(0xc39db3);
- application::process *init_process = new application::process(init_memory);
+ application::process *init_process =
+ new application::process(init_memory, utility::string("init", 4));
init_process->add_environment_variable(
utility::string("ARGC", 4), utility::string("1", 1));
init_process->add_environment_variable(
diff --git a/kernel/source/interrupts.cpp b/kernel/source/interrupts.cpp
index 41d632c..1a1f4d1 100644
--- a/kernel/source/interrupts.cpp
+++ b/kernel/source/interrupts.cpp
@@ -79,6 +79,11 @@ extern "C" [[noreturn]] void print_exception() {
print_reg("r14", exception_info.r14);
print_reg("r15", exception_info.r15);
+ if (application::running_thread != 0) {
+ serial_putstr("running app = ");
+ serial_putstr(application::running_thread->owner->name);
+ }
+
panic(0xba40bb);
}
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;
}