@@ -32,12 +32,12 @@ struct FakeFrame {
3232// is not popped but remains there for quite some time until gets used again.
3333// So, we poison the objects on the fake stack when function returns.
3434// It helps us find use-after-return bugs.
35+ //
3536// The FakeStack objects is allocated by a single mmap call and has no other
3637// pointers. The size of the fake stack depends on the actual thread stack size
3738// and thus can not be a constant.
3839// stack_size is a power of two greater or equal to the thread's stack size;
3940// we store it as its logarithm (stack_size_log).
40- // FakeStack is padded such that GetFrame() is aligned to BytesInSizeClass().
4141// FakeStack has kNumberOfSizeClasses (11) size classes, each size class
4242// is a power of two, starting from 64 bytes. Each size class occupies
4343// stack_size bytes and thus can allocate
@@ -56,9 +56,6 @@ struct FakeFrame {
5656class FakeStack {
5757 static const uptr kMinStackFrameSizeLog = 6 ; // Min frame is 64B.
5858 static const uptr kMaxStackFrameSizeLog = 16 ; // Max stack frame is 64K.
59- static_assert (kMaxStackFrameSizeLog >= kMinStackFrameSizeLog );
60-
61- static const u64 kMaxStackFrameSize = 1 << kMaxStackFrameSizeLog ;
6259
6360 public:
6461 static const uptr kNumberOfSizeClasses =
@@ -69,7 +66,7 @@ class FakeStack {
6966
7067 void Destroy (int tid);
7168
72- // min_uar_stack_size_log is 16 (stack_size >= 64KB)
69+ // stack_size_log is at least 15 (stack_size >= 32K).
7370 static uptr SizeRequiredForFlags (uptr stack_size_log) {
7471 return ((uptr)1 ) << (stack_size_log + 1 - kMinStackFrameSizeLog );
7572 }
@@ -113,28 +110,6 @@ class FakeStack {
113110 }
114111
115112 // 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).
138113 u8 *GetFrame (uptr stack_size_log, uptr class_id, uptr pos) {
139114 return reinterpret_cast <u8 *>(this ) + kFlagsOffset +
140115 SizeRequiredForFlags (stack_size_log) +
@@ -181,18 +156,15 @@ class FakeStack {
181156
182157 private:
183158 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.
185160 // Must match the number of uses of DEFINE_STACK_MALLOC_FREE_WITH_CLASS_ID
186161 COMPILER_CHECK (kNumberOfSizeClasses == 11 );
187162 static const uptr kMaxStackMallocSize = ((uptr)1 ) << kMaxStackFrameSizeLog ;
188163
189164 uptr hint_position_[kNumberOfSizeClasses ];
190165 uptr stack_size_log_;
166+ // a bit is set if something was allocated from the corresponding size class.
191167 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;
196168};
197169
198170FakeStack *GetTLSFakeStack ();
0 commit comments