From 9af5588c30c4126a2800aae1afcb0de2c373dc6c Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Mon, 20 May 2024 17:40:47 -0400 Subject: rewrite application stuff in the kernel to support multitasking --- euler/include/euler/start_process.hpp | 30 +++++++++++++++++ euler/include/euler/syscall.hpp | 28 ++++++++++++++++ euler/include/type_traits | 23 +++++++++++++ euler/include/utility | 12 +++++++ euler/include/vector | 62 +++++++++++++++++++++++++++++++++++ 5 files changed, 155 insertions(+) create mode 100644 euler/include/euler/start_process.hpp create mode 100644 euler/include/type_traits create mode 100644 euler/include/utility create mode 100644 euler/include/vector (limited to 'euler/include') diff --git a/euler/include/euler/start_process.hpp b/euler/include/euler/start_process.hpp new file mode 100644 index 0000000..00ebbab --- /dev/null +++ b/euler/include/euler/start_process.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +namespace euler { + + struct start_process { + + private: + const char *path; + uint64_t path_len; + std::vector<__euler_env_var_spec> env_var_specs; + std::vector<__euler_gift_stream_spec> gift_stream_specs; + + public: + //path needs to stay valid through any call to start + start_process(const char *path); + + //name and value need to stay valid through any call to start + void add_env_variable(const char *name, const char *value); + + void gift_stream( + __euler_stream_handle to_gifter, __euler_stream_handle to_giftee); + + __euler_stream_result start(__euler_process_handle &handle_out); + + }; + +} diff --git a/euler/include/euler/syscall.hpp b/euler/include/euler/syscall.hpp index 761dbcc..981925f 100644 --- a/euler/include/euler/syscall.hpp +++ b/euler/include/euler/syscall.hpp @@ -27,6 +27,7 @@ enum __euler_seek_from : uint8_t { }; typedef uint64_t __euler_stream_handle; +typedef uint64_t __euler_process_handle; extern "C" __euler_stream_result __euler_open_file( const char *path, uint64_t path_len, __euler_stream_handle &handle_out, @@ -72,3 +73,30 @@ enum __euler_input_packet_type : uint8_t { extern "C" __euler_input_packet_type __euler_get_input_packet( __euler_mouse_buttons &buttons_out, int16_t &x_change_out, int16_t &y_change_out, uint32_t &keyboard_packet_out); + +struct [[gnu::packed]] __euler_env_var_spec { + uint64_t name_len; + const char *name; + uint64_t value_len; + const char *value; +}; + +struct [[gnu::packed]] __euler_gift_stream_spec { + __euler_stream_handle stream_handle_to_gifter; + __euler_stream_handle stream_handle_to_giftee; +}; + +struct [[gnu::packed]] __euler_process_start_info { + uint64_t file_path_length; + const char *file_path; + uint64_t env_var_count; + const __euler_env_var_spec *env_vars; + uint64_t gift_stream_count; + const __euler_gift_stream_spec *gift_streams; +}; + +extern "C" __euler_stream_result __euler_start_process( + const __euler_process_start_info &info, __euler_process_handle &handle_out); + +extern "C" __euler_stream_result __euler_get_other_end_process_handle( + __euler_stream_handle handle_in, __euler_process_handle &handle_out); diff --git a/euler/include/type_traits b/euler/include/type_traits new file mode 100644 index 0000000..fcea013 --- /dev/null +++ b/euler/include/type_traits @@ -0,0 +1,23 @@ +#pragma once + +namespace std { + + template + struct remove_reference { + typedef t type; + }; + + template + struct remove_reference { + typedef t type; + }; + + template + struct remove_reference { + typedef t type; + }; + + template + using remove_reference_t = typename remove_reference::type; + +} diff --git a/euler/include/utility b/euler/include/utility new file mode 100644 index 0000000..23648c4 --- /dev/null +++ b/euler/include/utility @@ -0,0 +1,12 @@ +#pragma once + +#include + +namespace std { + + template + constexpr std::remove_reference_t &&move(t &&x) { + return static_cast &&>(x); + } + +} diff --git a/euler/include/vector b/euler/include/vector new file mode 100644 index 0000000..f5083ed --- /dev/null +++ b/euler/include/vector @@ -0,0 +1,62 @@ +#pragma once + +#include +#include + +namespace std { + + template + class vector { + + t *buffer; + size_t buffer_length;//always positive + size_t count; + + public: + vector() : buffer(new t[16]), buffer_length(16), count(0) {} + + ~vector() { + delete[] buffer; + } + + t &operator[](size_t pos) { + return buffer[pos]; + } + + const t &operator[](size_t pos) const { + return buffer[pos]; + } + + t *data() { + return buffer; + } + + const t *data() const { + return buffer; + } + + size_t size() const { + return count; + } + + void reserve(size_t new_length) { + if (new_length <= buffer_length) + return; + t *new_buffer = new t[new_length]; + for (size_t i = 0; i < count; ++i) + new_buffer[i] = std::move(buffer[i]); + delete[] buffer; + buffer = new_buffer; + buffer_length = new_length; + } + + void push_back(t &&value) { + if (count == buffer_length) + reserve(count * 2); + buffer[count++] = std::move(value); + } + + //TODO + }; + +} -- cgit v1.2.3