blob: e52e47cc5f5496eda6dbe93af8ca65ba73d625e6 [file] [log] [blame]
njnf536bbb2005-06-13 04:21:38 +00001
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
sewardj03f8d3f2012-08-05 15:46:46 +000010 Copyright (C) 2000-2012 Julian Seward
njnf536bbb2005-06-13 04:21:38 +000011 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
njn4a164d02005-06-18 18:49:40 +000031#ifndef __PUB_TOOL_MACHINE_H
32#define __PUB_TOOL_MACHINE_H
njnf536bbb2005-06-13 04:21:38 +000033
florian78627012012-10-07 19:47:04 +000034#include "libvex.h" // VexArchInfo
35
sewardjf1c91e02006-10-17 01:35:58 +000036#if defined(VGP_x86_linux)
njna5ad9ba2005-11-10 15:20:37 +000037# define VG_MIN_INSTR_SZB 1 // min length of native instruction
38# define VG_MAX_INSTR_SZB 16 // max length of native instruction
sewardj0ec07f32006-01-12 12:32:32 +000039# define VG_CLREQ_SZB 14 // length of a client request, may
njna5ad9ba2005-11-10 15:20:37 +000040 // be larger than VG_MAX_INSTR_SZB
sewardjc2812332005-12-23 23:34:51 +000041# define VG_STACK_REDZONE_SZB 0 // number of addressable bytes below %RSP
sewardj59570ff2010-01-01 11:59:33 +000042
sewardjf1c91e02006-10-17 01:35:58 +000043#elif defined(VGP_amd64_linux)
njnaf839f52005-06-23 03:27:57 +000044# define VG_MIN_INSTR_SZB 1
45# define VG_MAX_INSTR_SZB 16
sewardj0ec07f32006-01-12 12:32:32 +000046# define VG_CLREQ_SZB 19
njnaf839f52005-06-23 03:27:57 +000047# define VG_STACK_REDZONE_SZB 128
sewardj59570ff2010-01-01 11:59:33 +000048
sewardjf1c91e02006-10-17 01:35:58 +000049#elif defined(VGP_ppc32_linux)
njnaf839f52005-06-23 03:27:57 +000050# define VG_MIN_INSTR_SZB 4
51# define VG_MAX_INSTR_SZB 4
sewardjd68ac3e2006-01-20 14:31:57 +000052# define VG_CLREQ_SZB 20
njnaf839f52005-06-23 03:27:57 +000053# define VG_STACK_REDZONE_SZB 0
sewardj59570ff2010-01-01 11:59:33 +000054
sewardjf1c91e02006-10-17 01:35:58 +000055#elif defined(VGP_ppc64_linux)
sewardj2c48c7b2005-11-29 13:05:56 +000056# define VG_MIN_INSTR_SZB 4
57# define VG_MAX_INSTR_SZB 4
sewardjd68ac3e2006-01-20 14:31:57 +000058# define VG_CLREQ_SZB 20
sewardjc2812332005-12-23 23:34:51 +000059# define VG_STACK_REDZONE_SZB 288 // number of addressable bytes below R1
sewardj59570ff2010-01-01 11:59:33 +000060 // from 64-bit PowerPC ELF ABI
61 // Supplement 1.7
62
63#elif defined(VGP_arm_linux)
sewardj1dbd3372010-08-22 12:21:14 +000064# define VG_MIN_INSTR_SZB 2
sewardj59570ff2010-01-01 11:59:33 +000065# define VG_MAX_INSTR_SZB 4
sewardj807725e2010-10-12 10:13:17 +000066# define VG_CLREQ_SZB 20
sewardj59570ff2010-01-01 11:59:33 +000067# define VG_STACK_REDZONE_SZB 0
68
sewardjb5b87402011-03-07 16:05:35 +000069#elif defined(VGP_s390x_linux)
70# define VG_MIN_INSTR_SZB 2
71# define VG_MAX_INSTR_SZB 6
72# define VG_CLREQ_SZB 10
73# define VG_STACK_REDZONE_SZB 0 // s390 has no redzone
74
njnf76d27a2009-05-28 01:53:07 +000075#elif defined(VGP_x86_darwin)
76# define VG_MIN_INSTR_SZB 1 // min length of native instruction
77# define VG_MAX_INSTR_SZB 16 // max length of native instruction
78# define VG_CLREQ_SZB 14 // length of a client request, may
79 // be larger than VG_MAX_INSTR_SZB
80# define VG_STACK_REDZONE_SZB 0 // number of addressable bytes below %RSP
sewardj59570ff2010-01-01 11:59:33 +000081
njnf76d27a2009-05-28 01:53:07 +000082#elif defined(VGP_amd64_darwin)
83# define VG_MIN_INSTR_SZB 1
84# define VG_MAX_INSTR_SZB 16
85# define VG_CLREQ_SZB 19
86# define VG_STACK_REDZONE_SZB 128
sewardj59570ff2010-01-01 11:59:33 +000087
sewardj5db15402012-06-07 09:13:21 +000088#elif defined(VGP_mips32_linux)
89# define VG_MIN_INSTR_SZB 4
90# define VG_MAX_INSTR_SZB 4
91# define VG_CLREQ_SZB 20
92# define VG_STACK_REDZONE_SZB 0
93
njnf536bbb2005-06-13 04:21:38 +000094#else
sewardjf1c91e02006-10-17 01:35:58 +000095# error Unknown platform
njnf536bbb2005-06-13 04:21:38 +000096#endif
97
98// Guest state accessors
sewardj1dbd3372010-08-22 12:21:14 +000099// Are mostly in the core_ header.
100// Only these two are available to tools.
101Addr VG_(get_IP) ( ThreadId tid );
102Addr VG_(get_SP) ( ThreadId tid );
njnf536bbb2005-06-13 04:21:38 +0000103
njnf536bbb2005-06-13 04:21:38 +0000104
sewardj9c606bd2008-09-18 18:12:50 +0000105// For get/set, 'area' is where the asked-for guest state will be copied
106// into/from. If shadowNo == 0, the real (non-shadow) guest state is
107// accessed. If shadowNo == 1, the first shadow area is accessed, and
108// if shadowNo == 2, the second shadow area is accessed. This gives a
109// completely general way to read/modify a thread's guest register state
110// providing you know the offsets you need.
sewardj7cf4e6b2008-05-01 20:24:26 +0000111void
112VG_(get_shadow_regs_area) ( ThreadId tid,
113 /*DST*/UChar* dst,
njnc4431bf2009-01-15 21:29:24 +0000114 /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size );
sewardj7cf4e6b2008-05-01 20:24:26 +0000115void
116VG_(set_shadow_regs_area) ( ThreadId tid,
njnc4431bf2009-01-15 21:29:24 +0000117 /*DST*/Int shadowNo, PtrdiffT offset, SizeT size,
sewardj7cf4e6b2008-05-01 20:24:26 +0000118 /*SRC*/const UChar* src );
njnf536bbb2005-06-13 04:21:38 +0000119
sewardj9c606bd2008-09-18 18:12:50 +0000120// Sets the shadow values for the syscall return value register(s).
121// This is platform specific.
122void VG_(set_syscall_return_shadows) ( ThreadId tid,
123 /* shadow vals for the result */
124 UWord s1res, UWord s2res,
125 /* shadow vals for the error val */
126 UWord s1err, UWord s2err );
127
njn6ace3ea2005-06-17 03:06:27 +0000128// Apply a function 'f' to all the general purpose registers in all the
129// current threads.
130// This is very Memcheck-specific -- it's used to find the roots when
131// doing leak checking.
philippea22f59d2012-01-26 23:13:52 +0000132extern void VG_(apply_to_GP_regs)(void (*f)(ThreadId tid,
florian6bd9dc12012-11-23 16:17:43 +0000133 const HChar* regname, UWord val));
njn6ace3ea2005-06-17 03:06:27 +0000134
sewardjb8b79ad2008-03-03 01:35:41 +0000135// This iterator lets you inspect each live thread's stack bounds.
136// Returns False at the end. 'tid' is the iterator and you can only
137// safely change it by making calls to these functions.
138extern void VG_(thread_stack_reset_iter) ( /*OUT*/ThreadId* tid );
139extern Bool VG_(thread_stack_next) ( /*MOD*/ThreadId* tid,
140 /*OUT*/Addr* stack_min,
141 /*OUT*/Addr* stack_max );
njnb506bd82005-06-21 04:01:51 +0000142
sewardjbbec7722007-11-25 14:08:53 +0000143// Returns .client_stack_highest_word for the given thread
144extern Addr VG_(thread_get_stack_max) ( ThreadId tid );
145
bart0fb03202008-03-29 09:25:53 +0000146// Returns how many bytes have been allocated for the stack of the given thread
bart019a43f2010-09-02 14:41:05 +0000147extern SizeT VG_(thread_get_stack_size) ( ThreadId tid );
bart0fb03202008-03-29 09:25:53 +0000148
bart83c5a922010-09-02 14:38:38 +0000149// Returns the bottommost address of the alternate signal stack.
150// See also the man page of sigaltstack().
151extern Addr VG_(thread_get_altstack_min) ( ThreadId tid );
152
153// Returns how many bytes have been allocated for the alternate signal stack.
154// See also the man page of sigaltstack().
155extern SizeT VG_(thread_get_altstack_size) ( ThreadId tid );
156
sewardj53ee1fc2005-12-23 02:29:58 +0000157// Given a pointer to a function as obtained by "& functionname" in C,
158// produce a pointer to the actual entry point for the function. For
159// most platforms it's the identity function. Unfortunately, on
160// ppc64-linux it isn't (sigh).
161extern void* VG_(fnptr_to_fnentry)( void* );
162
sewardj98763d52012-06-03 22:40:07 +0000163/* Returns the size of the largest guest register that we will
164 simulate in this run. This depends on both the guest architecture
165 and on the specific capabilities we are simulating for that guest
166 (eg, AVX or non-AVX ?, for amd64). */
167extern Int VG_(machine_get_size_of_largest_guest_register) ( void );
168
florian78627012012-10-07 19:47:04 +0000169/* Return host cpu info. */
170extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*,
171 /*OUT*/VexArchInfo* );
172
njn4a164d02005-06-18 18:49:40 +0000173#endif // __PUB_TOOL_MACHINE_H
njnf536bbb2005-06-13 04:21:38 +0000174
175/*--------------------------------------------------------------------*/
176/*--- end ---*/
177/*--------------------------------------------------------------------*/