git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Kernel address space isolation and make the kernel heap global to all processes.
[lunaix-os.git]
/
lunaix-os
/
kernel
/
mm
/
kalloc.c
diff --git
a/lunaix-os/kernel/mm/kalloc.c
b/lunaix-os/kernel/mm/kalloc.c
index 91905b4139cb2ee4933c07ddb7f4f5b37e1c93ef..4d9a5d1ee8fe463c3041a08c2d254b95ef2f3812 100644
(file)
--- a/
lunaix-os/kernel/mm/kalloc.c
+++ b/
lunaix-os/kernel/mm/kalloc.c
@@
-57,27
+57,32
@@
lx_grow_heap(heap_context_t* heap, size_t sz);
Note: the brk always point to the beginning of epilogue.
*/
Note: the brk always point to the beginning of epilogue.
*/
+static heap_context_t kheap;
+
int
kalloc_init() {
int
kalloc_init() {
- heap_context_t* kheap = &__current->mm.k_heap;
- kheap->start = &__kernel_heap_start;
- kheap->brk = NULL;
- kheap->max_addr = (void*)KSTACK_START;
+ kheap.start = &__kernel_heap_start;
+ kheap.brk = NULL;
+ kheap.max_addr = (void*)KSTACK_START;
- if (!dmm_init(kheap)) {
+ if (!dmm_init(
&
kheap)) {
return 0;
}
return 0;
}
- SW(kheap
->
start, PACK(4, M_ALLOCATED));
- SW(kheap
->
start + WSIZE, PACK(0, M_ALLOCATED));
- kheap
->
brk += WSIZE;
+ SW(kheap
.
start, PACK(4, M_ALLOCATED));
+ SW(kheap
.
start + WSIZE, PACK(0, M_ALLOCATED));
+ kheap
.
brk += WSIZE;
- return lx_grow_heap(kheap, HEAP_INIT_SIZE) != NULL;
+ return lx_grow_heap(
&
kheap, HEAP_INIT_SIZE) != NULL;
}
void*
lxmalloc(size_t size) {
}
void*
lxmalloc(size_t size) {
- return lx_malloc_internal(&__current->mm.k_heap, size);
+ mutex_lock(&kheap.lock);
+ void* r = lx_malloc_internal(&kheap, size);
+ mutex_unlock(&kheap.lock);
+
+ return r;
}
void*
}
void*
@@
-102,6
+107,7
@@
lxfree(void* ptr) {
if (!ptr) {
return;
}
if (!ptr) {
return;
}
+ mutex_lock(&kheap.lock);
uint8_t* chunk_ptr = (uint8_t*)ptr - WSIZE;
uint32_t hdr = LW(chunk_ptr);
uint8_t* chunk_ptr = (uint8_t*)ptr - WSIZE;
uint32_t hdr = LW(chunk_ptr);
@@
-122,6
+128,8
@@
lxfree(void* ptr) {
SW(next_hdr, LW(next_hdr) | M_PREV_FREE);
coalesce(chunk_ptr);
SW(next_hdr, LW(next_hdr) | M_PREV_FREE);
coalesce(chunk_ptr);
+
+ mutex_unlock(&kheap.lock);
}
}