mirror of
https://github.com/hermitcore/libhermit.git
synced 2025-03-30 00:00:15 +01:00
reserve at boot time a region for the heap
=> no race between stack und heap creation
This commit is contained in:
parent
9d6375b8fb
commit
cadacc24ae
4 changed files with 31 additions and 6 deletions
|
@ -42,7 +42,8 @@ extern "C" {
|
||||||
#define CACHE_LINE 64
|
#define CACHE_LINE 64
|
||||||
#define KERNEL_STACK_SIZE (8*1024)
|
#define KERNEL_STACK_SIZE (8*1024)
|
||||||
#define DEFAULT_STACK_SIZE (256*1024)
|
#define DEFAULT_STACK_SIZE (256*1024)
|
||||||
#define HEAP_START (1ULL << 34)
|
#define HEAP_START (PAGE_2M_FLOOR((size_t)&kernel_end) + 4*PAGE_SIZE)
|
||||||
|
#define HEAP_SIZE (1ULL << 32)
|
||||||
#define KMSG_SIZE (4*1024)
|
#define KMSG_SIZE (4*1024)
|
||||||
#define INT_SYSCALL 0x80
|
#define INT_SYSCALL 0x80
|
||||||
#define MAILBOX_SIZE 128
|
#define MAILBOX_SIZE 128
|
||||||
|
|
|
@ -392,7 +392,9 @@ static int initd(void* arg)
|
||||||
curr_task->heap->start = PAGE_FLOOR(heap);
|
curr_task->heap->start = PAGE_FLOOR(heap);
|
||||||
curr_task->heap->end = PAGE_FLOOR(heap);
|
curr_task->heap->end = PAGE_FLOOR(heap);
|
||||||
|
|
||||||
// reserve VMA region
|
// region is already reserved for the heap, we have to change the
|
||||||
|
// property of the first page
|
||||||
|
vma_free(curr_task->heap->start, curr_task->heap->start+PAGE_SIZE);
|
||||||
vma_add(curr_task->heap->start, curr_task->heap->start+PAGE_SIZE, VMA_HEAP|VMA_USER);
|
vma_add(curr_task->heap->start, curr_task->heap->start+PAGE_SIZE, VMA_HEAP|VMA_USER);
|
||||||
|
|
||||||
//create_kernel_task(NULL, foo, "foo1", NORMAL_PRIO);
|
//create_kernel_task(NULL, foo, "foo1", NORMAL_PRIO);
|
||||||
|
@ -595,6 +597,7 @@ int hermit_main(void)
|
||||||
PAUSE;
|
PAUSE;
|
||||||
|
|
||||||
print_status();
|
print_status();
|
||||||
|
//vma_dump();
|
||||||
|
|
||||||
create_kernel_task_on_core(NULL, initd, NULL, NORMAL_PRIO, boot_processor);
|
create_kernel_task_on_core(NULL, initd, NULL, NORMAL_PRIO, boot_processor);
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,13 @@
|
||||||
#include <lwip/err.h>
|
#include <lwip/err.h>
|
||||||
#include <lwip/stats.h>
|
#include <lwip/stats.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note that linker symbols are not variables, they have no memory allocated for
|
||||||
|
* maintaining a value, rather their address is their value.
|
||||||
|
*/
|
||||||
|
extern const void kernel_start;
|
||||||
|
extern const void kernel_end;
|
||||||
|
|
||||||
//TODO: don't use one big kernel lock to comminicate with all proxies
|
//TODO: don't use one big kernel lock to comminicate with all proxies
|
||||||
static spinlock_irqsave_t lwip_lock = SPINLOCK_IRQSAVE_INIT;
|
static spinlock_irqsave_t lwip_lock = SPINLOCK_IRQSAVE_INIT;
|
||||||
|
|
||||||
|
@ -244,11 +251,19 @@ ssize_t sys_sbrk(ssize_t incr)
|
||||||
spinlock_lock(&heap_lock);
|
spinlock_lock(&heap_lock);
|
||||||
|
|
||||||
ret = heap->end;
|
ret = heap->end;
|
||||||
heap->end += incr;
|
|
||||||
|
|
||||||
// reserve VMA regions
|
// check heapp boundaries
|
||||||
if (PAGE_CEIL(heap->end) > PAGE_CEIL(ret))
|
if ((heap->end >= HEAP_START) && (heap->end+incr < HEAP_START + HEAP_SIZE)) {
|
||||||
vma_add(PAGE_CEIL(ret), PAGE_FLOOR(heap->end), VMA_HEAP|VMA_USER);
|
heap->end += incr;
|
||||||
|
|
||||||
|
// reserve VMA regions
|
||||||
|
if (PAGE_CEIL(heap->end) > PAGE_CEIL(ret)) {
|
||||||
|
// region is already reserved for the heap, we have to change the
|
||||||
|
// property
|
||||||
|
vma_free(PAGE_CEIL(ret), PAGE_FLOOR(heap->end));
|
||||||
|
vma_add(PAGE_CEIL(ret), PAGE_FLOOR(heap->end), VMA_HEAP|VMA_USER);
|
||||||
|
}
|
||||||
|
} else ret = -ENOMEM;
|
||||||
|
|
||||||
// allocation and mapping of new pages for the heap
|
// allocation and mapping of new pages for the heap
|
||||||
// is catched by the pagefault handler
|
// is catched by the pagefault handler
|
||||||
|
|
6
mm/vma.c
6
mm/vma.c
|
@ -68,6 +68,11 @@ int vma_init(void)
|
||||||
if (BUILTIN_EXPECT(ret, 0))
|
if (BUILTIN_EXPECT(ret, 0))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
// reserve space for the heap
|
||||||
|
ret = vma_add(HEAP_START, HEAP_START+HEAP_SIZE, VMA_NO_ACCESS);
|
||||||
|
if (BUILTIN_EXPECT(ret, 0))
|
||||||
|
goto out;
|
||||||
|
|
||||||
#ifdef CONFIG_VGA
|
#ifdef CONFIG_VGA
|
||||||
// add VGA video memory
|
// add VGA video memory
|
||||||
ret = vma_add(VIDEO_MEM_ADDR, VIDEO_MEM_ADDR + PAGE_SIZE, VMA_READ|VMA_WRITE);
|
ret = vma_add(VIDEO_MEM_ADDR, VIDEO_MEM_ADDR + PAGE_SIZE, VMA_READ|VMA_WRITE);
|
||||||
|
@ -141,6 +146,7 @@ found:
|
||||||
new->flags = flags;
|
new->flags = flags;
|
||||||
new->next = succ;
|
new->next = succ;
|
||||||
new->prev = pred;
|
new->prev = pred;
|
||||||
|
LOG_DEBUG("vma_alloc: create new vma, new->start 0x%zx, new->end 0x%zx\n", new->start, new->end);
|
||||||
|
|
||||||
if (succ)
|
if (succ)
|
||||||
succ->prev = new;
|
succ->prev = new;
|
||||||
|
|
Loading…
Add table
Reference in a new issue