Merge branch 'master' of github.com:Minep/lunaix-os
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / cake.h
index e05a6b2ab79d6cf37489cb07df41c00ad972670e..cf1c16e63c49bdf89fcf6db10c8c6b6cf3d6c1e4 100644 (file)
@@ -2,6 +2,7 @@
 #define __LUNAIX_CAKE_H
 
 #include <lunaix/ds/llist.h>
+#include <lunaix/spike.h>
 
 #define PILE_NAME_MAXLEN 20
 
@@ -23,7 +24,7 @@ struct cake_pile
     u32_t alloced_pieces;
     u32_t pieces_per_cake;
     u32_t pg_per_cake;
-    char pile_name[PILE_NAME_MAXLEN];
+    char pile_name[PILE_NAME_MAXLEN+1];
 
     pile_cb ctor;
 };
@@ -87,4 +88,13 @@ cake_export();
 void
 cake_ctor_zeroing(struct cake_pile* pile, void* piece);
 
+#define DEADCAKE_MARK 0xdeadcafeUL
+
+static inline void
+cake_ensure_valid(void* area) {
+    if (unlikely(*(unsigned int*)area == DEADCAKE_MARK)) {
+        fail("access to freed cake piece");
+    }
+}
+
 #endif /* __LUNAIX_VALLOC_H */