njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- The trampoline code page. pub_core_trampoline.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
sewardj | b3a1e4b | 2015-08-21 11:32:26 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2015 Julian Seward |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 11 | jseward@acm.org |
| 12 | |
| 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. |
| 17 | |
| 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. |
| 22 | |
| 23 | You should have received a copy of the GNU General Public License |
| 24 | along with this program; if not, write to the Free Software |
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 26 | 02111-1307, USA. |
| 27 | |
| 28 | The GNU General Public License is contained in the file COPYING. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __PUB_CORE_TRAMPOLINE_H |
| 32 | #define __PUB_CORE_TRAMPOLINE_H |
| 33 | |
florian | 535fb1b | 2013-09-15 13:54:34 +0000 | [diff] [blame] | 34 | #include "pub_core_basics.h" // VG_ macro |
| 35 | |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 36 | //-------------------------------------------------------------------- |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 37 | // PURPOSE: This module defines a few replacement functions for Linux |
| 38 | // vsyscalls, which we can't implement directly. It also contains |
| 39 | // stubs for signal returns. Note, all the code within runs on the |
| 40 | // simulated CPU. The vsyscall stubs are gotten to by use of the |
| 41 | // redirect mechanism. |
sewardj | a672ea3 | 2006-04-29 18:03:14 +0000 | [diff] [blame] | 42 | // |
| 43 | // Note: generally, putting replacement functions in here is a bad |
| 44 | // idea, since any Dwarf frame-unwind info attached to them will not |
| 45 | // be seen by the unwinder in gcc's runtime support. This means |
| 46 | // unwinding during exception handling by gcc tends to fail if it |
| 47 | // encounters one of these replacement functions. A better place to |
| 48 | // put them is in one of the .so's preloaded into the client, since |
| 49 | // the client's ld.so will know about it and so gcc's unwinder |
| 50 | // (somehow) is able to get hold of it. |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 51 | //-------------------------------------------------------------------- |
| 52 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 53 | /* These two delimit our handwritten assembly code, so we can tell |
| 54 | tools which track memory that this area should be regarded as |
| 55 | readable, at least. Otherwise Memcheck complains we're jumping to |
| 56 | invalid addresses. */ |
njn | 7d2a9c4 | 2005-06-19 21:49:28 +0000 | [diff] [blame] | 57 | |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 58 | extern Addr VG_(trampoline_stuff_start); |
| 59 | extern Addr VG_(trampoline_stuff_end); |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 60 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 61 | #if defined(VGP_x86_linux) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 62 | extern Addr VG_(x86_linux_SUBST_FOR_sigreturn); |
| 63 | extern Addr VG_(x86_linux_SUBST_FOR_rt_sigreturn); |
sewardj | 6a443b2 | 2005-11-20 19:37:54 +0000 | [diff] [blame] | 64 | extern Char* VG_(x86_linux_REDIR_FOR_index) ( const Char*, Int ); |
sewardj | d28cc96 | 2011-03-28 08:22:55 +0000 | [diff] [blame] | 65 | extern UInt VG_(x86_linux_REDIR_FOR_strlen)( void* ); |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 66 | #endif |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 67 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 68 | #if defined(VGP_amd64_linux) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 69 | extern Addr VG_(amd64_linux_SUBST_FOR_rt_sigreturn); |
| 70 | extern Addr VG_(amd64_linux_REDIR_FOR_vgettimeofday); |
| 71 | extern Addr VG_(amd64_linux_REDIR_FOR_vtime); |
tom | d6ae9e6 | 2012-02-09 11:54:16 +0000 | [diff] [blame] | 72 | extern Addr VG_(amd64_linux_REDIR_FOR_vgetcpu); |
sewardj | b57e693 | 2009-08-02 12:21:31 +0000 | [diff] [blame] | 73 | extern UInt VG_(amd64_linux_REDIR_FOR_strlen)( void* ); |
Elliott Hughes | a0664b9 | 2017-04-18 17:46:52 -0700 | [diff] [blame^] | 74 | extern Char* VG_(amd64_linux_REDIR_FOR_index) ( const Char*, Int ); |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 75 | #endif |
sewardj | ad50be3 | 2005-08-18 11:54:30 +0000 | [diff] [blame] | 76 | |
| 77 | #if defined(VGP_ppc32_linux) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 78 | extern Addr VG_(ppc32_linux_SUBST_FOR_sigreturn); |
| 79 | extern Addr VG_(ppc32_linux_SUBST_FOR_rt_sigreturn); |
sewardj | 31d8342 | 2005-10-15 02:00:41 +0000 | [diff] [blame] | 80 | extern UInt VG_(ppc32_linux_REDIR_FOR_strlen)( void* ); |
| 81 | extern UInt VG_(ppc32_linux_REDIR_FOR_strcmp)( void*, void* ); |
| 82 | extern void* VG_(ppc32_linux_REDIR_FOR_strchr)( void*, Int ); |
sewardj | ad50be3 | 2005-08-18 11:54:30 +0000 | [diff] [blame] | 83 | #endif |
sewardj | f0915fc | 2006-01-05 14:07:04 +0000 | [diff] [blame] | 84 | |
carll | cae0cc2 | 2014-08-07 23:17:29 +0000 | [diff] [blame] | 85 | #if defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 86 | extern Addr VG_(ppc64_linux_SUBST_FOR_rt_sigreturn); |
sewardj | f0915fc | 2006-01-05 14:07:04 +0000 | [diff] [blame] | 87 | extern UInt VG_(ppc64_linux_REDIR_FOR_strlen)( void* ); |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 88 | extern void* VG_(ppc64_linux_REDIR_FOR_strchr)( void*, Int ); |
sewardj | 658f05a | 2006-01-17 02:21:09 +0000 | [diff] [blame] | 89 | /* A label (sans dot) marking the ultra-magical return stub via which |
| 90 | all redirected and wrapped functions are made to "return" on |
sewardj | 6e9de46 | 2011-06-28 07:25:29 +0000 | [diff] [blame] | 91 | ppc64-linux. The one insn at this label is never really |
| 92 | translated. Instead, m_translate generates IR to restore the |
| 93 | thread's LR and R2 registers from a small stack in the ppc64 guest |
| 94 | state structure, and then branch to LR. Convoluted? Confusing? |
| 95 | You betcha. Could I think of anything simpler? No. */ |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 96 | extern Addr VG_(ppctoc_magic_redirect_return_stub); |
sewardj | f832bb9 | 2006-10-17 01:54:54 +0000 | [diff] [blame] | 97 | #endif |
| 98 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 99 | #if defined(VGP_arm_linux) |
sewardj | bc33be6 | 2011-11-20 09:35:51 +0000 | [diff] [blame] | 100 | extern Addr VG_(arm_linux_SUBST_FOR_sigreturn); |
| 101 | extern Addr VG_(arm_linux_SUBST_FOR_rt_sigreturn); |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 102 | extern UInt VG_(arm_linux_REDIR_FOR_strlen)( void* ); |
| 103 | //extern void* VG_(arm_linux_REDIR_FOR_index) ( void*, Int ); |
| 104 | extern void* VG_(arm_linux_REDIR_FOR_memcpy)( void*, void*, Int ); |
mjw | 1cd2378 | 2014-08-28 14:59:04 +0000 | [diff] [blame] | 105 | extern void* VG_(arm_linux_REDIR_FOR_strcmp)( void*, void* ); |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 106 | #endif |
| 107 | |
sewardj | 112711a | 2015-04-10 12:30:09 +0000 | [diff] [blame] | 108 | #if defined(VGP_tilegx_linux) |
| 109 | extern Addr VG_(tilegx_linux_SUBST_FOR_rt_sigreturn); |
| 110 | extern UInt VG_(tilegx_linux_REDIR_FOR_strlen)( void* ); |
| 111 | #endif |
| 112 | |
sewardj | f0c1250 | 2014-01-12 12:54:00 +0000 | [diff] [blame] | 113 | #if defined(VGP_arm64_linux) |
| 114 | extern Addr VG_(arm64_linux_SUBST_FOR_rt_sigreturn); |
sewardj | 7aa6651 | 2014-03-09 09:44:32 +0000 | [diff] [blame] | 115 | extern ULong VG_(arm64_linux_REDIR_FOR_strlen)( void* ); |
| 116 | extern void* VG_(arm64_linux_REDIR_FOR_index) ( void*, Long ); |
| 117 | extern Long VG_(arm64_linux_REDIR_FOR_strcmp)( void*, void* ); |
sewardj | f0c1250 | 2014-01-12 12:54:00 +0000 | [diff] [blame] | 118 | #endif |
| 119 | |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 120 | #if defined(VGP_x86_darwin) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 121 | extern Addr VG_(x86_darwin_SUBST_FOR_sigreturn); |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 122 | extern SizeT VG_(x86_darwin_REDIR_FOR_strlen)( void* ); |
| 123 | extern SizeT VG_(x86_darwin_REDIR_FOR_strcmp)( void*, void* ); |
| 124 | extern void* VG_(x86_darwin_REDIR_FOR_strcat)( void*, void * ); |
| 125 | extern char* VG_(x86_darwin_REDIR_FOR_strcpy)( char *s1, char *s2 ); |
| 126 | extern SizeT VG_(x86_darwin_REDIR_FOR_strlcat)( char *s1, const char *s2, |
| 127 | SizeT size ); |
| 128 | #endif |
| 129 | |
| 130 | #if defined(VGP_amd64_darwin) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 131 | extern Addr VG_(amd64_darwin_SUBST_FOR_sigreturn); |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 132 | extern SizeT VG_(amd64_darwin_REDIR_FOR_strlen)( void* ); |
| 133 | extern SizeT VG_(amd64_darwin_REDIR_FOR_strcmp)( void*, void* ); |
| 134 | extern void* VG_(amd64_darwin_REDIR_FOR_strcat)( void*, void * ); |
| 135 | extern char* VG_(amd64_darwin_REDIR_FOR_strcpy)( char *s1, char *s2 ); |
| 136 | extern SizeT VG_(amd64_darwin_REDIR_FOR_strlcat)( char *s1, const char *s2, |
| 137 | SizeT size ); |
| 138 | extern UInt VG_(amd64_darwin_REDIR_FOR_arc4random)( void ); |
sewardj | 704bf0e | 2014-06-21 09:34:22 +0000 | [diff] [blame] | 139 | # if DARWIN_VERS == DARWIN_10_9 |
| 140 | extern char* VG_(amd64_darwin_REDIR_FOR_strchr)( const char*, int ); |
| 141 | # endif |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 142 | #endif |
| 143 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 144 | #if defined(VGP_s390x_linux) |
| 145 | extern Addr VG_(s390x_linux_SUBST_FOR_sigreturn); |
| 146 | extern Addr VG_(s390x_linux_SUBST_FOR_rt_sigreturn); |
florian | ae6e3ac | 2014-09-03 16:01:10 +0000 | [diff] [blame] | 147 | // Note: Long for the 2nd parameter because according to z-series ABI, |
| 148 | // section "Parameter Passing" SIMPLE_ARG: |
| 149 | // "Values shorter than 64 bits are sign- or zero-extended |
| 150 | // (as appropriate) to 64 bits." |
| 151 | extern void* VG_(s390x_linux_REDIR_FOR_index) ( void*, Long ); |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 152 | #endif |
| 153 | |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 154 | #if defined(VGP_mips32_linux) |
| 155 | extern Addr VG_(mips32_linux_SUBST_FOR_sigreturn); |
| 156 | extern Addr VG_(mips32_linux_SUBST_FOR_rt_sigreturn); |
| 157 | extern UInt VG_(mips32_linux_REDIR_FOR_strlen)( void* ); |
| 158 | #endif |
| 159 | |
petarj | 4df0bfc | 2013-02-27 23:17:33 +0000 | [diff] [blame] | 160 | #if defined(VGP_mips64_linux) |
| 161 | extern Addr VG_(mips64_linux_SUBST_FOR_rt_sigreturn); |
| 162 | extern UInt VG_(mips64_linux_REDIR_FOR_strlen)( void* ); |
| 163 | #endif |
| 164 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 165 | #if defined(VGP_x86_solaris) |
| 166 | extern SizeT VG_(x86_solaris_REDIR_FOR_strcmp)(const HChar *, const HChar *); |
| 167 | extern SizeT VG_(x86_solaris_REDIR_FOR_strlen)(const HChar *); |
| 168 | #endif |
| 169 | |
| 170 | #if defined(VGP_amd64_solaris) |
| 171 | extern HChar *VG_(amd64_solaris_REDIR_FOR_strcpy)(HChar *, const HChar *); |
| 172 | extern HChar *VG_(amd64_solaris_REDIR_FOR_strncpy)(HChar *, const HChar *, |
| 173 | SizeT); |
| 174 | extern Int VG_(amd64_solaris_REDIR_FOR_strcmp)(const HChar *, const HChar *); |
| 175 | extern HChar *VG_(amd64_solaris_REDIR_FOR_strcat)(HChar *, const HChar *); |
| 176 | extern SizeT VG_(amd64_solaris_REDIR_FOR_strlen)(const HChar *); |
| 177 | #endif |
| 178 | |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 179 | #endif // __PUB_CORE_TRAMPOLINE_H |
| 180 | |
| 181 | /*--------------------------------------------------------------------*/ |
| 182 | /*--- end ---*/ |
| 183 | /*--------------------------------------------------------------------*/ |