aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/include/process.h17
-rw-r--r--src/kernel/user/elf.c2
-rw-r--r--src/kernel/user/process.c19
-rw-r--r--src/kernel/user/syscall.c28
-rw-r--r--src/lib/libkogata/syscall.c7
5 files changed, 33 insertions, 40 deletions
diff --git a/src/kernel/include/process.h b/src/kernel/include/process.h
index 82ba8dd..c9615d7 100644
--- a/src/kernel/include/process.h
+++ b/src/kernel/include/process.h
@@ -24,8 +24,18 @@
#define USERSTACK_ADDR 0xB8000000
#define USERSTACK_SIZE 0x00020000 // 32 KB
-struct process;
-typedef struct process process_t;
+struct user_region;
+typedef struct process {
+ pagedir_t *pd;
+ struct user_region *regions;
+
+ hashtbl_t *filesystems;
+
+ thread_t *thread;
+
+ int pid;
+ struct process *parent;
+} process_t;
typedef void* proc_entry_t;
@@ -34,9 +44,6 @@ process_t *current_process();
process_t *new_process(process_t *parent);
// void delete_process(process_t *p); // TODO define semantics for freeing stuff
-pagedir_t *proc_pagedir(process_t *p);
-int proc_pid(process_t *p);
-
bool start_process(process_t *p, proc_entry_t entry); // maps a region for user stack
bool proc_add_fs(process_t *p, fs_t *fs, const char* name);
diff --git a/src/kernel/user/elf.c b/src/kernel/user/elf.c
index 905577d..00b3c54 100644
--- a/src/kernel/user/elf.c
+++ b/src/kernel/user/elf.c
@@ -21,7 +21,7 @@ proc_entry_t elf_load(fs_handle_t *f, process_t* process) {
int i;
pagedir_t *r = get_current_pagedir();
- switch_pagedir(proc_pagedir(process));
+ switch_pagedir(process->pd);
// TODO : when we fail, free ressources ?
diff --git a/src/kernel/user/process.c b/src/kernel/user/process.c
index 579c33d..d1fdf32 100644
--- a/src/kernel/user/process.c
+++ b/src/kernel/user/process.c
@@ -17,18 +17,6 @@ typedef struct user_region {
struct user_region *next;
} user_region_t;
-typedef struct process {
- pagedir_t *pd;
- user_region_t *regions;
-
- hashtbl_t *filesystems;
-
- thread_t *thread;
-
- int pid;
- struct process *parent;
-} process_t;
-
static int next_pid = 1;
static void proc_user_exception(registers_t *regs);
@@ -114,13 +102,6 @@ bool start_process(process_t *p, void* entry) {
return true;
}
-pagedir_t *proc_pagedir(process_t *p) {
- return p->pd;
-}
-
-int proc_pid(process_t *p) {
- return p->pid;
-}
// ================================== //
// MANAGING FILESYSTEMS FOR PROCESSES //
diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c
index 563957c..26032ad 100644
--- a/src/kernel/user/syscall.c
+++ b/src/kernel/user/syscall.c
@@ -8,12 +8,25 @@ typedef uint32_t (*syscall_handler_t)(uint32_t, uint32_t, uint32_t, uint32_t, ui
static syscall_handler_t sc_handlers[SC_MAX] = { 0 };
+static char* sc_copy_string(uint32_t s, uint32_t slen) {
+ const char* addr = (const char*)s;
+ probe_for_read(addr, slen);
+
+ char* buf = malloc(slen+1);
+ if (buf == 0) return 0;
+
+ memcpy(buf, addr, slen);
+ buf[slen] = 0;
+
+ return buf;
+}
+
// ==================== //
// THE SYSCALLS CODE !! //
// ==================== //
static uint32_t exit_sc(uint32_t code, uint32_t uu1, uint32_t uu2, uint32_t uu3, uint32_t uu4) {
- dbg_printf("Proc %d exit with code %d\n", proc_pid(current_process()), code);
+ dbg_printf("Proc %d exit with code %d\n", current_process()->pid, code);
// TODO : use code... and process exiting is not supposed to be done this way
exit();
@@ -25,16 +38,13 @@ static uint32_t yield_sc() {
return 0;
}
-static uint32_t dbg_print_sc(uint32_t x, uint32_t uu1, uint32_t uu2, uint32_t uu3, uint32_t uu4) {
- const char* addr = (const char*)x;
- probe_for_read(addr, 256);
-
- char buf[256];
- memcpy(buf, addr, 256);
- buf[255] = 0;
+static uint32_t dbg_print_sc(uint32_t s, uint32_t slen, uint32_t uu2, uint32_t uu3, uint32_t uu4) {
+ char* msg = sc_copy_string(s, slen);
+ if (msg == 0) return -1;
- dbg_print(buf);
+ dbg_print(msg);
+ free(msg);
return 0;
}
diff --git a/src/lib/libkogata/syscall.c b/src/lib/libkogata/syscall.c
index dc7e648..342426b 100644
--- a/src/lib/libkogata/syscall.c
+++ b/src/lib/libkogata/syscall.c
@@ -4,12 +4,7 @@
#include <string.h>
void dbg_print(const char* str) {
-
- char buf[256];
- strncpy(buf, str, 256);
- buf[255] = 0;
-
- asm volatile("int $0x40"::"a"(SC_DBG_PRINT),"b"(buf));
+ asm volatile("int $0x40"::"a"(SC_DBG_PRINT),"b"(str),"c"(strlen(str)));
}
void yield() {