Commit 53931030 authored by Nicolas Pitre's avatar Nicolas Pitre Committed by Martí Bolívar
Browse files

hello_world_user: don't always assume userspace



Print whether or not the code is actually in usermode.
Fail the execution with an assertion if not the case.

Signed-off-by: default avatarNicolas Pitre <npitre@baylibre.com>
parent 31b148ab
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -7,6 +7,9 @@ Overview
********
A simple Hello World example that can be used with any supported board and
prints 'Hello World from UserSpace!' to the console.
If unavailable or unconfigured then 'Hello World from privileged mode.'
is printed instead.

This application can be built into modes:

* single thread
+4 −1
Original line number Diff line number Diff line
@@ -13,7 +13,10 @@ K_THREAD_STACK_DEFINE(user_stack, USER_STACKSIZE);

static void user_function(void *p1, void *p2, void *p3)
{
	printf("Hello World from UserSpace! %s\n", CONFIG_BOARD);
	printf("Hello World from %s (%s)\n",
	       k_is_user_context() ? "UserSpace!" : "privileged mode.",
	       CONFIG_BOARD);
	__ASSERT(k_is_user_context(), "User mode execution was expected");
}