Skip to content

Commit

Permalink
tests: protection: don't do exec tests on x86
Browse files Browse the repository at this point in the history
The IA32 MMU has no concept of a "no execute" flag, this is
unfortunately only implemented in x86_64.

Signed-off-by: Andrew Boie <[email protected]>
  • Loading branch information
Andrew Boie authored and andrewboie committed Jul 10, 2017
1 parent ed1962a commit e55fd56
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tests/kernel/protection/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,20 @@ void _SysFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf)
#define DO_BARRIERS() do { } while (0)
#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)
{
return (i + 1);
}

#ifdef NO_EXECUTE_SUPPORT
static void execute_from_buffer(u8_t *dst)
{
void *src = FUNC_TO_PTR(add_one);
Expand All @@ -79,6 +88,7 @@ static void execute_from_buffer(u8_t *dst)
INFO("Did not get expected return value!\n");
}
}
#endif

static void write_ro(void)
{
Expand Down Expand Up @@ -130,6 +140,7 @@ static void write_text(void)
zassert_unreachable("Write to text did not fault");
}

#ifdef NO_EXECUTE_SUPPORT
static void exec_data(void)
{
execute_from_buffer(data_buf);
Expand All @@ -154,17 +165,20 @@ static void exec_heap(void)
zassert_unreachable("Execute from heap did not fault");
}
#endif
#endif /* NO_EXECUTE_SUPPORT */

void test_main(void *unused1, void *unused2, void *unused3)
{
ztest_test_suite(test_protection,
ztest_unit_test(write_ro),
ztest_unit_test(write_text),
#ifdef NO_EXECUTE_SUPPORT
ztest_unit_test(exec_data),
ztest_unit_test(exec_stack)
ztest_unit_test(exec_stack),
#if (CONFIG_HEAP_MEM_POOL_SIZE > 0)
, ztest_unit_test(exec_heap)
ztest_unit_test(exec_heap),
#endif
#endif /* NO_EXECUTE_SUPPORT */
ztest_unit_test(write_ro),
ztest_unit_test(write_text)
);
ztest_run_test_suite(test_protection);
}

0 comments on commit e55fd56

Please sign in to comment.