Turn off unused result warnings
[valgrind.git] / include / pub_tool_machine.h
blobf462072572873df4cdc83620d4268c08471b070d
2 /*--------------------------------------------------------------------*/
3 /*--- Machine-related stuff. pub_tool_machine.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2000-2017 Julian Seward
11 jseward@acm.org
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
29 #ifndef __PUB_TOOL_MACHINE_H
30 #define __PUB_TOOL_MACHINE_H
32 #include "pub_tool_basics.h" // ThreadID
33 #include "libvex.h" // VexArchInfo
35 #if defined(VGP_x86_linux) || defined(VGP_x86_solaris) || defined(VGP_x86_freebsd)
36 # define VG_MIN_INSTR_SZB 1 // min length of native instruction
37 # define VG_MAX_INSTR_SZB 16 // max length of native instruction
38 # define VG_CLREQ_SZB 14 // length of a client request, may
39 // be larger than VG_MAX_INSTR_SZB
40 # define VG_STACK_REDZONE_SZB 0 // number of addressable bytes below %RSP
42 #elif defined(VGP_amd64_linux) || defined(VGP_amd64_solaris) || defined(VGP_amd64_freebsd)
43 # define VG_MIN_INSTR_SZB 1
44 # define VG_MAX_INSTR_SZB 16
45 # define VG_CLREQ_SZB 19
46 # define VG_STACK_REDZONE_SZB 128
48 #elif defined(VGP_ppc32_linux)
49 # define VG_MIN_INSTR_SZB 4
50 # define VG_MAX_INSTR_SZB 4
51 # define VG_CLREQ_SZB 20
52 # define VG_STACK_REDZONE_SZB 0
54 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
55 # define VG_MIN_INSTR_SZB 4
56 # define VG_MAX_INSTR_SZB 8 // Prefix inst 8 bytes, word inst 4 bytes
57 # define VG_CLREQ_SZB 20
58 # define VG_STACK_REDZONE_SZB 288 // number of addressable bytes below R1
59 // from 64-bit PowerPC ELF ABI
60 // Supplement 1.7
62 #elif defined(VGP_arm_linux)
63 # define VG_MIN_INSTR_SZB 2
64 # define VG_MAX_INSTR_SZB 4
65 # define VG_CLREQ_SZB 20
66 # define VG_STACK_REDZONE_SZB 0
68 #elif defined(VGP_arm64_linux) || defined(VGP_arm64_freebsd)
69 # define VG_MIN_INSTR_SZB 4
70 # define VG_MAX_INSTR_SZB 4
71 # define VG_CLREQ_SZB 20
72 # define VG_STACK_REDZONE_SZB 0
74 #elif defined(VGP_s390x_linux)
75 # define VG_MIN_INSTR_SZB 2
76 # define VG_MAX_INSTR_SZB 6
77 # define VG_CLREQ_SZB 10
78 # define VG_STACK_REDZONE_SZB 0 // s390 has no redzone
80 #elif defined(VGP_x86_darwin)
81 # define VG_MIN_INSTR_SZB 1 // min length of native instruction
82 # define VG_MAX_INSTR_SZB 16 // max length of native instruction
83 # define VG_CLREQ_SZB 14 // length of a client request, may
84 // be larger than VG_MAX_INSTR_SZB
85 # define VG_STACK_REDZONE_SZB 0 // number of addressable bytes below %RSP
87 #elif defined(VGP_amd64_darwin)
88 # define VG_MIN_INSTR_SZB 1
89 # define VG_MAX_INSTR_SZB 16
90 # define VG_CLREQ_SZB 19
91 # define VG_STACK_REDZONE_SZB 128
93 #elif defined(VGP_mips32_linux)
94 # define VG_MIN_INSTR_SZB 4
95 # define VG_MAX_INSTR_SZB 8
96 # define VG_CLREQ_SZB 20
97 # define VG_STACK_REDZONE_SZB 0
99 #elif defined(VGP_mips64_linux)
100 # define VG_MIN_INSTR_SZB 4
101 # define VG_MAX_INSTR_SZB 8
102 # define VG_CLREQ_SZB 20
103 # define VG_STACK_REDZONE_SZB 0
105 #elif defined(VGP_nanomips_linux)
106 # define VG_MIN_INSTR_SZB 2
107 # define VG_MAX_INSTR_SZB 6
108 # define VG_CLREQ_SZB 20
109 # define VG_STACK_REDZONE_SZB 0
111 #else
112 # error Unknown platform
113 #endif
115 // Guest state accessors
116 // Are mostly in the core_ header.
117 // Only these two are available to tools.
118 Addr VG_(get_IP) ( ThreadId tid );
119 Addr VG_(get_SP) ( ThreadId tid );
121 // Get and set the shadow1 SP register
122 Addr VG_(get_SP_s1) ( ThreadId tid );
123 void VG_(set_SP_s1) ( ThreadId tid, Addr sp );
125 // For get/set, 'area' is where the asked-for guest state will be copied
126 // into/from. If shadowNo == 0, the real (non-shadow) guest state is
127 // accessed. If shadowNo == 1, the first shadow area is accessed, and
128 // if shadowNo == 2, the second shadow area is accessed. This gives a
129 // completely general way to read/modify a thread's guest register state
130 // providing you know the offsets you need.
131 void
132 VG_(get_shadow_regs_area) ( ThreadId tid,
133 /*DST*/UChar* dst,
134 /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size );
135 void
136 VG_(set_shadow_regs_area) ( ThreadId tid,
137 /*DST*/Int shadowNo, PtrdiffT offset, SizeT size,
138 /*SRC*/const UChar* src );
140 // Apply a function 'f' to all the general purpose registers in all the
141 // current threads. This is all live threads, or (when the process is exiting)
142 // all threads that were instructed to die by the thread calling exit.
143 // This is very Memcheck-specific -- it's used to find the roots when
144 // doing leak checking.
145 extern void VG_(apply_to_GP_regs)(void (*f)(ThreadId tid,
146 const HChar* regname, UWord val));
148 // This iterator lets you inspect each live thread's stack bounds.
149 // Returns False at the end. 'tid' is the iterator and you can only
150 // safely change it by making calls to these functions.
151 extern void VG_(thread_stack_reset_iter) ( /*OUT*/ThreadId* tid );
152 // stack_min is the address of the lowest stack byte,
153 // stack_max is the address of the highest stack byte.
154 // In other words, the live stack is [stack_min, stack_max].
155 extern Bool VG_(thread_stack_next) ( /*MOD*/ThreadId* tid,
156 /*OUT*/Addr* stack_min,
157 /*OUT*/Addr* stack_max );
159 // Returns .client_stack_highest_byte for the given thread
160 // i.e. the highest addressable byte of the stack.
161 extern Addr VG_(thread_get_stack_max) ( ThreadId tid );
163 // Returns how many bytes have been allocated for the stack of the given thread
164 extern SizeT VG_(thread_get_stack_size) ( ThreadId tid );
166 // Returns the lowest address of the alternate signal stack.
167 // See also the man page of sigaltstack().
168 extern Addr VG_(thread_get_altstack_min) ( ThreadId tid );
170 // Returns how many bytes have been allocated for the alternate signal stack.
171 // See also the man page of sigaltstack().
172 extern SizeT VG_(thread_get_altstack_size) ( ThreadId tid );
174 // Given a pointer to a function as obtained by "& functionname" in C,
175 // produce a pointer to the actual entry point for the function. For
176 // most platforms it's the identity function. Unfortunately, on
177 // ppc64-linux it isn't (sigh).
178 extern void* VG_(fnptr_to_fnentry)( void* );
180 /* Returns the size of the largest guest register that we will
181 simulate in this run. This depends on both the guest architecture
182 and on the specific capabilities we are simulating for that guest
183 (eg, AVX or non-AVX ?, for amd64). */
184 extern Int VG_(machine_get_size_of_largest_guest_register) ( void );
186 /* Return host cpu info. */
187 extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*,
188 /*OUT*/VexArchInfo* );
190 #endif // __PUB_TOOL_MACHINE_H
192 /*--------------------------------------------------------------------*/
193 /*--- end ---*/
194 /*--------------------------------------------------------------------*/