µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
exit.c
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2015-2025 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
9 * be obtained from https://opensource.org/licenses/mit.
10 */
11
12#if defined(__clang__)
13#pragma clang diagnostic ignored "-Wempty-translation-unit"
14#endif
15
16#if defined(__ARM_EABI__)
17
18// ----------------------------------------------------------------------------
19
20#if defined(OS_USE_OS_APP_CONFIG_H)
21#include <cmsis-plus/os-app-config.h>
22#endif
23
26#include <cmsis_device.h>
27
28#include <stdlib.h>
29#include <stdbool.h>
30#include "atexit.h"
31
32// ----------------------------------------------------------------------------
33
34void __attribute__ ((noreturn))
35os_exit (int code);
36
37extern void
39
40// ----------------------------------------------------------------------------
41
42void __attribute__ ((weak, noreturn))
43abort (void)
44{
45 trace_puts ("abort(), exiting...");
46
47 _Exit (1);
48 /* NOTREACHED */
49}
50
51// ----------------------------------------------------------------------------
52
69void __attribute__ ((noreturn))
70exit (int code)
71{
72 trace_printf ("%s(%d)\n", __func__, code);
73
74 // Call the cleanup functions enrolled with atexit().
75 __call_exitprocs (code, NULL);
76
77 // Run the C++ static destructors.
79
80 // This should normally be the end of it.
81 _Exit (code);
82
83 // Reset again, in case _Exit() did not kill it.
84 // This normally should not happen, but since it can be
85 // overloaded by the application, better safe than sorry.
86 os_terminate (code);
87
88 // If it does not want o die, loop.
89 while (true)
90 {
91 __NOP ();
92 }
93 /* NOTREACHED */
94}
95
96// ----------------------------------------------------------------------------
97
98#pragma GCC diagnostic push
99#if defined(__clang__)
100#elif defined(__GNUC__)
101#pragma GCC diagnostic ignored "-Wunused-parameter"
102#endif
103
104// On Release, call the hardware reset procedure.
105// On Debug, use a breakpoint to notify the debugger.
106//
107// It can be redefined by the application, if more functionality
108// is required. For example, when semihosting is used, this
109// function sends the return code to the host.
110
111void __attribute__ ((weak, noreturn))
112_Exit (int code)
113{
114 trace_printf ("%s()\n", __func__);
115
116 // Print some statistics about memory use.
118
119 // Gracefully terminate the trace session.
120 trace_flush ();
121
122// By default disable it, since it prevents standalone tests
123// to terminate properly.
124#if defined(DEBUG) && defined(OS_ENABLE_BKPT_ON_EXIT)
125
126#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
127 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) != 0)
128 {
129 // Break only if the debugger is connected.
130 __BKPT (0);
131 }
132#endif /* defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) */
133
134#endif /* defined(DEBUG) */
135
136 // Reset hardware or terminate the semihosting session.
137 os_terminate (code);
138
139 while (true)
140 {
141 __NOP ();
142 }
143 /* NOTREACHED */
144}
145
146#pragma GCC diagnostic pop
147
148#pragma GCC diagnostic push
149#pragma GCC diagnostic ignored "-Wmissing-attributes"
150
151void __attribute__ ((weak, alias ("_Exit"), noreturn))
152_exit (int status);
153
154#pragma GCC diagnostic pop
155
156// ----------------------------------------------------------------------------
157
158// Semihosting defines this function to terminate the semihosting session.
159#if !defined(OS_USE_SEMIHOSTING_SYSCALLS)
160
166void __attribute__ ((noreturn, weak))
167os_terminate (int code __attribute__ ((unused)))
168{
169 NVIC_SystemReset ();
170 while (1)
171 ;
172 /* NOTREACHED */
173}
174
175#endif
176
177// ----------------------------------------------------------------------------
178
179#endif /* defined(__ARM_EABI__) */
void __call_exitprocs(int, void *)
void os_run_fini_array(void)
Definition startup.cpp:187
void os_exit(int code)
void exit(int code)
Definition exit.c:70
void abort(void)
Definition exit.c:43
void _exit(int status)
void _Exit(int code)
Definition exit.c:112
void os_goodbye(void)
void os_terminate(int code)
Terminate the application. There is no more life after this.
void os_terminate_goodbye(void)
Display statistics and say goodbye before terminating.
Definition os-main.cpp:194
void trace_flush(void)
Definition trace.cpp:177
int trace_printf(const char *format,...)
int trace_puts(const char *s)