1
/* Copyright (C) 2005 PrimeBase Technologies GmbH
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* 2005-01-04 Paul McCullagh
23
#ifndef __xt_memory_h__
24
#define __xt_memory_h__
38
#define XT_MM_STACK_TRACE 200
39
#define XT_MM_TRACE_DEPTH 4
40
#define XT_MM_TRACE_INC ((char *) 1)
41
#define XT_MM_TRACE_DEC ((char *) 2)
42
#define XT_MM_TRACE_SW_INC ((char *) 1)
43
#define XT_MM_TRACE_SW_DEC ((char *) 2)
44
#define XT_MM_TRACE_ERROR ((char *) 3)
46
typedef struct XTMMTraceRef {
49
u_int mm_line[XT_MM_STACK_TRACE];
50
c_char *mm_trace[XT_MM_STACK_TRACE];
51
} XTMMTraceRefRec, *XTMMTraceRefPtr;
53
#define XT_MM_TRACE_INIT(x) (x)->mm_pos = 0
55
extern char *mm_watch_point;
57
#define XT_MEMMOVE(b, d, s, l) xt_mm_memmove(b, d, s, l)
58
#define XT_MEMCPY(b, d, s, l) xt_mm_memcpy(b, d, s, l)
59
#define XT_MEMSET(b, d, v, l) xt_mm_memset(b, d, v, l)
61
#define xt_malloc(t, s) xt_mm_malloc(t, s, __LINE__, __FILE__)
62
#define xt_calloc(t, s) xt_mm_calloc(t, s, __LINE__, __FILE__)
63
#define xt_realloc(t, p, s) xt_mm_realloc(t, p, s, __LINE__, __FILE__)
64
#define xt_free xt_mm_free
65
#define xt_pfree xt_mm_pfree
67
#define xt_malloc_ns(s) xt_mm_malloc(NULL, s, __LINE__, __FILE__)
68
#define xt_calloc_ns(s) xt_mm_calloc(NULL, s, __LINE__, __FILE__)
69
#define xt_realloc_ns(p, s) xt_mm_sys_realloc(NULL, p, s, __LINE__, __FILE__)
70
#define xt_free_ns(p) xt_mm_free(NULL, p)
72
void xt_mm_memmove(void *block, void *dest, void *source, size_t size);
73
void xt_mm_memcpy(void *block, void *dest, void *source, size_t size);
74
void xt_mm_memset(void *block, void *dest, int value, size_t size);
76
void *xt_mm_malloc(struct XTThread *self, size_t size, u_int line, const char *file);
77
void *xt_mm_calloc(struct XTThread *self, size_t size, u_int line, const char *file);
78
xtBool xt_mm_realloc(struct XTThread *self, void **ptr, size_t size, u_int line, const char *file);
79
void xt_mm_free(struct XTThread *self, void *ptr);
80
void xt_mm_pfree(struct XTThread *self, void **ptr);
81
size_t xt_mm_malloc_size(struct XTThread *self, void *ptr);
82
void xt_mm_check_ptr(struct XTThread *self, void *ptr);
83
xtBool xt_mm_sys_realloc(struct XTThread *self, void **ptr, size_t newsize, u_int line, const char *file);
85
#ifndef XT_SCAN_CORE_DEFINED
86
#define XT_SCAN_CORE_DEFINED
87
xtBool xt_mm_scan_core(void);
90
void mm_trace_print_id(void *ptr);
91
void mm_trace_inc(struct XTThread *self, XTMMTraceRefPtr tr);
92
void mm_trace_dec(struct XTThread *self, XTMMTraceRefPtr tr);
93
void mm_trace_init(struct XTThread *self, XTMMTraceRefPtr tr);
94
void mm_trace_print(XTMMTraceRefPtr tr);
98
#define XT_MEMMOVE(b, d, s, l) memmove(d, s, l)
99
#define XT_MEMCPY(b, d, s, l) memcpy(d, s, l)
100
#define XT_MEMSET(b, d, v, l) memset(d, v, l)
102
void *xt_malloc(struct XTThread *self, size_t size);
103
void *xt_calloc(struct XTThread *self, size_t size);
104
xtBool xt_realloc(struct XTThread *self, void **ptr, size_t size);
105
void xt_free(struct XTThread *self, void *ptr);
106
void xt_pfree(struct XTThread *self, void **ptr);
108
void *xt_malloc_ns(size_t size);
109
void *xt_calloc_ns(size_t size);
110
xtBool xt_realloc_ns(void **ptr, size_t size);
111
void xt_free_ns(void *ptr);
113
#define xt_pfree(t, p) xt_pfree(t, (void **) p)
118
#define xt_dup_string(t, s) xt_mm_dup_string(t, s, __LINE__, __FILE__)
120
char *xt_mm_dup_string(struct XTThread *self, const char *path, u_int line, const char *file);
122
char *xt_dup_string(struct XTThread *self, const char *path);
125
char *xt_long_to_str(struct XTThread *self, long v);
126
char *xt_dup_nstr(struct XTThread *self, const char *str, int start, size_t len);
128
xtBool xt_init_memory(void);
129
void xt_exit_memory(void);