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
10   Copyright (C) 2000-2013 Julian Seward
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_TOOL_MACHINE_H
32#define __PUB_TOOL_MACHINE_H
33
34#include "pub_tool_basics.h"           // ThreadID
35#include "libvex.h"                    // VexArchInfo
36
37#if defined(VGP_x86_linux)
38#  define VG_MIN_INSTR_SZB          1  // min length of native instruction
39#  define VG_MAX_INSTR_SZB         16  // max length of native instruction
40#  define VG_CLREQ_SZB             14  // length of a client request, may
41                                       //   be larger than VG_MAX_INSTR_SZB
42#  define VG_STACK_REDZONE_SZB      0  // number of addressable bytes below %RSP
43
44#elif defined(VGP_amd64_linux)
45#  define VG_MIN_INSTR_SZB          1
46#  define VG_MAX_INSTR_SZB         16
47#  define VG_CLREQ_SZB             19
48#  define VG_STACK_REDZONE_SZB    128
49
50#elif defined(VGP_ppc32_linux)
51#  define VG_MIN_INSTR_SZB          4
52#  define VG_MAX_INSTR_SZB          4
53#  define VG_CLREQ_SZB             20
54#  define VG_STACK_REDZONE_SZB      0
55
56#elif defined(VGP_ppc64_linux)
57#  define VG_MIN_INSTR_SZB          4
58#  define VG_MAX_INSTR_SZB          4
59#  define VG_CLREQ_SZB             20
60#  define VG_STACK_REDZONE_SZB    288  // number of addressable bytes below R1
61                                       // from 64-bit PowerPC ELF ABI
62                                       // Supplement 1.7
63
64#elif defined(VGP_arm_linux)
65#  define VG_MIN_INSTR_SZB          2
66#  define VG_MAX_INSTR_SZB          4
67#  define VG_CLREQ_SZB             20
68#  define VG_STACK_REDZONE_SZB      0
69
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
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
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
88
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
94
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
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
107#else
108#  error Unknown platform
109#endif
110
111// Guest state accessors
112// 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 );
116
117
118// 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.
124void
125VG_(get_shadow_regs_area) ( ThreadId tid,
126                            /*DST*/UChar* dst,
127                            /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size );
128void
129VG_(set_shadow_regs_area) ( ThreadId tid,
130                            /*DST*/Int shadowNo, PtrdiffT offset, SizeT size,
131                            /*SRC*/const UChar* src );
132
133// Apply a function 'f' to all the general purpose registers in all the
134// 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.
136// This is very Memcheck-specific -- it's used to find the roots when
137// doing leak checking.
138extern void VG_(apply_to_GP_regs)(void (*f)(ThreadId tid,
139                                            const HChar* regname, UWord val));
140
141// 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 );
145extern Bool VG_(thread_stack_next)       ( /*MOD*/ThreadId* tid,
146                                           /*OUT*/Addr* stack_min,
147                                           /*OUT*/Addr* stack_max );
148
149// Returns .client_stack_highest_word for the given thread
150extern Addr VG_(thread_get_stack_max) ( ThreadId tid );
151
152// Returns how many bytes have been allocated for the stack of the given thread
153extern SizeT VG_(thread_get_stack_size) ( ThreadId tid );
154
155// Returns the bottommost address of the alternate signal stack.
156// See also the man page of sigaltstack().
157extern Addr VG_(thread_get_altstack_min) ( ThreadId tid );
158
159// Returns how many bytes have been allocated for the alternate signal stack.
160// See also the man page of sigaltstack().
161extern SizeT VG_(thread_get_altstack_size) ( ThreadId tid );
162
163// Given a pointer to a function as obtained by "& functionname" in C,
164// produce a pointer to the actual entry point for the function.  For
165// most platforms it's the identity function.  Unfortunately, on
166// ppc64-linux it isn't (sigh).
167extern void* VG_(fnptr_to_fnentry)( void* );
168
169/* Returns the size of the largest guest register that we will
170   simulate in this run.  This depends on both the guest architecture
171   and on the specific capabilities we are simulating for that guest
172   (eg, AVX or non-AVX ?, for amd64). */
173extern Int VG_(machine_get_size_of_largest_guest_register) ( void );
174
175/* Return host cpu info. */
176extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*,
177                                          /*OUT*/VexArchInfo* );
178
179#endif   // __PUB_TOOL_MACHINE_H
180
181/*--------------------------------------------------------------------*/
182/*--- end                                                          ---*/
183/*--------------------------------------------------------------------*/
184