summaryrefslogtreecommitdiffstats
path: root/sys/syscall_objdir.c
blob: 277639f14e11ce1037cc53306fde5fdf94ef0437 (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
35
36
37
38
39
40
41
42
43
44
#include "arch/x86_64/hal/obj.h"
#include "hal/process.h"
#include "jove.h"
#include "lib/printf.h"
#include "syscall.h"

int
s_syscall_objdir_objtype(
        jove_owned_obj_t *objdir,
        jove_owned_obj_t *target_dir,
        size_t payload_size,
        void *payload_data)
{
    size_t bytes_needed = 2;
    CHECK_TOOSMALL(bytes_needed, payload_size, "Message is too small for payload.");

    uint16_t local_idx = *((uint16_t*)payload_data);
    if(local_idx > JOVE_OBJDIR_ENTRIES) {
        kprintf("%s: Object index is out of bounds (>= 512)\n", __func__);
        return EOOB;
    }

    jove_obj_t local_obj = objdir_peeklocal(target_dir, local_idx);
    return obj_peektype(local_obj);
}

int
_syscall_handle_objdir(
        jove_owned_obj_t *pcb_obj,
        jove_owned_obj_t *objdir,
        jove_owned_obj_t *message_obj,
        jove_owned_obj_t *target_obj,
        struct syscall_header *header,
        size_t bytes_left,
        void *payload)
{
    switch(header->callid) {
        case SYSCALL_OBJDIR_OBJTYPE:
            return s_syscall_objdir_objtype(objdir, target_obj, bytes_left, payload);
        default:
            kprintf("syscall_handle_objdir: Objdir does not support syscall %i\n", header->callid);
            return EBADARG;
    }
}