-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
c18n: Support for C++ exceptions #688
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1868,6 +1868,9 @@ class _LIBUNWIND_HIDDEN Registers_arm64 { | |
uintptr_t __lr; // Link register r30 | ||
uintptr_t __sp; // Stack pointer r31 | ||
uintptr_t __pc; // Program counter | ||
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX) | ||
uintptr_t __csp; // Executive stack pointer | ||
#endif | ||
uint64_t __ra_sign_state; // RA sign state register | ||
}; | ||
|
||
|
@@ -1884,8 +1887,13 @@ inline Registers_arm64::Registers_arm64(const void *registers) { | |
"arm64 registers do not fit into unw_context_t"); | ||
memcpy(&_registers, registers, sizeof(_registers)); | ||
#ifdef __CHERI_PURE_CAPABILITY__ | ||
static_assert(sizeof(GPRs) == 0x220, | ||
"expected VFP registers to be at offset 544"); | ||
#ifdef RTLD_SANDBOX | ||
static_assert(sizeof(GPRs) == 0x230, | ||
"expected VFP registers to be at offset 560"); | ||
#else | ||
static_assert(sizeof(GPRs) == 0x220, | ||
"expected VFP registers to be at offset 544"); | ||
#endif | ||
#else | ||
static_assert(sizeof(GPRs) == 0x110, | ||
"expected VFP registers to be at offset 272"); | ||
|
@@ -1910,6 +1918,8 @@ inline bool Registers_arm64::validRegister(int regNum) const { | |
#ifdef __CHERI_PURE_CAPABILITY__ | ||
if ((regNum >= UNW_ARM64_C0) && (regNum <= UNW_ARM64_C31)) | ||
return true; | ||
if (regNum == UNW_ARM64_CCSP) | ||
return true; | ||
#endif | ||
if (regNum > 95) | ||
return false; | ||
|
@@ -1936,6 +1946,10 @@ inline uintptr_t Registers_arm64::getRegister(int regNum) const { | |
#ifdef __CHERI_PURE_CAPABILITY__ | ||
if ((regNum >= UNW_ARM64_C0) && (regNum <= UNW_ARM64_C31)) | ||
return _registers.__x[regNum - UNW_ARM64_C0]; | ||
#ifdef RTLD_SANDBOX | ||
if (regNum == UNW_ARM64_CCSP) | ||
return _registers.__csp; | ||
#endif | ||
#endif | ||
_LIBUNWIND_ABORT("unsupported arm64 register"); | ||
} | ||
|
@@ -1956,6 +1970,10 @@ inline void Registers_arm64::setRegister(int regNum, uintptr_t value) { | |
#ifdef __CHERI_PURE_CAPABILITY__ | ||
else if ((regNum >= UNW_ARM64_C0) && (regNum <= UNW_ARM64_C31)) | ||
_registers.__x[regNum - UNW_ARM64_C0] = value; | ||
#ifdef RTLD_SANDBOX | ||
else if (regNum == UNW_ARM64_CCSP) | ||
_registers.__csp = value; | ||
#endif | ||
#endif | ||
else | ||
_LIBUNWIND_ABORT("unsupported arm64 register"); | ||
|
@@ -1969,6 +1987,8 @@ inline bool Registers_arm64::validCapabilityRegister(int regNum) const { | |
return true; | ||
if ((regNum >= UNW_ARM64_C0) && (regNum <= UNW_ARM64_C31)) | ||
return true; | ||
if (regNum == UNW_ARM64_CCSP) | ||
return true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not true for !RTLD_SANDBOX |
||
return false; | ||
} | ||
|
||
|
@@ -2184,6 +2204,8 @@ inline const char *Registers_arm64::getRegisterName(int regNum) { | |
return "clr"; | ||
case UNW_ARM64_C31: | ||
return "csp"; | ||
case UNW_ARM64_CCSP: | ||
return "ccsp"; | ||
default: | ||
return "unknown register"; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -824,6 +824,13 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext) | |
|
||
#elif defined(__aarch64__) | ||
|
||
#if defined(__CHERI_PURE_CAPABILITY__) && defined(RTLD_SANDBOX) | ||
DEFINE_LIBUNWIND_FUNCTION(__rtld_unw_getcontext) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explicitly hooking into rtld from libunwind feels pretty gross... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did the same for libc and libthr. Is libunwind any different? Hooking into rtld seems to be the only way to access Executive mode registers from libunwind... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because they’re developed by and for FreeBSD, rather than being a third-party library, and they already have such hooks. |
||
ret | ||
END_LIBUNWIND_FUNCTION(__rtld_unw_getcontext) | ||
WEAK_ALIAS(__rtld_unw_getcontext, _rtld_unw_getcontext) | ||
#endif | ||
|
||
// | ||
// extern int __unw_getcontext(unw_context_t* thread_state) | ||
// | ||
|
@@ -848,12 +855,20 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext) | |
stp c24,c25, [c0, #0x180] | ||
stp c26,c27, [c0, #0x1a0] | ||
stp c28,c29, [c0, #0x1c0] | ||
str c30, [c0, #0x1e0] | ||
mov c1,csp | ||
str c1, [c0, #0x1f0] | ||
mov c1, csp | ||
stp c30,c1, [c0, #0x1e0] | ||
str c30, [c0, #0x200] // store return address as pcc | ||
#ifdef RTLD_SANDBOX | ||
add c0, c0, #0x210 | ||
// Store Executive stack pointer here | ||
bl _rtld_unw_getcontext | ||
ldr c30, [c0, #-0x10] | ||
// skip cpsr | ||
add c0, c0, #0x20 | ||
#else | ||
// skip cpsr | ||
add c0, c0, #0x220 | ||
#endif | ||
stp d0, d1, [c0, #0x000] | ||
stp d2, d3, [c0, #0x010] | ||
stp d4, d5, [c0, #0x020] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just use the __builtin_cheri_foo directly; so far libunwind doesn't use any CHERI headers. Definitely not cheri/cheric.h though, that's CheriBSD-specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should I include to use the
CHERI_PERM_EXECUTIVE
below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be an equivalent macro pre-defined by the compiler itself, something like
__ARM_CAP_PERM_EXECUTIVE__