Browse Source

Added some debug stuff

Thomas Johnson 5 months ago
parent
commit
26580c0355
1 changed files with 37 additions and 0 deletions
  1. 37
    0
      main.c

+ 37
- 0
main.c View File

@@ -1,3 +1,4 @@
1
+#include <stdlib.h>
1 2
 #include <stdio.h>
2 3
 #include <stdint.h>
3 4
 #include <stddef.h>
@@ -18,6 +19,42 @@ void error(char *msg) {
18 19
   printf("=== ALLOCATOR ERROR ===\n%s\n====== END ERROR ======\n", msg);
19 20
 }
20 21
 
22
+struct AllocationRecord {
23
+  uintptr_t size;
24
+  void *allocation;
25
+  void *reference;
26
+  struct AllocationRecord *next;
27
+  struct AllocationRecord *prev;
28
+}
29
+
30
+void insert_record(struct AllocationRecord *dummy, void *allocation, uintptr_t size) {
31
+  struct AllocationRecord *record = malloc(sizeof(struct AllocationRecord));
32
+  record->size = size;
33
+  record->allocation = allocation;
34
+  record->reference = malloc(size);
35
+  record->next = dummy;
36
+  record->prev = dummy->prev;
37
+  dummy->prev->next = record;
38
+  dummy->prev = record;
39
+  dummy->size += 1;
40
+  memcpy(record->reference, allocation, size);
41
+}
42
+
43
+void delete_record(struct AllocationRecord *dummy, struct AllocationRecord *delete) {
44
+  free(delete->reference);
45
+  delete->prev->next = delete->next;
46
+  delete->next->prev = delete->prev;
47
+  free(delete);
48
+  dummy->size -= 1;
49
+}
50
+
51
+int validate_record(struct AllocationRecord *record) {
52
+  if (memcmp(record->allocation, record->reference, record->size) != 0) {
53
+    return 0;
54
+  }
55
+  return 1;
56
+}
57
+
21 58
 int main() {
22 59
 	printf("Hello, World!\n");
23 60
   struct Arena arena = {

Loading…
Cancel
Save