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 | 9eecbbb | 2010-05-03 21:37:12 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2010 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 | |
| 34 | //-------------------------------------------------------------------- |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 35 | // PURPOSE: This module defines a few replacement functions for Linux |
| 36 | // vsyscalls, which we can't implement directly. It also contains |
| 37 | // stubs for signal returns. Note, all the code within runs on the |
| 38 | // simulated CPU. The vsyscall stubs are gotten to by use of the |
| 39 | // redirect mechanism. |
sewardj | a672ea3 | 2006-04-29 18:03:14 +0000 | [diff] [blame] | 40 | // |
| 41 | // Note: generally, putting replacement functions in here is a bad |
| 42 | // idea, since any Dwarf frame-unwind info attached to them will not |
| 43 | // be seen by the unwinder in gcc's runtime support. This means |
| 44 | // unwinding during exception handling by gcc tends to fail if it |
| 45 | // encounters one of these replacement functions. A better place to |
| 46 | // put them is in one of the .so's preloaded into the client, since |
| 47 | // the client's ld.so will know about it and so gcc's unwinder |
| 48 | // (somehow) is able to get hold of it. |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 49 | //-------------------------------------------------------------------- |
| 50 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 51 | /* These two delimit our handwritten assembly code, so we can tell |
| 52 | tools which track memory that this area should be regarded as |
| 53 | readable, at least. Otherwise Memcheck complains we're jumping to |
| 54 | invalid addresses. */ |
njn | 7d2a9c4 | 2005-06-19 21:49:28 +0000 | [diff] [blame] | 55 | |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 56 | extern Addr VG_(trampoline_stuff_start); |
| 57 | extern Addr VG_(trampoline_stuff_end); |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 58 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 59 | #if defined(VGP_x86_linux) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 60 | extern Addr VG_(x86_linux_SUBST_FOR_sigreturn); |
| 61 | extern Addr VG_(x86_linux_SUBST_FOR_rt_sigreturn); |
sewardj | 6a443b2 | 2005-11-20 19:37:54 +0000 | [diff] [blame] | 62 | extern Char* VG_(x86_linux_REDIR_FOR_index) ( const Char*, Int ); |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 63 | #endif |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 64 | |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 65 | #if defined(VGP_amd64_linux) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 66 | extern Addr VG_(amd64_linux_SUBST_FOR_rt_sigreturn); |
| 67 | extern Addr VG_(amd64_linux_REDIR_FOR_vgettimeofday); |
| 68 | extern Addr VG_(amd64_linux_REDIR_FOR_vtime); |
sewardj | b57e693 | 2009-08-02 12:21:31 +0000 | [diff] [blame] | 69 | extern UInt VG_(amd64_linux_REDIR_FOR_strlen)( void* ); |
sewardj | b9bce63 | 2005-06-21 01:41:34 +0000 | [diff] [blame] | 70 | #endif |
sewardj | ad50be3 | 2005-08-18 11:54:30 +0000 | [diff] [blame] | 71 | |
| 72 | #if defined(VGP_ppc32_linux) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 73 | extern Addr VG_(ppc32_linux_SUBST_FOR_sigreturn); |
| 74 | extern Addr VG_(ppc32_linux_SUBST_FOR_rt_sigreturn); |
sewardj | 31d8342 | 2005-10-15 02:00:41 +0000 | [diff] [blame] | 75 | extern UInt VG_(ppc32_linux_REDIR_FOR_strlen)( void* ); |
| 76 | extern UInt VG_(ppc32_linux_REDIR_FOR_strcmp)( void*, void* ); |
| 77 | extern void* VG_(ppc32_linux_REDIR_FOR_strchr)( void*, Int ); |
sewardj | ad50be3 | 2005-08-18 11:54:30 +0000 | [diff] [blame] | 78 | #endif |
sewardj | f0915fc | 2006-01-05 14:07:04 +0000 | [diff] [blame] | 79 | |
| 80 | #if defined(VGP_ppc64_linux) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 81 | extern Addr VG_(ppc64_linux_SUBST_FOR_rt_sigreturn); |
sewardj | f0915fc | 2006-01-05 14:07:04 +0000 | [diff] [blame] | 82 | extern UInt VG_(ppc64_linux_REDIR_FOR_strlen)( void* ); |
sewardj | 1a85f4f | 2006-01-12 21:15:35 +0000 | [diff] [blame] | 83 | extern void* VG_(ppc64_linux_REDIR_FOR_strchr)( void*, Int ); |
sewardj | 658f05a | 2006-01-17 02:21:09 +0000 | [diff] [blame] | 84 | /* A label (sans dot) marking the ultra-magical return stub via which |
| 85 | all redirected and wrapped functions are made to "return" on |
sewardj | f832bb9 | 2006-10-17 01:54:54 +0000 | [diff] [blame] | 86 | ppc64-linux/ppc64-aix5/ppc32-aix5. The one insn at this label is |
| 87 | never really translated. Instead, m_translate generates IR to |
| 88 | restore the thread's LR and R2 registers from a small stack in the |
| 89 | ppc64 guest state structure, and then branch to LR. Convoluted? |
| 90 | Confusing? You betcha. Could I think of anything simpler? No. */ |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 91 | extern Addr VG_(ppctoc_magic_redirect_return_stub); |
sewardj | f832bb9 | 2006-10-17 01:54:54 +0000 | [diff] [blame] | 92 | #endif |
| 93 | |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 94 | #if defined(VGP_arm_linux) |
| 95 | extern UInt VG_(arm_linux_REDIR_FOR_strlen)( void* ); |
| 96 | //extern void* VG_(arm_linux_REDIR_FOR_index) ( void*, Int ); |
| 97 | extern void* VG_(arm_linux_REDIR_FOR_memcpy)( void*, void*, Int ); |
| 98 | #endif |
| 99 | |
sewardj | f832bb9 | 2006-10-17 01:54:54 +0000 | [diff] [blame] | 100 | #if defined(VGP_ppc32_aix5) |
| 101 | /* A label (sans dot) marking the client start point for ppc32_aix5. |
| 102 | This function is entered with r3 holding a pointer to the |
| 103 | AIX5PreloadPage struct set up by m_initimg. It first tries to |
| 104 | __loadx the _core.so and _tool.so preloads mentioned in the struct; |
| 105 | then it cleans up the register state to be more what it really |
| 106 | should be at client startup, and finally it jumps to the client's |
| 107 | real entry point. */ |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 108 | extern Addr VG_(ppc32_aix5_do_preloads_then_start_client); |
sewardj | f832bb9 | 2006-10-17 01:54:54 +0000 | [diff] [blame] | 109 | |
| 110 | /* See comment for VG_(ppctoc_magic_redirect_return_stub) above. */ |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 111 | extern Addr VG_(ppctoc_magic_redirect_return_stub); |
sewardj | f832bb9 | 2006-10-17 01:54:54 +0000 | [diff] [blame] | 112 | #endif |
| 113 | |
| 114 | #if defined(VGP_ppc64_aix5) |
| 115 | /* See comment for VG_(ppctoc_magic_redirect_return_stub) above. */ |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 116 | extern Addr VG_(ppctoc_magic_redirect_return_stub); |
sewardj | f832bb9 | 2006-10-17 01:54:54 +0000 | [diff] [blame] | 117 | |
| 118 | /* See comment for ppc32_aix5 equivalent above. */ |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 119 | extern Addr VG_(ppc64_aix5_do_preloads_then_start_client); |
sewardj | f0915fc | 2006-01-05 14:07:04 +0000 | [diff] [blame] | 120 | #endif |
njn | cda2f0f | 2009-05-18 02:12:08 +0000 | [diff] [blame] | 121 | |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 122 | #if defined(VGP_x86_darwin) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 123 | extern Addr VG_(x86_darwin_SUBST_FOR_sigreturn); |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 124 | extern SizeT VG_(x86_darwin_REDIR_FOR_strlen)( void* ); |
| 125 | extern SizeT VG_(x86_darwin_REDIR_FOR_strcmp)( void*, void* ); |
| 126 | extern void* VG_(x86_darwin_REDIR_FOR_strcat)( void*, void * ); |
| 127 | extern char* VG_(x86_darwin_REDIR_FOR_strcpy)( char *s1, char *s2 ); |
| 128 | extern SizeT VG_(x86_darwin_REDIR_FOR_strlcat)( char *s1, const char *s2, |
| 129 | SizeT size ); |
| 130 | #endif |
| 131 | |
| 132 | #if defined(VGP_amd64_darwin) |
bart | becedea | 2010-07-29 18:12:23 +0000 | [diff] [blame] | 133 | extern Addr VG_(amd64_darwin_SUBST_FOR_sigreturn); |
njn | ea2d6fd | 2010-07-01 00:20:20 +0000 | [diff] [blame] | 134 | extern SizeT VG_(amd64_darwin_REDIR_FOR_strlen)( void* ); |
| 135 | extern SizeT VG_(amd64_darwin_REDIR_FOR_strcmp)( void*, void* ); |
| 136 | extern void* VG_(amd64_darwin_REDIR_FOR_strcat)( void*, void * ); |
| 137 | extern char* VG_(amd64_darwin_REDIR_FOR_strcpy)( char *s1, char *s2 ); |
| 138 | extern SizeT VG_(amd64_darwin_REDIR_FOR_strlcat)( char *s1, const char *s2, |
| 139 | SizeT size ); |
| 140 | extern UInt VG_(amd64_darwin_REDIR_FOR_arc4random)( void ); |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 141 | #endif |
| 142 | |
njn | a7598f6 | 2005-06-18 03:27:58 +0000 | [diff] [blame] | 143 | #endif // __PUB_CORE_TRAMPOLINE_H |
| 144 | |
| 145 | /*--------------------------------------------------------------------*/ |
| 146 | /*--- end ---*/ |
| 147 | /*--------------------------------------------------------------------*/ |