| 1 | /* Author: Mark Moraes <moraes@csri.toronto.edu> */ |
|---|
| 2 | |
|---|
| 3 | /* Modified by Alan Schwartz for PennMUSH. |
|---|
| 4 | * Should be included after config.h |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #ifndef __CSRIMALLOC_H |
|---|
| 8 | #define __CSRIMALLOC_H |
|---|
| 9 | |
|---|
| 10 | #include "config.h" |
|---|
| 11 | #define univptr_t Malloc_t |
|---|
| 12 | #define memsize_t size_t |
|---|
| 13 | #include "confmagic.h" |
|---|
| 14 | |
|---|
| 15 | /* |
|---|
| 16 | * defined so users of new features of this malloc can #ifdef |
|---|
| 17 | * invocations of those features. |
|---|
| 18 | */ |
|---|
| 19 | #define CSRIMALLOC |
|---|
| 20 | |
|---|
| 21 | #ifdef CSRI_TRACE |
|---|
| 22 | /* Tracing malloc definitions - helps find leaks */ |
|---|
| 23 | |
|---|
| 24 | univptr_t trace__malloc(size_t nbytes, const char *fname, int linenum); |
|---|
| 25 | univptr_t trace__calloc |
|---|
| 26 | (size_t nelem, size_t elsize, const char *fname, int linenum); |
|---|
| 27 | univptr_t trace__realloc |
|---|
| 28 | (univptr_t cp, size_t nbytes, const char *fname, int linenum); |
|---|
| 29 | univptr_t trace__valloc(size_t size, const char *fname, int linenum); |
|---|
| 30 | univptr_t trace__memalign |
|---|
| 31 | (size_t alignment, size_t size, const char *fname, int linenum); |
|---|
| 32 | univptr_t trace__emalloc(size_t nbytes, const char *fname, int linenum); |
|---|
| 33 | univptr_t trace__ecalloc |
|---|
| 34 | (size_t nelem, size_t sz, const char *fname, int linenum); |
|---|
| 35 | univptr_t trace__erealloc |
|---|
| 36 | (univptr_t ptr, size_t nbytes, const char *fname, int linenum); |
|---|
| 37 | char *trace__strdup(const char *s, const char *fname, int linenum); |
|---|
| 38 | char *trace__strsave(const char *s, const char *fname, int linenum); |
|---|
| 39 | void trace__free(univptr_t cp, const char *fname, int linenum); |
|---|
| 40 | void trace__cfree(univptr_t cp, const char *fname, int linenum); |
|---|
| 41 | |
|---|
| 42 | #define malloc(x) trace__malloc((x), __FILE__, __LINE__) |
|---|
| 43 | #define calloc(x, n) trace__calloc((x), (n), __FILE__, __LINE__) |
|---|
| 44 | #define realloc(p, x) trace__realloc((p), (x), __FILE__, __LINE__) |
|---|
| 45 | #define memalign(x, n) trace__memalign((x), (n), __FILE__, __LINE__) |
|---|
| 46 | #define valloc(x) trace__valloc((x), __FILE__, __LINE__) |
|---|
| 47 | #define emalloc(x) trace__emalloc((x), __FILE__, __LINE__) |
|---|
| 48 | #define ecalloc(x, n) trace__ecalloc((x), (n), __FILE__, __LINE__) |
|---|
| 49 | #define erealloc(p, x) trace__erealloc((p), (x), __FILE__, __LINE__) |
|---|
| 50 | #define strdup(p) trace__strdup((p), __FILE__, __LINE__) |
|---|
| 51 | #define strsave(p) trace__strsave((p), __FILE__, __LINE__) |
|---|
| 52 | /* cfree and free are identical */ |
|---|
| 53 | #define cfree(p) trace__free((p), __FILE__, __LINE__) |
|---|
| 54 | #define free(p) trace__free((p), __FILE__, __LINE__) |
|---|
| 55 | |
|---|
| 56 | #else /* CSRI_TRACE */ |
|---|
| 57 | |
|---|
| 58 | univptr_t malloc(size_t nbytes); |
|---|
| 59 | univptr_t calloc(size_t nelem, size_t elsize); |
|---|
| 60 | univptr_t realloc(univptr_t cp, size_t nbytes); |
|---|
| 61 | univptr_t valloc(size_t size); |
|---|
| 62 | univptr_t memalign(size_t alignment, size_t size); |
|---|
| 63 | univptr_t emalloc(size_t nbytes); |
|---|
| 64 | univptr_t ecalloc(size_t nelem, size_t sz); |
|---|
| 65 | univptr_t erealloc(univptr_t ptr, size_t nbytes); |
|---|
| 66 | char *strdup(const char *s); |
|---|
| 67 | char *strsave(const char *s); |
|---|
| 68 | void free(univptr_t cp); |
|---|
| 69 | void cfree(univptr_t cp); |
|---|
| 70 | |
|---|
| 71 | #endif /* CSRI_TRACE */ |
|---|
| 72 | |
|---|
| 73 | void mal_debug(int level); |
|---|
| 74 | void mal_dumpleaktrace(FILE * fp); |
|---|
| 75 | void mal_heapdump(FILE * fp); |
|---|
| 76 | void mal_leaktrace(int value); |
|---|
| 77 | void mal_sbrkset(int n); |
|---|
| 78 | void mal_slopset(int n); |
|---|
| 79 | void mal_statsdump(FILE * fp); |
|---|
| 80 | void mal_setstatsfile(FILE * fp); |
|---|
| 81 | void mal_trace(int value); |
|---|
| 82 | int mal_verify(int fullcheck); |
|---|
| 83 | void mal_mmap(char *fname); |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | /* |
|---|
| 87 | * You may or may not want this - In gcc version 1.30, on Sun3s running |
|---|
| 88 | * SunOS3.5, this works fine. |
|---|
| 89 | */ |
|---|
| 90 | #ifdef __GNUC__ |
|---|
| 91 | #ifndef alloca |
|---|
| 92 | #define alloca(n) __builtin_alloca(n) |
|---|
| 93 | #endif |
|---|
| 94 | #endif /* __GNUC__ */ |
|---|
| 95 | #ifdef sparc |
|---|
| 96 | #define alloca(n) __builtin_alloca(n) |
|---|
| 97 | #endif /* sparc */ |
|---|
| 98 | |
|---|
| 99 | |
|---|
| 100 | #endif /* __CSRIMALLOC_H__ */ /* Do not add anything after this line */ |
|---|