[rtems commit] sapi: New implementation of rtems_panic()

Sebastian Huber sebh at rtems.org
Wed Nov 22 12:02:12 UTC 2017


Module:    rtems
Branch:    master
Commit:    15e19273b2a6ebda3b2d55b28d693e7b8a0740b2
Changeset: http://git.rtems.org/rtems/commit/?id=15e19273b2a6ebda3b2d55b28d693e7b8a0740b2

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Tue Nov 21 11:29:01 2017 +0100

sapi: New implementation of rtems_panic()

The previous rtems_panic() implementation was quite heavy weight.  It
depended on _exit() which calls the global destructors.  It used
fprintf(stderr, ...) for output which depends on an initialized console
device and the complex fprintf().

Introduce a new fatal source RTEMS_FATAL_SOURCE_PANIC for rtems_panic()
and output via vprintk().

Update #3244.

---

 cpukit/libcsupport/include/rtems/error.h  | 10 +---------
 cpukit/libcsupport/src/error.c            | 15 ---------------
 cpukit/sapi/Makefile.am                   |  1 +
 cpukit/sapi/include/rtems/fatal.h         | 12 ++++++++++++
 cpukit/sapi/src/panic.c                   | 32 +++++++++++++++++++++++++++++++
 cpukit/score/include/rtems/score/interr.h |  7 +++++++
 testsuites/sptests/sperror03/init.c       | 15 +++++----------
 7 files changed, 58 insertions(+), 34 deletions(-)

diff --git a/cpukit/libcsupport/include/rtems/error.h b/cpukit/libcsupport/include/rtems/error.h
index f72d78c..617f596 100644
--- a/cpukit/libcsupport/include/rtems/error.h
+++ b/cpukit/libcsupport/include/rtems/error.h
@@ -48,7 +48,7 @@
 #define _RTEMS_RTEMS_ERROR_H
 
 #include <rtems/rtems/status.h>
-#include <rtems/score/interr.h>
+#include <rtems/fatal.h>
 
 #include <stdarg.h>
 
@@ -124,14 +124,6 @@ int rtems_verror(
   va_list             arglist
 );
 
-/**
- * rtems_panic is shorthand for rtems_error(RTEMS_ERROR_PANIC, ...)
- */
-void rtems_panic(
-  const char *printf_format,
-  ...
-) RTEMS_NO_RETURN;
-
 extern int rtems_panic_in_progress;
 
 #ifdef __cplusplus
diff --git a/cpukit/libcsupport/src/error.c b/cpukit/libcsupport/src/error.c
index 44cc1ee..0e65f89 100644
--- a/cpukit/libcsupport/src/error.c
+++ b/cpukit/libcsupport/src/error.c
@@ -98,18 +98,3 @@ int rtems_error(
 
   return chars_written;
 }
-
-void rtems_panic(
-  const char *printf_format,
-  ...
-)
-{
-  va_list arglist;
-
-  va_start(arglist, printf_format);
-  (void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist);
-  va_end(arglist);
-
-  rtems_error(0, "fatal error, exiting");
-  _exit(errno);
-}
diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 85d89ef..326d67f 100644
--- a/cpukit/sapi/Makefile.am
+++ b/cpukit/sapi/Makefile.am
@@ -43,6 +43,7 @@ libsapi_a_SOURCES += src/delaynano.c
 libsapi_a_SOURCES += src/rbtree.c
 libsapi_a_SOURCES += src/rbtreefind.c
 libsapi_a_SOURCES += src/rbtreeinsert.c
+libsapi_a_SOURCES += src/panic.c
 libsapi_a_SOURCES += src/profilingiterate.c
 libsapi_a_SOURCES += src/profilingreportxml.c
 libsapi_a_SOURCES += src/tcsimpleinstall.c
diff --git a/cpukit/sapi/include/rtems/fatal.h b/cpukit/sapi/include/rtems/fatal.h
index 80929cd..291af42 100644
--- a/cpukit/sapi/include/rtems/fatal.h
+++ b/cpukit/sapi/include/rtems/fatal.h
@@ -89,6 +89,18 @@ RTEMS_NO_RETURN RTEMS_INLINE_ROUTINE void rtems_fatal(
 }
 
 /**
+ * @brief Prints the specified message via printk() and terminates the system.
+ *
+ * @param[in] fmt The message format.
+ * @param[in] ... The message parameters.
+ *
+ * @see _Terminate().
+ */
+RTEMS_NO_RETURN void rtems_panic(
+  const char *fmt, ...
+) RTEMS_PRINTFLIKE( 1, 2 );
+
+/**
  * @brief Returns a text for a fatal source.
  *
  * The text for each fatal source is the enumerator constant.
diff --git a/cpukit/sapi/src/panic.c b/cpukit/sapi/src/panic.c
new file mode 100644
index 0000000..34b6f75
--- /dev/null
+++ b/cpukit/sapi/src/panic.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/fatal.h>
+
+#include <stdarg.h>
+
+void rtems_panic( const char *fmt, ... )
+{
+  va_list ap;
+
+  va_start( ap, fmt );
+  vprintk( fmt, ap );
+  va_end( ap);
+
+  _Terminate( RTEMS_FATAL_SOURCE_PANIC, (Internal_errors_t) fmt );
+}
diff --git a/cpukit/score/include/rtems/score/interr.h b/cpukit/score/include/rtems/score/interr.h
index 4de9406..a93eaf6 100644
--- a/cpukit/score/include/rtems/score/interr.h
+++ b/cpukit/score/include/rtems/score/interr.h
@@ -124,6 +124,13 @@ typedef enum {
   RTEMS_FATAL_SOURCE_SMP = 10,
 
   /**
+   * @brief Fatal source of rtems_panic().
+   *
+   * @see rtem
+   */
+  RTEMS_FATAL_SOURCE_PANIC = 11,
+
+  /**
    * @brief The last available fatal source.
    *
    * This enum value ensures that the enum type needs at least 32-bits for
diff --git a/testsuites/sptests/sperror03/init.c b/testsuites/sptests/sperror03/init.c
index f4323a5..ad42d96 100644
--- a/testsuites/sptests/sperror03/init.c
+++ b/testsuites/sptests/sperror03/init.c
@@ -16,8 +16,7 @@
 
 const char rtems_test_name[] = "SPERROR 3";
 
-/* forward declarations to avoid warnings */
-rtems_task Init(rtems_task_argument argument);
+static const char fmt[] = "Dummy panic\n";
 
 static void fatal_extension(
   rtems_fatal_source source,
@@ -26,24 +25,20 @@ static void fatal_extension(
 )
 {
   if (
-    source == RTEMS_FATAL_SOURCE_EXIT
+    source == RTEMS_FATAL_SOURCE_PANIC
       && !always_set_to_false
-      && error == 0
+      && error == (rtems_fatal_code) fmt
   ) {
     TEST_END();
   }
 }
 
-rtems_task Init(
+static rtems_task Init(
   rtems_task_argument argument
 )
 {
   TEST_BEGIN();
-
-  rtems_panic(
-    "Dummy panic\n"
-  );
-
+  rtems_panic( fmt );
   rtems_test_assert(0);
 }
 




More information about the vc mailing list