From: Julian Seward Date: Fri, 16 Aug 2002 18:51:49 +0000 (+0000) Subject: Fix stupid bug arising as a result of the call to __libc_freeres() at the X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90428ac638c5ddfb7e0096636c9d44ff15c1890d;p=thirdparty%2Fvalgrind.git Fix stupid bug arising as a result of the call to __libc_freeres() at the end, in which the return value of the process was not correctly propagated. MERGE TO HEAD git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_1_0_BRANCH@594 --- diff --git a/vg_include.h b/vg_include.h index 0d38c92332..1e831c3fac 100644 --- a/vg_include.h +++ b/vg_include.h @@ -1569,6 +1569,11 @@ extern UInt VG_(current_epoch); /* This is the ThreadId of the last thread the scheduler ran. */ extern ThreadId VG_(last_run_tid); +/* This is the argument to __NR_exit() supplied by the first thread to + call that syscall. We eventually pass that to __NR_exit() for + real. */ +extern UInt VG_(exitcode); + /* --- Counters, for informational purposes only. --- */ diff --git a/vg_main.c b/vg_main.c index 5cce13d2e8..2634af27dd 100644 --- a/vg_main.c +++ b/vg_main.c @@ -339,6 +339,11 @@ UInt VG_(current_epoch) = 0; /* This is the ThreadId of the last thread the scheduler ran. */ ThreadId VG_(last_run_tid) = 0; +/* This is the argument to __NR_exit() supplied by the first thread to + call that syscall. We eventually pass that to __NR_exit() for + real. */ +UInt VG_(exitcode) = 0; + /* --------------------------------------------------------------------- Counters, for informational purposes only. @@ -1222,7 +1227,7 @@ void VG_(main) ( void ) vg_assert(tst->status == VgTs_Runnable); /* The thread's %EBX will hold the arg to exit(), so we just do exit with that arg. */ - VG_(exit)( tst->m_ebx ); + VG_(exit)( VG_(exitcode) ); /* NOT ALIVE HERE! */ VG_(panic)("entered the afterlife in vg_main() -- ExitSyscall"); break; /* what the hell :) */ diff --git a/vg_scheduler.c b/vg_scheduler.c index 0ad56b10c5..1275511271 100644 --- a/vg_scheduler.c +++ b/vg_scheduler.c @@ -1382,6 +1382,11 @@ VgSchedReturnCode VG_(scheduler) ( void ) If not valgrinding (cachegrinding, etc) don't do this. __libc_freeres does some invalid frees which crash the unprotected malloc/free system. */ + + /* If __NR_exit, remember the supplied argument. */ + if (VG_(threads)[tid].m_eax == __NR_exit) + VG_(exitcode) = VG_(threads)[tid].m_ebx; /* syscall arg1 */ + if (VG_(threads)[tid].m_eax == __NR_exit && !VG_(clo_instrument)) { if (VG_(clo_trace_syscalls) || VG_(clo_trace_sched)) {