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 | |
njn | 9f20746 | 2009-03-10 22:02:09 +0000 | [diff] [blame^] | 10 | Copyright (C) 2000-2009 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 | |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 34 | #if defined(VGP_x86_linux) |
njn | a5ad9ba | 2005-11-10 15:20:37 +0000 | [diff] [blame] | 35 | # define VG_MIN_INSTR_SZB 1 // min length of native instruction |
| 36 | # define VG_MAX_INSTR_SZB 16 // max length of native instruction |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 37 | # define VG_CLREQ_SZB 14 // length of a client request, may |
njn | a5ad9ba | 2005-11-10 15:20:37 +0000 | [diff] [blame] | 38 | // be larger than VG_MAX_INSTR_SZB |
sewardj | c281233 | 2005-12-23 23:34:51 +0000 | [diff] [blame] | 39 | # define VG_STACK_REDZONE_SZB 0 // number of addressable bytes below %RSP |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 40 | #elif defined(VGP_amd64_linux) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 41 | # define VG_MIN_INSTR_SZB 1 |
| 42 | # define VG_MAX_INSTR_SZB 16 |
sewardj | 0ec07f3 | 2006-01-12 12:32:32 +0000 | [diff] [blame] | 43 | # define VG_CLREQ_SZB 19 |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 44 | # define VG_STACK_REDZONE_SZB 128 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 45 | #elif defined(VGP_ppc32_linux) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 46 | # define VG_MIN_INSTR_SZB 4 |
| 47 | # define VG_MAX_INSTR_SZB 4 |
sewardj | d68ac3e | 2006-01-20 14:31:57 +0000 | [diff] [blame] | 48 | # define VG_CLREQ_SZB 20 |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 49 | # define VG_STACK_REDZONE_SZB 0 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 50 | #elif defined(VGP_ppc64_linux) |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +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 |
sewardj | c281233 | 2005-12-23 23:34:51 +0000 | [diff] [blame] | 54 | # define VG_STACK_REDZONE_SZB 288 // number of addressable bytes below R1 |
| 55 | // from 64-bit PowerPC ELF ABI Supplement 1.7 |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 56 | #elif defined(VGP_ppc32_aix5) |
| 57 | # define VG_MIN_INSTR_SZB 4 |
| 58 | # define VG_MAX_INSTR_SZB 4 |
| 59 | # define VG_CLREQ_SZB 20 |
| 60 | /* The PowerOpen ABI actually says 220 bytes, but that is not an |
| 61 | 8-aligned number, and frequently forces Memcheck's |
| 62 | mc_{new,die}_mem_stack_N routines into slow cases by losing |
| 63 | 8-alignment of the area to be messed with. So let's just say |
| 64 | 224 instead. Gdb has a similar kludge. */ |
| 65 | # define VG_STACK_REDZONE_SZB 224 |
| 66 | #elif defined(VGP_ppc64_aix5) |
| 67 | # define VG_MIN_INSTR_SZB 4 |
| 68 | # define VG_MAX_INSTR_SZB 4 |
| 69 | # define VG_CLREQ_SZB 20 |
| 70 | # define VG_STACK_REDZONE_SZB 288 // is this right? |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 71 | #else |
sewardj | f1c91e0 | 2006-10-17 01:35:58 +0000 | [diff] [blame] | 72 | # error Unknown platform |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 73 | #endif |
| 74 | |
| 75 | // Guest state accessors |
| 76 | extern Addr VG_(get_SP) ( ThreadId tid ); |
| 77 | extern Addr VG_(get_IP) ( ThreadId tid ); |
| 78 | extern Addr VG_(get_FP) ( ThreadId tid ); |
sewardj | acaec5f | 2005-08-19 16:02:59 +0000 | [diff] [blame] | 79 | extern Addr VG_(get_LR) ( ThreadId tid ); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 80 | |
| 81 | extern void VG_(set_SP) ( ThreadId tid, Addr sp ); |
| 82 | extern void VG_(set_IP) ( ThreadId tid, Addr ip ); |
| 83 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 84 | // For get/set, 'area' is where the asked-for guest state will be copied |
| 85 | // into/from. If shadowNo == 0, the real (non-shadow) guest state is |
| 86 | // accessed. If shadowNo == 1, the first shadow area is accessed, and |
| 87 | // if shadowNo == 2, the second shadow area is accessed. This gives a |
| 88 | // completely general way to read/modify a thread's guest register state |
| 89 | // providing you know the offsets you need. |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 90 | void |
| 91 | VG_(get_shadow_regs_area) ( ThreadId tid, |
| 92 | /*DST*/UChar* dst, |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 93 | /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size ); |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 94 | void |
| 95 | VG_(set_shadow_regs_area) ( ThreadId tid, |
njn | c4431bf | 2009-01-15 21:29:24 +0000 | [diff] [blame] | 96 | /*DST*/Int shadowNo, PtrdiffT offset, SizeT size, |
sewardj | 7cf4e6b | 2008-05-01 20:24:26 +0000 | [diff] [blame] | 97 | /*SRC*/const UChar* src ); |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 98 | |
sewardj | 9c606bd | 2008-09-18 18:12:50 +0000 | [diff] [blame] | 99 | // Sets the shadow values for the syscall return value register(s). |
| 100 | // This is platform specific. |
| 101 | void VG_(set_syscall_return_shadows) ( ThreadId tid, |
| 102 | /* shadow vals for the result */ |
| 103 | UWord s1res, UWord s2res, |
| 104 | /* shadow vals for the error val */ |
| 105 | UWord s1err, UWord s2err ); |
| 106 | |
njn | 6ace3ea | 2005-06-17 03:06:27 +0000 | [diff] [blame] | 107 | // Apply a function 'f' to all the general purpose registers in all the |
| 108 | // current threads. |
| 109 | // This is very Memcheck-specific -- it's used to find the roots when |
| 110 | // doing leak checking. |
| 111 | extern void VG_(apply_to_GP_regs)(void (*f)(UWord val)); |
| 112 | |
sewardj | b8b79ad | 2008-03-03 01:35:41 +0000 | [diff] [blame] | 113 | // This iterator lets you inspect each live thread's stack bounds. |
| 114 | // Returns False at the end. 'tid' is the iterator and you can only |
| 115 | // safely change it by making calls to these functions. |
| 116 | extern void VG_(thread_stack_reset_iter) ( /*OUT*/ThreadId* tid ); |
| 117 | extern Bool VG_(thread_stack_next) ( /*MOD*/ThreadId* tid, |
| 118 | /*OUT*/Addr* stack_min, |
| 119 | /*OUT*/Addr* stack_max ); |
njn | b506bd8 | 2005-06-21 04:01:51 +0000 | [diff] [blame] | 120 | |
sewardj | bbec772 | 2007-11-25 14:08:53 +0000 | [diff] [blame] | 121 | // Returns .client_stack_highest_word for the given thread |
| 122 | extern Addr VG_(thread_get_stack_max) ( ThreadId tid ); |
| 123 | |
bart | 0fb0320 | 2008-03-29 09:25:53 +0000 | [diff] [blame] | 124 | // Returns how many bytes have been allocated for the stack of the given thread |
| 125 | extern Addr VG_(thread_get_stack_size) ( ThreadId tid ); |
| 126 | |
sewardj | 53ee1fc | 2005-12-23 02:29:58 +0000 | [diff] [blame] | 127 | // Given a pointer to a function as obtained by "& functionname" in C, |
| 128 | // produce a pointer to the actual entry point for the function. For |
| 129 | // most platforms it's the identity function. Unfortunately, on |
| 130 | // ppc64-linux it isn't (sigh). |
| 131 | extern void* VG_(fnptr_to_fnentry)( void* ); |
| 132 | |
njn | 4a164d0 | 2005-06-18 18:49:40 +0000 | [diff] [blame] | 133 | #endif // __PUB_TOOL_MACHINE_H |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 134 | |
| 135 | /*--------------------------------------------------------------------*/ |
| 136 | /*--- end ---*/ |
| 137 | /*--------------------------------------------------------------------*/ |