blob: ca69228ef4f867821779ecfcf4177ecce456544d (
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
|
#include "arch/x86_64/hal/obj.h"
#include "jove.h"
#include "memory.h"
size_t
untyped_size(jove_owned_obj_t *tgt)
{
return ((jove_untyped_t*)obj_deref(tgt))->limit;
}
uintptr_t
untyped_address(jove_owned_obj_t *tgt)
{
return (uintptr_t)obj_deref(tgt);
}
int
untyped_split(jove_owned_obj_t *tgt, jove_owned_obj_t *dst, size_t bytes)
{
jove_untyped_t *tgt_untyped = obj_deref(tgt);
if(tgt_untyped->limit - bytes < JOVE_UNTYPED_MINSIZE) return -ETOOSMALL;
tgt_untyped->limit -= bytes;
obj_settype(dst, JOVE_OBJ_UNTYPED);
obj_setvalue(dst, (uintptr_t)tgt_untyped + tgt_untyped->limit);
jove_untyped_t *dst_untyped = obj_deref(dst);
dst_untyped->limit = bytes;
return 0;
}
int
untyped_merge(jove_owned_obj_t *a, jove_owned_obj_t *b)
{
jove_untyped_t *a_untyped = obj_deref(a);
jove_untyped_t *b_untyped = obj_deref(b);
if((uintptr_t)a_untyped + a_untyped->limit == (uintptr_t)b_untyped) {
return -EBADARG;
}
if((uintptr_t)b_untyped + b_untyped->limit == (uintptr_t)a_untyped) {
return untyped_merge(b, a);
}
a_untyped->limit += b_untyped->limit;
obj_settype(b, JOVE_OBJ_NONE);
return 0;
}
int untyped_retype(jove_owned_obj_t *tgt, uint8_t newtype)
{
obj_settype(tgt, newtype);
return 0;
}
|