blob: 783d2f45329669caf6fa08cc57c2af4b8ea2b9aa (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#include "obj.h"
#include "arch/x86_64/lock.h"
#include "hal/obj.h"
#include "jove.h"
jove_owned_obj_t*
obj_take(jove_obj_t *obj)
{
take_mutex(&obj->lock);
return (jove_owned_obj_t*)obj;
}
jove_obj_t*
obj_release(jove_owned_obj_t *obj)
{
release_mutex((atomic_flag*)&obj->lock);
return (jove_obj_t*)obj;
}
void*
obj_deref(jove_owned_obj_t *obj)
{
return (void*)(((uintptr_t)obj_getvalue(obj)) | 0xFFFF800000000000ULL);
}
uint8_t
obj_gettype(jove_owned_obj_t *obj)
{
return obj->type;
}
void
obj_settype(jove_owned_obj_t *obj, uint8_t type)
{
obj->type = type;
}
uintmax_t
obj_getvalue(jove_owned_obj_t *obj)
{
return obj->value;
}
void
obj_setvalue(jove_owned_obj_t *obj, uintmax_t value)
{
obj->value = value & 0x00007FFFFFFFFFFFULL;
}
jove_obj_t*
objdir_getlocal(
jove_owned_obj_t *objdir_obj,
uint16_t entry)
{
if(objdir_obj->type != JOVE_OBJ_OBJDIR) {
reterr(EBADOBJ);
}
if(entry >= JOVE_OBJDIR_ENTRIES) {
reterr(EOOB);
}
jove_objdir_t *objtab = obj_deref(objdir_obj);
return &objtab->entries[entry];
}
jove_owned_obj_t*
objdir_getobj(
jove_owned_obj_t *objdir_obj,
const uint16_t *path,
size_t path_len)
{
if(path_len == 0) {
return objdir_obj;
}
{
jove_obj_t *child_locked_objdir = objdir_getlocal(objdir_obj, path[0]);
if(child_locked_objdir == NULL) {
return 0;
}
jove_owned_obj_t *child_objdir = obj_take(child_locked_objdir);
jove_owned_obj_t *target_obj = objdir_getobj(child_objdir, path + 1, path_len - 1);
obj_release(child_objdir);
return target_obj;
}
}
|