[kernel] Have process_start syscall take a list of handles

This also prompted a change of the process initialization protocol to
allow handles to get typed, and changing to marking them as just
self/other handls. This also means exposing the object type enum to
userspace.
This commit is contained in:
Justin C. Miller
2021-01-23 20:34:03 -08:00
parent c0f304559f
commit 16b9d4fd8b
10 changed files with 59 additions and 44 deletions

View File

@@ -41,7 +41,7 @@ main(int argc, const char **argv)
j6_init_framebuffer *fb = nullptr;
for (unsigned i = 0; i < initc; ++i) {
if (initv[i].type == j6_init_desc_framebuffer) {
fb = reinterpret_cast<j6_init_framebuffer*>(initv[i].value);
fb = reinterpret_cast<j6_init_framebuffer*>(initv[i].data);
break;
}
}

View File

@@ -15,7 +15,6 @@ extern j6_handle_t __handle_sys;
j6_handle_t endp = j6_handle_invalid;
extern "C" {
void _init_libc(j6_process_init *);
int main(int, const char **);
}

View File

@@ -3,18 +3,25 @@
/// Types used in process and thread initialization
#include <stdint.h>
#include "j6/types.h"
enum j6_init_type { // `value` is a:
j6_init_handle_system, // Handle to the system
j6_init_handle_process, // Handle to this process
j6_init_handle_thread, // Handle to this thread
j6_init_handle_space, // Handle to this process' address space
j6_init_handle_self, // Handle to the system
j6_init_handle_other, // Handle to this process
j6_init_desc_framebuffer // Pointer to a j6_init_framebuffer descriptor
};
struct j6_typed_handle {
enum j6_object_type type;
j6_handle_t handle;
};
struct j6_init_value {
enum j6_init_type type;
uint64_t value;
union {
struct j6_typed_handle handle;
void *data;
};
};
/// Structure defining a framebuffer.

View File

@@ -0,0 +1,12 @@
OBJECT_TYPE( none, 0x00 )
OBJECT_TYPE( system, 0x01 )
OBJECT_TYPE( event, 0x02 )
OBJECT_TYPE( channel, 0x03 )
OBJECT_TYPE( endpoint, 0x04 )
OBJECT_TYPE( vma, 0x05 )
OBJECT_TYPE( process, 0x06 )
OBJECT_TYPE( thread, 0x07 )

View File

@@ -36,15 +36,10 @@ typedef uint64_t j6_handle_t;
#define j6_handle_id_mask 0xffffffffull
#define j6_handle_invalid 0xffffffffull
/// A process' initial data structure for communicating with the system
struct j6_process_init
{
j6_handle_t process;
j6_handle_t handles[3];
};
enum j6_object_type {
#define OBJECT_TYPE( name, val ) j6_object_type_ ## name = val,
#include "j6/object_types.inc"
#undef OBJECT_TYPE
/// A thread's initial data structure
struct j6_thread_init
{
j6_handle_t thread;
j6_object_type_max
};

View File

@@ -9,7 +9,7 @@ SYSCALL(0x0a, object_signal, j6_handle_t, j6_signal_t)
SYSCALL(0x0b, object_close, j6_handle_t)
SYSCALL(0x10, process_create, j6_handle_t *)
SYSCALL(0x11, process_start, j6_handle_t *, uintptr_t)
SYSCALL(0x11, process_start, j6_handle_t, uintptr_t, j6_handle_t *, size_t)
SYSCALL(0x11, process_kill, j6_handle_t)
SYSCALL(0x17, process_exit, int32_t)

View File

@@ -16,17 +16,9 @@ public:
/// Types of kernel objects.
enum class type : uint16_t
{
none,
system,
event,
channel,
endpoint,
vma,
process,
thread,
#define OBJECT_TYPE( name, val ) name = val,
#include "j6/object_types.inc"
#undef OBJECT_TYPE
max
};

View File

@@ -119,27 +119,26 @@ load_process_image(const kernel::args::program *program)
fb_desc->flags |= 1;
j6_init_value *initv = push<j6_init_value>(tcb->rsp3);
initv->type = j6_init_handle_system;
initv->value = static_cast<uint64_t>(proc.add_handle(&system::get()));
initv->type = j6_init_handle_other;
initv->handle.type = j6_object_type_system;
initv->handle.handle = proc.add_handle(&system::get());
initv = push<j6_init_value>(tcb->rsp3);
initv->type = j6_init_handle_process;
initv->value = static_cast<uint64_t>(proc.self_handle());
initv->type = j6_init_handle_self;
initv->handle.type = j6_object_type_process;
initv->handle.handle = proc.self_handle();
initv = push<j6_init_value>(tcb->rsp3);
initv->type = j6_init_handle_thread;
initv->value = static_cast<uint64_t>(th.self_handle());
initv = push<j6_init_value>(tcb->rsp3);
initv->type = j6_init_handle_space;
//initv->value = static_cast<uint64_t>(proc.add_handle(&space));
initv->type = j6_init_handle_self;
initv->handle.type = j6_object_type_thread;
initv->handle.handle = th.self_handle();
initv = push<j6_init_value>(tcb->rsp3);
initv->type = j6_init_desc_framebuffer;
initv->value = reinterpret_cast<uint64_t>(fb_desc);
initv->data = fb_desc;
uint64_t *initc = push<uint64_t>(tcb->rsp3);
*initc = 5;
*initc = 4;
char **argv0 = push<char*>(tcb->rsp3);
*argv0 = message_arg;

View File

@@ -16,8 +16,18 @@ process_create(j6_handle_t *handle)
}
j6_status_t
process_start(j6_handle_t *handle, uintptr_t entrypoint)
process_start(j6_handle_t handle, uintptr_t entrypoint, j6_handle_t *handles, size_t handle_count)
{
process &p = process::current();
process *c = get_handle<process>(handle);
if (handle_count && !handles)
return j6_err_invalid_arg;
for (size_t i = 0; i < handle_count; ++i) {
kobject *o = p.lookup_handle(handles[i]);
if (o) c->add_handle(o);
}
return j6_err_nyi;
}

View File

@@ -28,8 +28,9 @@ _init_libc(uint64_t *rsp)
__initv = (struct j6_init_value *)rsp;
for (unsigned i = 0; i < __initc; ++i) {
if (__initv[i].type == j6_init_handle_system) {
__handle_sys = __initv[i].value;
if (__initv[i].type == j6_init_handle_other &&
__initv[i].handle.type == j6_object_type_system) {
__handle_sys = __initv[i].handle.handle;
break;
}
}