diff options
author | dzwdz | 2022-08-19 18:03:59 +0200 |
---|---|---|
committer | dzwdz | 2022-08-19 18:03:59 +0200 |
commit | 7a4bc281958c639cd52ff4f192933aa161ba81a4 (patch) | |
tree | 6afc254b32bc724d872227f4fb3699ef03f511a0 /src | |
parent | e9161cdcda9e5170f3ea5f18a8275395004ffce4 (diff) |
kernel: kzalloc
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel/arch/amd64/pagedir.c | 4 | ||||
-rw-r--r-- | src/kernel/arch/generic.h | 2 | ||||
-rw-r--r-- | src/kernel/handle.c | 3 | ||||
-rw-r--r-- | src/kernel/mem/alloc.h | 7 | ||||
-rw-r--r-- | src/kernel/proc.c | 6 | ||||
-rw-r--r-- | src/kernel/syscalls.c | 4 |
6 files changed, 13 insertions, 13 deletions
diff --git a/src/kernel/arch/amd64/pagedir.c b/src/kernel/arch/amd64/pagedir.c index 75c9746..f0e45d5 100644 --- a/src/kernel/arch/amd64/pagedir.c +++ b/src/kernel/arch/amd64/pagedir.c @@ -31,9 +31,7 @@ static __user void *addr_canonize(const __user void *addr) { struct pagedir *pagedir_new(void) { - struct pagedir *dir = page_alloc(1); - memset(dir, 0, sizeof *dir); - return dir; + return page_zalloc(1); } void pagedir_free(struct pagedir *dir) { diff --git a/src/kernel/arch/generic.h b/src/kernel/arch/generic.h index b213962..0cf4d50 100644 --- a/src/kernel/arch/generic.h +++ b/src/kernel/arch/generic.h @@ -1,11 +1,9 @@ #pragma once - #include <camellia/types.h> #include <kernel/arch/amd64/registers.h> #include <stdarg.h> #include <stdbool.h> #include <stddef.h> - struct process; // i have no idea where else to put it diff --git a/src/kernel/handle.c b/src/kernel/handle.c index 3e31a12..d95962c 100644 --- a/src/kernel/handle.c +++ b/src/kernel/handle.c @@ -7,8 +7,7 @@ #include <shared/mem.h> struct handle *handle_init(enum handle_type type) { - struct handle *h = kmalloc(sizeof *h); - memset(h, 0, sizeof *h); + struct handle *h = kzalloc(sizeof *h); h->type = type; h->refcount = 1; return h; diff --git a/src/kernel/mem/alloc.h b/src/kernel/mem/alloc.h index fa2798a..671a468 100644 --- a/src/kernel/mem/alloc.h +++ b/src/kernel/mem/alloc.h @@ -1,5 +1,6 @@ #pragma once #include <kernel/arch/generic.h> +#include <shared/mem.h> #include <stddef.h> extern struct malloc_hdr *malloc_last; @@ -20,3 +21,9 @@ void page_free(void *first, size_t pages); void kmalloc_sanity(const void *addr); void *kmalloc(size_t len); void kfree(void *ptr); + +static inline void *kzalloc(size_t len) { + void *b = kmalloc(len); + memset(b, 0, len); + return b; +} diff --git a/src/kernel/proc.c b/src/kernel/proc.c index a9ad37a..77c861c 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -21,8 +21,7 @@ static _Noreturn void process_switch(struct process *proc); struct process *process_seed(void *data, size_t datalen) { assert(!process_first); - process_first = kmalloc(sizeof *process_first); - memset(process_first, 0, sizeof *process_first); + process_first = kzalloc(sizeof *process_first); process_first->state = PS_RUNNING; process_first->pages = pagedir_new(); process_first->mount = vfs_mount_seed(); @@ -48,8 +47,7 @@ struct process *process_seed(void *data, size_t datalen) { } struct process *process_fork(struct process *parent, int flags) { - struct process *child = kmalloc(sizeof *child); - memset(child, 0, sizeof *child); + struct process *child = kzalloc(sizeof *child); if (flags & FORK_SHAREMEM) { if (!parent->pages_refcount) { diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index 5f380b6..d6b23d0 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -323,8 +323,8 @@ void __user *_syscall_memflag(void __user *addr, size_t len, int flags) { phys = pagedir_virt2phys(pages, iter, false, false); if (!phys) { - phys = page_alloc(1); - memset(phys, 0, PAGE_SIZE); // TODO somehow test this + // TODO test zeroing of user pages + phys = page_zalloc(1); pagedir_map(pages, iter, phys, true, true); } } |