Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-31 08:32:47

0001 
0002 /*--------------------------------------------------------------------*/
0003 /*--- Machine-related stuff.                    pub_tool_machine.h ---*/
0004 /*--------------------------------------------------------------------*/
0005 
0006 /*
0007    This file is part of Valgrind, a dynamic binary instrumentation
0008    framework.
0009 
0010    Copyright (C) 2000-2017 Julian Seward
0011       jseward@acm.org
0012 
0013    This program is free software; you can redistribute it and/or
0014    modify it under the terms of the GNU General Public License as
0015    published by the Free Software Foundation; either version 2 of the
0016    License, or (at your option) any later version.
0017 
0018    This program is distributed in the hope that it will be useful, but
0019    WITHOUT ANY WARRANTY; without even the implied warranty of
0020    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0021    General Public License for more details.
0022 
0023    You should have received a copy of the GNU General Public License
0024    along with this program; if not, see <http://www.gnu.org/licenses/>.
0025 
0026    The GNU General Public License is contained in the file COPYING.
0027 */
0028 
0029 #ifndef __PUB_TOOL_MACHINE_H
0030 #define __PUB_TOOL_MACHINE_H
0031 
0032 #include "pub_tool_basics.h"           // ThreadID
0033 #include "libvex.h"                    // VexArchInfo
0034 
0035 #if defined(VGP_x86_linux) || defined(VGP_x86_solaris) || defined(VGP_x86_freebsd)
0036 #  define VG_MIN_INSTR_SZB          1  // min length of native instruction
0037 #  define VG_MAX_INSTR_SZB         16  // max length of native instruction
0038 #  define VG_CLREQ_SZB             14  // length of a client request, may
0039                                        //   be larger than VG_MAX_INSTR_SZB
0040 #  define VG_STACK_REDZONE_SZB      0  // number of addressable bytes below %RSP
0041 
0042 #elif defined(VGP_amd64_linux) || defined(VGP_amd64_solaris) || defined(VGP_amd64_freebsd)
0043 #  define VG_MIN_INSTR_SZB          1
0044 #  define VG_MAX_INSTR_SZB         16
0045 #  define VG_CLREQ_SZB             19
0046 #  define VG_STACK_REDZONE_SZB    128
0047 
0048 #elif defined(VGP_ppc32_linux)
0049 #  define VG_MIN_INSTR_SZB          4
0050 #  define VG_MAX_INSTR_SZB          4 
0051 #  define VG_CLREQ_SZB             20
0052 #  define VG_STACK_REDZONE_SZB      0
0053 
0054 #elif defined(VGP_ppc64be_linux)  || defined(VGP_ppc64le_linux)
0055 #  define VG_MIN_INSTR_SZB          4
0056 #  define VG_MAX_INSTR_SZB          8 // Prefix inst 8 bytes, word inst 4 bytes
0057 #  define VG_CLREQ_SZB             20
0058 #  define VG_STACK_REDZONE_SZB    288  // number of addressable bytes below R1
0059                                        // from 64-bit PowerPC ELF ABI 
0060                                        // Supplement 1.7
0061 
0062 #elif defined(VGP_arm_linux)
0063 #  define VG_MIN_INSTR_SZB          2
0064 #  define VG_MAX_INSTR_SZB          4 
0065 #  define VG_CLREQ_SZB             20
0066 #  define VG_STACK_REDZONE_SZB      0
0067 
0068 #elif defined(VGP_arm64_linux) || defined(VGP_arm64_freebsd)
0069 #  define VG_MIN_INSTR_SZB          4
0070 #  define VG_MAX_INSTR_SZB          4 
0071 #  define VG_CLREQ_SZB             20
0072 #  define VG_STACK_REDZONE_SZB      0
0073 
0074 #elif defined(VGP_s390x_linux)
0075 #  define VG_MIN_INSTR_SZB          2
0076 #  define VG_MAX_INSTR_SZB          6
0077 #  define VG_CLREQ_SZB             10
0078 #  define VG_STACK_REDZONE_SZB      0  // s390 has no redzone
0079 
0080 #elif defined(VGP_x86_darwin)
0081 #  define VG_MIN_INSTR_SZB          1  // min length of native instruction
0082 #  define VG_MAX_INSTR_SZB         16  // max length of native instruction
0083 #  define VG_CLREQ_SZB             14  // length of a client request, may
0084                                        //   be larger than VG_MAX_INSTR_SZB
0085 #  define VG_STACK_REDZONE_SZB      0  // number of addressable bytes below %RSP
0086 
0087 #elif defined(VGP_amd64_darwin)
0088 #  define VG_MIN_INSTR_SZB          1
0089 #  define VG_MAX_INSTR_SZB         16
0090 #  define VG_CLREQ_SZB             19
0091 #  define VG_STACK_REDZONE_SZB    128
0092 
0093 #elif defined(VGP_mips32_linux)
0094 #  define VG_MIN_INSTR_SZB          4
0095 #  define VG_MAX_INSTR_SZB          8
0096 #  define VG_CLREQ_SZB             20
0097 #  define VG_STACK_REDZONE_SZB      0
0098 
0099 #elif defined(VGP_mips64_linux)
0100 #  define VG_MIN_INSTR_SZB          4
0101 #  define VG_MAX_INSTR_SZB          8
0102 #  define VG_CLREQ_SZB             20
0103 #  define VG_STACK_REDZONE_SZB      0
0104 
0105 #elif defined(VGP_nanomips_linux)
0106 #  define VG_MIN_INSTR_SZB          2
0107 #  define VG_MAX_INSTR_SZB          6
0108 #  define VG_CLREQ_SZB             20
0109 #  define VG_STACK_REDZONE_SZB      0
0110 
0111 #elif defined(VGP_riscv64_linux)
0112 #  define VG_MIN_INSTR_SZB          2
0113 #  define VG_MAX_INSTR_SZB          4
0114 #  define VG_CLREQ_SZB             20
0115 #  define VG_STACK_REDZONE_SZB      0
0116 
0117 #else
0118 #  error Unknown platform
0119 #endif
0120 
0121 // Guest state accessors
0122 // Are mostly in the core_ header.
0123 //  Only these two are available to tools.
0124 Addr VG_(get_IP) ( ThreadId tid );
0125 Addr VG_(get_SP) ( ThreadId tid );
0126 
0127 // Get and set the shadow1 SP register
0128 Addr VG_(get_SP_s1) ( ThreadId tid );
0129 void VG_(set_SP_s1) ( ThreadId tid, Addr sp );
0130 
0131 // For get/set, 'area' is where the asked-for guest state will be copied
0132 // into/from.  If shadowNo == 0, the real (non-shadow) guest state is
0133 // accessed.  If shadowNo == 1, the first shadow area is accessed, and
0134 // if shadowNo == 2, the second shadow area is accessed.  This gives a
0135 // completely general way to read/modify a thread's guest register state
0136 // providing you know the offsets you need.
0137 void
0138 VG_(get_shadow_regs_area) ( ThreadId tid, 
0139                             /*DST*/UChar* dst,
0140                             /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size );
0141 void
0142 VG_(set_shadow_regs_area) ( ThreadId tid, 
0143                             /*DST*/Int shadowNo, PtrdiffT offset, SizeT size,
0144                             /*SRC*/const UChar* src );
0145 
0146 // Apply a function 'f' to all the general purpose registers in all the
0147 // current threads. This is all live threads, or (when the process is exiting)
0148 // all threads that were instructed to die by the thread calling exit.
0149 // This is very Memcheck-specific -- it's used to find the roots when
0150 // doing leak checking.
0151 extern void VG_(apply_to_GP_regs)(void (*f)(ThreadId tid,
0152                                             const HChar* regname, UWord val));
0153 
0154 // This iterator lets you inspect each live thread's stack bounds.
0155 // Returns False at the end.  'tid' is the iterator and you can only
0156 // safely change it by making calls to these functions.
0157 extern void VG_(thread_stack_reset_iter) ( /*OUT*/ThreadId* tid );
0158 // stack_min is the address of the lowest stack byte,
0159 // stack_max is the address of the highest stack byte.
0160 // In other words, the live stack is [stack_min, stack_max].
0161 extern Bool VG_(thread_stack_next)       ( /*MOD*/ThreadId* tid,
0162                                            /*OUT*/Addr* stack_min, 
0163                                            /*OUT*/Addr* stack_max );
0164 
0165 // Returns .client_stack_highest_byte for the given thread
0166 // i.e. the highest addressable byte of the stack.
0167 extern Addr VG_(thread_get_stack_max) ( ThreadId tid );
0168 
0169 // Returns how many bytes have been allocated for the stack of the given thread
0170 extern SizeT VG_(thread_get_stack_size) ( ThreadId tid );
0171 
0172 // Returns the lowest address of the alternate signal stack.
0173 // See also the man page of sigaltstack().
0174 extern Addr VG_(thread_get_altstack_min) ( ThreadId tid );
0175 
0176 // Returns how many bytes have been allocated for the alternate signal stack.
0177 // See also the man page of sigaltstack().
0178 extern SizeT VG_(thread_get_altstack_size) ( ThreadId tid );
0179 
0180 // Given a pointer to a function as obtained by "& functionname" in C,
0181 // produce a pointer to the actual entry point for the function.  For
0182 // most platforms it's the identity function.  Unfortunately, on
0183 // ppc64-linux it isn't (sigh).
0184 extern void* VG_(fnptr_to_fnentry)( void* );
0185 
0186 /* Returns the size of the largest guest register that we will
0187    simulate in this run.  This depends on both the guest architecture
0188    and on the specific capabilities we are simulating for that guest
0189    (eg, AVX or non-AVX ?, for amd64). */
0190 extern Int VG_(machine_get_size_of_largest_guest_register) ( void );
0191 
0192 /* Return host cpu info. */
0193 extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*,
0194                                           /*OUT*/VexArchInfo* );
0195 
0196 #endif   // __PUB_TOOL_MACHINE_H
0197 
0198 /*--------------------------------------------------------------------*/
0199 /*--- end                                                          ---*/
0200 /*--------------------------------------------------------------------*/