@@ -32,12 +32,12 @@ struct FakeFrame {
32
32
// is not popped but remains there for quite some time until gets used again.
33
33
// So, we poison the objects on the fake stack when function returns.
34
34
// It helps us find use-after-return bugs.
35
+ //
35
36
// The FakeStack objects is allocated by a single mmap call and has no other
36
37
// pointers. The size of the fake stack depends on the actual thread stack size
37
38
// and thus can not be a constant.
38
39
// stack_size is a power of two greater or equal to the thread's stack size;
39
40
// we store it as its logarithm (stack_size_log).
40
- // FakeStack is padded such that GetFrame() is aligned to BytesInSizeClass().
41
41
// FakeStack has kNumberOfSizeClasses (11) size classes, each size class
42
42
// is a power of two, starting from 64 bytes. Each size class occupies
43
43
// stack_size bytes and thus can allocate
@@ -56,9 +56,6 @@ struct FakeFrame {
56
56
class FakeStack {
57
57
static const uptr kMinStackFrameSizeLog = 6 ; // Min frame is 64B.
58
58
static const uptr kMaxStackFrameSizeLog = 16 ; // Max stack frame is 64K.
59
- static_assert (kMaxStackFrameSizeLog >= kMinStackFrameSizeLog );
60
-
61
- static const u64 kMaxStackFrameSize = 1 << kMaxStackFrameSizeLog ;
62
59
63
60
public:
64
61
static const uptr kNumberOfSizeClasses =
@@ -69,7 +66,7 @@ class FakeStack {
69
66
70
67
void Destroy (int tid);
71
68
72
- // min_uar_stack_size_log is 16 (stack_size >= 64KB)
69
+ // stack_size_log is at least 15 (stack_size >= 32K).
73
70
static uptr SizeRequiredForFlags (uptr stack_size_log) {
74
71
return ((uptr)1 ) << (stack_size_log + 1 - kMinStackFrameSizeLog );
75
72
}
@@ -113,28 +110,6 @@ class FakeStack {
113
110
}
114
111
115
112
// Get frame by class_id and pos.
116
- // Return values are guaranteed to be aligned to BytesInSizeClass(class_id),
117
- // which is useful in combination with
118
- // ASanStackFrameLayout::ComputeASanStackFrameLayout().
119
- //
120
- // Note that alignment to 1<<kMaxStackFrameSizeLog (aka
121
- // BytesInSizeClass(max_class_id)) implies alignment to BytesInSizeClass()
122
- // for any class_id, since the class sizes are increasing powers of 2.
123
- //
124
- // 1) (this + kFlagsOffset + SizeRequiredForFlags())) is aligned to
125
- // 1<<kMaxStackFrameSizeLog (see FakeStack::Create)
126
- //
127
- // Note that SizeRequiredForFlags(16) == 2048. If FakeStack::Create() had
128
- // merely returned an address from mmap (4K-aligned), the addition would
129
- // not be 4K-aligned.
130
- // 2) We know that stack_size_log >= kMaxStackFrameSizeLog (otherwise you
131
- // couldn't store a single frame of that size in the entire stack)
132
- // hence (1<<stack_size_log) is aligned to 1<<kMaxStackFrameSizeLog
133
- // and ((1<<stack_size_log) * class_id) is aligned to
134
- // 1<<kMaxStackFrameSizeLog
135
- // 3) BytesInSizeClass(class_id) * pos is aligned to
136
- // BytesInSizeClass(class_id)
137
- // The sum of these is aligned to BytesInSizeClass(class_id).
138
113
u8 *GetFrame (uptr stack_size_log, uptr class_id, uptr pos) {
139
114
return reinterpret_cast <u8 *>(this ) + kFlagsOffset +
140
115
SizeRequiredForFlags (stack_size_log) +
@@ -181,18 +156,15 @@ class FakeStack {
181
156
182
157
private:
183
158
FakeStack () { }
184
- static const uptr kFlagsOffset = 4096 ; // This is where the flags begin.
159
+ static const uptr kFlagsOffset = 4096 ; // This is were the flags begin.
185
160
// Must match the number of uses of DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID
186
161
COMPILER_CHECK (kNumberOfSizeClasses == 11 );
187
162
static const uptr kMaxStackMallocSize = ((uptr)1 ) << kMaxStackFrameSizeLog ;
188
163
189
164
uptr hint_position_[kNumberOfSizeClasses ];
190
165
uptr stack_size_log_;
166
+ // a bit is set if something was allocated from the corresponding size class.
191
167
bool needs_gc_;
192
- // We allocated more memory than needed to ensure the FakeStack (and, by
193
- // extension, each of the fake stack frames) is aligned. We keep track of the
194
- // true start so that we can unmap it.
195
- void *true_start;
196
168
};
197
169
198
170
FakeStack *GetTLSFakeStack ();
0 commit comments