diff options
author | Marvin Borner | 2021-03-21 14:31:08 +0100 |
---|---|---|
committer | Marvin Borner | 2021-03-21 14:31:08 +0100 |
commit | 3d0c30e6697b2b6ae77a03adefa2a8b81ebe4d92 (patch) | |
tree | aaa59a9fa43ddf50dafcc89bf979fb20de351941 /libc | |
parent | 09c3bdb186868204cb03d457244e05e12eb685d6 (diff) |
Cleaner shared memory implementation
Diffstat (limited to 'libc')
-rw-r--r-- | libc/alloc.c | 7 | ||||
-rw-r--r-- | libc/inc/sys.h | 7 | ||||
-rw-r--r-- | libc/sys.c | 19 |
3 files changed, 18 insertions, 15 deletions
diff --git a/libc/alloc.c b/libc/alloc.c index 8522203..b8139d0 100644 --- a/libc/alloc.c +++ b/libc/alloc.c @@ -26,12 +26,15 @@ static int liballoc_free(void *ptr, u32 p) static void *liballoc_alloc(u32 p) { - return sys_alloc(p); + u32 addr; + assert(sys_alloc(p, &addr) == EOK); + return (void *)addr; } static int liballoc_free(void *ptr, u32 p) { - sys_free(ptr, p); + UNUSED(p); + assert(sys_free(ptr) == EOK); return 0; } diff --git a/libc/inc/sys.h b/libc/inc/sys.h index 8f30dbb..caa1dbd 100644 --- a/libc/inc/sys.h +++ b/libc/inc/sys.h @@ -17,7 +17,6 @@ enum sys { SYS_LOOP, // To infinity and beyond (debug)! SYS_ALLOC, // Allocate memory - SYS_SHALLOC, // Allocate shared memory SYS_SHACCESS, // Access shared memory SYS_FREE, // Free memory SYS_STAT, // Get file information @@ -78,10 +77,10 @@ res yield(void); res boot(u32 cmd); u32 time(void); -void *sys_alloc(u32 size); -res shalloc(u32 size, u32 *id); +res sys_alloc(u32 size, u32 *addr); +res sys_free(void *ptr); +res shalloc(u32 size, u32 *addr, u32 *id); res shaccess(u32 id, u32 *addr, u32 *size); -void sys_free(void *ptr, u32 size); static inline u32 getpid(void) { @@ -2,6 +2,7 @@ // Syscall implementation #include <arg.h> +#include <assert.h> #include <errno.h> #include <sys.h> @@ -78,25 +79,25 @@ res sys5(enum sys num, int d1, int d2, int d3, int d4, int d5) * Syscalls */ -void *sys_alloc(u32 size) +res sys_alloc(u32 size, u32 *addr) { - return (void *)sys1(SYS_ALLOC, (int)size); + u32 id = 0; + return sys4(SYS_ALLOC, (int)size, (int)addr, (int)&id, 0); } -res shalloc(u32 size, u32 *id) +res sys_free(void *ptr) { - return (res)sys2(SYS_SHALLOC, (int)size, (int)id); + return sys1(SYS_FREE, (int)ptr); } -res shaccess(u32 id, u32 *addr, u32 *size) +res shalloc(u32 size, u32 *addr, u32 *id) { - return (res)sys3(SYS_SHACCESS, (int)id, (int)addr, (int)size); + return sys4(SYS_ALLOC, (int)size, (int)addr, (int)id, 1); } -// TODO: Freeing by ptr + size could be a security risk -> only by address! -void sys_free(void *ptr, u32 size) +res shaccess(u32 id, u32 *addr, u32 *size) { - sys2(SYS_FREE, (int)ptr, (int)size); + return sys3(SYS_SHACCESS, (int)id, (int)addr, (int)size); } void loop(void) |