-
Notifications
You must be signed in to change notification settings - Fork 11
/
jemalloc.py
144 lines (104 loc) · 3.9 KB
/
jemalloc.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# unmask_jemalloc - De Mysteriis Dom jemalloc
#
# Copyright (c) 2014 Patroklos Argyroudis <argp at domain census-labs.com>
# Copyright (c) 2014 Chariton Karamitas <huku at domain census-labs.com>
# Copyright (c) 2014 Census, Inc. (http://www.census-labs.com/)
import sys
import warnings
sys.path.append('.')
import gdbutil
true = True
false = False
VERSION = 'v0.8'
class jemalloc:
def __init__(self, chunks = [], chunk_size = 0, \
arenas = [], narenas = 0, runs = [], nbins = 0, \
magrack_size = 0, magaz_flag = false, \
standalone_flag = false):
self.chunks = chunks
self.chunk_size = chunk_size
self.arenas = arenas
self.narenas = narenas
self.nbins = nbins
self.ntbins = 0
self.nsbins = 0
self.nqbins = 0
self.magrack_size = magrack_size
self.DWORD_SIZE = gdbutil.get_dword_size()
self.runs = runs
self.MAGAZINES = magaz_flag
self.STANDALONE = standalone_flag
def __str__(self):
if self.MAGAZINES == false:
return '[unmask_jemalloc] [jemalloc] [arenas %02d] [bins %02d]' \
' [runs %02d]' % (self.narenas, self.nbins, len(self.runs))
else:
return '[unmask_jemalloc] [jemalloc] [arenas %02d] [bins %02d] ' \
'[runs %02d] [magazine rack/tcache size %04d]' % \
(self.narenas, self.nbins, len(self.runs), self.magrack_size)
class arena_chunk:
def __init__(self, addr = 0, arena = 0):
self.addr = addr
self.arena = arena
def __str__(self):
if self.arena != 0:
return '[unmask_jemalloc] [chunk %#x] [arena %#x]' % (self.addr, self.arena)
else:
return '[unmask_jemalloc] [chunk %#x] [orphan]' % (self.addr)
class arena_run:
def __init__(self, start = 0, end = 0, size = 0, bin = 0, \
region_size = 0, reg0_offset = 0, total_regions = 0, \
free_regions = 0, regions = []):
self.start = start
self.end = end
self.size = size
self.bin = bin
self.region_size = region_size
self.reg0_offset = reg0_offset
self.total_regions = total_regions
self.free_regions = free_regions
self.regions = regions
self.regs_mask = ''
def __str__(self):
return '[unmask_jemalloc] [run %#x] [size %05d] [bin %#x] [region size %04d] ' \
'[total regions %03d] [free regions %03d]' % \
(self.start, self.size, self.bin, \
self.region_size, self.total_regions, self.free_regions)
class arena_bin:
def __init__(self, addr, index, runcur):
self.addr = addr
self.index = index
self.run = runcur
def __str__(self):
return '[unmask_jemalloc] [bin %02d (%#x)] [size class %04d] [runcur %#x]' % \
(self.index, self.addr, self.run.region_size, self.run.start)
class region:
def __init__(self, index = 0, addr = 0, is_free = 1):
self.index = index
self.addr = addr
self.is_free = is_free
self.content_preview = ''
def __str__(self):
str = '[unmask_jemalloc] [region %03d]' % (self.index)
if self.is_free == 1:
str += ' [free]'
elif self.is_free == 0:
str += ' [used]'
if self.content_preview != '':
str += ' [%#x] [%s]' % (self.addr, self.content_preview)
else:
str += ' [%#x]' % (self.addr)
return str
class arena:
def __init__(self, addr = 0, index = 0, bins = []):
self.addr = addr
self.index = index
self.bins = bins
def __str__(self):
return '[unmask_jemalloc] [arena %02d (%#x)] [bins %02d]' % \
(self.index, self.addr, len(self.bins))
# unit testing
if __name__ == '__main__':
print('[unmask_jemalloc] unit testing not implemented yet')
sys.exit(0)
# EOF