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