|
From: <sv...@va...> - 2005-06-17 21:56:54
|
Author: njn
Date: 2005-06-17 22:31:45 +0100 (Fri, 17 Jun 2005)
New Revision: 3922
Log:
Moved the basic syscall stuff out of m_libcbase.c into a new module
m_syscall.c. Plus some associated cleanups.
Moved VG_(sigreturn) into m_signals.c and made it local.
Added:
trunk/coregrind/m_syscall.c
trunk/coregrind/pub_core_syscall.h
Modified:
trunk/coregrind/Makefile.am
trunk/coregrind/core.h
trunk/coregrind/m_aspacemgr/aspacemgr.c
trunk/coregrind/m_libcassert.c
trunk/coregrind/m_libcbase.c
trunk/coregrind/m_libcfile.c
trunk/coregrind/m_libcmman.c
trunk/coregrind/m_libcproc.c
trunk/coregrind/m_libcsignal.c
trunk/coregrind/m_scheduler/scheduler.c
trunk/coregrind/m_signals.c
trunk/coregrind/m_syscalls/syscall-amd64-linux.S
trunk/coregrind/m_syscalls/syscall-arm-linux.S
trunk/coregrind/m_syscalls/syscall-x86-linux.S
trunk/coregrind/m_syscalls/syscalls-amd64-linux.c
trunk/coregrind/m_syscalls/syscalls-generic.c
trunk/coregrind/m_syscalls/syscalls-linux.c
trunk/coregrind/m_syscalls/syscalls-main.c
trunk/coregrind/m_syscalls/syscalls-x86-linux.c
trunk/coregrind/pub_core_libcbase.h
Modified: trunk/coregrind/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/Makefile.am 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/Makefile.am 2005-06-17 21:31:45 UTC (rev 3922)
@@ -114,6 +114,7 @@
m_signals.c \
m_skiplist.c \
m_stacktrace.c \
+ m_syscall.c \
m_threadmodel.c \
m_tooliface.c \
m_translate.c \
Modified: trunk/coregrind/core.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/core.h 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/core.h 2005-06-17 21:31:45 UTC (rev 3922)
@@ -64,12 +64,6 @@
#define VG_USERREQ__LIBC_FREERES_DONE 0x3029
=20
/* ---------------------------------------------------------------------
- Exports of vg_syscall.S
- ------------------------------------------------------------------ */
-
-extern void VG_(sigreturn)(void);
-
-/* ---------------------------------------------------------------------
Exports of vg_helpers.S
------------------------------------------------------------------ */
=20
Modified: trunk/coregrind/m_aspacemgr/aspacemgr.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-06-17 19:28:29 UTC (rev =
3921)
+++ trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-06-17 21:31:45 UTC (rev =
3922)
@@ -40,6 +40,7 @@
#include "pub_core_libcproc.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
+#include "pub_core_syscall.h"
#include "pub_core_syscalls.h"
#include "pub_core_tooliface.h"
#include "pub_core_transtab.h"
Modified: trunk/coregrind/m_libcassert.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcassert.c 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/m_libcassert.c 2005-06-17 21:31:45 UTC (rev 3922)
@@ -35,6 +35,7 @@
#include "pub_core_libcproc.h"
#include "pub_core_main.h"
#include "pub_core_stacktrace.h"
+#include "pub_core_syscall.h"
#include "pub_core_tooliface.h"
#include "vki_unistd.h"
=20
Modified: trunk/coregrind/m_libcbase.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcbase.c 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/m_libcbase.c 2005-06-17 21:31:45 UTC (rev 3922)
@@ -471,95 +471,6 @@
#undef SORT
}
=20
-/* ---------------------------------------------------------------------
- A function for doing syscalls.
- ------------------------------------------------------------------ */
-
-#if defined(VGP_x86_linux)
-extern UInt do_syscall_x86_linux_WRK (
- UInt syscall_no,=20
- UInt a1, UInt a2, UInt a3,
- UInt a4, UInt a5, UInt a6
- );
-asm(
-"do_syscall_x86_linux_WRK:\n"
-" push %esi\n"
-" push %edi\n"
-" push %ebx\n"
-" push %ebp\n"
-" movl 16+ 4(%esp),%eax\n"
-" movl 16+ 8(%esp),%ebx\n"
-" movl 16+12(%esp),%ecx\n"
-" movl 16+16(%esp),%edx\n"
-" movl 16+20(%esp),%esi\n"
-" movl 16+24(%esp),%edi\n"
-" movl 16+28(%esp),%ebp\n"
-" int $0x80\n"
-" popl %ebp\n"
-" popl %ebx\n"
-" popl %edi\n"
-" popl %esi\n"
-" ret\n"
-);
-#endif
-
-
-#if defined(VGP_amd64_linux)
-/* Perform a Linux syscall with the "syscall" instruction.
-=09
- Incoming args (syscall number + up to 6 args) come in %rdi, %rsi,
- %rdx, %rcx, %r8, %r9, and the last one on the stack (ie. the C
- calling convention).
-
- They are passed to the syscall in the regs %rdi, %rsi, %rdx, %r10,
- %r8, %r9 (yes, really %r10, not %rcx), ie. the kernel's syscall
- calling convention.
-
- %rax holds the syscall number and gets the return value. %rcx and
- %r11 are clobbered by the syscall; no matter, they are caller-save
- (the syscall clobbers no callee-save regs, so we don't have to do
- any register saving/restoring).
-*/
-extern ULong do_syscall_amd64_linux_WRK (
- ULong syscall_no,=20
- ULong a1, ULong a2, ULong a3,
- ULong a4, ULong a5, ULong a6
- );
-asm(
-"do_syscall_amd64_linux_WRK:\n"
- /* Convert function calling convention --> syscall calling
- convention */
-" movq %rdi, %rax\n"
-" movq %rsi, %rdi\n"
-" movq %rdx, %rsi\n"
-" movq %rcx, %rdx\n"
-" movq %r8, %r10\n"
-" movq %r9, %r8\n"
-" movq 8(%rsp), %r9\n" /* last arg from stack */
-" syscall\n"
-" ret\n"
-);
-#endif
-
-
-SysRes VG_(do_syscall) ( UWord sysno, UWord a1, UWord a2, UWord a3,=20
- UWord a4, UWord a5, UWord a6 )
-{
- SysRes res;
-
-#if defined(VGP_x86_linux)
- UInt eax =3D do_syscall_x86_linux_WRK(sysno,a1,a2,a3,a4,a5,a6);
- res =3D VG_(mk_SysRes_x86_linux)( eax );
-#elif defined(VGP_amd64_linux)
- ULong rax =3D do_syscall_amd64_linux_WRK(sysno,a1,a2,a3,a4,a5,a6);
- res =3D VG_(mk_SysRes_amd64_linux)( rax );
-#else
-# error VG_(do_syscall): unimplemented on this platform
-#endif
-
- return res;
-}
-
/*--------------------------------------------------------------------*/
/*--- end ---*/
/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/m_libcfile.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcfile.c 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/m_libcfile.c 2005-06-17 21:31:45 UTC (rev 3922)
@@ -34,6 +34,7 @@
#include "pub_core_libcfile.h"
#include "pub_core_mallocfree.h"
#include "pub_core_options.h"
+#include "pub_core_syscall.h"
#include "vki_unistd.h"
=20
/* ---------------------------------------------------------------------
Modified: trunk/coregrind/m_libcmman.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcmman.c 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/m_libcmman.c 2005-06-17 21:31:45 UTC (rev 3922)
@@ -35,6 +35,7 @@
#include "pub_core_libcmman.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
+#include "pub_core_syscall.h"
#include "vki_unistd.h"
=20
SysRes VG_(mmap_native)(void *start, SizeT length, UInt prot, UInt flags=
,
Modified: trunk/coregrind/m_libcproc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcproc.c 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/m_libcproc.c 2005-06-17 21:31:45 UTC (rev 3922)
@@ -34,6 +34,7 @@
#include "pub_core_libcprint.h"
#include "pub_core_libcproc.h"
#include "pub_core_mallocfree.h"
+#include "pub_core_syscall.h"
#include "vki_unistd.h"
=20
/* ---------------------------------------------------------------------
Modified: trunk/coregrind/m_libcsignal.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcsignal.c 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/m_libcsignal.c 2005-06-17 21:31:45 UTC (rev 3922)
@@ -32,6 +32,7 @@
#include "pub_core_libcbase.h"
#include "pub_core_libcassert.h"
#include "pub_core_libcsignal.h"
+#include "pub_core_syscall.h"
#include "vki_unistd.h"
=20
/* sigemptyset, sigfullset, sigaddset and sigdelset return 0 on
Modified: trunk/coregrind/m_scheduler/scheduler.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_scheduler/scheduler.c 2005-06-17 19:28:29 UTC (rev =
3921)
+++ trunk/coregrind/m_scheduler/scheduler.c 2005-06-17 21:31:45 UTC (rev =
3922)
@@ -77,6 +77,7 @@
#include "pub_core_scheduler.h"
#include "pub_core_signals.h"
#include "pub_core_stacktrace.h"
+#include "pub_core_syscall.h"
#include "pub_core_syscalls.h"
#include "pub_core_tooliface.h"
#include "pub_core_translate.h"
Modified: trunk/coregrind/m_signals.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_signals.c 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/m_signals.c 2005-06-17 21:31:45 UTC (rev 3922)
@@ -96,8 +96,10 @@
#include "pub_core_signals.h"
#include "pub_core_sigframe.h"
#include "pub_core_stacktrace.h"
+#include "pub_core_syscall.h"
#include "pub_core_syscalls.h"
#include "pub_core_tooliface.h"
+#include "vki_unistd.h"
=20
=20
/* Define to give more sanity checking for signals. */
@@ -131,7 +133,7 @@
# define VGP_UCONTEXT_SYSCALL_NUM(uc) ((uc)->uc_mcontext.eax)
# define VGP_UCONTEXT_SYSCALL_SYSRES(uc) \
/* Convert the value in uc_mcontext.eax into a SysRes. */ \
- VG_(mk_SysRes_x86_linux)( (uc)->uc_mcontext.eax )
+ VG_(mk_SysRes)( (uc)->uc_mcontext.eax )
=20
#elif defined(VGP_amd64_linux)
# define VGP_UCONTEXT_INSTR_PTR(uc) ((uc)->uc_mcontext.rip)
@@ -140,7 +142,7 @@
# define VGP_UCONTEXT_SYSCALL_NUM(uc) ((uc)->uc_mcontext.rax)
# define VGP_UCONTEXT_SYSCALL_SYSRES(uc) \
/* Convert the value in uc_mcontext.rax into a SysRes. */ \
- VG_(mk_SysRes_amd64_linux)( (uc)->uc_mcontext.rax )
+ VG_(mk_SysRes)( (uc)->uc_mcontext.rax )
=20
#elif defined(VGP_arm_linux)
# define VGP_UCONTEXT_INSTR_PTR(uc) ((uc)->uc_mcontext.arm_pc)
@@ -379,6 +381,30 @@
After a possible SCSS change, update SKSS and the kernel itself.
------------------------------------------------------------------ */
=20
+// We need two levels of macro-expansion here to convert __NR_rt_sigretu=
rn
+// to a number before converting it to a string... sigh.
+extern void my_sigreturn(void);
+
+#if defined(VGP_x86_linux)
+# define _MYSIG(name) \
+ "my_sigreturn:\n" \
+ " movl $" #name ", %eax\n" \
+ " int $0x80\n"
+#elif defined(VGP_amd64_linux)
+# define _MYSIG(name) \
+ "my_sigreturn:\n" \
+ " movq $" #name ", %rax\n" \
+ " syscall\n"
+#else
+# error Unknown platform
+#endif
+
+#define MYSIG(name) _MYSIG(name)
+asm(
+ MYSIG(__NR_rt_sigreturn)
+);
+
+
static void handle_SCSS_change ( Bool force_update )
{
Int res, sig;
@@ -409,7 +435,7 @@
=20
ksa.ksa_handler =3D skss.skss_per_sig[sig].skss_handler;
ksa.sa_flags =3D skss.skss_per_sig[sig].skss_flags;
- ksa.sa_restorer =3D VG_(sigreturn);
+ ksa.sa_restorer =3D my_sigreturn;
=20
/* block all signals in handler */
VG_(sigfillset)( &ksa.sa_mask );
@@ -437,7 +463,7 @@
vg_assert(ksa_old.sa_flags=20
=3D=3D skss_old.skss_per_sig[sig].skss_flags);
vg_assert(ksa_old.sa_restorer=20
- =3D=3D VG_(sigreturn));
+ =3D=3D my_sigreturn);
VG_(sigaddset)( &ksa_old.sa_mask, VKI_SIGKILL );
VG_(sigaddset)( &ksa_old.sa_mask, VKI_SIGSTOP );
vg_assert(VG_(isfullsigset)( &ksa_old.sa_mask ));
Added: trunk/coregrind/m_syscall.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscall.c 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/m_syscall.c 2005-06-17 21:31:45 UTC (rev 3922)
@@ -0,0 +1,163 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Doing syscalls. m_syscall.c ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward=20
+ js...@ac...
+
+ 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"
+#include "pub_core_syscall.h"
+
+/* ---------------------------------------------------------------------
+ Building syscall return values.
+ ------------------------------------------------------------------ */
+
+/* Make a SysRes value from an syscall return value. This is
+ Linux-specific.
+
+ From:
+ http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/unix/sysv/
+ linux/i386/sysdep.h?
+ rev=3D1.28&content-type=3Dtext/x-cvsweb-markup&cvsroot=3Dglibc
+
+ Linux uses a negative return value to indicate syscall errors,
+ unlike most Unices, which use the condition codes' carry flag.
+
+ Since version 2.1 the return value of a system call might be
+ negative even if the call succeeded. E.g., the 'lseek' system call
+ might return a large offset. Therefore we must not anymore test
+ for < 0, but test for a real error by making sure the value in %eax
+ is a real error number. Linus said he will make sure the no
+ syscall returns a value in -1 .. -4095 as a valid result so we can
+ safely test with -4095.
+*/
+SysRes VG_(mk_SysRes) ( UWord val ) {
+ SysRes res;
+#if defined(VGP_x86_linux)
+ res.isError =3D val >=3D -4095 && val <=3D -1;
+ res.val =3D res.isError ? -val : val;
+#elif defined(VGP_amd64_linux)
+ res.isError =3D val >=3D -4095 && val <=3D -1;
+ res.val =3D res.isError ? -val : val;
+#else
+# error Unknown platform
+#endif
+ return res;
+}
+
+SysRes VG_(mk_SysRes_Error) ( UWord val ) {
+ SysRes r =3D { val, True };
+ return r;
+}
+
+SysRes VG_(mk_SysRes_Success) ( UWord val ) {
+ SysRes r =3D { val, False };
+ return r;
+}
+
+
+/* ---------------------------------------------------------------------
+ A function for doing syscalls.
+ ------------------------------------------------------------------ */
+
+extern UInt do_syscall_WRK (
+ UInt syscall_no,=20
+ UInt a1, UInt a2, UInt a3,
+ UInt a4, UInt a5, UInt a6
+ );
+#if defined(VGP_x86_linux)
+/* Incoming args (syscall number + up to 6 args) come on the stack.
+ (ie. the C calling convention).
+
+ The syscall number goes in %eax. The args are passed to the syscall =
in
+ the regs %ebx, %ecx, %edx, %esi, %edi, %ebp, ie. the kernel's syscall
+ calling convention.
+
+ %eax gets the return value. Not sure which registers the kernel
+ clobbers, so we preserve all the callee-save regs (%esi, %edi, %ebx,
+ %ebp).
+*/
+asm(
+"do_syscall_WRK:\n"
+" push %esi\n"
+" push %edi\n"
+" push %ebx\n"
+" push %ebp\n"
+" movl 16+ 4(%esp),%eax\n"
+" movl 16+ 8(%esp),%ebx\n"
+" movl 16+12(%esp),%ecx\n"
+" movl 16+16(%esp),%edx\n"
+" movl 16+20(%esp),%esi\n"
+" movl 16+24(%esp),%edi\n"
+" movl 16+28(%esp),%ebp\n"
+" int $0x80\n"
+" popl %ebp\n"
+" popl %ebx\n"
+" popl %edi\n"
+" popl %esi\n"
+" ret\n"
+);
+#elif defined(VGP_amd64_linux)
+/* Incoming args (syscall number + up to 6 args) come in %rdi, %rsi,
+ %rdx, %rcx, %r8, %r9, and the last one on the stack (ie. the C
+ calling convention).
+
+ The syscall number goes in %rax. The args are passed to the syscall =
in
+ the regs %rdi, %rsi, %rdx, %r10, %r8, %r9 (yes, really %r10, not %rcx=
),
+ ie. the kernel's syscall calling convention.
+
+ %rax gets the return value. %rcx and %r11 are clobbered by the sysca=
ll;
+ no matter, they are caller-save (the syscall clobbers no callee-save
+ regs, so we don't have to do any register saving/restoring).
+*/
+asm(
+"do_syscall_WRK:\n"
+ /* Convert function calling convention --> syscall calling
+ convention */
+" movq %rdi, %rax\n"
+" movq %rsi, %rdi\n"
+" movq %rdx, %rsi\n"
+" movq %rcx, %rdx\n"
+" movq %r8, %r10\n"
+" movq %r9, %r8\n"
+" movq 8(%rsp), %r9\n" /* last arg from stack */
+" syscall\n"
+" ret\n"
+);
+#else
+# error Unknown platform
+#endif
+
+SysRes VG_(do_syscall) ( UWord sysno, UWord a1, UWord a2, UWord a3,
+ UWord a4, UWord a5, UWord a6 )
+{
+ UWord val =3D do_syscall_WRK(sysno,a1,a2,a3,a4,a5,a6);
+ return VG_(mk_SysRes)( val );
+}
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
Modified: trunk/coregrind/m_syscalls/syscall-amd64-linux.S
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscall-amd64-linux.S 2005-06-17 19:28:29 =
UTC (rev 3921)
+++ trunk/coregrind/m_syscalls/syscall-amd64-linux.S 2005-06-17 21:31:45 =
UTC (rev 3922)
@@ -34,12 +34,6 @@
=20
=20
/*----------------------------------------------------------------*/
-.globl VG_(sigreturn)
-VG_(sigreturn):
- movq $__NR_rt_sigreturn, %rax
- syscall
-
-/*----------------------------------------------------------------*/
/*
Perform a syscall for the client. This will run a syscall
with the client's specific per-thread signal mask.
Modified: trunk/coregrind/m_syscalls/syscall-arm-linux.S
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscall-arm-linux.S 2005-06-17 19:28:29 UT=
C (rev 3921)
+++ trunk/coregrind/m_syscalls/syscall-arm-linux.S 2005-06-17 21:31:45 UT=
C (rev 3922)
@@ -33,6 +33,8 @@
=20
# XXX: must reinstate comments also -- see x86-linux/syscall.S
=20
+# XXX: this is now all way out of date...
+
.globl VG_(do_syscall)
VG_(do_syscall):
swi
@@ -41,10 +43,6 @@
VG_(clone):
swi
=20
-.globl VG_(sigreturn)
-VG_(sigreturn):
- swi
-
# ToDo XXX: Assembler did not like this...
#/* Let the linker know we don't need an executable stack */
#.section .note.GNU-stack,"",@progbits
Modified: trunk/coregrind/m_syscalls/syscall-x86-linux.S
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscall-x86-linux.S 2005-06-17 19:28:29 UT=
C (rev 3921)
+++ trunk/coregrind/m_syscalls/syscall-x86-linux.S 2005-06-17 21:31:45 UT=
C (rev 3922)
@@ -34,12 +34,6 @@
=09
=09
/*----------------------------------------------------------------*/
-.globl VG_(sigreturn)
-VG_(sigreturn):
- movl $__NR_rt_sigreturn, %eax
- int $0x80
-
-/*----------------------------------------------------------------*/
/*
Perform a syscall for the client. This will run a syscall
with the client's specific per-thread signal mask.
Modified: trunk/coregrind/m_syscalls/syscalls-amd64-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscalls-amd64-linux.c 2005-06-17 19:28:29=
UTC (rev 3921)
+++ trunk/coregrind/m_syscalls/syscalls-amd64-linux.c 2005-06-17 21:31:45=
UTC (rev 3922)
@@ -41,6 +41,7 @@
#include "pub_core_libcsignal.h"
#include "pub_core_sigframe.h"
#include "pub_core_signals.h"
+#include "pub_core_syscall.h"
#include "pub_core_syscalls.h"
#include "pub_core_tooliface.h"
=20
@@ -420,7 +421,7 @@
start_thread_NORETURN, stack, flags, &VG_(threads)[ctid],
child_tidptr, parent_tidptr, NULL
);
- res =3D VG_(mk_SysRes_amd64_linux)( rax );
+ res =3D VG_(mk_SysRes)( rax );
=20
VG_(sigprocmask)(VKI_SIG_SETMASK, &savedmask, NULL);
=20
@@ -655,9 +656,7 @@
denote either success or failure, we must set up so that the
driver logic copies it back unchanged. Also, note %RAX is of
the guest registers written by VG_(sigframe_destroy). */
- SET_STATUS_from_SysRes(
- VG_(mk_SysRes_amd64_linux)( tst->arch.vex.guest_RAX )=20
- );
+ SET_STATUS_from_SysRes( VG_(mk_SysRes)( tst->arch.vex.guest_RAX ) );
=20
/* Check to see if some any signals arose as a result of this. */
*flags |=3D SfPollAfter;
Modified: trunk/coregrind/m_syscalls/syscalls-generic.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscalls-generic.c 2005-06-17 19:28:29 UTC=
(rev 3921)
+++ trunk/coregrind/m_syscalls/syscalls-generic.c 2005-06-17 21:31:45 UTC=
(rev 3922)
@@ -44,6 +44,7 @@
#include "pub_core_tooliface.h"
#include "pub_core_options.h"
#include "pub_core_signals.h"
+#include "pub_core_syscall.h"
#include "pub_core_syscalls.h"
=20
#include "priv_types_n_macros.h"
Modified: trunk/coregrind/m_syscalls/syscalls-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscalls-linux.c 2005-06-17 19:28:29 UTC (=
rev 3921)
+++ trunk/coregrind/m_syscalls/syscalls-linux.c 2005-06-17 21:31:45 UTC (=
rev 3922)
@@ -40,6 +40,7 @@
#include "pub_core_tooliface.h"
#include "pub_core_options.h"
#include "pub_core_signals.h"
+#include "pub_core_syscall.h"
=20
#include "priv_types_n_macros.h"
#include "priv_syscalls-generic.h"
Modified: trunk/coregrind/m_syscalls/syscalls-main.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscalls-main.c 2005-06-17 19:28:29 UTC (r=
ev 3921)
+++ trunk/coregrind/m_syscalls/syscalls-main.c 2005-06-17 21:31:45 UTC (r=
ev 3922)
@@ -39,6 +39,7 @@
#include "pub_core_tooliface.h"
#include "pub_core_options.h"
#include "pub_core_signals.h"
+#include "pub_core_syscall.h"
#include "pub_core_syscalls.h"
=20
#include "priv_types_n_macros.h"
Modified: trunk/coregrind/m_syscalls/syscalls-x86-linux.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_syscalls/syscalls-x86-linux.c 2005-06-17 19:28:29 U=
TC (rev 3921)
+++ trunk/coregrind/m_syscalls/syscalls-x86-linux.c 2005-06-17 21:31:45 U=
TC (rev 3922)
@@ -47,6 +47,7 @@
#include "pub_core_mallocfree.h"
#include "pub_core_sigframe.h"
#include "pub_core_signals.h"
+#include "pub_core_syscall.h"
#include "pub_core_syscalls.h"
#include "pub_core_tooliface.h"
=20
@@ -443,7 +444,7 @@
start_thread_NORETURN, stack, flags, &VG_(threads)[ctid],
child_tidptr, parent_tidptr, NULL
);
- res =3D VG_(mk_SysRes_x86_linux)( eax );
+ res =3D VG_(mk_SysRes)( eax );
=20
VG_(sigprocmask)(VKI_SIG_SETMASK, &savedmask, NULL);
=20
@@ -1142,9 +1143,7 @@
denote either success or failure, we must set up so that the
driver logic copies it back unchanged. Also, note %EAX is of
the guest registers written by VG_(sigframe_destroy). */
- SET_STATUS_from_SysRes(
- VG_(mk_SysRes_x86_linux)( tst->arch.vex.guest_EAX )=20
- );
+ SET_STATUS_from_SysRes( VG_(mk_SysRes)( tst->arch.vex.guest_EAX ) );
=20
/* Check to see if some any signals arose as a result of this. */
*flags |=3D SfPollAfter;
@@ -1175,9 +1174,7 @@
denote either success or failure, we must set up so that the
driver logic copies it back unchanged. Also, note %EAX is of
the guest registers written by VG_(sigframe_destroy). */
- SET_STATUS_from_SysRes(
- VG_(mk_SysRes_x86_linux)( tst->arch.vex.guest_EAX )=20
- );
+ SET_STATUS_from_SysRes( VG_(mk_SysRes)( tst->arch.vex.guest_EAX ) );
=20
/* Check to see if some any signals arose as a result of this. */
*flags |=3D SfPollAfter;
Modified: trunk/coregrind/pub_core_libcbase.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_libcbase.h 2005-06-17 19:28:29 UTC (rev 3921=
)
+++ trunk/coregrind/pub_core_libcbase.h 2005-06-17 21:31:45 UTC (rev 3922=
)
@@ -39,89 +39,6 @@
=20
#include "pub_tool_libcbase.h"
=20
-/* ---------------------------------------------------------------------
- Fundamental functions for doing syscalls on this platform.
- ------------------------------------------------------------------ */
-
-/* Do a syscall on this platform, with 6 args, and return the result
- in canonical format in a SysRes value. */
-
-// We use a full prototype for VG_(do_syscall) rather than "..." to ensu=
re
-// that all arguments get converted to a UWord appropriately. Not doing=
so
-// can cause problems when passing 32-bit integers on 64-bit platforms,
-// because the top 32-bits might not be zeroed appropriately, eg. as wou=
ld
-// happen with the 6th arg on AMD64 which is passed on the stack.
-
-extern SysRes VG_(do_syscall) ( UWord sysno,=20
- UWord, UWord, UWord,=20
- UWord, UWord, UWord );
-
-/* Macros make life easier. */
-
-#define vgPlain_do_syscall0(s) VG_(do_syscall)((s),0,0,0,0,0=
,0)
-#define vgPlain_do_syscall1(s,a) VG_(do_syscall)((s),(a),0,0,0=
,0,0)
-#define vgPlain_do_syscall2(s,a,b) VG_(do_syscall)((s),(a),(b),0=
,0,0,0)
-#define vgPlain_do_syscall3(s,a,b,c) VG_(do_syscall)((s),(a),(b),(=
c),0,0,0)
-#define vgPlain_do_syscall4(s,a,b,c,d) VG_(do_syscall)((s),(a),(b),\
- (c),(d),0,0)
-#define vgPlain_do_syscall5(s,a,b,c,d,e) VG_(do_syscall)((s),(a),(b),\
- (c),(d),(e),0=
)
-#define vgPlain_do_syscall6(s,a,b,c,d,e,f) VG_(do_syscall)((s),(a),(b),\
- (c),(d),(e),(=
f))
-
-
-/* Build SysRes values -- occasionally useful. */
-
-static inline SysRes VG_(mk_SysRes_Error) ( UWord err ) {
- SysRes r =3D { err, True };
- return r;
-}
-
-static inline SysRes VG_(mk_SysRes_Success) ( UWord err ) {
- SysRes r =3D { err, False };
- return r;
-}
-
-
-/* This is absolutely the wrong place for these, but I can't figure
- out anywhere else for them to go. */
-
-/* Make a SysRes value from an %eax syscall return value on
- x86-linux.
-
- From:
- http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/sysdeps/unix/sysv/
- linux/i386/sysdep.h?
- rev=3D1.28&content-type=3Dtext/x-cvsweb-markup&cvsroot=3Dglibc
-
- Linux uses a negative return value to indicate syscall errors,
- unlike most Unices, which use the condition codes' carry flag.
-
- Since version 2.1 the return value of a system call might be
- negative even if the call succeeded. E.g., the 'lseek' system call
- might return a large offset. Therefore we must not anymore test
- for < 0, but test for a real error by making sure the value in %eax
- is a real error number. Linus said he will make sure the no
- syscall returns a value in -1 .. -4095 as a valid result so we can
- safely test with -4095.
-*/
-static inline SysRes VG_(mk_SysRes_x86_linux) ( Int eax ) {
- SysRes res;
- res.isError =3D eax >=3D -4095 && eax <=3D -1;
- res.val =3D res.isError ? -eax : eax;
- return res;
-}
-
-/* Similarly .. */
-static inline SysRes VG_(mk_SysRes_amd64_linux) ( Long rax ) {
- SysRes res;
- res.isError =3D rax >=3D -4095 && rax <=3D -1;
- res.val =3D res.isError ? -rax : rax;
- return res;
-}
-
-
-
#endif // __PUB_CORE_LIBCBASE_H
=20
/*--------------------------------------------------------------------*/
Added: trunk/coregrind/pub_core_syscall.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_syscall.h 2005-06-17 19:28:29 UTC (rev 3921)
+++ trunk/coregrind/pub_core_syscall.h 2005-06-17 21:31:45 UTC (rev 3922)
@@ -0,0 +1,83 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Doing system calls. pub_core_syscall.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+ This file is part of Valgrind, a dynamic binary instrumentation
+ framework.
+
+ Copyright (C) 2000-2005 Julian Seward
+ js...@ac...
+
+ 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.
+*/
+
+#ifndef __PUB_CORE_SYSCALL_H
+#define __PUB_CORE_SYSCALL_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module contains the code for actually executing syscall=
s.
+//--------------------------------------------------------------------
+
+/* Do a syscall on this platform, with 6 args, and return the result
+ in canonical format in a SysRes value. */
+
+// We use a full prototype for VG_(do_syscall) rather than "..." to ensu=
re
+// that all arguments get converted to a UWord appropriately. Not doing=
so
+// can cause problems when passing 32-bit integers on 64-bit platforms,
+// because the top 32-bits might not be zeroed appropriately, eg. as wou=
ld
+// happen with the 6th arg on AMD64 which is passed on the stack.
+
+extern SysRes VG_(do_syscall) ( UWord sysno,=20
+ UWord, UWord, UWord,=20
+ UWord, UWord, UWord );
+
+/* Macros make life easier. */
+
+#define vgPlain_do_syscall0(s) VG_(do_syscall)((s),0,0,0,0,0=
,0)
+#define vgPlain_do_syscall1(s,a) VG_(do_syscall)((s),(a),0,0,0=
,0,0)
+#define vgPlain_do_syscall2(s,a,b) VG_(do_syscall)((s),(a),(b),0=
,0,0,0)
+#define vgPlain_do_syscall3(s,a,b,c) VG_(do_syscall)((s),(a),(b),(=
c),0,0,0)
+#define vgPlain_do_syscall4(s,a,b,c,d) VG_(do_syscall)((s),(a),(b),\
+ (c),(d),0,0)
+#define vgPlain_do_syscall5(s,a,b,c,d,e) VG_(do_syscall)((s),(a),(b),\
+ (c),(d),(e),0=
)
+#define vgPlain_do_syscall6(s,a,b,c,d,e,f) VG_(do_syscall)((s),(a),(b),\
+ (c),(d),(e),(=
f))
+
+extern SysRes VG_(mk_SysRes) ( UWord val );
+extern SysRes VG_(mk_SysRes_Error) ( UWord val );
+extern SysRes VG_(mk_SysRes_Success) ( UWord val );
+
+// The _WRK function is handwritten assembly. It has some very magic
+// properties. See comments at the top of
+// VG_(fixup_guest_state_after_syscall_interrupted) below for details.
+extern
+void VG_(do_syscall_for_client_WRK)( Int syscallno,=20
+ void* guest_state,
+ const vki_sigset_t *syscall_mask,
+ const vki_sigset_t *restore_mask,
+ Int nsigwords );
+
+#endif // __PUB_CORE_SYSCALL_H
+
+/*--------------------------------------------------------------------*/
+/*--- end ---*/
+/*--------------------------------------------------------------------*/
+
|