Skip to content

Commit 5d4bc78

Browse files
dpgaoresistor
authored andcommitted
[Headers] Add new caprelocs permission for code pointers
Code pointers are like function pointers, but they should not be wrapped in trampolines when c18n is enabled. They are mainly used for C++ exceptions landing pads, among other things. This permissions should be OR'ed with the existing 'function' permission when used. Note that, absent a c18n implementation, which will need to have custom handling of function relocations and so cannot use this implementation, the two can be treated identically.
1 parent abca333 commit 5d4bc78

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

clang/lib/Headers/cheri_init_globals.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ static const __SIZE_TYPE__ global_pointer_permissions_mask =
6767
__CHERI_CAP_PERMISSION_PERMIT_EXECUTE__);
6868
static const __SIZE_TYPE__ indirect_reloc_flag = (__SIZE_TYPE__)1
6969
<< (__SIZE_WIDTH__ - 3);
70+
static const __SIZE_TYPE__ code_reloc_flag = (__SIZE_TYPE__)1
71+
<< (__SIZE_WIDTH__ - 4);
7072

7173
__attribute__((weak)) extern struct capreloc __start___cap_relocs[];
7274
__attribute__((weak)) extern struct capreloc __stop___cap_relocs[];
@@ -186,7 +188,8 @@ cheri_init_globals_impl(const struct capreloc *start_relocs,
186188
__builtin_trap();
187189
#endif
188190
}
189-
if (reloc->permissions == function_reloc_flag) {
191+
if (reloc->permissions == function_reloc_flag ||
192+
reloc->permissions == (function_reloc_flag | code_reloc_flag)) {
190193
base_cap = code_cap; /* code pointer */
191194
/* Do not set tight bounds for functions (unless we are in the plt ABI) */
192195
can_set_bounds = tight_code_bounds;

0 commit comments

Comments
 (0)