mesh-rb 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/ext/mesh/extconf.rb +22 -4
- data/ext/mesh/mesh.tar.gz +0 -0
- data/lib/mesh/version.rb +1 -1
- data/mesh.gemspec +3 -2
- metadata +4 -120
- data/ext/mesh/mesh/.bazelrc +0 -20
- data/ext/mesh/mesh/.bazelversion +0 -1
- data/ext/mesh/mesh/.clang-format +0 -15
- data/ext/mesh/mesh/.dockerignore +0 -5
- data/ext/mesh/mesh/.editorconfig +0 -16
- data/ext/mesh/mesh/.gitattributes +0 -4
- data/ext/mesh/mesh/.github/workflows/main.yml +0 -144
- data/ext/mesh/mesh/.gitignore +0 -51
- data/ext/mesh/mesh/AUTHORS +0 -5
- data/ext/mesh/mesh/CMakeLists.txt +0 -270
- data/ext/mesh/mesh/CODE_OF_CONDUCT.md +0 -77
- data/ext/mesh/mesh/Dockerfile +0 -30
- data/ext/mesh/mesh/LICENSE +0 -201
- data/ext/mesh/mesh/Makefile +0 -81
- data/ext/mesh/mesh/README.md +0 -97
- data/ext/mesh/mesh/WORKSPACE +0 -50
- data/ext/mesh/mesh/bazel +0 -350
- data/ext/mesh/mesh/mesh-pldi19-powers.pdf +0 -0
- data/ext/mesh/mesh/src/BUILD +0 -222
- data/ext/mesh/mesh/src/CMakeLists.txt +0 -85
- data/ext/mesh/mesh/src/bitmap.h +0 -590
- data/ext/mesh/mesh/src/cheap_heap.h +0 -170
- data/ext/mesh/mesh/src/common.h +0 -377
- data/ext/mesh/mesh/src/copts.bzl +0 -31
- data/ext/mesh/mesh/src/d_assert.cc +0 -75
- data/ext/mesh/mesh/src/fixed_array.h +0 -124
- data/ext/mesh/mesh/src/global_heap.cc +0 -547
- data/ext/mesh/mesh/src/global_heap.h +0 -569
- data/ext/mesh/mesh/src/gnu_wrapper.cc +0 -75
- data/ext/mesh/mesh/src/internal.h +0 -356
- data/ext/mesh/mesh/src/libmesh.cc +0 -239
- data/ext/mesh/mesh/src/mac_wrapper.cc +0 -528
- data/ext/mesh/mesh/src/measure_rss.cc +0 -44
- data/ext/mesh/mesh/src/measure_rss.h +0 -20
- data/ext/mesh/mesh/src/meshable_arena.cc +0 -776
- data/ext/mesh/mesh/src/meshable_arena.h +0 -309
- data/ext/mesh/mesh/src/meshing.h +0 -60
- data/ext/mesh/mesh/src/mini_heap.h +0 -532
- data/ext/mesh/mesh/src/mmap_heap.h +0 -104
- data/ext/mesh/mesh/src/one_way_mmap_heap.h +0 -77
- data/ext/mesh/mesh/src/partitioned_heap.h +0 -111
- data/ext/mesh/mesh/src/plasma/mesh.h +0 -33
- data/ext/mesh/mesh/src/real.cc +0 -52
- data/ext/mesh/mesh/src/real.h +0 -36
- data/ext/mesh/mesh/src/rng/mwc.h +0 -296
- data/ext/mesh/mesh/src/rng/mwc64.h +0 -58
- data/ext/mesh/mesh/src/rpl_printf.c +0 -1991
- data/ext/mesh/mesh/src/runtime.cc +0 -393
- data/ext/mesh/mesh/src/runtime.h +0 -114
- data/ext/mesh/mesh/src/shuffle_vector.h +0 -287
- data/ext/mesh/mesh/src/size_classes.def +0 -251
- data/ext/mesh/mesh/src/static/if.h +0 -36
- data/ext/mesh/mesh/src/static/log.h +0 -43
- data/ext/mesh/mesh/src/testing/benchmark/local_refill.cc +0 -103
- data/ext/mesh/mesh/src/testing/big-alloc.c +0 -28
- data/ext/mesh/mesh/src/testing/fragmenter.cc +0 -128
- data/ext/mesh/mesh/src/testing/global-large-stress.cc +0 -25
- data/ext/mesh/mesh/src/testing/local-alloc.c +0 -16
- data/ext/mesh/mesh/src/testing/meshing_benchmark.cc +0 -189
- data/ext/mesh/mesh/src/testing/thread.cc +0 -35
- data/ext/mesh/mesh/src/testing/unit/alignment.cc +0 -56
- data/ext/mesh/mesh/src/testing/unit/bitmap_test.cc +0 -274
- data/ext/mesh/mesh/src/testing/unit/concurrent_mesh_test.cc +0 -185
- data/ext/mesh/mesh/src/testing/unit/mesh_test.cc +0 -143
- data/ext/mesh/mesh/src/testing/unit/rng_test.cc +0 -22
- data/ext/mesh/mesh/src/testing/unit/size_class_test.cc +0 -66
- data/ext/mesh/mesh/src/testing/unit/triple_mesh_test.cc +0 -285
- data/ext/mesh/mesh/src/testing/userfaultfd-kernel-copy.cc +0 -164
- data/ext/mesh/mesh/src/thread_local_heap.cc +0 -163
- data/ext/mesh/mesh/src/thread_local_heap.h +0 -268
- data/ext/mesh/mesh/src/wrapper.cc +0 -433
- data/ext/mesh/mesh/support/export_mesh.cmake +0 -28
- data/ext/mesh/mesh/support/gen-size-classes +0 -57
- data/ext/mesh/mesh/support/install_all_configs +0 -33
- data/ext/mesh/mesh/support/remove_export_mesh.cmake +0 -48
- data/ext/mesh/mesh/support/update-bazelisk +0 -8
- data/ext/mesh/mesh/theory/32m80.png +0 -0
- data/ext/mesh/mesh/theory/64m80ind.png +0 -0
- data/ext/mesh/mesh/theory/bound_comparison.py +0 -67
- data/ext/mesh/mesh/theory/bounds/impdeg+1 +0 -135
- data/ext/mesh/mesh/theory/choose.py +0 -43
- data/ext/mesh/mesh/theory/common.py +0 -42
- data/ext/mesh/mesh/theory/compute_exp_Y.py +0 -134
- data/ext/mesh/mesh/theory/createRandomString.py +0 -69
- data/ext/mesh/mesh/theory/deg_bound_check.py +0 -100
- data/ext/mesh/mesh/theory/degcheck.py +0 -47
- data/ext/mesh/mesh/theory/dumps/32,1,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,2,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,3,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,4,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,5,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,6,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,7,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,8,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/dumps/32,9,80,dumb.txt +0 -81
- data/ext/mesh/mesh/theory/experiment.py +0 -303
- data/ext/mesh/mesh/theory/experiment_raw_results/.gitignore +0 -0
- data/ext/mesh/mesh/theory/greedy_experiment.py +0 -66
- data/ext/mesh/mesh/theory/greedy_experiment_copy.py +0 -46
- data/ext/mesh/mesh/theory/greedy_experiment_q.py +0 -75
- data/ext/mesh/mesh/theory/makeGraph.py +0 -64
- data/ext/mesh/mesh/theory/manyreps.png +0 -0
- data/ext/mesh/mesh/theory/manystrings.png +0 -0
- data/ext/mesh/mesh/theory/match_vs_color_experiment.py +0 -94
- data/ext/mesh/mesh/theory/maxmatch_vs_E[Y].py +0 -162
- data/ext/mesh/mesh/theory/maxmatch_vs_greedymatch.py +0 -96
- data/ext/mesh/mesh/theory/maxvdeg+1imp++32,80.png +0 -0
- data/ext/mesh/mesh/theory/mesh_util.py +0 -322
- data/ext/mesh/mesh/theory/meshers.py +0 -452
- data/ext/mesh/mesh/theory/meshingBenchmark.py +0 -96
- data/ext/mesh/mesh/theory/occupancyComparison.py +0 -133
- data/ext/mesh/mesh/theory/randmatch_vs_greedymatch.py +0 -97
- data/ext/mesh/mesh/theory/randmatch_vs_greedymatch_q.py +0 -103
- data/ext/mesh/mesh/theory/randmatch_vs_greedymatch_time.py +0 -117
- data/ext/mesh/mesh/theory/read_mesh_dump.py +0 -82
- data/ext/mesh/mesh/theory/test.py +0 -70
- data/ext/mesh/mesh/tools/bazel +0 -1
@@ -1,528 +0,0 @@
|
|
1
|
-
// -*- C++ -*-
|
2
|
-
|
3
|
-
/**
|
4
|
-
* @file macwrapper.cpp
|
5
|
-
* @brief Replaces malloc family on Macs with custom versions.
|
6
|
-
* @author Emery Berger <http://www.emeryberger.com>
|
7
|
-
* @note Copyright (C) 2010-2018 by Emery Berger, University of Massachusetts Amherst.
|
8
|
-
*/
|
9
|
-
|
10
|
-
#ifndef __APPLE__
|
11
|
-
#error "This file is for use on Mac OS only."
|
12
|
-
#endif
|
13
|
-
|
14
|
-
#include <cstdlib>
|
15
|
-
using namespace std;
|
16
|
-
|
17
|
-
#include <stdlib.h>
|
18
|
-
#include <stdio.h>
|
19
|
-
#include <string.h>
|
20
|
-
#include <malloc/malloc.h>
|
21
|
-
#include <errno.h>
|
22
|
-
|
23
|
-
#include <unistd.h>
|
24
|
-
|
25
|
-
/*
|
26
|
-
To use this library,
|
27
|
-
you only need to define the following allocation functions:
|
28
|
-
|
29
|
-
- xxmalloc
|
30
|
-
- xxfree
|
31
|
-
- xxmalloc_usable_size
|
32
|
-
- xxmalloc_lock
|
33
|
-
- xxmalloc_unlock
|
34
|
-
|
35
|
-
See the extern "C" block below for function prototypes and more
|
36
|
-
details. YOU SHOULD NOT NEED TO MODIFY ANY OF THE CODE HERE TO
|
37
|
-
SUPPORT ANY ALLOCATOR.
|
38
|
-
|
39
|
-
|
40
|
-
LIMITATIONS:
|
41
|
-
|
42
|
-
- This wrapper assumes that the underlying allocator will do "the
|
43
|
-
right thing" when xxfree() is called with a pointer internal to an
|
44
|
-
allocated object. Header-based allocators, for example, need not
|
45
|
-
apply.
|
46
|
-
|
47
|
-
- This wrapper also assumes that there is some way to lock all the
|
48
|
-
heaps used by a given allocator; however, such support is only
|
49
|
-
required by programs that also call fork(). In case your program
|
50
|
-
does not, the lock and unlock calls given below can be no-ops.
|
51
|
-
|
52
|
-
*/
|
53
|
-
|
54
|
-
#include <assert.h>
|
55
|
-
|
56
|
-
#include "wrappers/macinterpose.h"
|
57
|
-
|
58
|
-
//////////
|
59
|
-
//////////
|
60
|
-
|
61
|
-
// All replacement functions get the prefix "replace_".
|
62
|
-
|
63
|
-
extern "C" {
|
64
|
-
|
65
|
-
MESH_EXPORT void *replace_malloc(size_t sz) {
|
66
|
-
void *ptr = xxmalloc(sz);
|
67
|
-
return ptr;
|
68
|
-
}
|
69
|
-
|
70
|
-
#if 0 // Disabled pending wider support for sized deallocation.
|
71
|
-
void replace_free_sized (void * ptr, size_t sz) {
|
72
|
-
xxfree_sized (ptr, sz);
|
73
|
-
}
|
74
|
-
#endif
|
75
|
-
|
76
|
-
MESH_EXPORT size_t replace_malloc_usable_size(void *ptr) {
|
77
|
-
if (ptr == nullptr) {
|
78
|
-
return 0;
|
79
|
-
}
|
80
|
-
auto objSize = xxmalloc_usable_size(ptr);
|
81
|
-
return objSize;
|
82
|
-
}
|
83
|
-
|
84
|
-
MESH_EXPORT void replace_free(void *ptr) {
|
85
|
-
xxfree(ptr);
|
86
|
-
}
|
87
|
-
|
88
|
-
MESH_EXPORT size_t replace_malloc_good_size(size_t sz) {
|
89
|
-
auto *ptr = xxmalloc(sz);
|
90
|
-
auto objSize = xxmalloc_usable_size(ptr);
|
91
|
-
xxfree(ptr);
|
92
|
-
return objSize;
|
93
|
-
}
|
94
|
-
|
95
|
-
static void *_extended_realloc(void *ptr, size_t sz, bool isReallocf) {
|
96
|
-
// NULL ptr = malloc.
|
97
|
-
if (ptr == NULL) {
|
98
|
-
return xxmalloc(sz);
|
99
|
-
}
|
100
|
-
|
101
|
-
// 0 size = free. We return a small object. This behavior is
|
102
|
-
// apparently required under Mac OS X and optional under POSIX.
|
103
|
-
if (sz == 0) {
|
104
|
-
xxfree(ptr);
|
105
|
-
return xxmalloc(1);
|
106
|
-
}
|
107
|
-
|
108
|
-
auto objSize = xxmalloc_usable_size(ptr);
|
109
|
-
|
110
|
-
// Custom logic here to ensure we only do a logarithmic number of
|
111
|
-
// reallocations (with a constant space overhead).
|
112
|
-
|
113
|
-
// Don't change size if the object is shrinking by less than half.
|
114
|
-
if ((objSize / 2 < sz) && (sz <= objSize)) {
|
115
|
-
// Do nothing.
|
116
|
-
return ptr;
|
117
|
-
}
|
118
|
-
#if 0
|
119
|
-
// If the object is growing by less than 2X, double it.
|
120
|
-
if ((objSize < sz) && (sz < objSize * 2)) {
|
121
|
-
sz = objSize * 2;
|
122
|
-
}
|
123
|
-
#endif
|
124
|
-
|
125
|
-
auto *buf = xxmalloc((size_t)sz);
|
126
|
-
|
127
|
-
if (buf != NULL) {
|
128
|
-
// Successful malloc.
|
129
|
-
// Copy the contents of the original object
|
130
|
-
// up to the size of the new block.
|
131
|
-
auto minSize = (objSize < sz) ? objSize : sz;
|
132
|
-
memcpy(buf, ptr, minSize);
|
133
|
-
xxfree(ptr);
|
134
|
-
} else {
|
135
|
-
if (isReallocf) {
|
136
|
-
// Free the old block if the new allocation failed.
|
137
|
-
// Specific behavior for Mac OS X reallocf().
|
138
|
-
xxfree(ptr);
|
139
|
-
}
|
140
|
-
}
|
141
|
-
|
142
|
-
// Return a pointer to the new one.
|
143
|
-
return buf;
|
144
|
-
}
|
145
|
-
|
146
|
-
MESH_EXPORT void *replace_realloc(void *ptr, size_t sz) {
|
147
|
-
return _extended_realloc(ptr, sz, false);
|
148
|
-
}
|
149
|
-
|
150
|
-
MESH_EXPORT void *replace_reallocf(void *ptr, size_t sz) {
|
151
|
-
return _extended_realloc(ptr, sz, true);
|
152
|
-
}
|
153
|
-
|
154
|
-
MESH_EXPORT void *replace_calloc(size_t elsize, size_t nelems) {
|
155
|
-
auto n = nelems * elsize;
|
156
|
-
if (elsize && (nelems != n / elsize)) {
|
157
|
-
return nullptr;
|
158
|
-
}
|
159
|
-
auto *ptr = xxmalloc(n);
|
160
|
-
if (ptr) {
|
161
|
-
memset(ptr, 0, n);
|
162
|
-
}
|
163
|
-
return ptr;
|
164
|
-
}
|
165
|
-
|
166
|
-
MESH_EXPORT char *replace_strdup(const char *s) {
|
167
|
-
char *newString = NULL;
|
168
|
-
if (s != NULL) {
|
169
|
-
auto len = strlen(s) + 1UL;
|
170
|
-
if ((newString = (char *)replace_malloc(len))) {
|
171
|
-
memcpy(newString, s, len);
|
172
|
-
}
|
173
|
-
}
|
174
|
-
return newString;
|
175
|
-
}
|
176
|
-
|
177
|
-
MESH_EXPORT void *replace_memalign(size_t alignment, size_t size) {
|
178
|
-
// Check for non power-of-two alignment, or mistake in size.
|
179
|
-
if (alignment < alignof(max_align_t)) {
|
180
|
-
alignment = alignof(max_align_t);
|
181
|
-
}
|
182
|
-
// Round up to next power of two.
|
183
|
-
if (alignment & (alignment - 1)) {
|
184
|
-
size_t a = alignof(max_align_t);
|
185
|
-
while (a < alignment) {
|
186
|
-
a <<= 1;
|
187
|
-
}
|
188
|
-
alignment = a;
|
189
|
-
}
|
190
|
-
// Try to just allocate an object of the requested size.
|
191
|
-
// If it happens to be aligned properly, just return it.
|
192
|
-
auto *ptr = replace_malloc(size);
|
193
|
-
if (((size_t)ptr & ~(alignment - 1)) == (size_t)ptr) {
|
194
|
-
// It is already aligned just fine; return it.
|
195
|
-
return ptr;
|
196
|
-
}
|
197
|
-
// It was not aligned as requested: free the object.
|
198
|
-
replace_free(ptr);
|
199
|
-
|
200
|
-
// Force size to be a multiple of alignment.
|
201
|
-
if (alignment < size) {
|
202
|
-
size = size + alignment - (size % alignment);
|
203
|
-
} else {
|
204
|
-
size = alignment;
|
205
|
-
}
|
206
|
-
|
207
|
-
ptr = replace_malloc(size);
|
208
|
-
// If the underlying malloc has "natural" alignment, this will work.
|
209
|
-
if (((size_t)ptr & ~(alignment - 1)) == (size_t)ptr) {
|
210
|
-
// It is already aligned just fine; return it.
|
211
|
-
return ptr;
|
212
|
-
}
|
213
|
-
// It was not aligned as requested: free the object.
|
214
|
-
replace_free(ptr);
|
215
|
-
|
216
|
-
// Now get a big chunk of memory and align the object within it.
|
217
|
-
// NOTE: this assumes that the underlying allocator will be able
|
218
|
-
// to free the aligned object, or ignore the free request.
|
219
|
-
auto *buf = replace_malloc(2 * alignment + size);
|
220
|
-
auto *alignedPtr = (void *)(((size_t)buf + alignment - 1) & ~(alignment - 1));
|
221
|
-
return alignedPtr;
|
222
|
-
}
|
223
|
-
|
224
|
-
#if 0
|
225
|
-
void * replace_aligned_alloc (size_t alignment, size_t size) {
|
226
|
-
// Per the man page: "The function aligned_alloc() is the same as
|
227
|
-
// memalign(), except for the added restriction that size should be
|
228
|
-
// a multiple of alignment." Rather than check and potentially fail,
|
229
|
-
// we just enforce this by rounding up the size, if necessary.
|
230
|
-
size = size + alignment - (size % alignment);
|
231
|
-
return replace_memalign (alignment, size);
|
232
|
-
}
|
233
|
-
#endif
|
234
|
-
|
235
|
-
MESH_EXPORT int replace_posix_memalign(void **memptr, size_t alignment, size_t size) {
|
236
|
-
// Check for non power-of-two alignment.
|
237
|
-
if ((alignment == 0) || (alignment & (alignment - 1))) {
|
238
|
-
return EINVAL;
|
239
|
-
}
|
240
|
-
auto *ptr = replace_memalign(alignment, size);
|
241
|
-
if (!ptr) {
|
242
|
-
return ENOMEM;
|
243
|
-
} else {
|
244
|
-
*memptr = ptr;
|
245
|
-
return 0;
|
246
|
-
}
|
247
|
-
}
|
248
|
-
|
249
|
-
MESH_EXPORT void *replace_valloc(size_t sz) {
|
250
|
-
// Equivalent to memalign(pagesize, sz).
|
251
|
-
void *ptr = replace_memalign(PAGE_SIZE, sz);
|
252
|
-
return ptr;
|
253
|
-
}
|
254
|
-
|
255
|
-
MESH_EXPORT void replace_vfree(void *ptr) {
|
256
|
-
replace_free(ptr);
|
257
|
-
}
|
258
|
-
}
|
259
|
-
|
260
|
-
/////////
|
261
|
-
/////////
|
262
|
-
|
263
|
-
extern "C" {
|
264
|
-
// operator new
|
265
|
-
MESH_EXPORT void *_Znwm(unsigned long);
|
266
|
-
MESH_EXPORT void *_Znam(unsigned long);
|
267
|
-
|
268
|
-
// operator delete
|
269
|
-
MESH_EXPORT void _ZdlPv(void *);
|
270
|
-
MESH_EXPORT void _ZdaPv(void *);
|
271
|
-
|
272
|
-
// nothrow variants
|
273
|
-
// operator new nothrow
|
274
|
-
MESH_EXPORT void *_ZnwmRKSt9nothrow_t();
|
275
|
-
MESH_EXPORT void *_ZnamRKSt9nothrow_t();
|
276
|
-
// operator delete nothrow
|
277
|
-
MESH_EXPORT void _ZdaPvRKSt9nothrow_t(void *);
|
278
|
-
MESH_EXPORT void _ZdlPvRKSt9nothrow_t(void *);
|
279
|
-
|
280
|
-
MESH_EXPORT void _malloc_fork_prepare();
|
281
|
-
MESH_EXPORT void _malloc_fork_parent();
|
282
|
-
MESH_EXPORT void _malloc_fork_child();
|
283
|
-
}
|
284
|
-
|
285
|
-
static malloc_zone_t theDefaultZone;
|
286
|
-
|
287
|
-
extern "C" {
|
288
|
-
|
289
|
-
MESH_EXPORT malloc_zone_t *replace_malloc_create_zone(vm_size_t, unsigned) {
|
290
|
-
// auto zone = (malloc_zone_t *) replace_malloc(sizeof(malloc_zone_t));
|
291
|
-
return nullptr; // zone;
|
292
|
-
}
|
293
|
-
|
294
|
-
MESH_EXPORT malloc_zone_t *replace_malloc_default_zone() {
|
295
|
-
return &theDefaultZone;
|
296
|
-
}
|
297
|
-
|
298
|
-
MESH_EXPORT malloc_zone_t *replace_malloc_default_purgeable_zone() {
|
299
|
-
return &theDefaultZone;
|
300
|
-
}
|
301
|
-
|
302
|
-
MESH_EXPORT void replace_malloc_destroy_zone(malloc_zone_t *) {
|
303
|
-
// Do nothing.
|
304
|
-
}
|
305
|
-
|
306
|
-
MESH_EXPORT kern_return_t replace_malloc_get_all_zones(task_t, memory_reader_t, vm_address_t **addresses,
|
307
|
-
unsigned *count) {
|
308
|
-
*addresses = 0;
|
309
|
-
count = 0;
|
310
|
-
return KERN_SUCCESS;
|
311
|
-
}
|
312
|
-
|
313
|
-
MESH_EXPORT const char *replace_malloc_get_zone_name(malloc_zone_t *z) {
|
314
|
-
return z->zone_name;
|
315
|
-
}
|
316
|
-
|
317
|
-
MESH_EXPORT void replace_malloc_printf(const char *, ...) {
|
318
|
-
}
|
319
|
-
|
320
|
-
MESH_EXPORT size_t replace_internal_malloc_zone_size(malloc_zone_t *, const void *ptr) {
|
321
|
-
return replace_malloc_usable_size((void *)ptr);
|
322
|
-
}
|
323
|
-
|
324
|
-
MESH_EXPORT int replace_malloc_jumpstart(int) {
|
325
|
-
return 1;
|
326
|
-
}
|
327
|
-
|
328
|
-
MESH_EXPORT void replace_malloc_set_zone_name(malloc_zone_t *, const char *) {
|
329
|
-
// do nothing.
|
330
|
-
}
|
331
|
-
|
332
|
-
MESH_EXPORT unsigned replace_malloc_zone_batch_malloc(malloc_zone_t *, size_t sz, void **results,
|
333
|
-
unsigned num_requested) {
|
334
|
-
for (auto i = 0U; i < num_requested; i++) {
|
335
|
-
results[i] = replace_malloc(sz);
|
336
|
-
if (results[i] == nullptr) {
|
337
|
-
return i;
|
338
|
-
}
|
339
|
-
}
|
340
|
-
return num_requested;
|
341
|
-
}
|
342
|
-
|
343
|
-
MESH_EXPORT void replace_malloc_zone_batch_free(malloc_zone_t *, void **to_be_freed, unsigned num) {
|
344
|
-
for (auto i = 0U; i < num; i++) {
|
345
|
-
replace_free(to_be_freed[i]);
|
346
|
-
}
|
347
|
-
}
|
348
|
-
|
349
|
-
MESH_EXPORT void *replace_malloc_zone_calloc(malloc_zone_t *, size_t n, size_t size) {
|
350
|
-
return replace_calloc(n, size);
|
351
|
-
}
|
352
|
-
|
353
|
-
MESH_EXPORT bool replace_malloc_zone_check(malloc_zone_t *) {
|
354
|
-
// Just return true for all zones.
|
355
|
-
return true;
|
356
|
-
}
|
357
|
-
|
358
|
-
MESH_EXPORT void replace_malloc_zone_free(malloc_zone_t *, void *ptr) {
|
359
|
-
replace_free(ptr);
|
360
|
-
}
|
361
|
-
|
362
|
-
MESH_EXPORT void replace_malloc_zone_free_definite_size(malloc_zone_t *, void *ptr, size_t) {
|
363
|
-
replace_free(ptr);
|
364
|
-
}
|
365
|
-
|
366
|
-
MESH_EXPORT malloc_zone_t *replace_malloc_zone_from_ptr(const void *) {
|
367
|
-
return replace_malloc_default_zone();
|
368
|
-
}
|
369
|
-
|
370
|
-
MESH_EXPORT void replace_malloc_zone_log(malloc_zone_t *, void *) {
|
371
|
-
// Do nothing.
|
372
|
-
}
|
373
|
-
|
374
|
-
MESH_EXPORT void *replace_malloc_zone_malloc(malloc_zone_t *, size_t size) {
|
375
|
-
return replace_malloc(size);
|
376
|
-
}
|
377
|
-
|
378
|
-
MESH_EXPORT void replace_malloc_zone_print(malloc_zone_t *, bool) {
|
379
|
-
// Do nothing.
|
380
|
-
}
|
381
|
-
|
382
|
-
MESH_EXPORT void replace_malloc_zone_print_ptr_info(void *) {
|
383
|
-
}
|
384
|
-
|
385
|
-
MESH_EXPORT void *replace_malloc_zone_realloc(malloc_zone_t *, void *ptr, size_t size) {
|
386
|
-
return replace_realloc(ptr, size);
|
387
|
-
}
|
388
|
-
|
389
|
-
MESH_EXPORT void replace_malloc_zone_register(malloc_zone_t *) {
|
390
|
-
}
|
391
|
-
|
392
|
-
MESH_EXPORT void *replace_malloc_zone_memalign(malloc_zone_t *, size_t alignment, size_t size) {
|
393
|
-
return replace_memalign(alignment, size);
|
394
|
-
}
|
395
|
-
|
396
|
-
MESH_EXPORT void replace_malloc_zone_unregister(malloc_zone_t *) {
|
397
|
-
}
|
398
|
-
|
399
|
-
MESH_EXPORT void *replace_malloc_zone_valloc(malloc_zone_t *, size_t size) {
|
400
|
-
return replace_valloc(size);
|
401
|
-
}
|
402
|
-
|
403
|
-
MESH_EXPORT void replace__malloc_fork_child() {
|
404
|
-
/* Called in the child process after a fork() to resume normal operation. In the MTASK case we also have to change
|
405
|
-
* memory inheritance so that the child does not share memory with the parent. */
|
406
|
-
xxmalloc_unlock();
|
407
|
-
}
|
408
|
-
|
409
|
-
MESH_EXPORT void replace__malloc_fork_parent() {
|
410
|
-
/* Called in the parent process after a fork() to resume normal operation. */
|
411
|
-
xxmalloc_unlock();
|
412
|
-
}
|
413
|
-
|
414
|
-
MESH_EXPORT void replace__malloc_fork_prepare() {
|
415
|
-
/* Prepare the malloc module for a fork by insuring that no thread is in a malloc critical section */
|
416
|
-
xxmalloc_lock();
|
417
|
-
}
|
418
|
-
}
|
419
|
-
|
420
|
-
extern "C" MESH_EXPORT void vfree(void *);
|
421
|
-
extern "C" MESH_EXPORT int malloc_jumpstart(int);
|
422
|
-
|
423
|
-
// Now interpose everything.
|
424
|
-
|
425
|
-
#ifndef HL_REPLACE_MALLOC_OPS
|
426
|
-
#define HL_REPLACE_MALLOC_OPS 1
|
427
|
-
#endif
|
428
|
-
|
429
|
-
#define HL_REPLACE_ZONES 0
|
430
|
-
|
431
|
-
#if HL_REPLACE_MALLOC_OPS
|
432
|
-
|
433
|
-
MAC_INTERPOSE(replace__malloc_fork_child, _malloc_fork_child);
|
434
|
-
MAC_INTERPOSE(replace__malloc_fork_parent, _malloc_fork_parent);
|
435
|
-
MAC_INTERPOSE(replace__malloc_fork_prepare, _malloc_fork_prepare);
|
436
|
-
// MAC_INTERPOSE(replace_aligned_alloc, aligned_alloc);
|
437
|
-
MAC_INTERPOSE(replace_calloc, calloc);
|
438
|
-
MAC_INTERPOSE(replace_free, _ZdaPv);
|
439
|
-
MAC_INTERPOSE(replace_free, _ZdaPvRKSt9nothrow_t);
|
440
|
-
MAC_INTERPOSE(replace_free, _ZdlPv);
|
441
|
-
MAC_INTERPOSE(replace_free, _ZdlPvRKSt9nothrow_t);
|
442
|
-
MAC_INTERPOSE(replace_free, free);
|
443
|
-
MAC_INTERPOSE(replace_free, vfree);
|
444
|
-
MAC_INTERPOSE(replace_malloc, _Znam);
|
445
|
-
MAC_INTERPOSE(replace_malloc, _ZnamRKSt9nothrow_t);
|
446
|
-
MAC_INTERPOSE(replace_malloc, _Znwm);
|
447
|
-
MAC_INTERPOSE(replace_malloc, _ZnwmRKSt9nothrow_t);
|
448
|
-
MAC_INTERPOSE(replace_malloc, malloc);
|
449
|
-
#if HL_REPLACE_ZONES
|
450
|
-
MAC_INTERPOSE(replace_malloc_create_zone, malloc_create_zone);
|
451
|
-
MAC_INTERPOSE(replace_malloc_default_purgeable_zone, malloc_default_purgeable_zone);
|
452
|
-
MAC_INTERPOSE(replace_malloc_default_zone, malloc_default_zone);
|
453
|
-
MAC_INTERPOSE(replace_malloc_destroy_zone, malloc_destroy_zone);
|
454
|
-
MAC_INTERPOSE(replace_malloc_get_all_zones, malloc_get_all_zones);
|
455
|
-
MAC_INTERPOSE(replace_malloc_get_zone_name, malloc_get_zone_name);
|
456
|
-
#endif
|
457
|
-
MAC_INTERPOSE(replace_malloc_good_size, malloc_good_size);
|
458
|
-
#if HL_REPLACE_ZONES
|
459
|
-
MAC_INTERPOSE(replace_malloc_jumpstart, malloc_jumpstart);
|
460
|
-
#endif
|
461
|
-
MAC_INTERPOSE(replace_malloc_printf, malloc_printf);
|
462
|
-
MAC_INTERPOSE(replace_malloc_set_zone_name, malloc_set_zone_name);
|
463
|
-
MAC_INTERPOSE(replace_malloc_usable_size, malloc_size);
|
464
|
-
#if HL_REPLACE_ZONES
|
465
|
-
MAC_INTERPOSE(replace_malloc_zone_batch_free, malloc_zone_batch_free);
|
466
|
-
MAC_INTERPOSE(replace_malloc_zone_batch_malloc, malloc_zone_batch_malloc);
|
467
|
-
MAC_INTERPOSE(replace_malloc_zone_calloc, malloc_zone_calloc);
|
468
|
-
MAC_INTERPOSE(replace_malloc_zone_check, malloc_zone_check);
|
469
|
-
MAC_INTERPOSE(replace_malloc_zone_free, malloc_zone_free);
|
470
|
-
MAC_INTERPOSE(replace_malloc_zone_from_ptr, malloc_zone_from_ptr);
|
471
|
-
MAC_INTERPOSE(replace_malloc_zone_log, malloc_zone_log);
|
472
|
-
MAC_INTERPOSE(replace_malloc_zone_malloc, malloc_zone_malloc);
|
473
|
-
MAC_INTERPOSE(replace_malloc_zone_memalign, malloc_zone_memalign);
|
474
|
-
MAC_INTERPOSE(replace_malloc_zone_print, malloc_zone_print);
|
475
|
-
MAC_INTERPOSE(replace_malloc_zone_print_ptr_info, malloc_zone_print_ptr_info);
|
476
|
-
MAC_INTERPOSE(replace_malloc_zone_realloc, malloc_zone_realloc);
|
477
|
-
MAC_INTERPOSE(replace_malloc_zone_register, malloc_zone_register);
|
478
|
-
MAC_INTERPOSE(replace_malloc_zone_unregister, malloc_zone_unregister);
|
479
|
-
MAC_INTERPOSE(replace_malloc_zone_valloc, malloc_zone_valloc);
|
480
|
-
#endif
|
481
|
-
MAC_INTERPOSE(replace_posix_memalign, posix_memalign);
|
482
|
-
MAC_INTERPOSE(replace_realloc, realloc);
|
483
|
-
MAC_INTERPOSE(replace_reallocf, reallocf);
|
484
|
-
MAC_INTERPOSE(replace_strdup, strdup);
|
485
|
-
MAC_INTERPOSE(replace_valloc, valloc);
|
486
|
-
|
487
|
-
#endif
|
488
|
-
|
489
|
-
// A class to initialize exactly one malloc zone with the calls used
|
490
|
-
// by our replacement.
|
491
|
-
|
492
|
-
static const char *theOneTrueZoneName = "DefaultMallocZone";
|
493
|
-
|
494
|
-
class initializeDefaultZone {
|
495
|
-
public:
|
496
|
-
initializeDefaultZone() {
|
497
|
-
theDefaultZone.size = replace_internal_malloc_zone_size;
|
498
|
-
theDefaultZone.malloc = replace_malloc_zone_malloc;
|
499
|
-
theDefaultZone.calloc = replace_malloc_zone_calloc;
|
500
|
-
theDefaultZone.valloc = replace_malloc_zone_valloc;
|
501
|
-
theDefaultZone.free = replace_malloc_zone_free;
|
502
|
-
theDefaultZone.realloc = replace_malloc_zone_realloc;
|
503
|
-
theDefaultZone.destroy = replace_malloc_destroy_zone;
|
504
|
-
theDefaultZone.zone_name = theOneTrueZoneName;
|
505
|
-
theDefaultZone.batch_malloc = replace_malloc_zone_batch_malloc;
|
506
|
-
theDefaultZone.batch_free = replace_malloc_zone_batch_free;
|
507
|
-
theDefaultZone.introspect = NULL;
|
508
|
-
theDefaultZone.version = 8;
|
509
|
-
theDefaultZone.memalign = replace_malloc_zone_memalign;
|
510
|
-
theDefaultZone.free_definite_size = replace_malloc_zone_free_definite_size;
|
511
|
-
theDefaultZone.pressure_relief = NULL;
|
512
|
-
// Unregister and reregister the default zone. Unregistering swaps
|
513
|
-
// the specified zone with the last one registered which for the
|
514
|
-
// default zone makes the more recently registered zone the default
|
515
|
-
// zone. The default zone is then re-registered to ensure that
|
516
|
-
// allocations made from it earlier will be handled correctly.
|
517
|
-
// Things are not guaranteed to work that way, but it's how they work now.
|
518
|
-
malloc_zone_t *default_zone = malloc_default_zone();
|
519
|
-
malloc_zone_unregister(default_zone);
|
520
|
-
malloc_zone_register(&theDefaultZone);
|
521
|
-
}
|
522
|
-
};
|
523
|
-
|
524
|
-
// Force initialization of the default zone.
|
525
|
-
|
526
|
-
#if REPLACE_ZONES
|
527
|
-
static initializeDefaultZone initMe;
|
528
|
-
#endif
|