6#include <__cheri_sealed.h>
8#define CHERI_PERM_GLOBAL (1U << 0)
9#define CHERI_PERM_LOAD_GLOBAL (1U << 1)
10#define CHERI_PERM_STORE (1U << 2)
11#define CHERI_PERM_LOAD_MUTABLE (1U << 3)
12#define CHERI_PERM_STORE_LOCAL (1U << 4)
13#define CHERI_PERM_LOAD (1U << 5)
14#define CHERI_PERM_LOAD_STORE_CAP (1U << 6)
15#define CHERI_PERM_ACCESS_SYS (1U << 7)
16#define CHERI_PERM_EXECUTE (1U << 8)
17#define CHERI_PERM_UNSEAL (1U << 9)
18#define CHERI_PERM_SEAL (1U << 10)
19#define CHERI_PERM_USER0 (1U << 11)
21#define CHERI_OTYPE_BITS 3
27static inline __always_inline ptraddr_t cheri_address_get(
void *x)
29 return __builtin_cheri_address_get(x);
32static inline __always_inline
auto cheri_address_set(
auto *x, ptrdiff_t y)
34 return __builtin_cheri_address_set(x, y);
37static inline __always_inline
auto cheri_address_increment(
auto *x, ptrdiff_t y)
39 return __builtin_cheri_address_increment(x, y);
42static inline __always_inline ptraddr_t cheri_base_get(
void *x)
44 return __builtin_cheri_base_get(x);
47static inline __always_inline ptraddr_t cheri_top_get(
void *x)
49 return __builtin_cheri_top_get(x);
52static inline __always_inline ptraddr_t cheri_length_get(
void *x)
54 return __builtin_cheri_length_get(x);
57static inline __always_inline
auto cheri_tag_clear(
void *x)
59 return __builtin_cheri_tag_clear(x);
62static inline __always_inline
auto cheri_tag_get(
void *x)
64 return __builtin_cheri_tag_get(x);
67static inline __always_inline
bool cheri_is_valid(
void *x)
69 return cheri_tag_get(x);
72static inline __always_inline
bool cheri_is_invalid(
void *x)
74 return !cheri_tag_get(x);
77static inline __always_inline
bool cheri_is_equal_exact(
void *x,
void *y)
79 return __builtin_cheri_equal_exact(x, y);
82static inline __always_inline
bool cheri_is_subset(
void *x,
void *y)
84 return __builtin_cheri_subset_test(x, y);
87static inline __always_inline
auto cheri_permissions_get(
void *x)
89 return __builtin_cheri_perms_get(x);
92static inline __always_inline
auto cheri_permissions_and(
void *x,
unsigned y)
94 return __builtin_cheri_perms_and(x, y);
97static inline __always_inline
auto cheri_type_get(
void *x)
99 return __builtin_cheri_type_get(x);
102static inline __always_inline
auto cheri_seal(
auto *x,
auto *y)
104 return __builtin_cheri_seal(x, y);
107static inline __always_inline
auto cheri_unseal(CHERI_SEALED(
auto *) x,
auto *y)
109 return __builtin_cheri_unseal(x, y);
112static inline __always_inline
auto cheri_bounds_set(
auto *a,
size_t b)
114 return __builtin_cheri_bounds_set(a, b);
117static inline __always_inline
auto cheri_bounds_set_exact(
auto *a,
size_t b)
119 return __builtin_cheri_bounds_set_exact(a, b);
122static inline __always_inline
auto cheri_subset_test(
void *a,
void *b)
124 return __builtin_cheri_subset_test(a, b);
127static inline __always_inline
auto
128cheri_representable_alignment_mask(
size_t len)
130 return __builtin_cheri_representable_alignment_mask(len);
133static inline __always_inline
auto cheri_round_representable_length(
size_t len)
135 return __builtin_cheri_round_representable_length(len);
139# ifndef __ASSEMBLER__
146# define cgetlen(foo) __builtin_cheri_length_get(foo)
147# pragma clang deprecated(cgetlen, "use cheri_length_get instead")
149# define cgetperms(foo) __builtin_cheri_perms_get(foo)
150# pragma clang deprecated(cgetperms, "use cheri_permissions_get instead")
152# define cgettype(foo) __builtin_cheri_type_get(foo)
153# pragma clang deprecated(cgettype, "use cheri_type_get instead")
155# define cgettag(foo) __builtin_cheri_tag_get(foo)
156# pragma clang deprecated(cgettag, "use cheri_tag_get instead")
158# define cincoffset(a, b) __builtin_cheri_offset_increment((a), (b))
159# pragma clang deprecated(cincoffset, \
160 "use cheri_address_increment instead")
162# define cgetaddr(a) __builtin_cheri_address_get(a)
163# pragma clang deprecated(cgetaddr, "use cheri_address_get instead")
165# define csetaddr(a, b) __builtin_cheri_address_set((a), (b))
166# pragma clang deprecated(csetaddr, "use cheri_address_set instead")
168# define cgetbase(foo) __builtin_cheri_base_get(foo)
169# pragma clang deprecated(cgetbase, "use cheri_base_get instead")
171# define candperms(a, b) __builtin_cheri_perms_and((a), (b))
172# pragma clang deprecated(candperms, "use cheri_permissions_and instead")
174# define cseal(a, b) __builtin_cheri_seal((a), (b))
175# pragma clang deprecated(cseal, "use cheri_seal instead")
177# define cunseal(a, b) __builtin_cheri_unseal((a), (b))
178# pragma clang deprecated(cunseal, "use cheri_unseal instead")
180# define csetbounds(a, b) __builtin_cheri_bounds_set((a), (b))
181# pragma clang deprecated(csetbounds, "use cheri_bounds_set instead")
183# define csetboundsext(a, b) __builtin_cheri_bounds_set_exact((a), (b))
184# pragma clang deprecated(csetboundsext, \
185 "use cheri_bounds_set_exact instead")
187# define cequalexact(a, b) __builtin_cheri_equal_exact((a), (b))
188# pragma clang deprecated(cequalexact, \
189 "use cheri_is_equal_exact instead")
191# define ctestsubset(a, b) __builtin_cheri_subset_test(a, b)
192# pragma clang deprecated(ctestsubset, "use cheri_subset_test instead")
194# define creplenalignmask(len) \
195 __builtin_cheri_representable_alignment_mask(len)
196# pragma clang deprecated( \
197 creplenalignmask, "use cheri_representable_alignment_mask instead")
199# define croundreplen(len) \
200 __builtin_cheri_round_representable_length(len)
201# pragma clang deprecated( \
202 croundreplen, "use cheri_round_representable_length instead")
204# define cheri_address_get(x) __builtin_cheri_address_get(x)
205# define cheri_address_set(x, y) __builtin_cheri_address_set((x), (y))
206# define cheri_address_increment(x, y) \
207 __builtin_cheri_offset_increment((x), (y))
208# define cheri_base_get(x) __builtin_cheri_base_get(x)
209# define cheri_top_get(x) __builtin_cheri_top_get(x)
210# define cheri_length_get(x) __builtin_cheri_length_get(x)
211# define cheri_tag_clear(x) __builtin_cheri_tag_clear(x)
212# define cheri_tag_get(x) __builtin_cheri_tag_get(x)
213# define cheri_is_valid(x) __builtin_cheri_tag_get(x)
214# define cheri_is_invalid(x) (!__builtin_cheri_tag_get(x))
215# define cheri_is_equal_exact(x, y) __builtin_cheri_equal_exact((x), (y))
216# define cheri_is_subset(x, y) __builtin_cheri_subset_test((x), (y))
217# define cheri_permissions_get(x) __builtin_cheri_perms_get(x)
218# define cheri_permissions_and(x, y) __builtin_cheri_perms_and((x), (y))
219# define cheri_type_get(x) __builtin_cheri_type_get(x)
220# define cheri_seal(a, b) \
221 (CHERI_SEALED((__typeof__((a)))) __builtin_cheri_seal((a), (b)))
222# define cheri_unseal(a, b) \
223 ((__typeof__(*(a)) *)__builtin_cheri_unseal((a), (b)))
224# define cheri_bounds_set(a, b) __builtin_cheri_bounds_set((a), (b))
225# define cheri_bounds_set_exact(a, b) \
226 __builtin_cheri_bounds_set_exact((a), (b))
227# define cheri_subset_test(a, b) __builtin_cheri_subset_test(a, b)
228# define cheri_representable_alignment_mask(len) \
229 __builtin_cheri_representable_alignment_mask(len)
230# define cheri_round_representable_length(len) \
231 __builtin_cheri_round_representable_length(len)