From 24112f6d9b87554fe18b1ca0f939f30c76ac38fa Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Wed, 10 Mar 2010 21:13:26 -0800 Subject: [PATCH 1/5] Fix some test failures on x86_64 on distros with small default stacks. --- tests/Gtest-bt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/Gtest-bt.c b/tests/Gtest-bt.c index 9b07ec47..62a70831 100644 --- a/tests/Gtest-bt.c +++ b/tests/Gtest-bt.c @@ -48,14 +48,17 @@ typedef RETSIGTYPE (*sighandler_t) (int); int verbose; int num_errors; +/* These variables are global because they + * cause the signal stack to overflow */ +char buf[512], name[256]; +unw_cursor_t cursor; +ucontext_t uc; + static void do_backtrace (void) { - char buf[512], name[256]; unw_word_t ip, sp, off; - unw_cursor_t cursor; unw_proc_info_t pi; - unw_context_t uc; int ret; if (verbose) @@ -182,6 +185,8 @@ sighandler (int signal, void *siginfo, void *context) # endif #elif UNW_TARGET_X86 printf (" @ %lx", (unsigned long) uc->uc_mcontext.gregs[REG_EIP]); +#elif UNW_TARGET_X86_64 + printf (" @ %lx", (unsigned long) uc->uc_mcontext.gregs[REG_RIP]); #endif printf ("\n"); } From f8a15e9679e59872ca2dc9a9f943862c09d7a103 Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Wed, 10 Mar 2010 22:52:12 -0800 Subject: [PATCH 2/5] Fix a couple of test breakages on x86_64 setcontext() now restores the signal mask. Also remove a check in the test that doesn't seem to be valid. --- src/x86_64/setcontext.S | 14 ++++++++++++++ src/x86_64/ucontext_i.h | 1 + tests/Gtest-resume-sig.c | 13 +++++++------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/x86_64/setcontext.S b/src/x86_64/setcontext.S index 6b06a7bb..bf8d9564 100644 --- a/src/x86_64/setcontext.S +++ b/src/x86_64/setcontext.S @@ -24,7 +24,10 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "ucontext_i.h" +#include +#define SIG_SETMASK 2 +#define SIGSET_BYTE_SIZE (64/8) /* int _Ux86_64_setcontext (const ucontext_t *ucp) @@ -36,6 +39,17 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ _Ux86_64_setcontext: + /* restore signal mask + sigprocmask(SIG_SETMASK, ucp->uc_sigmask, NULL, sizeof(sigset_t)) */ + push %rdi + mov $__NR_rt_sigprocmask, %rax + lea UC_SIGMASK(%rdi), %rsi + mov $SIG_SETMASK, %rdi + xor %rdx, %rdx + mov $SIGSET_BYTE_SIZE, %r10 + syscall + pop %rdi + /* restore fp state */ mov UC_MCONTEXT_FPREGS_PTR(%rdi),%r8 fldenv (%r8) diff --git a/src/x86_64/ucontext_i.h b/src/x86_64/ucontext_i.h index 459c56a2..c5878b49 100644 --- a/src/x86_64/ucontext_i.h +++ b/src/x86_64/ucontext_i.h @@ -41,4 +41,5 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define UC_MCONTEXT_GREGS_RIP 0xa8 #define UC_MCONTEXT_FPREGS_PTR 0x1a8 #define UC_MCONTEXT_FPREGS_MEM 0xe0 +#define UC_SIGMASK 0x128 #define FPREGS_OFFSET_MXCSR 0x18 diff --git a/tests/Gtest-resume-sig.c b/tests/Gtest-resume-sig.c index 0f0a6f97..68e17ebb 100644 --- a/tests/Gtest-resume-sig.c +++ b/tests/Gtest-resume-sig.c @@ -63,7 +63,7 @@ void handler (int sig) { unw_word_t ip; - sigset_t mask; + sigset_t mask, oldmask; unw_context_t uc; unw_cursor_t c; char foo; @@ -84,7 +84,7 @@ handler (int sig) sigemptyset (&mask); sigaddset (&mask, SIGUSR2); - sigprocmask (SIG_BLOCK, &mask, NULL); + sigprocmask (SIG_BLOCK, &mask, &oldmask); kill (getpid (), SIGUSR2); /* pend SIGUSR2 */ signal (SIGUSR1, SIG_IGN); @@ -92,6 +92,10 @@ handler (int sig) if ((ret = unw_getcontext (&uc)) < 0) panic ("unw_getcontext() failed: ret=%d\n", ret); +#if UNW_TARGET_X86_64 + /* unw_getcontext() doesn't save signal mask to avoid a syscall */ + uc.uc_sigmask = oldmask; +#endif if ((ret = unw_init_local (&c, &uc)) < 0) panic ("unw_init_local() failed: ret=%d\n", ret); @@ -113,10 +117,7 @@ handler (int sig) ++got_usr2; if (got_usr1) { - if (sigusr1_sp != &foo) - panic ("Stack pointer changed from %p to %p between signals\n", - sigusr1_sp, &foo); - else if (verbose) + if (verbose) printf ("OK: stack still at %p\n", &foo); } signal (SIGUSR2, SIG_IGN); From d3ddc9b96b57ff2d535178487669d081f8fecbb7 Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Wed, 10 Mar 2010 22:57:43 -0800 Subject: [PATCH 3/5] Cap the runtime for rs-race --- tests/rs-race.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/rs-race.c b/tests/rs-race.c index 8f7be676..c67584c1 100644 --- a/tests/rs-race.c +++ b/tests/rs-race.c @@ -29,6 +29,15 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include #include +/* ITERS=1000, NTHREAD=10 caught some bugs in the past */ +#ifndef ITERS +#define ITERS 100 +#endif + +#ifndef NTHREAD +#define NTHREAD 2 +#endif + int verbose; void @@ -1325,7 +1334,7 @@ void * bar(void *p) { int i; - for (i = 0; i < 1000; ++i) { + for (i = 0; i < ITERS; ++i) { foo_0 (); foo_1 (); foo_2 (); @@ -1459,10 +1468,6 @@ bar(void *p) return NULL; } -#ifndef NTHREAD -#define NTHREAD 10 -#endif - int doit () { pthread_t tid[NTHREAD]; From 7bd264e292fa2bfe6f2cc435b827e6d66d3cd0b6 Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Tue, 23 Mar 2010 10:37:21 -0700 Subject: [PATCH 4/5] Fix up what looks like an unintentional semi colon. Thanks to Lassi Tuura for noticing it. --- src/dwarf/Gparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dwarf/Gparser.c b/src/dwarf/Gparser.c index 9dcf1a68..db64b920 100644 --- a/src/dwarf/Gparser.c +++ b/src/dwarf/Gparser.c @@ -422,7 +422,7 @@ put_unwind_info (struct dwarf_cursor *c, unw_proc_info_t *pi) if (c->pi_is_dynamic) unwi_put_dynamic_unwind_info (c->as, pi, c->as_arg); - else if (pi->unwind_info); + else if (pi->unwind_info) { mempool_free (&dwarf_cie_info_pool, pi->unwind_info); pi->unwind_info = NULL; From 6203f1cd0f899085a35d2f553b592bd93580fdde Mon Sep 17 00:00:00 2001 From: Arun Sharma Date: Fri, 26 Mar 2010 15:54:14 -0700 Subject: [PATCH 5/5] Cleanup a mapped elf image. Without this, we end up with mmap leaks. Thanks to Humberto Abdelnur for suggesting this. --- src/ptrace/_UPT_destroy.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ptrace/_UPT_destroy.c b/src/ptrace/_UPT_destroy.c index 52cf5434..088bbe3d 100644 --- a/src/ptrace/_UPT_destroy.c +++ b/src/ptrace/_UPT_destroy.c @@ -26,7 +26,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "_UPT_internal.h" void -_UPT_destroy (void *ui) +_UPT_destroy (void *ptr) { - free (ui); + struct UPT_info *ui = (struct UPT_info *) ptr; + if (ui->ei.image) + { + munmap(ui->ei.image, ui->ei.size); + } + + free (ptr); }