2014-02-24 16:13:06 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Freie Universitaet Berlin (FUB) and INRIA
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
|
|
|
* Public License. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup core_util
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file crash.c
|
|
|
|
* @brief Crash handling functions implementation for 'native' port
|
|
|
|
*
|
|
|
|
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
|
|
|
|
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "crash.h"
|
|
|
|
|
|
|
|
/* "public" variables holding the crash data (look for them in your debugger) */
|
|
|
|
char panic_str[80];
|
|
|
|
int panic_code;
|
|
|
|
|
|
|
|
/* flag preventing "recursive crash printing loop" */
|
|
|
|
static int crashed = 0;
|
|
|
|
|
|
|
|
NORETURN void core_panic(int crash_code, const char *message)
|
|
|
|
{
|
|
|
|
if (crashed == 0) {
|
|
|
|
crashed = 1;
|
|
|
|
/* copy the crash data to "long-lived" global variables */
|
|
|
|
panic_code = crash_code;
|
|
|
|
strncpy(panic_str, message, 80);
|
|
|
|
/* try to print panic message to console (if possible) */
|
|
|
|
puts("******** SYSTEM FAILURE ********\n");
|
|
|
|
puts(message);
|
2014-02-26 16:48:44 +01:00
|
|
|
#if DEVELHELP
|
2014-02-24 16:13:06 +01:00
|
|
|
puts("******** RIOT HALTS HERE ********\n");
|
2014-02-26 16:48:44 +01:00
|
|
|
#else
|
|
|
|
puts("******** RIOT WILL REBOOT ********\n");
|
|
|
|
#endif
|
2014-02-24 16:13:06 +01:00
|
|
|
puts("\n\n");
|
|
|
|
}
|
2014-02-26 16:48:44 +01:00
|
|
|
|
|
|
|
dINT();
|
|
|
|
#if DEVELHELP
|
2014-02-24 16:13:06 +01:00
|
|
|
/* since we're atop an Unix-like platform,
|
|
|
|
just use the (developer-)friendly core-dump feature */
|
|
|
|
kill(getpid(), SIGTRAP);
|
2014-02-26 16:48:44 +01:00
|
|
|
#else
|
2014-03-01 09:36:17 +01:00
|
|
|
(void) reboot(RB_AUTOBOOT);
|
2014-02-26 16:48:44 +01:00
|
|
|
#endif
|
|
|
|
|
2014-03-16 23:53:56 +01:00
|
|
|
/* tell the compiler that we won't return from this function
|
2014-02-24 16:13:06 +01:00
|
|
|
(even if we actually won't even get here...) */
|
2014-03-16 23:53:56 +01:00
|
|
|
#if ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)) || (__GNUC__ >= 5)
|
|
|
|
__builtin_unreachable();
|
|
|
|
#else
|
2014-02-24 16:13:06 +01:00
|
|
|
while (1) {
|
2014-03-16 23:53:56 +01:00
|
|
|
/* do nothing, but do it often */
|
2014-02-24 16:13:06 +01:00
|
|
|
}
|
2014-03-16 23:53:56 +01:00
|
|
|
#endif
|
2014-02-24 16:13:06 +01:00
|
|
|
}
|