Add sys_exec () and libprocess wrapper, fix ramdisk tar parsing
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m26s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m26s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
make -C boot/limine
|
||||
rm -rf iso_root
|
||||
mkdir -p iso_root/boot/limine
|
||||
mkdir -p iso_root/EFI/BOOT
|
||||
|
||||
|
||||
2
ce/.gitignore
vendored
Normal file
2
ce/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.o
|
||||
ce
|
||||
1
ce/Makefile
Normal file
1
ce/Makefile
Normal file
@@ -0,0 +1 @@
|
||||
include ../make/user.mk
|
||||
7
ce/ce.c
Normal file
7
ce/ce.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <m/system.h>
|
||||
|
||||
void app_main (void) {
|
||||
for (;;) {
|
||||
test ('x');
|
||||
}
|
||||
}
|
||||
3
ce/doc.txt
Normal file
3
ce/doc.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
CE - Command Executor
|
||||
|
||||
This is a shell application. TODO!
|
||||
@@ -13,5 +13,6 @@
|
||||
#define ST_EXISTS 9
|
||||
#define ST_OOB_ERROR 10
|
||||
#define ST_BAD_PATH 11
|
||||
#define ST_EXEC_ERROR 12
|
||||
|
||||
#endif // _M_STATUS_H
|
||||
|
||||
@@ -13,5 +13,6 @@
|
||||
#define SYS_MUTEX_UNLOCK 10
|
||||
#define SYS_ARGUMENT_PTR 11
|
||||
#define SYS_DEVICE_DO 12
|
||||
#define SYS_EXEC 13
|
||||
|
||||
#endif // _M_SYSCALL_DEFS_H
|
||||
|
||||
2
init/.gitignore
vendored
2
init/.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
*.o
|
||||
*.exe
|
||||
init
|
||||
|
||||
@@ -1 +1 @@
|
||||
app := init.exe
|
||||
app := init
|
||||
|
||||
@@ -34,6 +34,8 @@ void app_main (void) {
|
||||
|
||||
letter = 'a';
|
||||
|
||||
process_exec ("ramdisk:/ce");
|
||||
|
||||
process_spawn (&app_proc, (void*)'b');
|
||||
process_spawn (&app_proc, (void*)'c');
|
||||
process_spawn (&app_proc, (void*)'d');
|
||||
|
||||
@@ -87,7 +87,7 @@ static void amd64_smp_bootstrap (struct limine_mp_info* mp_info) {
|
||||
|
||||
atomic_fetch_sub (&cpu_counter, 1);
|
||||
|
||||
struct proc* spin_proc = proc_from_file ("ramdisk", "/spin.exe");
|
||||
struct proc* spin_proc = proc_from_file ("ramdisk", "/spin");
|
||||
struct cpu* spin_cpu = thiscpu;
|
||||
proc_register (spin_proc, &spin_cpu);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
bool path_validate_char (char ch) {
|
||||
return ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
|
||||
(ch == '_') || (ch == '_'));
|
||||
(ch == '_') || (ch == '-') || (ch == '/'));
|
||||
}
|
||||
|
||||
bool path_validate (const char* path) {
|
||||
@@ -13,21 +13,6 @@ bool path_validate (const char* path) {
|
||||
|
||||
const char* ptr = path;
|
||||
|
||||
if (*ptr == ':')
|
||||
return false;
|
||||
|
||||
while (*ptr != ':' && *ptr != '\0') {
|
||||
if (!path_validate_char (*ptr))
|
||||
return false;
|
||||
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (*ptr != ':')
|
||||
return false;
|
||||
|
||||
ptr++;
|
||||
|
||||
if (*ptr != '/')
|
||||
return false;
|
||||
|
||||
@@ -41,7 +26,7 @@ bool path_validate (const char* path) {
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (ptr > path && *(ptr - 1) == '/' && *(ptr - 2) != ':')
|
||||
if (ptr > path + 1 && *(ptr - 1) == '/')
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <limine/requests.h>
|
||||
#include <m/fs_desc_buffer.h>
|
||||
#include <m/status.h>
|
||||
#include <sys/debug.h>
|
||||
|
||||
struct ramdisk_tar_header {
|
||||
char filename[100];
|
||||
@@ -24,15 +25,16 @@ struct ramdisk_tar_file {
|
||||
size_t size;
|
||||
};
|
||||
|
||||
#define RAMDISK_FILES_MAX 128
|
||||
#define RAMDISK_PATH "/boot/mop3dist.tar"
|
||||
#define RAMDISK_FILES_MAX 128
|
||||
#define RAMDISK_FILENAME_MAX 128
|
||||
#define RAMDISK_PATH "/boot/mop3dist.tar"
|
||||
|
||||
static struct ramdisk_tar_file ramdisk_files[RAMDISK_FILES_MAX];
|
||||
|
||||
static struct ramdisk_tar_file* ramdisk_get_file (const char* filename) {
|
||||
for (size_t i = 0; i < RAMDISK_FILES_MAX; i++) {
|
||||
if ((ramdisk_files[i].header != NULL) &&
|
||||
(memcmp (ramdisk_files[i].header->filename, filename, strlen (filename)) == 0))
|
||||
(strncmp (ramdisk_files[i].header->filename, filename, RAMDISK_FILENAME_MAX) == 0))
|
||||
return &ramdisk_files[i];
|
||||
}
|
||||
return NULL;
|
||||
@@ -52,10 +54,10 @@ static size_t ramdisk_tar_get_size (uint8_t* in) {
|
||||
static size_t ramdisk_tar_parse (uint8_t* addr) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0;; i++) {
|
||||
for (i = 0; i < RAMDISK_FILES_MAX; i++) {
|
||||
struct ramdisk_tar_header* hdr = (struct ramdisk_tar_header*)addr;
|
||||
|
||||
if (hdr->filename[i] == '\0')
|
||||
if (hdr->filename[0] == '\0')
|
||||
break;
|
||||
|
||||
size_t size = ramdisk_tar_get_size (hdr->size);
|
||||
@@ -64,10 +66,7 @@ static size_t ramdisk_tar_parse (uint8_t* addr) {
|
||||
ramdisk_files[i].content = (uint8_t*)((uintptr_t)hdr + 512);
|
||||
ramdisk_files[i].size = ramdisk_tar_get_size ((uint8_t*)hdr->size);
|
||||
|
||||
addr += ((size / 512) + 1) * 512;
|
||||
|
||||
if (size % 512)
|
||||
addr += 512;
|
||||
addr += 512 + ((size + 511) & ~511);
|
||||
}
|
||||
|
||||
return i;
|
||||
@@ -83,7 +82,7 @@ bool ramdiskfs_mount (struct vfs_mountpoint* mountpoint) {
|
||||
for (size_t i = 0; i < module->module_count; i++) {
|
||||
struct limine_file* file = module->modules[i];
|
||||
|
||||
if (memcmp (file->path, RAMDISK_PATH, strlen (RAMDISK_PATH)) == 0) {
|
||||
if (strncmp (file->path, RAMDISK_PATH, strlen (RAMDISK_PATH)) == 0) {
|
||||
rd_addr = file->address;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,3 +44,16 @@ int memcmp (const void* s1, const void* s2, size_t n) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int strncmp (const char* s1, const char* s2, size_t n) {
|
||||
while (n && *s1 && (*s1 == *s2)) {
|
||||
++s1;
|
||||
++s2;
|
||||
--n;
|
||||
}
|
||||
if (n == 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return (*(unsigned char*)s1 - *(unsigned char*)s2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ size_t memcpy (void* dst, const void* src, size_t n);
|
||||
void strncpy (char* dst, const char* src, size_t n);
|
||||
size_t strlen (const char* str);
|
||||
int memcmp (const void* s1, const void* s2, size_t n);
|
||||
int strncmp (const char* s1, const char* s2, size_t n);
|
||||
|
||||
#define strlen_null(x) (strlen ((x)) + 1)
|
||||
|
||||
|
||||
@@ -299,11 +299,11 @@ void proc_init (void) {
|
||||
irq_attach (&proc_irq_sched, NULL, CPU_REQUEST_SCHED);
|
||||
#endif
|
||||
|
||||
struct proc* spin_proc = proc_from_file ("ramdisk", "/spin.exe");
|
||||
struct proc* spin_proc = proc_from_file ("ramdisk", "/spin");
|
||||
struct cpu* spin_cpu = thiscpu;
|
||||
proc_register (spin_proc, &spin_cpu);
|
||||
|
||||
struct proc* init = proc_from_file ("ramdisk", "/init.exe");
|
||||
struct proc* init = proc_from_file ("ramdisk", "/init");
|
||||
init->procgroup->capabilities |= PROC_CAP_TERMINAL;
|
||||
struct cpu* init_cpu = thiscpu;
|
||||
proc_register (init, &init_cpu);
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#include <aux/compiler.h>
|
||||
#include <device/device.h>
|
||||
#include <fs/path.h>
|
||||
#include <fs/vfs.h>
|
||||
#include <libk/assert.h>
|
||||
#include <libk/fieldlengthof.h>
|
||||
#include <libk/fieldsizeof.h>
|
||||
#include <libk/std.h>
|
||||
#include <limine/requests.h>
|
||||
#include <m/status.h>
|
||||
@@ -181,7 +184,7 @@ DEFINE_SYSCALL (sys_device_do) {
|
||||
uintptr_t out_paddr;
|
||||
|
||||
if (!(cmd >= 0 && cmd < (int)fieldlengthof (struct device, ops)))
|
||||
return -ST_BAD_DEVICE_OP;
|
||||
return SYSRESULT (-ST_BAD_DEVICE_OP);
|
||||
|
||||
spin_lock (&proc->procgroup->lock);
|
||||
|
||||
@@ -206,7 +209,7 @@ DEFINE_SYSCALL (sys_device_do) {
|
||||
struct device* device = device_find (device_id);
|
||||
|
||||
if (device == NULL)
|
||||
return -ST_NOT_FOUND;
|
||||
return SYSRESULT (-ST_NOT_FOUND);
|
||||
|
||||
spin_lock (&device->lock);
|
||||
|
||||
@@ -214,7 +217,43 @@ DEFINE_SYSCALL (sys_device_do) {
|
||||
|
||||
spin_unlock (&device->lock);
|
||||
|
||||
return ret;
|
||||
return SYSRESULT (ret);
|
||||
}
|
||||
|
||||
/* int exec (char* path) */
|
||||
DEFINE_SYSCALL (sys_exec) {
|
||||
uintptr_t uvaddr_path = a1;
|
||||
|
||||
struct limine_hhdm_response* hhdm = limine_hhdm_request.response;
|
||||
|
||||
uintptr_t out_paddr;
|
||||
|
||||
spin_lock (&proc->procgroup->lock);
|
||||
out_paddr = mm_v2p (&proc->procgroup->pd, uvaddr_path);
|
||||
spin_unlock (&proc->procgroup->lock);
|
||||
|
||||
if (out_paddr == 0)
|
||||
return SYSRESULT (-ST_BAD_ADDRESS_SPACE);
|
||||
|
||||
const char* path = (const char*)((uintptr_t)hhdm->offset + out_paddr);
|
||||
|
||||
char mountpoint[fieldsizeof (struct vfs_mountpoint, key)];
|
||||
const char* subpath = NULL;
|
||||
|
||||
if (!path_parse (path, mountpoint, &subpath))
|
||||
return SYSRESULT (-ST_BAD_PATH);
|
||||
|
||||
struct proc* new = proc_from_file (mountpoint, subpath);
|
||||
|
||||
if (new == NULL)
|
||||
return SYSRESULT (-ST_EXEC_ERROR);
|
||||
|
||||
int pid = new->pid;
|
||||
|
||||
if (proc_register (new, reschedule_cpu) == PROC_NEED_RESCHEDULE)
|
||||
*reschedule = true;
|
||||
|
||||
return SYSRESULT (pid);
|
||||
}
|
||||
|
||||
static syscall_handler_func_t handler_table[] = {
|
||||
@@ -230,6 +269,7 @@ static syscall_handler_func_t handler_table[] = {
|
||||
[SYS_MUTEX_LOCK] = &sys_mutex_lock,
|
||||
[SYS_MUTEX_UNLOCK] = &sys_mutex_unlock,
|
||||
[SYS_DEVICE_DO] = &sys_device_do,
|
||||
[SYS_EXEC] = &sys_exec,
|
||||
};
|
||||
|
||||
syscall_handler_func_t syscall_find_handler (int syscall_num) {
|
||||
|
||||
@@ -38,3 +38,5 @@ void* argument_ptr (void) { return (void*)do_syscall (SYS_ARGUMENT_PTR, 0); }
|
||||
int device_do (int device_id, int cmd, void* a1, void* a2, void* a3, void* a4) {
|
||||
return (int)do_syscall (SYS_DEVICE_DO, device_id, cmd, a1, a2, a3, a4);
|
||||
}
|
||||
|
||||
int exec (const char* path) { return (int)do_syscall (SYS_EXEC, path); }
|
||||
|
||||
@@ -49,4 +49,7 @@ void* argument_ptr (void);
|
||||
/* Call a device command */
|
||||
int device_do (int device_id, int cmd, void* a1, void* a2, void* a3, void* a4);
|
||||
|
||||
/* Run external ELF program */
|
||||
int exec (const char* path);
|
||||
|
||||
#endif // _LIBMSL_M_SYSTEM_H
|
||||
|
||||
@@ -17,3 +17,5 @@ int process_spawn (process_func_t func, void* argument_ptr) {
|
||||
int process_quit (void) { return quit (); }
|
||||
|
||||
void* process_argument (void) { return argument_ptr (); }
|
||||
|
||||
int process_exec (const char* path) { return exec (path); }
|
||||
|
||||
@@ -18,4 +18,7 @@ int process_quit (void);
|
||||
/* Get process argument pointer */
|
||||
void* process_argument (void);
|
||||
|
||||
/* Run ELF process */
|
||||
int process_exec (const char* path);
|
||||
|
||||
#endif // _LIBPROCESS_PROCESS_PROCESS_H
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
apps := init spin
|
||||
apps := \
|
||||
init \
|
||||
spin \
|
||||
ce
|
||||
|
||||
all_apps:
|
||||
@for d in $(apps); do make -C $$d platform=$(platform) all; done
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
exe := $(foreach d,$(apps),$(wildcard $(d)/*.exe))
|
||||
exe := $(foreach d,$(apps),$(wildcard $(d)/$(d)))
|
||||
|
||||
all_dist: mop3dist.tar
|
||||
|
||||
|
||||
2
spin/.gitignore
vendored
2
spin/.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
*.o
|
||||
*.exe
|
||||
spin
|
||||
|
||||
@@ -1 +1 @@
|
||||
app := spin.exe
|
||||
app := spin
|
||||
|
||||
Reference in New Issue
Block a user