memory: implememt sbrk() clone for dlmalloc
This commit is contained in:
parent
cd287fe8cb
commit
8d53812b36
26
memory/heap_break.c
Normal file
26
memory/heap_break.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
#include "heap_break.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "paging_internal.h"
|
||||||
|
#include "../runtime/stdio.h"
|
||||||
|
|
||||||
|
|
||||||
|
static uintptr_t heapBreak = KERNEL_HEAP_VIRTUAL, pageBreak = KERNEL_HEAP_VIRTUAL;
|
||||||
|
|
||||||
|
void *memory_AddBreak(intptr_t inc) {
|
||||||
|
if (heapBreak + inc < KERNEL_HEAP_VIRTUAL)
|
||||||
|
return (void *)-1;
|
||||||
|
|
||||||
|
heapBreak += inc;
|
||||||
|
|
||||||
|
if (heapBreak > pageBreak) {
|
||||||
|
// we need more pages
|
||||||
|
int pageCount = roundUpToPageCount(heapBreak - pageBreak);
|
||||||
|
io_Printf("memory_AddBreak(): 0x%llx -> 0x%llx, add %d, allocating %d pages\n", heapBreak - inc, heapBreak, inc, pageCount);
|
||||||
|
paging_map_PageAllocated(pageBreak, pageCount, MAP_PROT_READ | MAP_PROT_WRITE);
|
||||||
|
pageBreak += SYSTEM_PAGE_SIZE * pageCount;
|
||||||
|
} else
|
||||||
|
io_Printf("memory_AddBreak(): 0x%llx -> 0x%llx, add %d\n", heapBreak - inc, heapBreak, inc);
|
||||||
|
|
||||||
|
return (void *)(heapBreak - inc);
|
||||||
|
}
|
10
memory/heap_break.h
Normal file
10
memory/heap_break.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../main.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
// memory_AddBreak is a sbrk() clone, increasing the kernel heap size mapped at KERNEL_HEAP_VIRTUAL.
|
||||||
|
// TODO It does not handle negative increments well (yet), as it does not unmap freed heap pages.
|
||||||
|
// I don't know if I should actually implement this, given it's a rather simple fix.
|
||||||
|
void *memory_AddBreak(intptr_t increment);
|
Loading…
Reference in New Issue
Block a user