summaryrefslogtreecommitdiffstats
path: root/memory/bump.c
blob: a6b0228a17549922a6ad6cfbd7361c3ade56bf5c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "bump.h"
#include "memory.h"

static void *s_next_free;

void*
bump_where(void)
{
    return s_next_free;
}

void *bump_alloc(size_t size)
{
    void *ret = s_next_free;
    s_next_free = (void*)((uintptr_t)s_next_free + size);
    vm_ensure(
            (uintptr_t)ret,
            (uintptr_t)s_next_free,
            (page_flags_t) {
                .present = true,
                .writeable = true,
                .useraccess = false,
                .executable = false
            });
    return ret;
}

void
bump_setup(void)
{
    extern void *_kernel_end;
    s_next_free = (void*)&_kernel_end;
}