bootstrap: create stdio file descriptors for use by other tasks

This commit is contained in:
2026-04-01 19:06:55 +01:00
parent 2f01138416
commit 70d32cd592
+54 -11
View File
@@ -5,11 +5,13 @@
#include <fs/allocator.h> #include <fs/allocator.h>
#include <fs/context.h> #include <fs/context.h>
#include <fs/file.h>
#include <heap/heap.h> #include <heap/heap.h>
#include <launch.h> #include <launch.h>
#include <mango/handle.h> #include <mango/handle.h>
#include <mango/log.h> #include <mango/log.h>
#include <mango/msg.h> #include <mango/msg.h>
#include <mango/object.h>
#include <mango/task.h> #include <mango/task.h>
#include <mango/types.h> #include <mango/types.h>
#include <pthread.h> #include <pthread.h>
@@ -90,6 +92,45 @@ static void _fs_free(struct fs_allocator *alloc, void *p)
heap_free(alloc->fs_arg, p); heap_free(alloc->fs_arg, p);
} }
static enum fs_status std_write(
struct fs_file *f,
const xpc_buffer_t *buf,
size_t count,
off_t *seek)
{
char data[1024];
xpc_buffer_read(buf, 0, data, sizeof data, NULL);
if (count > sizeof data - 1) {
count = sizeof data - 1;
}
data[count] = 0;
if (data[count - 1] == '\n') {
data[count - 1] = 0;
}
kern_log(data);
*seek += count;
return FS_SUCCESS;
}
static const struct fs_file_ops stdio_ops = {
.f_write = std_write,
};
static void create_stdio(struct fs_context *ctx, kern_handle_t out[3])
{
for (int i = 0; i < 3; i++) {
port_create(&out[i]);
kern_object_info_t info;
kern_object_query(out[i], &info);
struct fs_file *file = fs_context_open_file(ctx, info.obj_id);
fs_file_set_ops(file, &stdio_ops);
port_connect(out[i], 0, 0);
}
}
int main( int main(
int argc, int argc,
const char **argv, const char **argv,
@@ -163,17 +204,6 @@ int main(
launch_ctx_init(&launch); launch_ctx_init(&launch);
launch.ctx_resolve_library = resolve_dependency; launch.ctx_resolve_library = resolve_dependency;
enum launch_status status
= launch_ctx_execute(&launch, &params, LAUNCH_F_NONE, &result);
if (status != KERN_OK) {
kern_logf("failed to start init: %d", status);
return -1;
}
kern_handle_close(result.r_task);
kern_handle_close(result.r_thread);
kern_handle_close(result.r_address_space);
heap_t heap = HEAP_INIT; heap_t heap = HEAP_INIT;
struct fs_allocator fs_allocator = { struct fs_allocator fs_allocator = {
@@ -190,6 +220,19 @@ int main(
return -1; return -1;
} }
create_stdio(fs, params.p_stdio);
enum launch_status status
= launch_ctx_execute(&launch, &params, LAUNCH_F_NONE, &result);
if (status != KERN_OK) {
kern_logf("failed to start init: %d", status);
return -1;
}
kern_handle_close(result.r_task);
kern_handle_close(result.r_thread);
kern_handle_close(result.r_address_space);
fs_context_set_channel(fs, channel); fs_context_set_channel(fs, channel);
enum fs_status fs_status = fs_context_mount_filesystem( enum fs_status fs_status = fs_context_mount_filesystem(
fs, fs,