summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brown2005-05-13 12:18:21 +0200
committerMichael Brown2005-05-13 12:18:21 +0200
commitf0d048bf9170f7b81f726f7a44079741f74b924a (patch)
tree30a43ce2193d835474f41c77ef96d64c2dd11197 /src
parentAdded old allot/forget calls for backwards compatibility. (diff)
downloadipxe-f0d048bf9170f7b81f726f7a44079741f74b924a.tar.gz
ipxe-f0d048bf9170f7b81f726f7a44079741f74b924a.tar.xz
ipxe-f0d048bf9170f7b81f726f7a44079741f74b924a.zip
Added ASSERT() macro
Diffstat (limited to 'src')
-rw-r--r--src/core/heap.c6
-rw-r--r--src/include/compiler.h17
2 files changed, 19 insertions, 4 deletions
diff --git a/src/core/heap.c b/src/core/heap.c
index 3476f4d25..05fbb6bac 100644
--- a/src/core/heap.c
+++ b/src/core/heap.c
@@ -3,8 +3,6 @@
#include "memsizes.h"
#include "heap.h"
-#define ASSERT(...)
-
struct heap_block {
size_t size;
char data[0];
@@ -102,7 +100,7 @@ void * emalloc ( size_t size, unsigned int align ) {
physaddr_t addr;
struct heap_block *block;
- ASSERT ( ! ( align & ( align - 1 ) ) );
+ ASSERT ( ( align & ( align - 1 ) ) == 0 );
addr = ( ( ( heap_ptr - size ) & ~( align - 1 ) )
- sizeof ( struct heap_block ) );
@@ -132,7 +130,7 @@ void * emalloc_all ( size_t *size ) {
void efree ( void *ptr ) {
struct heap_block *block;
- ASSERT ( ptr == ( heap_ptr + sizeof ( size_t ) ) );
+ ASSERT ( ptr == phys_to_virt ( heap_ptr + sizeof ( size_t ) ) );
block = ( struct heap_block * )
( ptr - offsetof ( struct heap_block, data ) );
diff --git a/src/include/compiler.h b/src/include/compiler.h
index 7d7c59605..4912b4242 100644
--- a/src/include/compiler.h
+++ b/src/include/compiler.h
@@ -67,6 +67,23 @@ __asm__ ( ".equ\tDEBUG_LEVEL, " DEBUG_SYMBOL_STR );
#define DBG2 DBG_PRINT
#endif
+/*
+ * ASSERT() macros
+ *
+ */
+#define ASSERT(x)
+
+#if DEBUG_SYMBOL >= 1
+#undef ASSERT
+#define ASSERT(x) \
+ do { \
+ if ( ! (x) ) { \
+ DBG ( "ASSERT(%s) failed at %s line %d [%s]\n", #x, \
+ __FILE__, __LINE__, __FUNCTION__ ); \
+ } \
+ } while (0)
+#endif
+
#define PACKED __attribute__((packed))
#define __unused __attribute__((unused))
#define __used __attribute__((used))