From 3896c5ffa877b24698ed8408c1bef2469f098682 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Wed, 27 Jul 2016 12:12:22 +0200 Subject: [PATCH] Added an assert impl --- README.md | 1 + assert/assert.cpp | 11 +++++++++++ include/assert.h | 15 +++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 assert/assert.cpp create mode 100644 include/assert.h diff --git a/README.md b/README.md index 928ca16..10e6f3b 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # libc-kernel +This is a series of source code files containing the C library MTGos links against internally. diff --git a/assert/assert.cpp b/assert/assert.cpp new file mode 100644 index 0000000..c0caad8 --- /dev/null +++ b/assert/assert.cpp @@ -0,0 +1,11 @@ +#include +#include +#include +void "C" __assert(const char *msg, const char *file, int line, int res) { + if(!res) { + MTGosHAL::err << "assert(" << msg << ") failed in " << file << " at line " << line << "!\n"; + MTGosHAL::err << "Kernel panic.\n"; + for(;;); + } + assert(0); +} \ No newline at end of file diff --git a/include/assert.h b/include/assert.h new file mode 100644 index 0000000..efdc0b9 --- /dev/null +++ b/include/assert.h @@ -0,0 +1,15 @@ +#ifndef __ASSERT_H +#define __ASSERT_H +#ifdef __cplusplus +extern "C" { +#endif +void __assert(const char *msg, const char *file, int line, int res); +#ifdef NDEBUG +#define assert(EX) +#else +#define assert(EX) (void)(__assert(#EX, __FILE__, __LINE__, EX)) +#endif +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file