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 /euler/source/entry.cpp | |
parent | 9af5588c30c4126a2800aae1afcb0de2c373dc6c (diff) | |
download | hilbert-os-fbfc078e9f44c1c1e95c9c484f1d5650bcf631b7.tar.gz |
lots and lots of userspace stuff
Diffstat (limited to 'euler/source/entry.cpp')
-rw-r--r-- | euler/source/entry.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/euler/source/entry.cpp b/euler/source/entry.cpp new file mode 100644 index 0000000..e79209c --- /dev/null +++ b/euler/source/entry.cpp @@ -0,0 +1,28 @@ +#include <euler/syscall.hpp> +#include <cstdlib> +#include <string> + +int main(int argc, char **argv); + +extern "C" [[noreturn]] void _start() { + + auto argc_raw = euler::syscall::try_get_environment_variable("ARGC"); + int argc = argc_raw.has_value() ? std::stoi(argc_raw.value()) : 0; + + std::vector<std::string> argv; + + for (int i = 0; i < argc; ++i) { + std::string arg_name = std::string("ARGV") + std::to_string(i); + auto arg_raw = euler::syscall::try_get_environment_variable(arg_name); + argv.push_back(arg_raw.has_value() ? arg_raw.value() : ""); + } + + std::vector<char *> c_argv(argc); + for (int i = 0; i < argc; ++i) + c_argv[i] = argv[i].data(); + + int exit_code = main(argc, c_argv.data()); + + euler::syscall::end_this_process(exit_code); + +} |