summaryrefslogtreecommitdiffstats
path: root/hal/obj.h
blob: 68f4bdc0aa15609c302fd7c730d53bae12b56bcf (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
45
46
47
48
49
50
51
52
53
54
#ifndef _JOVE_HAL_OBJ_H
#define _JOVE_HAL_OBJ_H 1

#include <stddef.h>

#include "api/obj.h"

#ifdef __x86_64__
#include "arch/x86_64/hal/obj.h"
#endif

typedef struct jove_objdir
{
    jove_obj_t entries[JOVE_OBJDIR_ENTRIES];
} jove_objdir_t;

/*Locks the mutex of the kernel object provided. Returns the locked version. */
jove_owned_obj_t *obj_take(jove_obj_t *obj);
jove_owned_obj_t *obj_trytake(jove_obj_t *obj);
/*Unlocks the mutex of the kernel object provided. Returns the unlocked version. */
jove_obj_t *obj_release(jove_owned_obj_t *obj);

/*Converts the value pointer of the object into a pointer to kernel memory.*/
void *obj_deref(jove_owned_obj_t *obj);

/*Getters and setters for accessing the type field of the kernel object. */
uint8_t obj_gettype(jove_owned_obj_t *obj);
uint8_t obj_peektype(jove_obj_t obj);
void obj_settype(jove_owned_obj_t *obj, uint8_t type);

/*Getters and setters for accessing the value field of the kernel object. */
uintmax_t obj_getvalue(jove_owned_obj_t *obj);
void obj_setvalue(jove_owned_obj_t *obj, uintmax_t value);

/*Returns the n'th entry of the object directory passed.
 * If the passed object is not an objdir, returns NULL and sets errno to EBADOBJ.
 * If the passed entry index is out of bounds, returns NULL and sets errno to EOOB.*/
jove_owned_obj_t *objdir_getlocal(jove_owned_obj_t *objdir_obj, uint16_t entry);
/*Same as objdir_getlocal except does not block if entry obj is taken.*/
jove_owned_obj_t *objdir_trygetlocal(jove_owned_obj_t *objdir_obj, uint16_t entry);
jove_obj_t objdir_peeklocal(jove_owned_obj_t *objdir_obj, uint16_t entry);

/*Recursively seeks through an object directory for an object following the passed
 * path variable.
 * If the path length is zero, returns the passed object.
 * If the passed object is not an objdir, returns NULL and sets errno to EBADOBJ.
 * If any object excluding the object at the end of the path is not an objdir,
 * returns NULL and sets errno to EBADOBJ.
 * If any entry in the path is out of bounds, returns NULL and sets errno to EBADOBJ.*/
jove_owned_obj_t *objdir_getobj(jove_owned_obj_t *objdir_obj, const uint16_t *path, size_t path_len);
/*Same as objdir_getobj but does not block if child objects are locked.*/
jove_owned_obj_t *objdir_trygetobj(jove_owned_obj_t *objdir_obj, const uint16_t *path, size_t path_len);

#endif