#define XTF_COMPILER_H
#define __aligned(x) __attribute__((__aligned__(x)))
+#define __noreturn __attribute__((__noreturn__))
#define __packed __attribute__((__packed__))
+#define __printf(f, v) __attribute__((__format__(__printf__, f, v)))
+#define __section(s) __attribute__((__section__(s)))
#define __used __attribute__((__used__))
+#define __weak __attribute__((__weak__))
#ifndef __noinline /* Avoid conflicting with cdefs.h */
#define __noinline __attribute__((__noinline__))
#define __always_inline __attribute__((__always_inline__))
#endif
-#define __weak __attribute__((weak))
-
-#define __noreturn __attribute__((__noreturn__))
#define unreachable() __builtin_unreachable()
-
-#define __printf(f, v) __attribute__((__format__(__printf__, f, v)))
-
#define barrier() __asm__ __volatile__ ("" ::: "memory")
+/* Convenience wrappers. */
+#define __user_text __section(".text.user")
+
#endif /* XTF_COMPILER_H */
/*
const char test_title[] = "XTF Selftests";
-bool test_wants_user_mappings = true;
-
static void test_int3_breakpoint(void)
{
printk("Test: int3 breakpoint\n");
USER_bad_cs,
};
-static unsigned long test_exec_user_cpl3(void)
+static unsigned long __user_text test_exec_user_cpl3(void)
{
return ((read_cs() & 3) == 3) ? USER_seen : USER_bad_cs;
}
void test_main(void)
{
+ /*
+ * Wherever possible, enable SMEP and SMAP to test the safety of the
+ * exec_user infrastructure.
+ */
+ if ( IS_DEFINED(CONFIG_HVM) )
+ {
+ unsigned long cr4 = read_cr4(), ocr4 = cr4;
+
+ if ( cpu_has_smep )
+ cr4 |= X86_CR4_SMEP;
+ if ( cpu_has_smap )
+ cr4 |= X86_CR4_SMAP;
+
+ if ( cr4 != ocr4 )
+ write_cr4(cr4);
+ }
+
test_int3_breakpoint();
test_extable();
test_exlog();