libunwind/backport-Ltest-mem-validate-Disable-inlining-for-consume_and_.patch
sxt1001 57d05dd4a5 fix some test fail
(cherry picked from commit f7bb07bf881c2885f30be53b6751734a89c9b215)
2023-02-21 15:32:19 +08:00

82 lines
2.3 KiB
Diff

From 62de804cb8f20a7cd6933a2fcf7b3394fec103de Mon Sep 17 00:00:00 2001
From: Zhaofeng Li <hello@zhaofeng.li>
Date: Sun, 27 Jun 2021 18:40:24 +0000
Subject: [PATCH] Ltest-mem-validate: Disable inlining for consume_and_run
See #222 and #227. The tests are so fragile :(
---
tests/Ltest-mem-validate.c | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/tests/Ltest-mem-validate.c b/tests/Ltest-mem-validate.c
index 1cacb9f..ac12dec 100644
--- a/tests/Ltest-mem-validate.c
+++ b/tests/Ltest-mem-validate.c
@@ -45,8 +45,11 @@ void * stack_start;
void do_backtrace (void)
{
- void* buffer[1024];
- int size = 1024;
+ /*
+ We make the assumption that we are able to rewind far enough
+ (steps > 5) before touching the forbidden region in the stack,
+ at which point the unwinding should stop gracefully.
+ */
mprotect((void*)((uintptr_t)stack_start & ~(PAGE_SIZE - 1)),
PAGE_SIZE, PROT_NONE);
@@ -66,6 +69,7 @@ void do_backtrace (void)
unw_get_reg (&cursor, UNW_REG_SP, &sp);
ret = unw_step (&cursor);
+ printf("ip=%lx, sp=%lx -> %d\n", ip, sp, ret);
if (ret < 0)
{
unw_get_reg (&cursor, UNW_REG_IP, &ip);
@@ -76,14 +80,16 @@ void do_backtrace (void)
if (steps < 5)
{
+ printf("not enough steps: %d, need 5\n", steps);
exit(-1);
}
+ printf("success, steps: %d\n", steps);
mprotect((void*)((uintptr_t)stack_start & ~(PAGE_SIZE - 1)),
PAGE_SIZE, PROT_READ|PROT_WRITE);
}
-void consume_and_run (int depth)
+void NOINLINE consume_and_run (int depth)
{
unw_cursor_t cursor;
unw_context_t uc;
@@ -106,6 +112,14 @@ main (int argc, char **argv UNUSED)
stack_start = &start;
+ /*
+ We need to make the frame at least the size protected by
+ the mprotect call so we are not forbidding access to
+ unrelated regions.
+ */
+ char string[PAGE_SIZE];
+ sprintf (string, "hello\n");
+
// Initialize pipe mem validate check, opens file descriptors
unw_getcontext(&uc);
if (unw_init_local (&cursor, &uc) < 0)
@@ -119,7 +133,7 @@ main (int argc, char **argv UNUSED)
if (!childpid)
{
/* Close fds and make sure we still work */
- int ret = close(i);
+ close(i);
}
int status;
--
2.27.0