Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-27 09:40:34

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 3 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) || defined(VGP_x86_darwin)
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) || defined(VGP_amd64_darwin)
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_mips32_linux)
0081 #  define VG_MIN_INSTR_SZB          4
0082 #  define VG_MAX_INSTR_SZB          8
0083 #  define VG_CLREQ_SZB             20
0084 #  define VG_STACK_REDZONE_SZB      0
0085 
0086 #elif defined(VGP_mips64_linux)
0087 #  define VG_MIN_INSTR_SZB          4
0088 #  define VG_MAX_INSTR_SZB          8
0089 #  define VG_CLREQ_SZB             20
0090 #  define VG_STACK_REDZONE_SZB      0
0091 
0092 #elif defined(VGP_nanomips_linux)
0093 #  define VG_MIN_INSTR_SZB          2
0094 #  define VG_MAX_INSTR_SZB          6
0095 #  define VG_CLREQ_SZB             20
0096 #  define VG_STACK_REDZONE_SZB      0
0097 
0098 #elif defined(VGP_riscv64_linux)
0099 #  define VG_MIN_INSTR_SZB          2
0100 #  define VG_MAX_INSTR_SZB          4
0101 #  define VG_CLREQ_SZB             20
0102 #  define VG_STACK_REDZONE_SZB      0
0103 
0104 #else
0105 #  error Unknown platform
0106 #endif
0107 
0108 // Guest state accessors
0109 // Are mostly in the core_ header.
0110 //  Only these two are available to tools.
0111 Addr VG_(get_IP) ( ThreadId tid );
0112 Addr VG_(get_SP) ( ThreadId tid );
0113 
0114 // Get and set the shadow1 SP register
0115 Addr VG_(get_SP_s1) ( ThreadId tid );
0116 void VG_(set_SP_s1) ( ThreadId tid, Addr sp );
0117 
0118 // For get/set, 'area' is where the asked-for guest state will be copied
0119 // into/from.  If shadowNo == 0, the real (non-shadow) guest state is
0120 // accessed.  If shadowNo == 1, the first shadow area is accessed, and
0121 // if shadowNo == 2, the second shadow area is accessed.  This gives a
0122 // completely general way to read/modify a thread's guest register state
0123 // providing you know the offsets you need.
0124 void
0125 VG_(get_shadow_regs_area) ( ThreadId tid, 
0126                             /*DST*/UChar* dst,
0127                             /*SRC*/Int shadowNo, PtrdiffT offset, SizeT size );
0128 void
0129 VG_(set_shadow_regs_area) ( ThreadId tid, 
0130                             /*DST*/Int shadowNo, PtrdiffT offset, SizeT size,
0131                             /*SRC*/const UChar* src );
0132 
0133 // Apply a function 'f' to all the general purpose registers in all the
0134 // current threads. This is all live threads, or (when the process is exiting)
0135 // all threads that were instructed to die by the thread calling exit.
0136 // This is very Memcheck-specific -- it's used to find the roots when
0137 // doing leak checking.
0138 extern void VG_(apply_to_GP_regs)(void (*f)(ThreadId tid,
0139                                             const HChar* regname, UWord val));
0140 
0141 // This iterator lets you inspect each live thread's stack bounds.
0142 // Returns False at the end.  'tid' is the iterator and you can only
0143 // safely change it by making calls to these functions.
0144 extern void VG_(thread_stack_reset_iter) ( /*OUT*/ThreadId* tid );
0145 // stack_min is the address of the lowest stack byte,
0146 // stack_max is the address of the highest stack byte.
0147 // In other words, the live stack is [stack_min, stack_max].
0148 extern Bool VG_(thread_stack_next)       ( /*MOD*/ThreadId* tid,
0149                                            /*OUT*/Addr* stack_min, 
0150                                            /*OUT*/Addr* stack_max );
0151 
0152 // Returns .client_stack_highest_byte for the given thread
0153 // i.e. the highest addressable byte of the stack.
0154 extern Addr VG_(thread_get_stack_max) ( ThreadId tid );
0155 
0156 // Returns how many bytes have been allocated for the stack of the given thread
0157 extern SizeT VG_(thread_get_stack_size) ( ThreadId tid );
0158 
0159 // Returns the lowest address of the alternate signal stack.
0160 // See also the man page of sigaltstack().
0161 extern Addr VG_(thread_get_altstack_min) ( ThreadId tid );
0162 
0163 // Returns how many bytes have been allocated for the alternate signal stack.
0164 // See also the man page of sigaltstack().
0165 extern SizeT VG_(thread_get_altstack_size) ( ThreadId tid );
0166 
0167 // Given a pointer to a function as obtained by "& functionname" in C,
0168 // produce a pointer to the actual entry point for the function.  For
0169 // most platforms it's the identity function.  Unfortunately, on
0170 // ppc64-linux it isn't (sigh).
0171 extern void* VG_(fnptr_to_fnentry)( void* );
0172 
0173 /* Returns the size of the largest guest register that we will
0174    simulate in this run.  This depends on both the guest architecture
0175    and on the specific capabilities we are simulating for that guest
0176    (eg, AVX or non-AVX ?, for amd64). */
0177 extern Int VG_(machine_get_size_of_largest_guest_register) ( void );
0178 
0179 /* Return host cpu info. */
0180 extern void VG_(machine_get_VexArchInfo)( /*OUT*/VexArch*,
0181                                           /*OUT*/VexArchInfo* );
0182 
0183 #endif   // __PUB_TOOL_MACHINE_H
0184 
0185 /*--------------------------------------------------------------------*/
0186 /*--- end                                                          ---*/
0187 /*--------------------------------------------------------------------*/