Skip to content

Commit 92e12a6

Browse files
author
Sagar Thakur
committed
[LSAN] Fix test swapcontext.cc on MIPS
There is no frame validity check in the slow unwinder like there is in the fast unwinder due to which lsan reports a leak even for heap allocated coroutine in the test swapcontext.cc. Since mips/linux uses slow unwindwer instead of fast unwinder, the test fails for mips/linux. Therefore adding the checks before unwinding fixes the test for mips/linux. Reviewed by aizatsky. Differential: http://reviews.llvm.org/D19961 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@269882 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f11f1f2 commit 92e12a6

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

lib/asan/asan_stack.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ void GetStackTraceWithPcBpAndContext(BufferedStackTrace *stack, uptr max_depth,
4848
uptr stack_top = t->stack_top();
4949
uptr stack_bottom = t->stack_bottom();
5050
ScopedUnwinding unwind_scope(t);
51-
stack->Unwind(max_depth, pc, bp, context, stack_top, stack_bottom, fast);
51+
if (!SANITIZER_MIPS || IsValidFrame(bp, stack_top, stack_bottom)) {
52+
stack->Unwind(max_depth, pc, bp, context, stack_top, stack_bottom,
53+
fast);
54+
}
5255
} else if (!t && !fast) {
5356
/* If GetCurrentThread() has failed, try to do slow unwind anyways. */
5457
stack->Unwind(max_depth, pc, bp, context, 0, 0, false);

lib/lsan/lsan.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
stack_top = t->stack_end(); \
2525
stack_bottom = t->stack_begin(); \
2626
} \
27-
stack.Unwind(max_size, StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), \
28-
/* context */ 0, stack_top, stack_bottom, fast); \
27+
if (!SANITIZER_MIPS || \
28+
IsValidFrame(GET_CURRENT_FRAME(), stack_top, stack_bottom)) { \
29+
stack.Unwind(max_size, StackTrace::GetCurrentPc(), GET_CURRENT_FRAME(), \
30+
/* context */ 0, stack_top, stack_bottom, fast); \
31+
} \
2932
}
3033

3134
#define GET_STACK_TRACE_FATAL \

lib/sanitizer_common/sanitizer_stacktrace.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ void BufferedStackTrace::Init(const uptr *pcs, uptr cnt, uptr extra_top_pc) {
4040
top_frame_bp = 0;
4141
}
4242

43-
// Check if given pointer points into allocated stack area.
44-
static inline bool IsValidFrame(uptr frame, uptr stack_top, uptr stack_bottom) {
45-
return frame > stack_bottom && frame < stack_top - 2 * sizeof (uhwptr);
46-
}
47-
4843
// In GCC on ARM bp points to saved lr, not fp, so we should check the next
4944
// cell in stack to be a saved frame pointer. GetCanonicFrame returns the
5045
// pointer to saved frame pointer in any case.

lib/sanitizer_common/sanitizer_stacktrace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ struct BufferedStackTrace : public StackTrace {
110110
void operator=(const BufferedStackTrace &);
111111
};
112112

113+
// Check if given pointer points into allocated stack area.
114+
static inline bool IsValidFrame(uptr frame, uptr stack_top, uptr stack_bottom) {
115+
return frame > stack_bottom && frame < stack_top - 2 * sizeof (uhwptr);
116+
}
117+
113118
} // namespace __sanitizer
114119

115120
// Use this macro if you want to print stack trace with the caller

0 commit comments

Comments
 (0)