forked from plasma-umass/scalene
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libscalene.cpp
72 lines (58 loc) · 1.58 KB
/
libscalene.cpp
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
#include <heaplayers.h>
#include "tprintf.h"
#include "common.hpp"
#include "mmaparray.hpp"
#include "dynarray.hpp"
#include "stack.hpp"
#include "buffer.hpp"
#include "classwarfare.hpp"
#include "bufferbump.hpp"
#include "cheapheap.hpp"
#include "sampleheap.hpp"
#include "repoman.hpp"
class TheCustomHeap;
static TheCustomHeap * theCustomHeap = nullptr;
const auto MallocSamplingRate = 1024 * 1024;
const auto FreeSamplingRate = 1024 * 1024;
const auto RepoSize = 4096;
typedef SampleHeap<MallocSamplingRate, FreeSamplingRate, RepoMan<RepoSize>> CustomHeapType;
//typedef SampleHeap<MallocSamplingRate, FreeSamplingRate, RepoMan<RepoSize>> CustomHeapType;
class TheCustomHeap : public CustomHeapType {
typedef CustomHeapType Super;
public:
TheCustomHeap() {
theCustomHeap = this;
}
inline void * malloc(size_t sz) {
auto ptr = Super::malloc(sz);
return ptr;
}
inline void free(void * ptr) {
Super::free(ptr);
}
};
TheCustomHeap& getTheCustomHeap() {
static TheCustomHeap thang;
return thang;
}
extern "C" void * xxmalloc(size_t sz) {
if (theCustomHeap) {
return theCustomHeap->malloc(sz);
} else {
return getTheCustomHeap().malloc(sz);
}
}
extern "C" void xxfree(void * ptr) {
theCustomHeap->free(ptr);
}
extern "C" void xxfree_sized(void * ptr, size_t sz) {
// TODO FIXME maybe make a sized-free version?
getTheCustomHeap().free(ptr);
}
extern "C" size_t xxmalloc_usable_size(void * ptr) {
return theCustomHeap->getSize(ptr); // TODO FIXME adjust for ptr offset?
}
extern "C" void xxmalloc_lock() {
}
extern "C" void xxmalloc_unlock() {
}