diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-14 11:07:31 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-14 11:07:31 +0100 |
commit | 630c28c3fd3297c7a0ea7ec7ad4417f521fdaa7f (patch) | |
tree | f8c1bfe9da8dc23a69d8982bfb2b4e19d517f820 /src/kernel/user/syscall.c | |
parent | 706c69d40fcc46e7d7f170dab932d3c7fcc7c34e (diff) | |
download | kogata-630c28c3fd3297c7a0ea7ec7ad4417f521fdaa7f.tar.gz kogata-630c28c3fd3297c7a0ea7ec7ad4417f521fdaa7f.zip |
Change a bit of structure
Diffstat (limited to 'src/kernel/user/syscall.c')
-rw-r--r-- | src/kernel/user/syscall.c | 28 |
1 files changed, 19 insertions, 9 deletions
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; } |