blob: 07b7b95f2153ae272e1cac78ec3703ea23b6a736 [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
Elliott Hughesed398002017-06-21 14:41:24 -070010 Copyright (C) 2000-2017 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
florian535fb1b2013-09-15 13:54:34 +000034#include "pub_tool_basics.h" // ThreadID
florian78627012012-10-07 19:47:04 +000035#include "libvex.h" // VexArchInfo
36
sewardj8eb8bab2015-07-21 14:44:28 +000037#if defined(VGP_x86_linux) || defined(VGP_x86_solaris)
njna5ad9ba2005-11-10 15:20:37 +000038# define VG_MIN_INSTR_SZB 1 // min length of native instruction
39# define VG_MAX_INSTR_SZB 16 // max length of native instruction
sewardj0ec07f32006-01-12 12:32:32 +000040# define VG_CLREQ_SZB 14 // length of a client request, may
njna5ad9ba2005-11-10 15:20:37 +000041 // be larger than VG_MAX_INSTR_SZB
sewardjc2812332005-12-23 23:34:51 +000042# define VG_STACK_REDZONE_SZB 0 // number of addressable bytes below %RSP
sewardj59570ff2010-01-01 11:59:33 +000043
sewardj8eb8bab2015-07-21 14:44:28 +000044#elif defined(VGP_amd64_linux) || defined(VGP_amd64_solaris)
njnaf839f52005-06-23 03:27:57 +000045# define VG_MIN_INSTR_SZB 1
46# define VG_MAX_INSTR_SZB 16
sewardj0ec07f32006-01-12 12:32:32 +000047# define VG_CLREQ_SZB 19
njnaf839f52005-06-23 03:27:57 +000048# define VG_STACK_REDZONE_SZB 128
sewardj59570ff2010-01-01 11:59:33 +000049
sewardjf1c91e02006-10-17 01:35:58 +000050#elif defined(VGP_ppc32_linux)
njnaf839f52005-06-23 03:27:57 +000051# define VG_MIN_INSTR_SZB 4
52# define VG_MAX_INSTR_SZB 4
sewardjd68ac3e2006-01-20 14:31:57 +000053# define VG_CLREQ_SZB 20
njnaf839f52005-06-23 03:27:57 +000054# define VG_STACK_REDZONE_SZB 0
sewardj59570ff2010-01-01 11:59:33 +000055
carllcae0cc22014-08-07 23:17:29 +000056#elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
sewardj2c48c7b2005-11-29 13:05:56 +000057# define VG_MIN_INSTR_SZB 4
58# define VG_MAX_INSTR_SZB 4
sewardjd68ac3e2006-01-20 14:31:57 +000059# define VG_CLREQ_SZB 20
sewardjc2812332005-12-23 23:34:51 +000060# define VG_STACK_REDZONE_SZB 288 // number of addressable bytes below R1
sewardj59570ff2010-01-01 11:59:33 +000061 // from 64-bit PowerPC ELF ABI
62 // Supplement 1.7
63
64#elif defined(VGP_arm_linux)
sewardj1dbd3372010-08-22 12:21:14 +000065# define VG_MIN_INSTR_SZB 2
sewardj59570ff2010-01-01 11:59:33 +000066# define VG_MAX_INSTR_SZB 4
sewardj807725e2010-10-12 10:13:17 +000067# define VG_CLREQ_SZB 20
sewardj59570ff2010-01-01 11:59:33 +000068# define VG_STACK_REDZONE_SZB 0
69
sewardjf0c12502014-01-12 12:54:00 +000070#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
sewardjb5b87402011-03-07 16:05:35 +000076#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
njnf76d27a2009-05-28 01:53:07 +000082#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
sewardj59570ff2010-01-01 11:59:33 +000088
njnf76d27a2009-05-28 01:53:07 +000089#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
sewardj59570ff2010-01-01 11:59:33 +000094
sewardj5db15402012-06-07 09:13:21 +000095#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
petarj4df0bfc2013-02-27 23:17:33 +0000101#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
njnf536bbb2005-06-13 04:21:38 +0000107#else
sewardjf1c91e02006-10-17 01:35:58 +0000108# error Unknown platform
njnf536bbb2005-06-13 04:21:38 +0000109#endif
110
111// Guest state accessors
sewardj1dbd3372010-08-22 12:21:14 +0000112// Are mostly in the core_ header.
113// Only these two are available to tools.
114Addr VG_(get_IP) ( ThreadId tid );
115Addr VG_(get_SP) ( ThreadId tid );
njnf536bbb2005-06-13 04:21:38 +0000116
njnf536bbb2005-06-13 04:21:38 +0000117
sewardj9c606bd2008-09-18 18:12:50 +0000118// For get/set, 'area' is where the asked-for guest state will be copied
119// into/from. If shadowNo == 0, the real (non-shadow) guest state is
120// accessed. If shadowNo == 1, the first shadow area is accessed, and
121// if shadowNo == 2, the second shadow area is accessed. This gives a
122// completely general way to read/modify a thread's guest register state
123// providing you know the offsets you need.
sewardj7cf4e6b2008-05-01 20:24:26 +0000124void
125VG_(get_shadow_regs_area) ( ThreadId tid,
126 /*DST*/UChar* dst,
njnc4431bf2009-01-15 21:29:24 +0000127 /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size );
sewardj7cf4e6b2008-05-01 20:24:26 +0000128void
129VG_(set_shadow_regs_area) ( ThreadId tid,
njnc4431bf2009-01-15 21:29:24 +0000130 /*DST*/Int shadowNo, PtrdiffT offset, SizeT size,
sewardj7cf4e6b2008-05-01 20:24:26 +0000131 /*SRC*/const UChar* src );
njnf536bbb2005-06-13 04:21:38 +0000132
njn6ace3ea2005-06-17 03:06:27 +0000133// Apply a function 'f' to all the general purpose registers in all the
philippeb8ba0312013-10-21 19:57:08 +0000134// current threads. This is all live threads, or (when the process is exiting)
135// all threads that were instructed to die by the thread calling exit.
njn6ace3ea2005-06-17 03:06:27 +0000136// This is very Memcheck-specific -- it's used to find the roots when
137// doing leak checking.
philippea22f59d2012-01-26 23:13:52 +0000138extern void VG_(apply_to_GP_regs)(void (*f)(ThreadId tid,
florian6bd9dc12012-11-23 16:17:43 +0000139 const HChar* regname, UWord val));
njn6ace3ea2005-06-17 03:06:27 +0000140
sewardjb8b79ad2008-03-03 01:35:41 +0000141// This iterator lets you inspect each live thread's stack bounds.
142// Returns False at the end. 'tid' is the iterator and you can only
143// safely change it by making calls to these functions.
144extern void VG_(thread_stack_reset_iter) ( /*OUT*/ThreadId* tid );
philippe38a74d22014-08-29 22:53:19 +0000145// stack_min is the address of the lowest stack byte,
146// stack_max is the address of the highest stack byte.
147// In other words, the live stack is [stack_min, stack_max].
sewardjb8b79ad2008-03-03 01:35:41 +0000148extern Bool VG_(thread_stack_next) ( /*MOD*/ThreadId* tid,
149 /*OUT*/Addr* stack_min,
150 /*OUT*/Addr* stack_max );
njnb506bd82005-06-21 04:01:51 +0000151
philippe38a74d22014-08-29 22:53:19 +0000152// Returns .client_stack_highest_byte for the given thread
153// i.e. the highest addressable byte of the stack.
sewardjbbec7722007-11-25 14:08:53 +0000154extern Addr VG_(thread_get_stack_max) ( ThreadId tid );
155
bart0fb03202008-03-29 09:25:53 +0000156// Returns how many bytes have been allocated for the stack of the given thread
bart019a43f2010-09-02 14:41:05 +0000157extern SizeT VG_(thread_get_stack_size) ( ThreadId tid );
bart0fb03202008-03-29 09:25:53 +0000158
philippe38a74d22014-08-29 22:53:19 +0000159// Returns the lowest address of the alternate signal stack.
bart83c5a922010-09-02 14:38:38 +0000160// See also the man page of sigaltstack().
161extern Addr VG_(thread_get_altstack_min) ( ThreadId tid );
162
163// Returns how many bytes have been allocated for the alternate signal stack.
164// See also the man page of sigaltstack().
165extern SizeT VG_(thread_get_altstack_size) ( ThreadId tid );
166
sewardj53ee1fc2005-12-23 02:29:58 +0000167// Given a pointer to a function as obtained by "& functionname" in C,
168// produce a pointer to the actual entry point for the function. For
169// most platforms it's the identity function. Unfortunately, on
170// ppc64-linux it isn't (sigh).
171extern void* VG_(fnptr_to_fnentry)( void* );
172
sewardj98763d52012-06-03 22:40:07 +0000173/* Returns the size of the largest guest register that we will
174 simulate in this run. This depends on both the guest architecture
175 and on the specific capabilities we are simulating for that guest
176 (eg, AVX or non-AVX ?, for amd64). */
177extern Int VG_(machine_get_size_of_largest_guest_register) ( void );
178
florian78627012012-10-07 19:47:04 +0000179/* Return host cpu info. */
180extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*,
181 /*OUT*/VexArchInfo* );
182
njn4a164d02005-06-18 18:49:40 +0000183#endif // __PUB_TOOL_MACHINE_H
njnf536bbb2005-06-13 04:21:38 +0000184
185/*--------------------------------------------------------------------*/
186/*--- end ---*/
187/*--------------------------------------------------------------------*/