2
2
#include " memory_region.h"
3
3
4
4
#if RUSTRT_TRACK_ALLOCATIONS >= 1
5
- # define PTR_SIZE (sizeof (void *))
5
+ // For some platforms, 16 byte alignment is required.
6
+ # define PTR_SIZE 16
6
7
# define ALIGN_PTR (x ) (((x)+PTR_SIZE-1 )/PTR_SIZE*PTR_SIZE)
7
8
# define HEADER_SIZE ALIGN_PTR (sizeof (alloc_header))
8
9
# define MAGIC 0xbadc0ffe
@@ -65,11 +66,15 @@ memory_region::realloc(void *mem, size_t orig_size) {
65
66
}
66
67
67
68
alloc_header *alloc = get_header (mem);
69
+ # if RUSTRT_TRACK_ALLOCATIONS >= 1
70
+ assert (alloc->magic == MAGIC);
71
+ # endif
72
+
68
73
size_t size = orig_size + HEADER_SIZE;
69
74
alloc_header *newMem = (alloc_header *)_srv->realloc (alloc, size);
70
75
71
76
# if RUSTRT_TRACK_ALLOCATIONS >= 1
72
- assert (alloc ->magic == MAGIC);
77
+ assert (newMem ->magic == MAGIC);
73
78
newMem->size = orig_size;
74
79
# endif
75
80
@@ -141,7 +146,7 @@ memory_region::~memory_region() {
141
146
alloc_header *header = (alloc_header*)_allocation_list[i];
142
147
printf (" allocation (%s) 0x%" PRIxPTR " was not freed\n " ,
143
148
header->tag ,
144
- (uintptr_t ) & header-> data );
149
+ (uintptr_t ) get_data ( header) );
145
150
++leak_count;
146
151
}
147
152
}
@@ -167,7 +172,7 @@ memory_region::release_alloc(void *mem) {
167
172
if (_synchronized) { _lock.lock (); }
168
173
if (_allocation_list[alloc->index ] != alloc) {
169
174
printf (" free: ptr 0x%" PRIxPTR " (%s) is not in allocation_list\n " ,
170
- (uintptr_t ) & alloc-> data , alloc->tag );
175
+ (uintptr_t ) get_data ( alloc) , alloc->tag );
171
176
_srv->fatal (" not in allocation_list" , __FILE__, __LINE__, " " );
172
177
}
173
178
else {
@@ -222,6 +227,5 @@ memory_region::maybe_poison(void *mem) {
222
227
// indent-tabs-mode: nil
223
228
// c-basic-offset: 4
224
229
// buffer-file-coding-system: utf-8-unix
225
- // compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
226
230
// End:
227
231
//
0 commit comments