tests: protection: don't do exec tests on x86

The IA32 MMU has no concept of a "no execute" flag, this is
unfortunately only implemented in x86_64.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-07-05 14:32:32 -07:00 committed by Andrew Boie
commit e55fd562ec

View file

@ -48,11 +48,20 @@ void _SysFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf)
#define DO_BARRIERS() do { } while (0) #define DO_BARRIERS() do { } while (0)
#endif #endif
#if defined(CONFIG_ARM)
#define NO_EXECUTE_SUPPORT 1
#elif defined(CONFIG_X86)
/* i386 MMU doesn't control execute capabilities, only on x86_64 */
#else
#error "Architecture not supported"
#endif
static int __attribute__((noinline)) add_one(int i) static int __attribute__((noinline)) add_one(int i)
{ {
return (i + 1); return (i + 1);
} }
#ifdef NO_EXECUTE_SUPPORT
static void execute_from_buffer(u8_t *dst) static void execute_from_buffer(u8_t *dst)
{ {
void *src = FUNC_TO_PTR(add_one); void *src = FUNC_TO_PTR(add_one);
@ -79,6 +88,7 @@ static void execute_from_buffer(u8_t *dst)
INFO("Did not get expected return value!\n"); INFO("Did not get expected return value!\n");
} }
} }
#endif
static void write_ro(void) static void write_ro(void)
{ {
@ -130,6 +140,7 @@ static void write_text(void)
zassert_unreachable("Write to text did not fault"); zassert_unreachable("Write to text did not fault");
} }
#ifdef NO_EXECUTE_SUPPORT
static void exec_data(void) static void exec_data(void)
{ {
execute_from_buffer(data_buf); execute_from_buffer(data_buf);
@ -154,17 +165,20 @@ static void exec_heap(void)
zassert_unreachable("Execute from heap did not fault"); zassert_unreachable("Execute from heap did not fault");
} }
#endif #endif
#endif /* NO_EXECUTE_SUPPORT */
void test_main(void *unused1, void *unused2, void *unused3) void test_main(void *unused1, void *unused2, void *unused3)
{ {
ztest_test_suite(test_protection, ztest_test_suite(test_protection,
ztest_unit_test(write_ro), #ifdef NO_EXECUTE_SUPPORT
ztest_unit_test(write_text),
ztest_unit_test(exec_data), ztest_unit_test(exec_data),
ztest_unit_test(exec_stack) ztest_unit_test(exec_stack),
#if (CONFIG_HEAP_MEM_POOL_SIZE > 0) #if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
, ztest_unit_test(exec_heap) ztest_unit_test(exec_heap),
#endif #endif
#endif /* NO_EXECUTE_SUPPORT */
ztest_unit_test(write_ro),
ztest_unit_test(write_text)
); );
ztest_run_test_suite(test_protection); ztest_run_test_suite(test_protection);
} }