Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:31

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