-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmdriver.h
executable file
·72 lines (61 loc) · 2.1 KB
/
mdriver.h
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef MM_MDRIVER_H
#define MM_MDRIVER_H
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "config.h"
#include "fsecs.h"
#include "memlib.h"
#include "allocator_interface.h"
/**********************
* Constants and macros
**********************/
/* Misc */
#define MAXLINE 1024 /* max string size */
#define HDRLINES 4 /* number of header lines in a trace file */
#define LINENUM(i) (i+5) /* cnvt trace request nums to linenums (origin 1) */
enum traceop_type {ALLOC, FREE, REALLOC} ; /* type of request */
/******************************
* The key compound data types
*****************************/
/* Characterizes a single trace operation (allocator request) */
typedef struct {
traceop_type type; /* type of request */
int index; /* index for free() to use later */
int size; /* byte size of alloc/realloc request */
} traceop_t;
/* Holds the information for one trace file*/
typedef struct {
int sugg_heapsize; /* suggested heap size (unused) */
int num_ids; /* number of alloc/realloc ids */
int num_ops; /* number of distinct requests */
int weight; /* weight for this trace (unused) */
traceop_t *ops; /* array of requests */
char **blocks; /* array of ptrs returned by malloc/realloc... */
size_t *block_sizes; /* ... and a corresponding array of payload sizes */
} trace_t;
/* Function pointers for a malloc implementation. This is used to allow a
* single validator to operate on both libc malloc, a buggy malloc, and the
* student "mm" malloc.
*/
typedef struct {
int (*init)(void);
void *(*malloc)(size_t size);
void *(*realloc)(void *ptr, size_t size);
void (*free)(void *ptr);
int (*check)();
void (*reset_brk)(void);
void *(*heap_lo)(void);
void *(*heap_hi)(void);
} malloc_impl_t;
/*********************
* Function prototypes
*********************/
void malloc_error(int tracenum, int opnum, char *msg);
void unix_error(char *msg);
void app_error(char *msg);
#endif /* MM_MDRIVER_H */