2 /*--------------------------------------------------------------------*/
3 /*--- Doing system calls. pub_core_syscall.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2000-2017 Julian Seward
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #ifndef __PUB_CORE_SYSCALL_H
30 #define __PUB_CORE_SYSCALL_H
32 #include "pub_core_basics.h" // VG_ macro
34 /* PPC64 supports two system call instructions. The flags are used to
35 identify which of the two system call instructions sc or scv is to be
36 used. The following flags must be consistently defined here and in
37 VEX/priv/guest_ppc_defs.h, in the do_syscall_WRK() assembly code
38 below and coregrind/m_syswrap/syscall-ppcle-linux.S code. */
42 //--------------------------------------------------------------------
43 // PURPOSE: This module contains the code for actually executing syscalls.
44 //--------------------------------------------------------------------
46 /* Do a syscall on this platform, with 8 args, and return the result
47 in canonical format in a SysRes value. */
49 // We use a full prototype for VG_(do_syscall) rather than "..." to ensure
50 // that all arguments get converted to a UWord appropriately. Not doing so
51 // can cause problems when passing 32-bit integers on 64-bit platforms,
52 // because the top 32-bits might not be zeroed appropriately, eg. as would
53 // happen with the 6th arg on AMD64 which is passed on the stack.
55 extern SysRes
VG_(do_syscall
) ( UWord sysno
,
56 RegWord
, RegWord
, RegWord
,
57 RegWord
, RegWord
, RegWord
,
60 /* Macros make life easier. */
62 #if defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
63 /* PPC64 uses the 7th argument to pass a flag indicating if the sc or scv
64 instruction is to be used for the system call. Need to set the flag to the
65 sc instruction by default. */
71 #define vgPlain_do_syscall0(s) VG_(do_syscall)((s),0,0,0,0,0,0,A7,0)
73 #define vgPlain_do_syscall1(s,a) VG_(do_syscall)((s),(a),\
75 #define vgPlain_do_syscall2(s,a,b) VG_(do_syscall)((s),(a),(b),\
77 #define vgPlain_do_syscall3(s,a,b,c) VG_(do_syscall)((s),(a),(b),(c),\
79 #define vgPlain_do_syscall4(s,a,b,c,d) VG_(do_syscall)((s),(a),(b),(c),\
81 #define vgPlain_do_syscall5(s,a,b,c,d,e) VG_(do_syscall)((s),(a),(b),(c),\
83 #define vgPlain_do_syscall6(s,a,b,c,d,e,f) VG_(do_syscall)((s),(a),(b),(c),\
85 #define vgPlain_do_syscall7(s,a,b,c,d,e,f,g) VG_(do_syscall)((s),(a),(b),(c),\
87 #define vgPlain_do_syscall8(s,a,b,c,d,e,f,g,h) VG_(do_syscall)((s),(a),(b),(c),\
90 extern SysRes
VG_(mk_SysRes_x86_linux
) ( Int val
);
91 extern SysRes
VG_(mk_SysRes_amd64_linux
) ( Long val
);
92 extern SysRes
VG_(mk_SysRes_ppc32_linux
) ( UInt val
, UInt cr0so
);
93 extern SysRes
VG_(mk_SysRes_ppc64_linux
) ( ULong val
, ULong cr0so
, UInt flag
);
94 extern SysRes
VG_(mk_SysRes_x86_freebsd
) ( UInt val
, UInt val2
, Bool err
);
95 extern SysRes
VG_(mk_SysRes_amd64_freebsd
)( ULong val
, ULong val2
, Bool err
);
96 extern SysRes
VG_(mk_SysRes_arm64_freebsd
)( ULong val
, ULong val2
, Bool err
);
97 extern SysRes
VG_(mk_SysRes_arm_linux
) ( Int val
);
98 extern SysRes
VG_(mk_SysRes_arm64_linux
) ( Long val
);
99 extern SysRes
VG_(mk_SysRes_x86_darwin
) ( UChar scclass
, Bool isErr
,
100 UInt wHI
, UInt wLO
);
101 extern SysRes
VG_(mk_SysRes_amd64_darwin
)( UChar scclass
, Bool isErr
,
102 ULong wHI
, ULong wLO
);
103 extern SysRes
VG_(mk_SysRes_s390x_linux
) ( Long val
);
104 extern SysRes
VG_(mk_SysRes_mips32_linux
)( UWord v0
, UWord v1
,
106 extern SysRes
VG_(mk_SysRes_mips64_linux
)( ULong v0
, ULong v1
,
108 extern SysRes
VG_(mk_SysRes_nanomips_linux
)( UWord a0
);
109 extern SysRes
VG_(mk_SysRes_x86_solaris
) ( Bool isErr
, UInt val
, UInt val2
);
110 extern SysRes
VG_(mk_SysRes_amd64_solaris
) ( Bool isErr
, ULong val
, ULong val2
);
111 extern SysRes
VG_(mk_SysRes_Error
) ( UWord val
);
112 extern SysRes
VG_(mk_SysRes_Success
) ( UWord val
);
114 #if defined(VGP_mips32_linux) || defined(VGP_mips64_linux) \
115 || defined(VGP_nanomips_linux)
116 /* On Linux/MIPS, VG_(mk_SysRes_Success) sets the second result word
117 to zero. Here is a version that allows setting both values. */
118 extern SysRes
VG_(mk_SysRes_SuccessEx
) ( UWord val
, UWord valEx
);
122 /* Return a string which gives the name of an error value. Note,
123 unlike the standard C syserror fn, the returned string is not
124 malloc-allocated or writable -- treat it as a constant. */
126 extern const HChar
* VG_(strerror
) ( UWord errnum
);
128 #endif // __PUB_CORE_SYSCALL_H
130 /*--------------------------------------------------------------------*/
132 /*--------------------------------------------------------------------*/