forked from RobertBonagura/mymalloc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmymalloc.h
More file actions
33 lines (26 loc) · 934 Bytes
/
mymalloc.h
File metadata and controls
33 lines (26 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef _MYMALLOC_H
#define _MYMALLOC_H
#include <stdio.h>
#include <limits.h>
#define malloc(x) mymalloc((x), __LINE__, __FILE__)
#define free(x) myfree((x), __LINE__, __FILE__)
/*
The size attribute of metadata is a signed short, conveying information about block size and usage.
block size: magnitude of metadata.size.
block used: sign of metadata.size; negative is unused, positive is used.
*/
typedef struct _metadata {
short size;
} metadata;
typedef enum _DetectableError {FreeA, FreeB, FreeC, MallocA} DetectableError;
// Allocation functions:
void* mymalloc(size_t user_size, int line, char* file);
metadata* find_block(size_t user_size, int line, char* file);
void* split_block(metadata* meta_ptr, size_t user_size);
// Free functions:
void myfree(void* user_ptr, int line, char* file);
metadata* mark_unused(void* user_ptr, int line, char* file);
int stitch();
// Debugging functions:
void print_status();
#endif