summaryrefslogtreecommitdiffstats
path: root/hal/shmem.c
blob: 3785c2e064b2b6c70e2af4255fa33745070bd755 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "api/error.h"
#include "hal/obj.h"
#include "lib/string.h"
#include "memory.h"

int 
shmem_new(jove_owned_obj_t *untyped_obj)
{
    jove_untyped_t *untyped = obj_deref(untyped_obj);
    if((uintptr_t)untyped & 0xFFF) return -EALIGN;
    if(untyped->limit & 0xFFF) return -EBADSIZE;

    size_t limit_pages = untyped->limit >> 12;
    if(limit_pages > JOVE_SMHEM_MAXPAGES) return -ETOOBIG;

    obj_setvalue(untyped_obj, (uintptr_t)untyped | limit_pages);
    obj_settype(untyped_obj, JOVE_OBJ_SHMEMORY);
    memset(untyped, 0, untyped->limit);
    return 0;
}