mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[kernel] Remove process & thread self-handles
For the coming switch to cap/handle ref-counting being the main lifetime determiner of objects, get rid of self handles for threads and processes to avoid circular references. Instead, passing 0 to syscalls expecting a thread or process handle signifies "this process/thread".
This commit is contained in:
@@ -9,11 +9,10 @@
|
||||
#include <j6/syscalls.h>
|
||||
#include <j6/types.h>
|
||||
|
||||
j6_handle_t __handle_self;
|
||||
|
||||
namespace {
|
||||
constexpr size_t static_arr_count = 8;
|
||||
j6_handle_descriptor handle_array[static_arr_count];
|
||||
j6_init_args init_args;
|
||||
} // namespace
|
||||
|
||||
j6_handle_t
|
||||
@@ -37,10 +36,12 @@ j6_find_first_handle(j6_object_type obj_type)
|
||||
return j6_handle_invalid;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
__init_libj6(uint64_t *rsp)
|
||||
extern "C" j6_init_args *
|
||||
__init_libj6(uint64_t arg0, uint64_t arg1)
|
||||
{
|
||||
__handle_self = j6_find_first_handle(j6_object_type_process);
|
||||
init_args.args[0] = arg0;
|
||||
init_args.args[1] = arg1;
|
||||
return &init_args;
|
||||
}
|
||||
|
||||
#endif // __j6kernel
|
||||
|
||||
@@ -8,6 +8,11 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct j6_init_args
|
||||
{
|
||||
uint64_t args[2];
|
||||
};
|
||||
|
||||
/// Find the first handle of the given type held by this process
|
||||
j6_handle_t j6_find_first_handle(j6_object_type obj_type);
|
||||
|
||||
|
||||
@@ -5,15 +5,21 @@ extern __init_libc
|
||||
|
||||
global _start:function (_start.end - _start)
|
||||
_start:
|
||||
mov rbp, rsp
|
||||
mov rdi, rsp
|
||||
call __init_libj6
|
||||
call __init_libc
|
||||
push 0 ; Add null frame
|
||||
push 0
|
||||
mov rbp, rsp
|
||||
|
||||
pop rdi
|
||||
mov rsi, rsp
|
||||
call main
|
||||
call __init_libj6
|
||||
mov rbx, rax
|
||||
|
||||
mov rdi, rax
|
||||
call exit
|
||||
call __init_libc
|
||||
|
||||
pop rdi
|
||||
mov rsi, rsp
|
||||
mov rdx, 0 ; TODO: actually parse stack for argc, argv, envp
|
||||
mov rcx, rbx
|
||||
call main
|
||||
|
||||
mov rdi, rax
|
||||
call exit
|
||||
.end:
|
||||
|
||||
@@ -11,11 +11,14 @@ namespace {
|
||||
void
|
||||
run_ctor_list(cb *array, cb *end)
|
||||
{
|
||||
if (!array || !end)
|
||||
return;
|
||||
|
||||
size_t i = 0;
|
||||
while (true) {
|
||||
const cb &ctor = array[i++];
|
||||
if (&ctor == end) return;
|
||||
ctor();
|
||||
if (ctor) ctor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user