+#define SLAB_DEBUG 1
+
+#if SLAB_DEBUG
+
+#define ALLOC_MAGIC 0x1acf
+#define FREE_MAGIC 0xfc1d
+
+struct alloc_header {
+ unsigned int file_id : 8;
+ unsigned int size : 24;
+ unsigned int line : 16;
+ unsigned int magic : 16;
+};
+
+static const char *file_ids[256];
+static struct file_id_entry {
+ const char *name;
+ unsigned int id : 8;
+} file_id_map[256];
+unsigned int file_ids_used;
+
+static int
+file_id_cmp(const void *a_, const void *b_)
+{
+ return strcmp(*(const char**)a_, *(const char**)b_);
+}
+
+static unsigned int
+get_file_id(const char *fname)
+{
+ struct file_id_entry *entry;
+
+ entry = bsearch(&fname, file_id_map, file_ids_used, sizeof(file_id_map[0]), file_id_cmp);
+ if (entry)
+ return entry->id;
+ entry = file_id_map + file_ids_used;
+ file_ids[file_ids_used] = fname;
+ entry->name = fname;
+ entry->id = file_ids_used;
+ qsort(file_id_map, ++file_ids_used, sizeof(file_id_map[0]), file_id_cmp);
+ return file_ids_used - 1;
+}
+
+typedef struct alloc_header alloc_header_t;
+
+#else
+
+typedef size_t alloc_header_t;
+
+#endif
+