]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Arch-abstraction:
authorNicholas Nethercote <n.nethercote@gmail.com>
Mon, 18 Oct 2004 15:34:14 +0000 (15:34 +0000)
committerNicholas Nethercote <n.nethercote@gmail.com>
Mon, 18 Oct 2004 15:34:14 +0000 (15:34 +0000)
- factor out code for restarting syscalls

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2786

coregrind/core.h
coregrind/stage1.c
coregrind/vg_syscalls.c
coregrind/x86-linux/Makefile.am
coregrind/x86-linux/syscalls.c [new file with mode: 0644]

index 43dfc9bc79a5ea6bc87ae361114beec00a905870..68ebcfe693d718e4e5199cb3cefff3236ec8c358 100644 (file)
@@ -1520,7 +1520,11 @@ extern void VGA_(push_signal_frame) ( ThreadId tid, Addr esp_top_of_frame,
                                       const vki_ksigset_t *mask);
 extern Int  VGA_(pop_signal_frame)  ( ThreadId tid );
 
+// ---------------------------------------------------------------------
+// Platform-specific things defined in eg. x86/*.c
+// ---------------------------------------------------------------------
 
+void VGA_(restart_syscall)(arch_thread_t *tst);
 
 /* ---------------------------------------------------------------------
    Finally - autoconf-generated settings
index c6ae5bc492f590a1f3916f9b4410ed2219bca771..0c4e0303b943e95bec54cf3f14d7a1361fc02926 100644 (file)
@@ -306,7 +306,7 @@ int main(int argc, char** argv)
       valgrind_lib = cp;
 
    // Initial stack pointer is to argc, which is immediately before argv[0]
-   // on the stack.
+   // on the stack.  Nb: Assumes argc is word-aligned.
    init_sp = argv - 1;
 
    /* Set the address space limit as high as it will go, since we make
index 92cd78c2b5e4b8e69ef844c9362f6e973f870919..887436110d2c0b0a3c57bfa78e8d5c70ce850819 100644 (file)
@@ -6352,23 +6352,7 @@ static void restart_syscall(ThreadId tid)
    vg_assert(tst->syscallno != -1);
 
    SYSNO = tst->syscallno;
-   tst->arch.m_eip -= 2;               /* sizeof(int $0x80) */
-
-   /* Make sure our caller is actually sane, and we're really backing
-      back over a syscall.
-
-      int $0x80 == CD 80 
-   */
-   {
-      UChar *p = (UChar *)tst->arch.m_eip;
-      
-      if (p[0] != 0xcd || p[1] != 0x80)
-        VG_(message)(Vg_DebugMsg, 
-                     "?! restarting over syscall at %p %02x %02x\n",
-                     tst->arch.m_eip, p[0], p[1]);
-
-      vg_assert(p[0] == 0xcd && p[1] == 0x80);
-   }
+   VGA_(restart_syscall)(&tst->arch);
 }
 
 void VG_(post_syscall) ( ThreadId tid, Bool restart )
index 451e4dc4521be72ee626424158dd9d0ee0a7971b..e0502a952f98beb3b208f05abc7c09df02680805 100644 (file)
@@ -11,4 +11,5 @@ noinst_LIBRARIES = libplatform.a
 
 
 libplatform_a_SOURCES = \
-       ldt.c
+       ldt.c \
+       syscalls.c
diff --git a/coregrind/x86-linux/syscalls.c b/coregrind/x86-linux/syscalls.c
new file mode 100644 (file)
index 0000000..d9e234a
--- /dev/null
@@ -0,0 +1,57 @@
+
+/*--------------------------------------------------------------------*/
+/*--- x86/Linux-specific syscalls, etc.                 syscalls.c ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, an extensible x86 protected-mode
+   emulator for monitoring program execution on x86-Unixes.
+
+   Copyright (C) 2000-2004 Nicholas Nethercote
+      njn25@cam.ac.uk
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#include "core.h"
+
+// Back up to restart a system call.
+void VGA_(restart_syscall)(arch_thread_t *tst)
+{
+   tst->m_eip -= 2;             // sizeof(int $0x80)
+
+   /* Make sure our caller is actually sane, and we're really backing
+      back over a syscall.
+
+      int $0x80 == CD 80 
+   */
+   {
+      UChar *p = (UChar *)tst->m_eip;
+      
+      if (p[0] != 0xcd || p[1] != 0x80)
+         VG_(message)(Vg_DebugMsg,
+                      "?! restarting over syscall at %p %02x %02x\n",
+                      tst->m_eip, p[0], p[1]); 
+
+      vg_assert(p[0] == 0xcd && p[1] == 0x80);
+   }
+}
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/