kernel: Treat aborting by main() as a fatal system error

An application-supplied main() routine is now considered to be
essential to system operation. Thus, if main() experiences an
error that aborts the main thread a fatal system error is raised.

Note: If main() completes its work and does a standard return-
to-caller the main thread terminates normally.

Change-Id: Icc9499f13578299244a856a246ad2a7d34a72f54
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
This commit is contained in:
Allan Stephens 2016-11-09 07:46:56 -06:00 committed by Benjamin Walsh
commit 073442ecc5
2 changed files with 8 additions and 9 deletions

View file

@ -17,9 +17,7 @@ The kernel spawns the following system threads.
**Main thread** **Main thread**
This thread performs kernel initialization, then calls the application's This thread performs kernel initialization, then calls the application's
:cpp:func:`main()` function. If the application does not supply a :cpp:func:`main()` function (if one is defined).
:cpp:func:`main()` function, the main thread terminates once initialization
is complete.
By default, the main thread uses the highest configured preemptible thread By default, the main thread uses the highest configured preemptible thread
priority (i.e. 0). If the kernel is not configured to support preemptible priority (i.e. 0). If the kernel is not configured to support preemptible
@ -27,10 +25,10 @@ The kernel spawns the following system threads.
priority (i.e. -1). priority (i.e. -1).
The main thread is an essential thread while it is performing kernel The main thread is an essential thread while it is performing kernel
initialization, which means a fatal system error is raised if the thread initialization or executing the application's :cpp:func:`main()` function;
aborts. Once initialization is complete the thread is considered this means a fatal system error is raised if the thread aborts. If
non-essential, so the termination or aborting of a :cpp:func:`main()` :cpp:func:`main()` is not defined, or if it executes and then does a normal
function supplied by the application does not cause a fatal system error. return, the main thread terminates normally and no error is raised.
**Idle thread** **Idle thread**
This thread executes when there is no other work for the system to do. This thread executes when there is no other work for the system to do.

View file

@ -200,8 +200,6 @@ static void _main(void *unused1, void *unused2, void *unused3)
_init_static_threads(); _init_static_threads();
_main_thread->flags &= ~K_ESSENTIAL;
#ifdef CONFIG_BOOT_TIME_MEASUREMENT #ifdef CONFIG_BOOT_TIME_MEASUREMENT
/* record timestamp for kernel's _main() function */ /* record timestamp for kernel's _main() function */
extern uint64_t __main_tsc; extern uint64_t __main_tsc;
@ -219,6 +217,9 @@ static void _main(void *unused1, void *unused2, void *unused3)
k_thread_priority_set(_main_thread, MDEF_MAIN_THREAD_PRIORITY); k_thread_priority_set(_main_thread, MDEF_MAIN_THREAD_PRIORITY);
#endif #endif
main(); main();
/* Terminate thread normally since it has no more work to do */
_main_thread->flags &= ~K_ESSENTIAL;
} }
void __weak main(void) void __weak main(void)