µ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++ distribution.
3 * (https://github.com/micro-os-plus)
4 * Copyright (c) 2015 Liviu Ionescu.
5 *
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
13 * conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#if defined(__clang__)
29#pragma clang diagnostic ignored "-Wempty-translation-unit"
30#endif
31
32#if defined(__ARM_EABI__)
33
34// ----------------------------------------------------------------------------
35
38#include <cmsis_device.h>
39
40#include <stdlib.h>
41#include <stdbool.h>
42#include "atexit.h"
43
44// ----------------------------------------------------------------------------
45
46void
47__attribute__ ((noreturn))
48os_exit (int code);
49
50extern void
52
53// ----------------------------------------------------------------------------
54
55void __attribute__((weak,noreturn))
56abort (void)
57{
58 trace_puts ("abort(), exiting...");
59
60 _Exit (1);
61 /* NOTREACHED */
62}
63
64// ----------------------------------------------------------------------------
65
82void
83__attribute__ ((noreturn))
84exit (int code)
85{
86 trace_printf ("%s(%d)\n", __func__, code);
87
88 // Call the cleanup functions enrolled with atexit().
89 __call_exitprocs (code, NULL);
90
91 // Run the C++ static destructors.
93
94 // This should normally be the end of it.
95 _Exit (code);
96
97 // Reset again, in case _Exit() did not kill it.
98 // This normally should not happen, but since it can be
99 // overloaded by the application, better safe than sorry.
100 os_terminate (code);
101
102 // If it does not want o die, loop.
103 while (true)
104 {
105 __NOP ();
106 }
107 /* NOTREACHED */
108}
109
110// ----------------------------------------------------------------------------
111
112#pragma GCC diagnostic push
113#pragma GCC diagnostic ignored "-Wunused-parameter"
114
115// On Release, call the hardware reset procedure.
116// On Debug, use a breakpoint to notify the debugger.
117//
118// It can be redefined by the application, if more functionality
119// is required. For example, when semihosting is used, this
120// function sends the return code to the host.
121
122void __attribute__((weak, noreturn))
123_Exit (int code)
124{
125 trace_printf ("%s()\n", __func__);
126
127 // Print some statistics about memory use.
129
130 // Gracefully terminate the trace session.
131 trace_flush ();
132
133#if defined(DEBUG)
134
135#if defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__)
136 if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) != 0)
137 {
138 // Break only if the debugger is connected.
139 __BKPT(0);
140 }
141#endif /* defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7EM__) */
142
143#endif /* defined(DEBUG) */
144
145 // Reset hardware or terminate the semihosting session.
146 os_terminate (code);
147
148 while (true)
149 {
150 __NOP ();
151 }
152 /* NOTREACHED */
153}
154
155#pragma GCC diagnostic pop
156
157void __attribute__((weak, alias ("_Exit"), noreturn))
158_exit (int status);
159
160// ----------------------------------------------------------------------------
161
162// Semihosting defines this function to terminate the semihosting session.
163#if !defined(OS_USE_SEMIHOSTING_SYSCALLS)
164
170void
171__attribute__ ((noreturn,weak))
172os_terminate(int code __attribute__((unused)))
173 {
175 while(1)
176 ;
177 /* NOTREACHED */
178 }
179
180#endif
181
182// ----------------------------------------------------------------------------
183
184#endif /* defined(__ARM_EABI__) */
void __call_exitprocs(int, void *)
void os_run_fini_array(void)
Definition startup.cpp:211
void os_exit(int code)
void exit(int code)
Definition exit.c:84
void abort(void)
Definition exit.c:56
void _exit(int status)
void _Exit(int code)
Definition exit.c:123
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:193
void NVIC_SystemReset(void)
void trace_flush(void)
Definition trace.cpp:177
int trace_printf(const char *format,...)
int trace_puts(const char *s)