if (!dprint_in_signal) {
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
} else { int ret; /* * No printf() functions are signal-safe. * They deadlock easily. Write the format * string to get some output, even if * incomplete.
*/
ret = write(1, format, strlen(format)); if (ret < 0) exit(1);
}
} #define dprintf_level(level, args...) do { \ if (level <= DEBUG_LEVEL) \
sigsafe_printf(args); \
} while (0) #define dprintf0(args...) dprintf_level(0, args) #define dprintf1(args...) dprintf_level(1, args) #define dprintf2(args...) dprintf_level(2, args) #define dprintf3(args...) dprintf_level(3, args) #define dprintf4(args...) dprintf_level(4, args)
externvoid abort_hooks(void); #define pkey_assert(condition) do { \ if (!(condition)) { \
dprintf0("assert() at %s::%d test_nr: %d iteration: %d\n", \
__FILE__, __LINE__, \
test_nr, iteration_nr); \
dprintf0("errno at assert: %d", errno); \
abort_hooks(); \ exit(__LINE__); \
} \
} while (0)
int sys_pkey_alloc(unsignedlong flags, unsignedlong init_val); int sys_pkey_free(unsignedlong pkey); int sys_mprotect_pkey(void *ptr, size_t size, unsignedlong orig_prot, unsignedlong pkey);
/* For functions called from protection_keys.c only */
noinline int read_ptr(int *ptr); void expected_pkey_fault(int pkey); int mprotect_pkey(void *ptr, size_t size, unsignedlong orig_prot, unsignedlong pkey); void record_pkey_malloc(void *ptr, long size, int prot);
/* * FIXME: Remove once the generic PKEY_UNRESTRICTED definition is merged.
*/ #ifndef PKEY_UNRESTRICTED #define PKEY_UNRESTRICTED 0x0 #endif
#ifndef set_pkey_bits staticinline u64 set_pkey_bits(u64 reg, int pkey, u64 flags)
{
u32 shift = pkey_bit_position(pkey); /* mask out bits from pkey in old value */
reg &= ~((u64)PKEY_MASK << shift); /* OR in new bits for pkey */
reg |= (flags & PKEY_MASK) << shift; return reg;
} #endif
#ifndef get_pkey_bits staticinline u64 get_pkey_bits(u64 reg, int pkey)
{
u32 shift = pkey_bit_position(pkey); /* * shift down the relevant bits to the lowest two, then * mask off all the other higher bits
*/ return ((reg >> shift) & PKEY_MASK);
} #endif
staticinlineint kernel_has_pkeys(void)
{ /* try allocating a key and see if it succeeds */ int ret = sys_pkey_alloc(0, PKEY_UNRESTRICTED); if (ret <= 0) { return 0;
}
sys_pkey_free(ret); return 1;
}
staticinlineint is_pkeys_supported(void)
{ /* check if the cpu supports pkeys */ if (!cpu_has_pkeys()) {
dprintf1("SKIP: %s: no CPU support\n", __func__); return 0;
}
/* check if the kernel supports pkeys */ if (!kernel_has_pkeys()) {
dprintf1("SKIP: %s: no kernel support\n", __func__); return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.