summaryrefslogtreecommitdiff
path: root/src/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel')
-rw-r--r--src/kernel/arch/amd64/driver/fsroot.c2
-rw-r--r--src/kernel/arch/amd64/driver/time.c2
-rw-r--r--src/kernel/handle.c2
-rw-r--r--src/kernel/handleset.c2
-rw-r--r--src/kernel/malloc.c26
-rw-r--r--src/kernel/malloc.h28
-rw-r--r--src/kernel/proc.c6
-rw-r--r--src/kernel/syscalls.c11
-rw-r--r--src/kernel/vfs/mount.c4
-rw-r--r--src/kernel/vfs/procfs.c4
-rw-r--r--src/kernel/vfs/request.c2
11 files changed, 67 insertions, 22 deletions
diff --git a/src/kernel/arch/amd64/driver/fsroot.c b/src/kernel/arch/amd64/driver/fsroot.c
index 228232e..a283daa 100644
--- a/src/kernel/arch/amd64/driver/fsroot.c
+++ b/src/kernel/arch/amd64/driver/fsroot.c
@@ -53,7 +53,7 @@ handle(VfsReq *req)
case Hdev:
if (!dev) {
dev_len = get_dev(NULL);
- dev = kmalloc(dev_len, "/ cache");
+ dev = kmalloc(dev_len, TagRootCache);
get_dev(dev);
}
lst = dev;
diff --git a/src/kernel/arch/amd64/driver/time.c b/src/kernel/arch/amd64/driver/time.c
index 8ae6fb2..f47cb74 100644
--- a/src/kernel/arch/amd64/driver/time.c
+++ b/src/kernel/arch/amd64/driver/time.c
@@ -24,7 +24,7 @@ handle(VfsReq *req)
TimeObj *h;
if (req->type == VFSOP_OPEN) {
if (reqpathcmp(req, "")) {
- h = kmalloc(sizeof *h, "dev/time");
+ h = kmalloc(sizeof *h, TagDevTime);
h->base = uptime_ns();
return (uintptr_t)h;
} else {
diff --git a/src/kernel/handle.c b/src/kernel/handle.c
index 06a810c..0703cac 100644
--- a/src/kernel/handle.c
+++ b/src/kernel/handle.c
@@ -8,7 +8,7 @@
#include <shared/mem.h>
Handle *handle_init(enum handle_type type) {
- Handle *h = kzalloc(sizeof *h, "handle");
+ Handle *h = kzalloc(sizeof *h, TagHandle);
h->type = type;
h->refcount = 1;
return h;
diff --git a/src/kernel/handleset.c b/src/kernel/handleset.c
index fc2d426..cf8160b 100644
--- a/src/kernel/handleset.c
+++ b/src/kernel/handleset.c
@@ -7,7 +7,7 @@
HandleSet *
hs_init(void)
{
- HandleSet *hs = kzalloc(sizeof *hs, "handles");
+ HandleSet *hs = kzalloc(sizeof *hs, TagHandleset);
hs->refcount = 1;
return hs;
}
diff --git a/src/kernel/malloc.c b/src/kernel/malloc.c
index 3c10108..ca44cfe 100644
--- a/src/kernel/malloc.c
+++ b/src/kernel/malloc.c
@@ -11,6 +11,27 @@
#define SCMIN 6 /* 1<<6 == 64 */
#define SCMAX 12 /* 1<<11 == 2048 */
+const char *tagnames[] = {
+ "TagInvalid",
+ "TagKernelFs",
+ "TagProcFs",
+ "TagUserFs",
+ "TagOpenPath",
+ "TagMountPath",
+ "TagMountUser",
+ "TagMountRoot",
+ "TagExecbuf",
+ "TagVfsReq",
+ "TagHandleset",
+ "TagHandle",
+ "TagProcess",
+ "TagProcessHandle",
+ "TagDevTime",
+ "TagRootCache",
+ "TagPageRefcount",
+};
+static_assert(sizeof(tagnames) == sizeof(const char *) * TagLast);
+
typedef struct Slab Slab;
struct Slab {
/* The slab is divided up into 1<<sizeclass sized regions.
@@ -108,13 +129,16 @@ getheader(void *addr)
}
void *
-kmalloc(size_t len, const char *desc)
+kmalloc(size_t len, enum MallocTag tag)
{
Slab *al;
void *ret;
int sizeclass, regsize;
uint64_t idx;
+ assert(tag != TagInvalid && tag < TagLast);
+ const char *desc = tagnames[tag] + 3; // very temporary
+
assert(len <= KMALLOC_MAX);
len += DESCLEN;
sizeclass = getsizeclass(len);
diff --git a/src/kernel/malloc.h b/src/kernel/malloc.h
index bda2745..a38d49b 100644
--- a/src/kernel/malloc.h
+++ b/src/kernel/malloc.h
@@ -10,6 +10,28 @@
* dead code. */
#define KMALLOC_MAX 1024
+/* also see the string table in malloc.c */
+enum MallocTag {
+ TagInvalid,
+ TagKernelFs,
+ TagProcFs,
+ TagUserFs,
+ TagOpenPath,
+ TagMountPath,
+ TagMountUser,
+ TagMountRoot,
+ TagExecbuf,
+ TagVfsReq,
+ TagHandleset,
+ TagHandle,
+ TagProcess,
+ TagProcessHandle,
+ TagDevTime,
+ TagRootCache,
+ TagPageRefcount,
+ TagLast,
+};
+
void mem_init(void *memtop);
void mem_reserve(void *addr, size_t len);
void mem_debugprint(void);
@@ -24,12 +46,12 @@ void *page_zalloc(size_t pages);
// frees `pages` consecutive pages starting from *first
void page_free(void *first, size_t pages);
-void *kmalloc(size_t len, const char *desc);
+void *kmalloc(size_t len, enum MallocTag tag);
void kfree(void *ptr);
// TODO calloc
-static inline void *kzalloc(size_t len, const char *desc) {
- void *b = kmalloc(len, desc);
+static inline void *kzalloc(size_t len, enum MallocTag tag) {
+ void *b = kmalloc(len, tag);
memset(b, 0, len);
return b;
}
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 61c1dad..6cc1679 100644
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -19,7 +19,7 @@ static void proc_prune_leaves(void);
Proc *proc_seed(void *data, size_t datalen) {
assert(!proc_first);
- proc_first = kzalloc(sizeof *proc_first, "init");
+ proc_first = kzalloc(sizeof *proc_first, TagProcess);
proc_first->state = PS_RUNNING;
proc_first->pages = pagedir_new();
proc_first->mount = vfs_mount_seed();
@@ -47,11 +47,11 @@ Proc *proc_seed(void *data, size_t datalen) {
}
Proc *proc_fork(Proc *parent, int flags) {
- Proc *child = kzalloc(sizeof *child, "proc");
+ Proc *child = kzalloc(sizeof *child, TagProcess);
if (flags & FORK_SHAREMEM) {
if (!parent->pages_refcount) {
- parent->pages_refcount = kmalloc(sizeof *parent->pages_refcount, "pagerefs");
+ parent->pages_refcount = kmalloc(sizeof *parent->pages_refcount, TagPageRefcount);
*parent->pages_refcount = 1;
}
*parent->pages_refcount += 1;
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 1e1cd2f..3fc09fa 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -38,7 +38,7 @@ long _sys_fork(int flags, hid_t __user *fs_front) {
SYSCALL_RETURN(-EMFILE);
}
- h->backend = kzalloc(sizeof *h->backend, "user fs");
+ h->backend = kzalloc(sizeof *h->backend, TagUserFs);
h->backend->usehcnt = 1; /* handle */
h->backend->is_user = true;
h->backend->user.provhcnt = 1;
@@ -68,7 +68,7 @@ hid_t _sys_open(const char __user *path, long len, int flags) {
/* Doesn't check for free handles. Another thread could use up all
* handles in the meantime anyways, or free some up. */
- path_buf = kmalloc(len, "path opn");
+ path_buf = kmalloc(len, TagOpenPath);
if (pcpy_from(proc_cur, path_buf, path, len) < (size_t)len) {
goto fail;
}
@@ -111,7 +111,7 @@ long _sys_mount(hid_t hid, const char __user *path, long len) {
if (PATH_MAX < len)
SYSCALL_RETURN(-1);
- path_buf = kmalloc(len, "path mnt");
+ path_buf = kmalloc(len, TagMountPath);
if (pcpy_from(proc_cur, path_buf, path, len) < (size_t)len) {
goto fail;
}
@@ -138,7 +138,7 @@ long _sys_mount(hid_t hid, const char __user *path, long len) {
// append to mount list
// TODO move to kernel/vfs/mount.c
- mount = kmalloc(sizeof *mount, "user mnt");
+ mount = kmalloc(sizeof *mount, TagMountUser);
mount->prev = proc_cur->mount;
mount->prefix = path_buf;
mount->prefix_owned = true;
@@ -463,9 +463,8 @@ long _sys_execbuf(void __user *ubuf, size_t len) {
SYSCALL_RETURN(-1);
if (proc_cur->execbuf.buf)
SYSCALL_RETURN(-1);
- // TODO consider supporting nesting execbufs
- char *kbuf = kmalloc(len, "execbuf");
+ char *kbuf = kmalloc(len, TagExecbuf);
if (pcpy_from(proc_cur, kbuf, ubuf, len) < len) {
kfree(kbuf);
SYSCALL_RETURN(-1);
diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c
index fa5d65b..bd47dd8 100644
--- a/src/kernel/vfs/mount.c
+++ b/src/kernel/vfs/mount.c
@@ -10,8 +10,8 @@ VfsMount *vfs_mount_seed(void) {
}
void vfs_root_register(const char *path, void (*accept)(VfsReq *)) {
- VfsBackend *backend = kmalloc(sizeof *backend, "root bck");
- VfsMount *mount = kmalloc(sizeof *mount, "root mnt");
+ VfsBackend *backend = kmalloc(sizeof *backend, TagKernelFs);
+ VfsMount *mount = kmalloc(sizeof *mount, TagMountRoot);
*backend = (VfsBackend) {
.is_user = false,
.usehcnt = 1,
diff --git a/src/kernel/vfs/procfs.c b/src/kernel/vfs/procfs.c
index 86042cd..ab57628 100644
--- a/src/kernel/vfs/procfs.c
+++ b/src/kernel/vfs/procfs.c
@@ -73,7 +73,7 @@ openpath(const char *path, size_t len, Proc *root)
return NULL;
}
- h = kmalloc(sizeof *h, "proc fd");
+ h = kmalloc(sizeof *h, TagProcessHandle);
h->gid = gid;
h->type = type;
return h;
@@ -182,7 +182,7 @@ isdigit(int c) {
VfsBackend *
procfs_backend(Proc *proc)
{
- VfsBackend *be = kzalloc(sizeof(VfsBackend), "kern fs");
+ VfsBackend *be = kzalloc(sizeof(VfsBackend), TagProcFs);
*be = (VfsBackend) {
.is_user = false,
.usehcnt = 1,
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c
index 8e6f14a..92b904f 100644
--- a/src/kernel/vfs/request.c
+++ b/src/kernel/vfs/request.c
@@ -34,7 +34,7 @@ vfsreq_dispatchcopy(VfsReq tmpl)
VfsBackend *backend;
/* allocate memory for the request and move it there */
- req = kmalloc(sizeof *req, "VfsReq");
+ req = kmalloc(sizeof *req, TagVfsReq);
memcpy(req, &tmpl, sizeof *req);
backend = req->backend;
if (backend) {