diff mbox

[v2,2/5] api: abort: add weak replacement for abort

Message ID 1422963328-31760-3-git-send-email-mike.holmes@linaro.org
State Accepted
Commit 04a00b80e1a8a4bdbab5adf8612a01162ba0ad8f
Headers show

Commit Message

Mike Holmes Feb. 3, 2015, 11:35 a.m. UTC
Introduce replaceable abort function using weak symbols.

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 include/odp/api/init.h                              | 16 ++++++++++++++++
 platform/linux-generic/include/odp_debug_internal.h |  4 ++--
 platform/linux-generic/odp_weak.c                   |  5 +++++
 3 files changed, 23 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/include/odp/api/init.h b/include/odp/api/init.h
index c73b321..4b9296b 100644
--- a/include/odp/api/init.h
+++ b/include/odp/api/init.h
@@ -29,6 +29,7 @@  extern "C" {
 
 
 #include <odp/std_types.h>
+#include <odp/hints.h>
 
 /** @defgroup odp_initialization ODP INITIALIZATION
  *  Initialisation operations.
@@ -71,6 +72,21 @@  typedef enum odp_log_level {
  */
 int odp_override_log(odp_log_level_e level, const char *fmt, ...);
 
+/**
+ * ODP abort function
+ *
+ * Instead of directly calling abort, all abort calls in the implementation
+ * should be done via this function or its wrappers.
+ *
+ * An Application can override the ODP implementation default abort function
+ * odp_override_abort() by providing an alternative to this weak symbol.
+ *
+ * @warning The override option is not portable and GNU linker dependent
+ * (utilizes function attribute "weak").
+ *
+ * @warning this function shall not return
+ */
+void odp_override_abort(void) ODP_NORETURN;
 
 /** Replaceable logging function */
 typedef int (*odp_log_func_t)(odp_log_level_e level, const char *fmt, ...);
diff --git a/platform/linux-generic/include/odp_debug_internal.h b/platform/linux-generic/include/odp_debug_internal.h
index a665644..20b6fcc 100644
--- a/platform/linux-generic/include/odp_debug_internal.h
+++ b/platform/linux-generic/include/odp_debug_internal.h
@@ -54,7 +54,7 @@  extern "C" {
 #define ODP_ASSERT(cond, msg) \
 	do { if ((ODP_DEBUG == 1) && (!(cond))) { \
 		ODP_ERR("%s\n", msg); \
-		abort(); } \
+		odp_override_abort(); } \
 	} while (0)
 
 /**
@@ -86,7 +86,7 @@  extern "C" {
 #define ODP_ABORT(fmt, ...) \
 	do { \
 		ODP_LOG(ODP_LOG_ABORT, fmt, ##__VA_ARGS__); \
-		abort(); \
+		odp_override_abort(); \
 	} while (0)
 
 /**
diff --git a/platform/linux-generic/odp_weak.c b/platform/linux-generic/odp_weak.c
index 2592fe9..9dc3a4a 100644
--- a/platform/linux-generic/odp_weak.c
+++ b/platform/linux-generic/odp_weak.c
@@ -21,3 +21,8 @@  ODP_WEAK_SYMBOL int odp_override_log(odp_log_level_e level ODP_UNUSED,
 
 	return r;
 }
+
+ODP_WEAK_SYMBOL void odp_override_abort(void)
+{
+	abort();
+}