njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- Machine-related stuff. pub_tool_machine.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 | f536bbb | 2005-06-13 04:21:38 +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 | |
njn | 4a164d0 | 2005-06-18 18:49:40 +0000 | [diff] [blame] | 31 | #ifndef __PUB_TOOL_MACHINE_H |
| 32 | #define __PUB_TOOL_MACHINE_H |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 33 | |
florian | 535fb1b | 2013-09-15 13:54:34 +0000 | [diff] [blame] | 34 | #include "pub_tool_basics.h" // ThreadID |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame] | 35 | #include "libvex.h" // VexArchInfo |
| 36 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 37 | #if defined(VGP_x86_linux) || defined(VGP_x86_solaris) |
njn | a5ad9ba | 2005-11-10 15:20:37 +0000 | [diff] [blame] | 38 | # define VG_MIN_INSTR_SZB 1 // min length of native instruction |
| 39 | # define VG_MAX_INSTR_SZB 16 // max length of native instruction |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 40 | # define VG_CLREQ_SZB 14 // length of a client request, may |
njn | a5ad9ba | 2005-11-10 15:20:37 +0000 | [diff] [blame] | 41 | // be larger than VG_MAX_INSTR_SZB |
sewardj | c281233 | 2005-12-23 23:34:51 +0000 | [diff] [blame] | 42 | # define VG_STACK_REDZONE_SZB 0 // number of addressable bytes below %RSP |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 43 | |
sewardj | 8eb8bab | 2015-07-21 14:44:28 +0000 | [diff] [blame] | 44 | #elif defined(VGP_amd64_linux) || defined(VGP_amd64_solaris) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 45 | # define VG_MIN_INSTR_SZB 1 |
| 46 | # define VG_MAX_INSTR_SZB 16 |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 47 | # define VG_CLREQ_SZB 19 |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 48 | # define VG_STACK_REDZONE_SZB 128 |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 49 | |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 50 | #elif defined(VGP_ppc32_linux) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 51 | # define VG_MIN_INSTR_SZB 4 |
| 52 | # define VG_MAX_INSTR_SZB 4 |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 53 | # define VG_CLREQ_SZB 20 |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 54 | # define VG_STACK_REDZONE_SZB 0 |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 55 | |
carll | cae0cc2 | 2014-08-07 23:17:29 +0000 | [diff] [blame] | 56 | #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux) |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 57 | # define VG_MIN_INSTR_SZB 4 |
| 58 | # define VG_MAX_INSTR_SZB 4 |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 59 | # define VG_CLREQ_SZB 20 |
sewardj | c281233 | 2005-12-23 23:34:51 +0000 | [diff] [blame] | 60 | # define VG_STACK_REDZONE_SZB 288 // number of addressable bytes below R1 |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 61 | // from 64-bit PowerPC ELF ABI |
| 62 | // Supplement 1.7 |
| 63 | |
| 64 | #elif defined(VGP_arm_linux) |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 65 | # define VG_MIN_INSTR_SZB 2 |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 66 | # define VG_MAX_INSTR_SZB 4 |
sewardj | 807725e | 2010-10-12 10:13:17 +0000 | [diff] [blame] | 67 | # define VG_CLREQ_SZB 20 |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 68 | # define VG_STACK_REDZONE_SZB 0 |
| 69 | |
sewardj | f0c1250 | 2014-01-12 12:54:00 +0000 | [diff] [blame] | 70 | #elif defined(VGP_arm64_linux) |
| 71 | # define VG_MIN_INSTR_SZB 4 |
| 72 | # define VG_MAX_INSTR_SZB 4 |
| 73 | # define VG_CLREQ_SZB 20 |
| 74 | # define VG_STACK_REDZONE_SZB 0 |
| 75 | |
sewardj | b5b8740 | 2011-03-07 16:05:35 +0000 | [diff] [blame] | 76 | #elif defined(VGP_s390x_linux) |
| 77 | # define VG_MIN_INSTR_SZB 2 |
| 78 | # define VG_MAX_INSTR_SZB 6 |
| 79 | # define VG_CLREQ_SZB 10 |
| 80 | # define VG_STACK_REDZONE_SZB 0 // s390 has no redzone |
| 81 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 82 | #elif defined(VGP_x86_darwin) |
| 83 | # define VG_MIN_INSTR_SZB 1 // min length of native instruction |
| 84 | # define VG_MAX_INSTR_SZB 16 // max length of native instruction |
| 85 | # define VG_CLREQ_SZB 14 // length of a client request, may |
| 86 | // be larger than VG_MAX_INSTR_SZB |
| 87 | # define VG_STACK_REDZONE_SZB 0 // number of addressable bytes below %RSP |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 88 | |
njn | f76d27a | 2009-05-28 01:53:07 +0000 | [diff] [blame] | 89 | #elif defined(VGP_amd64_darwin) |
| 90 | # define VG_MIN_INSTR_SZB 1 |
| 91 | # define VG_MAX_INSTR_SZB 16 |
| 92 | # define VG_CLREQ_SZB 19 |
| 93 | # define VG_STACK_REDZONE_SZB 128 |
sewardj | 59570ff | 2010-01-01 11:59:33 +0000 | [diff] [blame] | 94 | |
sewardj | 5db1540 | 2012-06-07 09:13:21 +0000 | [diff] [blame] | 95 | #elif defined(VGP_mips32_linux) |
| 96 | # define VG_MIN_INSTR_SZB 4 |
| 97 | # define VG_MAX_INSTR_SZB 4 |
| 98 | # define VG_CLREQ_SZB 20 |
| 99 | # define VG_STACK_REDZONE_SZB 0 |
| 100 | |
petarj | 4df0bfc | 2013-02-27 23:17:33 +0000 | [diff] [blame] | 101 | #elif defined(VGP_mips64_linux) |
| 102 | # define VG_MIN_INSTR_SZB 4 |
| 103 | # define VG_MAX_INSTR_SZB 4 |
| 104 | # define VG_CLREQ_SZB 20 |
| 105 | # define VG_STACK_REDZONE_SZB 0 |
| 106 | |
sewardj | 112711a | 2015-04-10 12:30:09 +0000 | [diff] [blame] | 107 | #elif defined(VGP_tilegx_linux) |
| 108 | # define VG_MIN_INSTR_SZB 8 |
| 109 | # define VG_MAX_INSTR_SZB 8 |
| 110 | # define VG_CLREQ_SZB 24 |
| 111 | # define VG_STACK_REDZONE_SZB 0 |
| 112 | |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 113 | #else |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 114 | # error Unknown platform |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 115 | #endif |
| 116 | |
| 117 | // Guest state accessors |
sewardj | 1dbd337 | 2010-08-22 12:21:14 +0000 | [diff] [blame] | 118 | // Are mostly in the core_ header. |
| 119 | // Only these two are available to tools. |
| 120 | Addr VG_(get_IP) ( ThreadId tid ); |
| 121 | Addr VG_(get_SP) ( ThreadId tid ); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 122 | |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 123 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 124 | // For get/set, 'area' is where the asked-for guest state will be copied |
| 125 | // into/from. If shadowNo == 0, the real (non-shadow) guest state is |
| 126 | // accessed. If shadowNo == 1, the first shadow area is accessed, and |
| 127 | // if shadowNo == 2, the second shadow area is accessed. This gives a |
| 128 | // completely general way to read/modify a thread's guest register state |
| 129 | // providing you know the offsets you need. |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 130 | void |
| 131 | VG_(get_shadow_regs_area) ( ThreadId tid, |
| 132 | /*DST*/UChar* dst, |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 133 | /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 134 | void |
| 135 | VG_(set_shadow_regs_area) ( ThreadId tid, |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 136 | /*DST*/Int shadowNo, PtrdiffT offset, SizeT size, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 137 | /*SRC*/const UChar* src ); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 138 | |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 139 | // Apply a function 'f' to all the general purpose registers in all the |
philippe | b8ba031 | 2013-10-21 19:57:08 +0000 | [diff] [blame] | 140 | // current threads. This is all live threads, or (when the process is exiting) |
| 141 | // all threads that were instructed to die by the thread calling exit. |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 142 | // This is very Memcheck-specific -- it's used to find the roots when |
| 143 | // doing leak checking. |
philippe | a22f59d | 2012-01-26 23:13:52 +0000 | [diff] [blame] | 144 | extern void VG_(apply_to_GP_regs)(void (*f)(ThreadId tid, |
florian | 6bd9dc1 | 2012-11-23 16:17:43 +0000 | [diff] [blame] | 145 | const HChar* regname, UWord val)); |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 146 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 147 | // This iterator lets you inspect each live thread's stack bounds. |
| 148 | // Returns False at the end. 'tid' is the iterator and you can only |
| 149 | // safely change it by making calls to these functions. |
| 150 | extern void VG_(thread_stack_reset_iter) ( /*OUT*/ThreadId* tid ); |
philippe | 38a74d2 | 2014-08-29 22:53:19 +0000 | [diff] [blame] | 151 | // stack_min is the address of the lowest stack byte, |
| 152 | // stack_max is the address of the highest stack byte. |
| 153 | // In other words, the live stack is [stack_min, stack_max]. |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 154 | extern Bool VG_(thread_stack_next) ( /*MOD*/ThreadId* tid, |
| 155 | /*OUT*/Addr* stack_min, |
| 156 | /*OUT*/Addr* stack_max ); |
njn | b506bd8 | 2005-06-21 04:01:51 +0000 | [diff] [blame] | 157 | |
philippe | 38a74d2 | 2014-08-29 22:53:19 +0000 | [diff] [blame] | 158 | // Returns .client_stack_highest_byte for the given thread |
| 159 | // i.e. the highest addressable byte of the stack. |
sewardj | bbec772 | 2007-11-25 14:08:53 +0000 | [diff] [blame] | 160 | extern Addr VG_(thread_get_stack_max) ( ThreadId tid ); |
| 161 | |
bart | 0fb0320 | 2008-03-29 09:25:53 +0000 | [diff] [blame] | 162 | // Returns how many bytes have been allocated for the stack of the given thread |
bart | 019a43f | 2010-09-02 14:41:05 +0000 | [diff] [blame] | 163 | extern SizeT VG_(thread_get_stack_size) ( ThreadId tid ); |
bart | 0fb0320 | 2008-03-29 09:25:53 +0000 | [diff] [blame] | 164 | |
philippe | 38a74d2 | 2014-08-29 22:53:19 +0000 | [diff] [blame] | 165 | // Returns the lowest address of the alternate signal stack. |
bart | 83c5a92 | 2010-09-02 14:38:38 +0000 | [diff] [blame] | 166 | // See also the man page of sigaltstack(). |
| 167 | extern Addr VG_(thread_get_altstack_min) ( ThreadId tid ); |
| 168 | |
| 169 | // Returns how many bytes have been allocated for the alternate signal stack. |
| 170 | // See also the man page of sigaltstack(). |
| 171 | extern SizeT VG_(thread_get_altstack_size) ( ThreadId tid ); |
| 172 | |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 173 | // Given a pointer to a function as obtained by "& functionname" in C, |
| 174 | // produce a pointer to the actual entry point for the function. For |
| 175 | // most platforms it's the identity function. Unfortunately, on |
| 176 | // ppc64-linux it isn't (sigh). |
| 177 | extern void* VG_(fnptr_to_fnentry)( void* ); |
| 178 | |
sewardj | 98763d5 | 2012-06-03 22:40:07 +0000 | [diff] [blame] | 179 | /* Returns the size of the largest guest register that we will |
| 180 | simulate in this run. This depends on both the guest architecture |
| 181 | and on the specific capabilities we are simulating for that guest |
| 182 | (eg, AVX or non-AVX ?, for amd64). */ |
| 183 | extern Int VG_(machine_get_size_of_largest_guest_register) ( void ); |
| 184 | |
florian | 7862701 | 2012-10-07 19:47:04 +0000 | [diff] [blame] | 185 | /* Return host cpu info. */ |
| 186 | extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*, |
| 187 | /*OUT*/VexArchInfo* ); |
| 188 | |
njn | 4a164d0 | 2005-06-18 18:49:40 +0000 | [diff] [blame] | 189 | #endif // __PUB_TOOL_MACHINE_H |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 190 | |
| 191 | /*--------------------------------------------------------------------*/ |
| 192 | /*--- end ---*/ |
| 193 | /*--------------------------------------------------------------------*/ |