-
Notifications
You must be signed in to change notification settings - Fork 1
/
ipa_overrides.c
61 lines (51 loc) · 1.15 KB
/
ipa_overrides.c
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
#include "ipa.h"
#ifdef IPA_SYSTEM_ALLOC
#if defined(__GNUC__) && !defined(NO_HOOK)
#include <malloc.h>
static void * ipa_hook (size_t size, const void * c){
return ipa_malloc(size);
}
static void ipafree_hook (void* payload, const void * c){
ipafree(payload);
}
static void * iparealloc_hook(void * payload, size_t size, const void * c) {
return iparealloc(payload, size);
}
static void * ipacalloc_hook(size_t a, size_t b, const void * c) {
return ipacalloc(a, b);
}
static void ipa_dehook() {
__malloc_hook = NULL;
__free_hook = NULL;
__realloc_hook = NULL;
#ifdef __calloc_hook
__calloc_hook = NULL;
#endif
}
void __attribute__((constructor)) ipa_hook() {
atexit(ipa_dehook);
__malloc_hook = ipa_hook;
__free_hook = ipafree_hook;
__realloc_hook = iparealloc_hook;
#ifdef __calloc_hook
__calloc_hook = ipacalloc_hook;
#endif
}
#else
void * malloc(size_t t) {
return ipa_malloc(t);
}
void free(void * p) {
ipafree(p);
}
size_t malloc_usable_size(void * p) {
return ipa_usable_space(p);
}
void * realloc(void * p, size_t size) {
return iparealloc(p, size);
}
void * calloc(size_t a, size_t b) {
return ipacalloc(a, b);
}
#endif
#endif