From 2498045362820cc340c10b8752f711b0f263c521 Mon Sep 17 00:00:00 2001 From: boreddevnl Date: Tue, 21 Apr 2026 00:29:11 +0200 Subject: [PATCH] feature: Add syscalls for ELF metadata parsing --- src/sys/syscall.c | 19 ++++++++++++++++++- src/sys/syscall.h | 2 ++ src/userland/libc/syscall.c | 11 +++++++++++ src/userland/libc/syscall.h | 21 +++++++++++++++++++++ 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/sys/syscall.c b/src/sys/syscall.c index e31fb8e..abae687 100644 --- a/src/sys/syscall.c +++ b/src/sys/syscall.c @@ -22,6 +22,7 @@ #include "tty.h" #include "font_manager.h" #include "graphics.h" +#include "app_metadata.h" extern bool ps2_ctrl_pressed; @@ -2087,7 +2088,21 @@ static uint64_t sys_cmd_tty_destroy(const syscall_args_t *args) { return tty_destroy(tty_id); } -#define SYS_CMD_TABLE_SIZE 76 +static uint64_t sys_cmd_get_elf_metadata(const syscall_args_t *args) { + const char *path = (const char *)args->arg2; + boredos_app_metadata_t *out = (boredos_app_metadata_t *)args->arg3; + if (!path || !out) return 0; + return app_metadata_read(path, out) ? 1 : 0; +} +static uint64_t sys_cmd_get_elf_primary_image(const syscall_args_t *args) { + const char *path = (const char *)args->arg2; + char *out_path = (char *)args->arg3; + size_t out_size = (size_t)args->arg4; + if (!path || !out_path || !out_size) return 0; + return app_metadata_get_primary_image(path, out_path, out_size) ? 1 : 0; +} + +#define SYS_CMD_TABLE_SIZE 78 static const syscall_handler_fn sys_cmd_table[SYS_CMD_TABLE_SIZE] = { [SYSTEM_CMD_SET_BG_COLOR] = sys_cmd_set_bg_color, [SYSTEM_CMD_SET_BG_PATTERN] = sys_cmd_set_bg_pattern, @@ -2150,6 +2165,8 @@ static const syscall_handler_fn sys_cmd_table[SYS_CMD_TABLE_SIZE] = { [SYSTEM_CMD_SIGACTION] = sys_cmd_sigaction, [SYSTEM_CMD_SIGPROCMASK] = sys_cmd_sigprocmask, [SYSTEM_CMD_SIGPENDING] = sys_cmd_sigpending, + [SYSTEM_CMD_GET_ELF_METADATA] = sys_cmd_get_elf_metadata, + [SYSTEM_CMD_GET_ELF_PRIMARY_IMAGE] = sys_cmd_get_elf_primary_image, }; static uint64_t handle_sys_write(const syscall_args_t *args) { diff --git a/src/sys/syscall.h b/src/sys/syscall.h index d98d030..5c1ddb3 100644 --- a/src/sys/syscall.h +++ b/src/sys/syscall.h @@ -117,6 +117,8 @@ typedef struct { #define SYSTEM_CMD_SIGACTION 73 #define SYSTEM_CMD_SIGPROCMASK 74 #define SYSTEM_CMD_SIGPENDING 75 +#define SYSTEM_CMD_GET_ELF_METADATA 76 +#define SYSTEM_CMD_GET_ELF_PRIMARY_IMAGE 77 void syscall_init(void); uint64_t syscall_handler_c(registers_t *regs); diff --git a/src/userland/libc/syscall.c b/src/userland/libc/syscall.c index f5068c4..dc99981 100644 --- a/src/userland/libc/syscall.c +++ b/src/userland/libc/syscall.c @@ -335,3 +335,14 @@ void sys_parallel_run(void (*fn)(void*), void **args, int count) { syscall5(SYS_SYSTEM, SYSTEM_CMD_PARALLEL_RUN, (uint64_t)fn, (uint64_t)args, (uint64_t)count, 0); } +// ELF metadata API +int sys_get_elf_metadata(const char *path, boredos_app_metadata_t *out_metadata) { + return (int)syscall4(SYS_SYSTEM, SYSTEM_CMD_GET_ELF_METADATA, + (uint64_t)path, (uint64_t)out_metadata, 0); +} + +int sys_get_elf_primary_image(const char *path, char *out_path, size_t out_path_size) { + return (int)syscall5(SYS_SYSTEM, SYSTEM_CMD_GET_ELF_PRIMARY_IMAGE, + (uint64_t)path, (uint64_t)out_path, (uint64_t)out_path_size, 0); +} + diff --git a/src/userland/libc/syscall.h b/src/userland/libc/syscall.h index 6b03bd9..a923c66 100644 --- a/src/userland/libc/syscall.h +++ b/src/userland/libc/syscall.h @@ -97,12 +97,30 @@ #define SYSTEM_CMD_SIGACTION 73 #define SYSTEM_CMD_SIGPROCMASK 74 #define SYSTEM_CMD_SIGPENDING 75 +#define SYSTEM_CMD_GET_ELF_METADATA 76 +#define SYSTEM_CMD_GET_ELF_PRIMARY_IMAGE 77 #define SPAWN_FLAG_TERMINAL 0x1 #define SPAWN_FLAG_INHERIT_TTY 0x2 #define SPAWN_FLAG_TTY_ID 0x4 #define SPAWN_FLAG_BACKGROUND 0x8 +// ELF app metadata (mirrors src/sys/elf.h, kept in sync manually) +#define BOREDOS_APP_METADATA_MAX_APP_NAME 64 +#define BOREDOS_APP_METADATA_MAX_DESCRIPTION 192 +#define BOREDOS_APP_METADATA_MAX_IMAGES 4 +#define BOREDOS_APP_METADATA_MAX_IMAGE_PATH 160 + +typedef struct __attribute__((packed)) { + uint32_t magic; + uint16_t version; + uint16_t image_count; + uint16_t reserved; + char app_name[BOREDOS_APP_METADATA_MAX_APP_NAME]; + char description[BOREDOS_APP_METADATA_MAX_DESCRIPTION]; + char images[BOREDOS_APP_METADATA_MAX_IMAGES][BOREDOS_APP_METADATA_MAX_IMAGE_PATH]; +} boredos_app_metadata_t; + // Internal assembly entry into Ring 0 extern uint64_t syscall0(uint64_t sys_num); extern uint64_t syscall1(uint64_t sys_num, uint64_t arg1); @@ -217,5 +235,8 @@ int sys_set_dns_server(const net_ipv4_address_t *ip); void sys_network_force_unlock(void); void sys_yield(void); +// ELF metadata API +int sys_get_elf_metadata(const char *path, boredos_app_metadata_t *out_metadata); +int sys_get_elf_primary_image(const char *path, char *out_path, size_t out_path_size); #endif