summaryrefslogtreecommitdiffstats
path: root/proc/init.c
blob: 65299f4a7045fbc14a46ae373684f9342a219654 (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
34
#include "init.h"
#include "hal/memory.h"
#include "panic/panic.h"

objpath_part_t s_last_untyped = JOVE_OBJDIR_ENTRIES-1;

jove_owned_obj_t
init_pop_alloc(void)
{
    jove_owned_obj_t *untyped_dir = objdir_trygetlocal(_rootdir_obj, ROOTDIR_UNTYPED_I);
    if(untyped_dir == 0) {
        kpanic("Untyped directory is locked!\n");
    }
    int cycles = 0;

    while(cycles++ < 512) {
        if(objdir_peeklocal(untyped_dir, s_last_untyped).type != JOVE_OBJ_UNTYPED) {
            s_last_untyped--;
            continue;
        }

        jove_owned_obj_t frame = { 0 };
        jove_owned_obj_t *untyped = objdir_getlocal(untyped_dir, s_last_untyped);

        if(untyped_split(untyped, &frame, 0x1000) < 0) {
            kpanic("%s: Failed to split last untyped.\n", __func__);
        }

        obj_release(untyped);
        obj_release(untyped_dir);
        return frame;
    }
    kpanic("%s: Kernel is out of memory!\n", __func__);
}