mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
[libj6] Update how init args are passed and used
Now the init args are a linked list - this also means ld.so can use its own plus those of the program (eg, SLP and VFS handles). __init_libj6 now adds the head of the list to its global init_args structure, and the j6_find_init_handle function can be used to find a handle in those args for a given proto. This fixes situations like the logger using the wrong mailbox for the service locator and never finding the uart driver.
This commit is contained in:
@@ -33,6 +33,13 @@ struct j6_arg_header
|
||||
{
|
||||
uint32_t size;
|
||||
uint16_t type;
|
||||
uint16_t reserved;
|
||||
j6_arg_header *next;
|
||||
};
|
||||
|
||||
struct j6_arg_none
|
||||
{
|
||||
add_header(none);
|
||||
};
|
||||
|
||||
struct j6_arg_loader
|
||||
@@ -67,14 +74,17 @@ struct j6_arg_handles
|
||||
|
||||
struct j6_init_args
|
||||
{
|
||||
uint64_t args[2];
|
||||
uint64_t argv[2];
|
||||
j6_arg_header *args;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Find the first handle of the given type held by this process
|
||||
j6_handle_t API j6_find_first_handle(j6_object_type obj_type);
|
||||
|
||||
/// Find the first handle tagged with the given proto in the process init args
|
||||
j6_handle_t API j6_find_init_handle(uint64_t proto);
|
||||
|
||||
/// Get the init args
|
||||
const j6_init_args * j6_get_init_args();
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace {
|
||||
constexpr size_t static_arr_count = 32;
|
||||
j6_handle_descriptor handle_array[static_arr_count];
|
||||
j6_init_args init_args;
|
||||
j6_init_args init_args = { 0, 0, 0 };
|
||||
} // namespace
|
||||
|
||||
j6_handle_t
|
||||
@@ -36,6 +36,26 @@ j6_find_first_handle(j6_object_type obj_type)
|
||||
return j6_handle_invalid;
|
||||
}
|
||||
|
||||
j6_handle_t
|
||||
j6_find_init_handle(uint64_t proto)
|
||||
{
|
||||
j6_arg_header *arg = init_args.args;
|
||||
while (arg) {
|
||||
if (arg->type == j6_arg_type_handles) {
|
||||
j6_arg_handles *harg = reinterpret_cast<j6_arg_handles*>(arg);
|
||||
for (unsigned i = 0; i < harg->nhandles; ++i) {
|
||||
j6_arg_handle_entry &ent = harg->handles[i];
|
||||
if (ent.proto == proto)
|
||||
return ent.handle;
|
||||
}
|
||||
}
|
||||
arg = arg->next;
|
||||
}
|
||||
|
||||
return j6_handle_invalid;
|
||||
}
|
||||
|
||||
|
||||
const j6_init_args * API
|
||||
j6_get_init_args()
|
||||
{
|
||||
@@ -43,10 +63,11 @@ j6_get_init_args()
|
||||
}
|
||||
|
||||
extern "C" void API
|
||||
__init_libj6(uint64_t arg0, uint64_t arg1)
|
||||
__init_libj6(uint64_t argv0, uint64_t argv1, j6_arg_header *args)
|
||||
{
|
||||
init_args.args[0] = arg0;
|
||||
init_args.args[1] = arg1;
|
||||
init_args.argv[0] = argv0;
|
||||
init_args.argv[1] = argv1;
|
||||
init_args.args = args;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ global _libc_crt0_start:function (_libc_crt0_start.end - _libc_crt0_start)
|
||||
|
||||
_start:
|
||||
_libc_crt0_start:
|
||||
mov rdx, [rsp] ; grab args pointer
|
||||
|
||||
push 0 ; Add null frame
|
||||
push 0
|
||||
mov rbp, rsp
|
||||
|
||||
Reference in New Issue
Block a user