-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgnuwrapper.cpp
More file actions
73 lines (55 loc) · 1.88 KB
/
gnuwrapper.cpp
File metadata and controls
73 lines (55 loc) · 1.88 KB
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
// -*- C++ -*-
/**
* @file gnuwrapper.cpp
* @brief Replaces malloc family on GNU/Linux with custom versions.
* @author Emery Berger <http://www.cs.umass.edu/~emery>
* @note Copyright (C) 2010 by Emery Berger, University of Massachusetts Amherst.
*/
#ifndef __GNUC__
#error "This file requires the GNU compiler."
#endif
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
#include <new>
#include <pthread.h>
#include <sys/cdefs.h>
/*
To use this library,
you only need to define the following allocation functions:
- xxmalloc
- xxfree
- xxmalloc_usable_size
- xxmalloc_lock
- xxmalloc_unlock
See the extern "C" block below for function prototypes and more
details. YOU SHOULD NOT NEED TO MODIFY ANY OF THE CODE HERE TO
SUPPORT ANY ALLOCATOR.
LIMITATIONS:
- This wrapper assumes that the underlying allocator will do "the
right thing" when xxfree() is called with a pointer internal to an
allocated object. Header-based allocators, for example, need not
apply.
*/
#define WEAK(x) __attribute__ ((weak, alias(#x)))
#ifndef __THROW
#define __THROW
#endif
#define CUSTOM_PREFIX(x) hoard_##x
#define WEAK_REDEF1(type,fname,arg1) type fname(arg1) __THROW WEAK(hoard_##fname)
#define WEAK_REDEF2(type,fname,arg1,arg2) type fname(arg1,arg2) __THROW WEAK(hoard_##fname)
#define WEAK_REDEF3(type,fname,arg1,arg2,arg3) type fname(arg1,arg2,arg3) __THROW WEAK(hoard_##fname)
extern "C" {
WEAK_REDEF1(void *, malloc, size_t);
WEAK_REDEF1(void, free, void *);
WEAK_REDEF1(void, cfree, void *);
WEAK_REDEF2(void *, calloc, size_t, size_t);
WEAK_REDEF2(void *, realloc, void *, size_t);
WEAK_REDEF2(void *, memalign, size_t, size_t);
WEAK_REDEF3(int, posix_memalign, void **, size_t, size_t);
WEAK_REDEF2(void *, aligned_alloc, size_t, size_t);
WEAK_REDEF1(size_t, malloc_usable_size, void *);
}
#include "wrapper.h"