aboutsummaryrefslogtreecommitdiff
path: root/sys/vm/vm_dynalloc.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2023-12-13 14:36:09 -0500
committerIan Moffett <ian@osmora.org>2023-12-13 14:36:09 -0500
commit2e6affc24baca5540d6c7f6406519663c15ae985 (patch)
tree9ecbdffd822de460cf51ee3b0072b3fe285380da /sys/vm/vm_dynalloc.c
parent496862183a101a9aceaeff968441fd2ad0bbbd7d (diff)
kernel: vm: Ensure calls are serialized
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys/vm/vm_dynalloc.c')
-rw-r--r--sys/vm/vm_dynalloc.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/sys/vm/vm_dynalloc.c b/sys/vm/vm_dynalloc.c
index e7acd19..a656a00 100644
--- a/sys/vm/vm_dynalloc.c
+++ b/sys/vm/vm_dynalloc.c
@@ -40,8 +40,12 @@ dynalloc(size_t sz)
{
/* TODO: Per CPU */
struct vm_ctx vm_ctx = vm_get_bsp_ctx();
+ void *tmp;
- return tlsf_malloc(vm_ctx.tlsf_ctx, sz);
+ spinlock_acquire(&vm_ctx.dynalloc_lock);
+ tmp = tlsf_malloc(vm_ctx.tlsf_ctx, sz);
+ spinlock_release(&vm_ctx.dynalloc_lock);
+ return tmp;
}
/*
@@ -55,8 +59,12 @@ dynrealloc(void *old_ptr, size_t newsize)
{
/* TODO: Per CPU */
struct vm_ctx vm_ctx = vm_get_bsp_ctx();
+ void *tmp;
- return tlsf_realloc(vm_ctx.tlsf_ctx, old_ptr, newsize);
+ spinlock_acquire(&vm_ctx.dynalloc_lock);
+ tmp = tlsf_realloc(vm_ctx.tlsf_ctx, old_ptr, newsize);
+ spinlock_release(&vm_ctx.dynalloc_lock);
+ return tmp;
}
/*
@@ -70,5 +78,7 @@ dynfree(void *ptr)
/* TODO: Per CPU */
struct vm_ctx vm_ctx = vm_get_bsp_ctx();
+ spinlock_acquire(&vm_ctx.dynalloc_lock);
tlsf_free(vm_ctx.tlsf_ctx, ptr);
+ spinlock_release(&vm_ctx.dynalloc_lock);
}