forked from capablevms/cheri-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seal.c
61 lines (53 loc) · 1.06 KB
/
seal.c
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
/***
* This is mostly an experiment and it doens't work
* The CHERI_GET_SEALCAP syscall is mips only
***/
#include "include/common.h"
#include <cheri/cheri.h>
#include <cheri/cheric.h>
#include <cheriintrin.h>
#include <machine/sysarch.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct cap
{
uint32_t perms : 16;
uint32_t padding : 4;
uint32_t otype : 18;
uint32_t internal_e : 1;
uint32_t T : 11;
uint32_t B : 14;
uint64_t address : 64;
} cap_t;
typedef union
{
void *ptr;
cap_t str;
uint64_t arr[2];
} cheri_pointer;
int main()
{
void *pcc = cheri_pcc_get();
pp_cap(pcc);
void *searling_root;
if (sysarch(CHERI_GET_SEALCAP, &searling_root) < 0)
searling_root = NULL;
cheri_pointer data;
void *first = malloc(64);
void *other = malloc(64);
data.ptr = first;
data.ptr = cheri_tag_clear(data.ptr);
data.arr[0] = 0;
data.arr[1] = 0;
first = cheri_seal(first, other);
pp_cap(first);
return 0;
for (uint32_t i = 0; i < 64; i++)
{
data.arr[0] |= (1 << i);
printf("i: %d ", i);
pp_cap(data.ptr);
data.arr[0] = 0;
}
}