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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user