blob: 6287aecb715351751862d48e24c88cde72f8e1ac [file] [log] [blame]
njn25e49d8e72002-09-23 09:36:25 +00001
2/*--------------------------------------------------------------------*/
3/*--- The only header your skin will ever need to #include... ---*/
4/*--- vg_skin.h ---*/
5/*--------------------------------------------------------------------*/
6
7/*
njnc9539842002-10-02 13:26:35 +00008 This file is part of Valgrind, an extensible x86 protected-mode
9 emulator for monitoring program execution on x86-Unixes.
njn25e49d8e72002-09-23 09:36:25 +000010
11 Copyright (C) 2000-2002 Julian Seward
12 jseward@acm.org
13
14 This program is free software; you can redistribute it and/or
15 modify it under the terms of the GNU General Public License as
16 published by the Free Software Foundation; either version 2 of the
17 License, or (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 02111-1307, USA.
28
29 The GNU General Public License is contained in the file COPYING.
30*/
31
32#ifndef __VG_SKIN_H
33#define __VG_SKIN_H
34
35#include <stdarg.h> /* ANSI varargs stuff */
36#include <setjmp.h> /* for jmp_buf */
37
38#include "vg_constants_skin.h"
39
40
41/*====================================================================*/
42/*=== Build options and table sizes. ===*/
43/*====================================================================*/
44
45/* You should be able to change these options or sizes, recompile, and
46 still have a working system. */
47
48/* The maximum number of pthreads that we support. This is
49 deliberately not very high since our implementation of some of the
50 scheduler algorithms is surely O(N) in the number of threads, since
51 that's simple, at least. And (in practice) we hope that most
52 programs do not need many threads. */
53#define VG_N_THREADS 50
54
55/* Maximum number of pthread keys available. Again, we start low until
56 the need for a higher number presents itself. */
57#define VG_N_THREAD_KEYS 50
58
59/* Total number of integer registers available for allocation -- all of
60 them except %esp, %ebp. %ebp permanently points at VG_(baseBlock).
61
62 If you change this you'll have to also change at least these:
njn4ba5a792002-09-30 10:23:54 +000063 - VG_(rank_to_realreg)()
64 - VG_(realreg_to_rank)()
njn25e49d8e72002-09-23 09:36:25 +000065 - ppRegsLiveness()
66 - the RegsLive type (maybe -- RegsLive type must have more than
67 VG_MAX_REALREGS bits)
68
69 Do not change this unless you really know what you are doing! */
70#define VG_MAX_REALREGS 6
71
72
73/*====================================================================*/
njn1a1dd8b2002-09-27 10:42:20 +000074/*=== Basic types, useful macros ===*/
njn25e49d8e72002-09-23 09:36:25 +000075/*====================================================================*/
76
njn25e49d8e72002-09-23 09:36:25 +000077typedef unsigned char UChar;
78typedef unsigned short UShort;
79typedef unsigned int UInt;
80typedef unsigned long long int ULong;
81
82typedef signed char Char;
83typedef signed short Short;
84typedef signed int Int;
85typedef signed long long int Long;
86
87typedef unsigned int Addr;
88
89typedef unsigned char Bool;
90#define False ((Bool)0)
91#define True ((Bool)1)
92
93
njn1a1dd8b2002-09-27 10:42:20 +000094#define mycat_wrk(aaa,bbb) aaa##bbb
95#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
96
97/* No, really. I _am_ that strange. */
98#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
99
njn25e49d8e72002-09-23 09:36:25 +0000100/* ---------------------------------------------------------------------
101 Now the basic types are set up, we can haul in the kernel-interface
102 definitions.
103 ------------------------------------------------------------------ */
104
njn2574bb4762002-09-24 11:23:50 +0000105#include "../coregrind/vg_kerneliface.h"
njn25e49d8e72002-09-23 09:36:25 +0000106
107
108/*====================================================================*/
109/*=== Command-line options ===*/
110/*====================================================================*/
111
112/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
113extern Int VG_(clo_verbosity);
114
115/* Profile? */
116extern Bool VG_(clo_profile);
117
njn25e49d8e72002-09-23 09:36:25 +0000118/* Call this if a recognised option was bad for some reason.
119 Note: don't use it just because an option was unrecognised -- return 'False'
120 from SKN_(process_cmd_line_option) to indicate that. */
121extern void VG_(bad_option) ( Char* opt );
122
123/* Client args */
124extern Int VG_(client_argc);
125extern Char** VG_(client_argv);
126
njnd5bb0a52002-09-27 10:24:48 +0000127/* Client environment. Can be inspected with VG_(getenv)() */
njn25e49d8e72002-09-23 09:36:25 +0000128extern Char** VG_(client_envp);
129
130
131/*====================================================================*/
132/*=== Printing messages for the user ===*/
133/*====================================================================*/
134
135/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
136 Should be used for all user output. */
137
138typedef
139 enum { Vg_UserMsg, /* '?' == '=' */
140 Vg_DebugMsg, /* '?' == '-' */
141 Vg_DebugExtraMsg /* '?' == '+' */
142 }
143 VgMsgKind;
144
145/* Functions for building a message from multiple parts. */
146extern void VG_(start_msg) ( VgMsgKind kind );
147extern void VG_(add_to_msg) ( Char* format, ... );
148/* Ends and prints the message. Appends a newline. */
149extern void VG_(end_msg) ( void );
150
njnd5bb0a52002-09-27 10:24:48 +0000151/* Send a single-part message. Appends a newline. */
njn25e49d8e72002-09-23 09:36:25 +0000152extern void VG_(message) ( VgMsgKind kind, Char* format, ... );
153
154
155/*====================================================================*/
156/*=== Profiling ===*/
157/*====================================================================*/
158
159/* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */
160#define VGP_CORE_LIST \
161 /* These ones depend on the core */ \
162 VGP_PAIR(VgpUnc, "unclassified"), \
163 VGP_PAIR(VgpRun, "running"), \
164 VGP_PAIR(VgpSched, "scheduler"), \
165 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
166 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
167 VGP_PAIR(VgpStack, "adjust-stack"), \
168 VGP_PAIR(VgpTranslate, "translate-main"), \
169 VGP_PAIR(VgpToUCode, "to-ucode"), \
170 VGP_PAIR(VgpFromUcode, "from-ucode"), \
171 VGP_PAIR(VgpImprove, "improve"), \
172 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
173 VGP_PAIR(VgpLiveness, "liveness-analysis"), \
174 VGP_PAIR(VgpDoLRU, "do-lru"), \
175 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
176 VGP_PAIR(VgpInitMem, "init-memory"), \
177 VGP_PAIR(VgpExeContext, "exe-context"), \
178 VGP_PAIR(VgpReadSyms, "read-syms"), \
179 VGP_PAIR(VgpSearchSyms, "search-syms"), \
180 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
181 VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
182 VGP_PAIR(VgpDemangle, "demangle"), \
njn37cea302002-09-30 11:24:00 +0000183 VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
184 VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000185 /* These ones depend on the skin */ \
186 VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
187 VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
188 VGP_PAIR(VgpInstrument, "instrument"), \
189 VGP_PAIR(VgpSkinSysWrap, "skin-syscall-wrapper"), \
njn37cea302002-09-30 11:24:00 +0000190 VGP_PAIR(VgpSkinCheapSanity, "skin-cheap-sanity"), \
191 VGP_PAIR(VgpSkinExpensiveSanity, "skin-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000192 VGP_PAIR(VgpFini, "fini")
193
194#define VGP_PAIR(n,name) n
195typedef enum { VGP_CORE_LIST } VgpCoreCC;
196#undef VGP_PAIR
197
198/* When registering skin profiling events, ensure that the 'n' value is in
199 * the range (VgpFini+1..) */
200extern void VGP_(register_profile_event) ( Int n, Char* name );
201
202extern void VGP_(pushcc) ( UInt cc );
203extern void VGP_(popcc) ( UInt cc );
204
205/* Define them only if they haven't already been defined by vg_profile.c */
206#ifndef VGP_PUSHCC
207# define VGP_PUSHCC(x)
208#endif
209#ifndef VGP_POPCC
210# define VGP_POPCC(x)
211#endif
212
213
214/*====================================================================*/
215/*=== Useful stuff to call from generated code ===*/
216/*====================================================================*/
217
218/* ------------------------------------------------------------------ */
219/* General stuff */
220
njn41557122002-10-14 09:25:37 +0000221/* 64-bit counter for the number of basic blocks done. */
222extern ULong VG_(bbs_done);
223
njn25e49d8e72002-09-23 09:36:25 +0000224/* Get the simulated %esp */
225extern Addr VG_(get_stack_pointer) ( void );
226
njnd5bb0a52002-09-27 10:24:48 +0000227/* Detect if an address is within Valgrind's stack or Valgrind's
228 m_state_static; useful for memory leak detectors to tell if a block
229 is used by Valgrind (and thus can be ignored). */
njn25e49d8e72002-09-23 09:36:25 +0000230extern Bool VG_(within_stack)(Addr a);
njn25e49d8e72002-09-23 09:36:25 +0000231extern Bool VG_(within_m_state_static)(Addr a);
232
233/* Check if an address is 4-byte aligned */
234#define IS_ALIGNED4_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 3))
235
236
237/* ------------------------------------------------------------------ */
238/* Thread-related stuff */
239
240/* Special magic value for an invalid ThreadId. It corresponds to
241 LinuxThreads using zero as the initial value for
242 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
243#define VG_INVALID_THREADID ((ThreadId)(0))
244
245/* ThreadIds are simply indices into the vg_threads[] array. */
246typedef
247 UInt
248 ThreadId;
249
njnd5bb0a52002-09-27 10:24:48 +0000250/* struct _ThreadState defined elsewhere; ThreadState is abstract as its
251 definition is not important for skins. */
njn25e49d8e72002-09-23 09:36:25 +0000252typedef
253 struct _ThreadState
254 ThreadState;
255
256extern ThreadId VG_(get_current_tid_1_if_root) ( void );
257extern ThreadState* VG_(get_ThreadState) ( ThreadId tid );
258
259
260/*====================================================================*/
261/*=== Valgrind's version of libc ===*/
262/*====================================================================*/
263
264/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
265 are its own versions of C library functions, but with VG_ prefixes. Note
266 that the types of some are slightly different to the real ones. Some
267 extra useful functions are provided too; descriptions of how they work
268 are given below. */
269
270#if !defined(NULL)
271# define NULL ((void*)0)
272#endif
273
274
275/* ------------------------------------------------------------------ */
276/* stdio.h
277 *
278 * Note that they all output to the file descriptor given by the
279 * --logfile-fd=N argument, which defaults to 2 (stderr). Hence no
280 * need for VG_(fprintf)().
njn25e49d8e72002-09-23 09:36:25 +0000281 */
282extern void VG_(printf) ( const char *format, ... );
283/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
284extern void VG_(sprintf) ( Char* buf, Char *format, ... );
285extern void VG_(vprintf) ( void(*send)(Char),
286 const Char *format, va_list vargs );
287
njn41557122002-10-14 09:25:37 +0000288extern Int VG_(rename) ( Char* old_name, Char* new_name );
289
njn25e49d8e72002-09-23 09:36:25 +0000290/* ------------------------------------------------------------------ */
291/* stdlib.h */
292
293extern void* VG_(malloc) ( Int nbytes );
njnd5bb0a52002-09-27 10:24:48 +0000294extern void VG_(free) ( void* p );
295extern void* VG_(calloc) ( Int n, Int nbytes );
296extern void* VG_(realloc) ( void* p, Int size );
297extern void* VG_(malloc_aligned) ( Int align_bytes, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000298
299extern void VG_(print_malloc_stats) ( void );
300
301
302extern void VG_(exit)( Int status )
303 __attribute__ ((__noreturn__));
njne427a662002-10-02 11:08:25 +0000304/* Prints a panic message (a constant string), appends newline and bug
305 reporting info, aborts. */
306__attribute__ ((__noreturn__))
307extern void VG_(skin_panic) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000308
njnd5bb0a52002-09-27 10:24:48 +0000309/* Looks up VG_(client_envp) */
njn25e49d8e72002-09-23 09:36:25 +0000310extern Char* VG_(getenv) ( Char* name );
311
312/* Crude stand-in for the glibc system() call. */
313extern Int VG_(system) ( Char* cmd );
314
njnd5bb0a52002-09-27 10:24:48 +0000315extern Long VG_(atoll) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000316
317/* Like atoll(), but converts a number of base 2..36 */
318extern Long VG_(atoll36) ( UInt base, Char* str );
319
320
321/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000322/* ctype.h */
njn25e49d8e72002-09-23 09:36:25 +0000323extern Bool VG_(isspace) ( Char c );
324extern Bool VG_(isdigit) ( Char c );
325extern Char VG_(toupper) ( Char c );
326
327
328/* ------------------------------------------------------------------ */
329/* string.h */
330extern Int VG_(strlen) ( const Char* str );
331extern Char* VG_(strcat) ( Char* dest, const Char* src );
332extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
333extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
334extern Char* VG_(strcpy) ( Char* dest, const Char* src );
335extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
336extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
337extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
338extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
339extern Char* VG_(strchr) ( const Char* s, Char c );
340extern Char* VG_(strdup) ( const Char* s);
341
njnd5bb0a52002-09-27 10:24:48 +0000342/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
njn25e49d8e72002-09-23 09:36:25 +0000343extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
njn25e49d8e72002-09-23 09:36:25 +0000344extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
345
njnd5bb0a52002-09-27 10:24:48 +0000346/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
347 last character. */
njn25e49d8e72002-09-23 09:36:25 +0000348extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
349
350/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
351 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
njn4ba5a792002-09-30 10:23:54 +0000352extern Bool VG_(string_match) ( Char* pat, Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000353
354
355/* ------------------------------------------------------------------ */
356/* math.h */
njnd5bb0a52002-09-27 10:24:48 +0000357/* Returns the base-2 logarithm of x. */
njn25e49d8e72002-09-23 09:36:25 +0000358extern Int VG_(log2) ( Int x );
359
360
361/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000362/* unistd.h, fcntl.h, sys/stat.h */
363extern Int VG_(getpid) ( void );
364
njn4aca2d22002-10-04 10:29:38 +0000365extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
366extern Int VG_(read) ( Int fd, void* buf, Int count);
367extern Int VG_(write) ( Int fd, void* buf, Int count);
368extern void VG_(close) ( Int fd );
njnd5bb0a52002-09-27 10:24:48 +0000369
njn41557122002-10-14 09:25:37 +0000370/* Nb: VG_(rename)() declared in stdio.h section above */
njn4aca2d22002-10-04 10:29:38 +0000371extern Int VG_(unlink) ( Char* file_name );
372extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
njn25e49d8e72002-09-23 09:36:25 +0000373
374
375/* ------------------------------------------------------------------ */
376/* assert.h */
377/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
378#define VG__STRING(__str) #__str
379
njne427a662002-10-02 11:08:25 +0000380#define sk_assert(expr) \
njn25e49d8e72002-09-23 09:36:25 +0000381 ((void) ((expr) ? 0 : \
njne427a662002-10-02 11:08:25 +0000382 (VG_(skin_assert_fail) (VG__STRING(expr), \
383 __FILE__, __LINE__, \
384 __PRETTY_FUNCTION__), 0)))
njn25e49d8e72002-09-23 09:36:25 +0000385
njne427a662002-10-02 11:08:25 +0000386__attribute__ ((__noreturn__))
387extern void VG_(skin_assert_fail) ( Char* expr, Char* file,
388 Int line, Char* fn );
njn25e49d8e72002-09-23 09:36:25 +0000389
390
391/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000392/* system/mman.h */
njn25e49d8e72002-09-23 09:36:25 +0000393extern void* VG_(mmap)( void* start, UInt length,
394 UInt prot, UInt flags, UInt fd, UInt offset );
395extern Int VG_(munmap)( void* start, Int length );
396
397/* Get memory by anonymous mmap. */
398extern void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who );
399
400
401/* ------------------------------------------------------------------ */
402/* signal.h.
403
404 Note that these use the vk_ (kernel) structure
405 definitions, which are different in places from those that glibc
406 defines -- hence the 'k' prefix. Since we're operating right at the
407 kernel interface, glibc's view of the world is entirely irrelevant. */
408
409/* --- Signal set ops --- */
njnd5bb0a52002-09-27 10:24:48 +0000410extern Int VG_(ksigfillset) ( vki_ksigset_t* set );
411extern Int VG_(ksigemptyset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000412
njnd5bb0a52002-09-27 10:24:48 +0000413extern Bool VG_(kisfullsigset) ( vki_ksigset_t* set );
414extern Bool VG_(kisemptysigset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000415
njnd5bb0a52002-09-27 10:24:48 +0000416extern Int VG_(ksigaddset) ( vki_ksigset_t* set, Int signum );
417extern Int VG_(ksigdelset) ( vki_ksigset_t* set, Int signum );
njn25e49d8e72002-09-23 09:36:25 +0000418extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
419
njnd5bb0a52002-09-27 10:24:48 +0000420extern void VG_(ksigaddset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
421extern void VG_(ksigdelset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
njn25e49d8e72002-09-23 09:36:25 +0000422
423/* --- Mess with the kernel's sig state --- */
njnd5bb0a52002-09-27 10:24:48 +0000424extern Int VG_(ksigprocmask) ( Int how, const vki_ksigset_t* set,
njn25e49d8e72002-09-23 09:36:25 +0000425 vki_ksigset_t* oldset );
njnd5bb0a52002-09-27 10:24:48 +0000426extern Int VG_(ksigaction) ( Int signum,
427 const vki_ksigaction* act,
428 vki_ksigaction* oldact );
njn25e49d8e72002-09-23 09:36:25 +0000429
njnd5bb0a52002-09-27 10:24:48 +0000430extern Int VG_(ksignal) ( Int signum, void (*sighandler)(Int) );
431extern Int VG_(ksigaltstack) ( const vki_kstack_t* ss, vki_kstack_t* oss );
njn25e49d8e72002-09-23 09:36:25 +0000432
sewardjdcaf3122002-09-30 23:12:33 +0000433extern Int VG_(kkill) ( Int pid, Int signo );
434extern Int VG_(ksigpending) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000435
436
437/*====================================================================*/
438/*=== UCode definition ===*/
439/*====================================================================*/
440
sewardje1042472002-09-30 12:33:11 +0000441/* Tags which describe what operands are. Must fit into 4 bits, which
442 they clearly do. */
njn25e49d8e72002-09-23 09:36:25 +0000443typedef
sewardje1042472002-09-30 12:33:11 +0000444enum { TempReg =0, /* virtual temp-reg */
445 ArchReg =1, /* simulated integer reg */
446 ArchRegS =2, /* simulated segment reg */
447 RealReg =3, /* real machine's real reg */
448 SpillNo =4, /* spill slot location */
449 Literal =5, /* literal; .lit32 field has actual value */
450 Lit16 =6, /* literal; .val[123] field has actual value */
451 NoValue =7 /* operand not in use */
452 }
453 Tag;
njn25e49d8e72002-09-23 09:36:25 +0000454
njnd5bb0a52002-09-27 10:24:48 +0000455/* Invalid register numbers (can't be negative) */
njn25e49d8e72002-09-23 09:36:25 +0000456#define INVALID_TEMPREG 999999999
457#define INVALID_REALREG 999999999
458
459/* Microinstruction opcodes. */
460typedef
461 enum {
njnd5bb0a52002-09-27 10:24:48 +0000462 NOP, /* Null op */
njn25e49d8e72002-09-23 09:36:25 +0000463
njnd5bb0a52002-09-27 10:24:48 +0000464 /* Moving values around */
465 GET, PUT, /* simulated register <--> TempReg */
466 GETF, PUTF, /* simulated %eflags <--> TempReg */
467 LOAD, STORE, /* memory <--> TempReg */
468 MOV, /* TempReg <--> TempReg */
469 CMOV, /* Used for cmpxchg and cmov */
njn25e49d8e72002-09-23 09:36:25 +0000470
njnd5bb0a52002-09-27 10:24:48 +0000471 /* Arithmetic/logical ops */
472 ADD, ADC, SUB, SBB, /* Add/subtract (w/wo carry) */
473 AND, OR, XOR, NOT, /* Boolean ops */
474 SHL, SHR, SAR, ROL, ROR, RCL, RCR, /* Shift/rotate (w/wo carry) */
475 NEG, /* Negate */
476 INC, DEC, /* Increment/decrement */
477 BSWAP, /* Big-endian <--> little-endian */
478 CC2VAL, /* Condition code --> 0 or 1 */
479 WIDEN, /* Signed or unsigned widening */
njn25e49d8e72002-09-23 09:36:25 +0000480
njnd5bb0a52002-09-27 10:24:48 +0000481 /* Conditional or unconditional jump */
482 JMP,
483
484 /* FPU ops */
485 FPU, /* Doesn't touch memory */
486 FPU_R, FPU_W, /* Reads/writes memory */
487
488 /* Not strictly needed, but improve address calculation translations. */
njn25e49d8e72002-09-23 09:36:25 +0000489 LEA1, /* reg2 := const + reg1 */
490 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
491
njnd5bb0a52002-09-27 10:24:48 +0000492 /* Hack for x86 REP insns. Jump to literal if TempReg/RealReg is zero. */
493 JIFZ,
njn25e49d8e72002-09-23 09:36:25 +0000494
njnd5bb0a52002-09-27 10:24:48 +0000495 /* Advance the simulated %eip by some small (< 128) number. */
496 INCEIP,
njn25e49d8e72002-09-23 09:36:25 +0000497
sewardje1042472002-09-30 12:33:11 +0000498 /* Dealing with segment registers */
499 GETSEG, PUTSEG, /* simulated segment register <--> TempReg */
500 USESEG, /* (LDT/GDT index, virtual addr) --> linear addr */
501
njnd5bb0a52002-09-27 10:24:48 +0000502 /* Not for translating x86 calls -- only to call helpers */
503 CALLM_S, CALLM_E, /* Mark start/end of CALLM push/pop sequence */
504 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers */
505 CALLM, /* Call assembly-code helper */
506
507 /* Not for translating x86 calls -- only to call C helper functions of
508 up to three arguments (or two if the functions has a return value).
509 Arguments and return value must be word-sized. More arguments can
510 be faked with global variables (eg. use VG_(set_global_var)()).
511
512 Seven possibilities: 'arg[123]' show where args go, 'ret' shows
513 where return value goes (if present).
njn25e49d8e72002-09-23 09:36:25 +0000514
515 CCALL(-, -, - ) void f(void)
516 CCALL(arg1, -, - ) void f(UInt arg1)
517 CCALL(arg1, arg2, - ) void f(UInt arg1, UInt arg2)
518 CCALL(arg1, arg2, arg3) void f(UInt arg1, UInt arg2, UInt arg3)
519 CCALL(-, -, ret ) UInt f(UInt)
520 CCALL(arg1, -, ret ) UInt f(UInt arg1)
njnd5bb0a52002-09-27 10:24:48 +0000521 CCALL(arg1, arg2, ret ) UInt f(UInt arg1, UInt arg2) */
njn25e49d8e72002-09-23 09:36:25 +0000522 CCALL,
523
njnd5bb0a52002-09-27 10:24:48 +0000524 /* This opcode makes it easy for skins that extend UCode to do this to
525 avoid opcode overlap:
njn25e49d8e72002-09-23 09:36:25 +0000526
njnd5bb0a52002-09-27 10:24:48 +0000527 enum { EU_OP1 = DUMMY_FINAL_UOPCODE + 1, ... }
njn25e49d8e72002-09-23 09:36:25 +0000528
529 WARNING: Do not add new opcodes after this one! They can be added
530 before, though. */
531 DUMMY_FINAL_UOPCODE
532 }
533 Opcode;
534
535
njnd5bb0a52002-09-27 10:24:48 +0000536/* Condition codes, using the Intel encoding. CondAlways is an extra. */
njn25e49d8e72002-09-23 09:36:25 +0000537typedef
538 enum {
539 CondO = 0, /* overflow */
540 CondNO = 1, /* no overflow */
541 CondB = 2, /* below */
542 CondNB = 3, /* not below */
543 CondZ = 4, /* zero */
544 CondNZ = 5, /* not zero */
545 CondBE = 6, /* below or equal */
546 CondNBE = 7, /* not below or equal */
547 CondS = 8, /* negative */
sewardje1042472002-09-30 12:33:11 +0000548 CondNS = 9, /* not negative */
njn25e49d8e72002-09-23 09:36:25 +0000549 CondP = 10, /* parity even */
550 CondNP = 11, /* not parity even */
551 CondL = 12, /* jump less */
552 CondNL = 13, /* not less */
553 CondLE = 14, /* less or equal */
554 CondNLE = 15, /* not less or equal */
555 CondAlways = 16 /* Jump always */
556 }
557 Condcode;
558
559
560/* Descriptions of additional properties of *unconditional* jumps. */
561typedef
562 enum {
563 JmpBoring=0, /* boring unconditional jump */
564 JmpCall=1, /* jump due to an x86 call insn */
565 JmpRet=2, /* jump due to an x86 ret insn */
566 JmpSyscall=3, /* do a system call, then jump */
567 JmpClientReq=4 /* do a client request, then jump */
568 }
569 JmpKind;
570
571
572/* Flags. User-level code can only read/write O(verflow), S(ign),
573 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
574 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
575 thusly:
576 76543210
577 DOSZACP
578 and bit 7 must always be zero since it is unused.
579*/
580typedef UChar FlagSet;
581
582#define FlagD (1<<6)
583#define FlagO (1<<5)
584#define FlagS (1<<4)
585#define FlagZ (1<<3)
586#define FlagA (1<<2)
587#define FlagC (1<<1)
588#define FlagP (1<<0)
589
590#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
591#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
592#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
593#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
594#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
595#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
596#define FlagsZCP ( FlagZ | FlagC | FlagP)
597#define FlagsOC (FlagO | FlagC )
598#define FlagsAC ( FlagA | FlagC )
599
600#define FlagsALL (FlagsOSZACP | FlagD)
601#define FlagsEmpty (FlagSet)0
602
603
604/* Liveness of general purpose registers, useful for code generation.
605 Reg rank order 0..N-1 corresponds to bits 0..N-1, ie. first
606 reg's liveness in bit 0, last reg's in bit N-1. Note that
607 these rankings don't match the Intel register ordering. */
608typedef UInt RRegSet;
609
610#define ALL_RREGS_DEAD 0 /* 0000...00b */
njne7c258c2002-10-03 08:57:01 +0000611#define ALL_RREGS_LIVE ((1 << VG_MAX_REALREGS)-1) /* 0011...11b */
njn25e49d8e72002-09-23 09:36:25 +0000612#define UNIT_RREGSET(rank) (1 << (rank))
613
614#define IS_RREG_LIVE(rank,rregs_live) (rregs_live & UNIT_RREGSET(rank))
615#define SET_RREG_LIVENESS(rank,rregs_live,b) \
616 do { RRegSet unit = UNIT_RREGSET(rank); \
617 if (b) rregs_live |= unit; \
618 else rregs_live &= ~unit; \
619 } while(0)
620
621
622/* A Micro (u)-instruction. */
623typedef
624 struct {
625 /* word 1 */
626 UInt lit32; /* 32-bit literal */
627
628 /* word 2 */
629 UShort val1; /* first operand */
630 UShort val2; /* second operand */
631
632 /* word 3 */
633 UShort val3; /* third operand */
634 UChar opcode; /* opcode */
635 UChar size; /* data transfer size */
636
637 /* word 4 */
638 FlagSet flags_r; /* :: FlagSet */
639 FlagSet flags_w; /* :: FlagSet */
640 UChar tag1:4; /* first operand tag */
641 UChar tag2:4; /* second operand tag */
642 UChar tag3:4; /* third operand tag */
643 UChar extra4b:4; /* Spare field, used by WIDEN for src
644 -size, and by LEA2 for scale (1,2,4 or 8),
645 and by JMPs for original x86 instr size */
646
647 /* word 5 */
648 UChar cond; /* condition, for jumps */
649 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
650 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
651
652 /* Additional properties for UInstrs that call C functions:
653 - CCALL
654 - PUT (when %ESP is the target)
655 - possibly skin-specific UInstrs
656 */
657 UChar argc:2; /* Number of args, max 3 */
658 UChar regparms_n:2; /* Number of args passed in registers */
659 Bool has_ret_val:1; /* Function has return value? */
660
661 /* RealReg liveness; only sensical after reg alloc and liveness
662 analysis done. This info is a little bit arch-specific --
663 VG_MAX_REALREGS can vary on different architectures. Note that
664 to use this information requires converting between register ranks
njn4ba5a792002-09-30 10:23:54 +0000665 and the Intel register numbers, using VG_(realreg_to_rank)()
666 and/or VG_(rank_to_realreg)() */
njn25e49d8e72002-09-23 09:36:25 +0000667 RRegSet regs_live_after:VG_MAX_REALREGS;
668 }
669 UInstr;
670
671
672/* Expandable arrays of uinstrs. */
673typedef
674 struct {
675 Int used;
676 Int size;
677 UInstr* instrs;
678 Int nextTemp;
679 }
680 UCodeBlock;
681
682
683/*====================================================================*/
684/*=== Instrumenting UCode ===*/
685/*====================================================================*/
686
687/* A structure for communicating TempReg and RealReg uses of UInstrs. */
688typedef
689 struct {
690 Int num;
691 Bool isWrite;
692 }
693 RegUse;
694
695/* Find what this instruction does to its regs. Tag indicates whether we're
696 * considering TempRegs (pre-reg-alloc) or RealRegs (post-reg-alloc).
697 * Useful for analysis/optimisation passes. */
njn4ba5a792002-09-30 10:23:54 +0000698extern Int VG_(get_reg_usage) ( UInstr* u, Tag tag, RegUse* arr );
njn25e49d8e72002-09-23 09:36:25 +0000699
700
701/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000702/* Used to register helper functions to be called from generated code. A
703 limited number of compact helpers can be registered; the code generated
704 to call them is slightly shorter -- so register the mostly frequently
705 called helpers as compact. */
njn25e49d8e72002-09-23 09:36:25 +0000706extern void VG_(register_compact_helper) ( Addr a );
707extern void VG_(register_noncompact_helper) ( Addr a );
708
709
710/* ------------------------------------------------------------------ */
711/* Virtual register allocation */
712
713/* Get a new virtual register */
njn4ba5a792002-09-30 10:23:54 +0000714extern Int VG_(get_new_temp) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000715
716/* Get a new virtual shadow register */
njn4ba5a792002-09-30 10:23:54 +0000717extern Int VG_(get_new_shadow) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000718
719/* Get a virtual register's corresponding virtual shadow register */
720#define SHADOW(tempreg) ((tempreg)+1)
721
722
723/* ------------------------------------------------------------------ */
724/* Low-level UInstr builders */
njn4ba5a792002-09-30 10:23:54 +0000725extern void VG_(new_NOP) ( UInstr* u );
726extern void VG_(new_UInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
727extern void VG_(new_UInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000728 Tag tag1, UInt val1 );
njn4ba5a792002-09-30 10:23:54 +0000729extern void VG_(new_UInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000730 Tag tag1, UInt val1,
731 Tag tag2, UInt val2 );
njn4ba5a792002-09-30 10:23:54 +0000732extern void VG_(new_UInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000733 Tag tag1, UInt val1,
734 Tag tag2, UInt val2,
735 Tag tag3, UInt val3 );
njn25e49d8e72002-09-23 09:36:25 +0000736
njn4ba5a792002-09-30 10:23:54 +0000737extern void VG_(set_flag_RW) ( UInstr* u, FlagSet fr, FlagSet fw );
738extern void VG_(set_lit_field) ( UCodeBlock* cb, UInt lit32 );
739extern void VG_(set_ccall_fields) ( UCodeBlock* cb, Addr fn, UChar argc,
740 UChar regparms_n, Bool has_ret_val );
njn25e49d8e72002-09-23 09:36:25 +0000741
njn4ba5a792002-09-30 10:23:54 +0000742extern void VG_(copy_UInstr) ( UCodeBlock* cb, UInstr* instr );
743
744extern Bool VG_(any_flag_use)( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +0000745
njnac6c1762002-10-04 14:34:15 +0000746/* Macro versions of the above; just shorter to type. */
747#define uInstr0 VG_(new_UInstr0)
748#define uInstr1 VG_(new_UInstr1)
749#define uInstr2 VG_(new_UInstr2)
750#define uInstr3 VG_(new_UInstr3)
751#define uLiteral VG_(set_lit_field)
752#define uCCall VG_(set_ccall_fields)
753#define newTemp VG_(get_new_temp)
754#define newShadow VG_(get_new_shadow)
755
njn25e49d8e72002-09-23 09:36:25 +0000756/* Refer to `the last instruction stuffed in' (can be lvalue). */
757#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
758
759
760/* ------------------------------------------------------------------ */
761/* Higher-level UInstr sequence builders */
njn4ba5a792002-09-30 10:23:54 +0000762extern void VG_(call_helper_0_0) ( UCodeBlock* cb, Addr f);
763extern void VG_(call_helper_1_0) ( UCodeBlock* cb, Addr f, UInt arg1,
764 UInt regparms_n);
765extern void VG_(call_helper_2_0) ( UCodeBlock* cb, Addr f, UInt arg1, UInt arg2,
766 UInt regparms_n);
njn25e49d8e72002-09-23 09:36:25 +0000767
768/* One way around the 3-arg C function limit is to pass args via global
769 * variables... ugly, but it works. */
njn4ba5a792002-09-30 10:23:54 +0000770extern void VG_(set_global_var) ( UCodeBlock* cb, Addr globvar_ptr, UInt val);
njn25e49d8e72002-09-23 09:36:25 +0000771
772/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000773/* Allocating/freeing basic blocks of UCode */
njn4ba5a792002-09-30 10:23:54 +0000774extern UCodeBlock* VG_(alloc_UCodeBlock) ( void );
775extern void VG_(free_UCodeBlock) ( UCodeBlock* cb );
njnd5bb0a52002-09-27 10:24:48 +0000776
777/* ------------------------------------------------------------------ */
778/* UCode pretty/ugly printing. Probably only useful to call from a skin
njn25e49d8e72002-09-23 09:36:25 +0000779 if VG_(needs).extended_UCode == True. */
780
781/* When True, all generated code is/should be printed. */
782extern Bool VG_(print_codegen);
783
njn4ba5a792002-09-30 10:23:54 +0000784/* Pretty/ugly printing functions */
785extern void VG_(pp_UCodeBlock) ( UCodeBlock* cb, Char* title );
786extern void VG_(pp_UInstr) ( Int instrNo, UInstr* u );
787extern void VG_(pp_UInstr_regs) ( Int instrNo, UInstr* u );
788extern void VG_(up_UInstr) ( Int instrNo, UInstr* u );
789extern Char* VG_(name_UOpcode) ( Bool upper, Opcode opc );
790extern void VG_(pp_UOperand) ( UInstr* u, Int operandNo,
791 Int sz, Bool parens );
njn25e49d8e72002-09-23 09:36:25 +0000792
njn25e49d8e72002-09-23 09:36:25 +0000793
794/*====================================================================*/
njnd5bb0a52002-09-27 10:24:48 +0000795/*=== Generating x86 code from UCode ===*/
njn25e49d8e72002-09-23 09:36:25 +0000796/*====================================================================*/
797
njnd5bb0a52002-09-27 10:24:48 +0000798/* All this only necessary for skins with VG_(needs).extends_UCode == True. */
njn25e49d8e72002-09-23 09:36:25 +0000799
sewardje1042472002-09-30 12:33:11 +0000800/* This is the Intel register encoding -- integer regs. */
njn25e49d8e72002-09-23 09:36:25 +0000801#define R_EAX 0
802#define R_ECX 1
803#define R_EDX 2
804#define R_EBX 3
805#define R_ESP 4
806#define R_EBP 5
807#define R_ESI 6
808#define R_EDI 7
809
810#define R_AL (0+R_EAX)
811#define R_CL (0+R_ECX)
812#define R_DL (0+R_EDX)
813#define R_BL (0+R_EBX)
814#define R_AH (4+R_EAX)
815#define R_CH (4+R_ECX)
816#define R_DH (4+R_EDX)
817#define R_BH (4+R_EBX)
818
sewardje1042472002-09-30 12:33:11 +0000819/* This is the Intel register encoding -- segment regs. */
820#define R_ES 0
821#define R_CS 1
822#define R_SS 2
823#define R_DS 3
824#define R_FS 4
825#define R_GS 5
826
njn25e49d8e72002-09-23 09:36:25 +0000827/* For pretty printing x86 code */
sewardje1042472002-09-30 12:33:11 +0000828extern Char* VG_(name_of_seg_reg) ( Int sreg );
njn4ba5a792002-09-30 10:23:54 +0000829extern Char* VG_(name_of_int_reg) ( Int size, Int reg );
830extern Char VG_(name_of_int_size) ( Int size );
njn25e49d8e72002-09-23 09:36:25 +0000831
njnac6c1762002-10-04 14:34:15 +0000832/* Shorter macros for convenience */
833#define nameIReg VG_(name_of_int_reg)
834#define nameISize VG_(name_of_int_size)
835#define nameSReg VG_(name_of_seg_reg)
836
njn25e49d8e72002-09-23 09:36:25 +0000837/* Randomly useful things */
838extern UInt VG_(extend_s_8to32) ( UInt x );
839
840/* Code emitters */
njn4ba5a792002-09-30 10:23:54 +0000841extern void VG_(emitB) ( UInt b );
842extern void VG_(emitW) ( UInt w );
843extern void VG_(emitL) ( UInt l );
844extern void VG_(new_emit) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000845
846/* Finding offsets */
njn4ba5a792002-09-30 10:23:54 +0000847extern Int VG_(helper_offset) ( Addr a );
848extern Int VG_(shadow_reg_offset) ( Int arch );
849extern Int VG_(shadow_flags_offset) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000850
njnd5bb0a52002-09-27 10:24:48 +0000851/* Convert reg ranks <-> Intel register ordering, for using register
852 liveness information. */
njn4ba5a792002-09-30 10:23:54 +0000853extern Int VG_(realreg_to_rank) ( Int realreg );
854extern Int VG_(rank_to_realreg) ( Int rank );
njn25e49d8e72002-09-23 09:36:25 +0000855
njnd5bb0a52002-09-27 10:24:48 +0000856/* Call a subroutine. Does no argument passing, stack manipulations, etc. */
njn4ba5a792002-09-30 10:23:54 +0000857extern void VG_(synth_call) ( Bool ensure_shortform, Int word_offset );
njn25e49d8e72002-09-23 09:36:25 +0000858
njnd5bb0a52002-09-27 10:24:48 +0000859/* For calling C functions -- saves caller save regs, pushes args, calls,
860 clears the stack, restores caller save regs. `fn' must be registered in
861 the baseBlock first. Acceptable tags are RealReg and Literal. Optimises
862 things, eg. by not preserving non-live caller-save registers.
njn25e49d8e72002-09-23 09:36:25 +0000863
njnd5bb0a52002-09-27 10:24:48 +0000864 WARNING: a UInstr should *not* be translated with synth_ccall() followed
865 by some other x86 assembly code; this will invalidate the results of
866 vg_realreg_liveness_analysis() and everything will fall over. */
njn4ba5a792002-09-30 10:23:54 +0000867extern void VG_(synth_ccall) ( Addr fn, Int argc, Int regparms_n, UInt argv[],
868 Tag tagv[], Int ret_reg,
869 RRegSet regs_live_before,
870 RRegSet regs_live_after );
njn25e49d8e72002-09-23 09:36:25 +0000871
872/* Addressing modes */
njn4ba5a792002-09-30 10:23:54 +0000873extern void VG_(emit_amode_offregmem_reg)( Int off, Int regmem, Int reg );
874extern void VG_(emit_amode_ereg_greg) ( Int e_reg, Int g_reg );
njn25e49d8e72002-09-23 09:36:25 +0000875
876/* v-size (4, or 2 with OSO) insn emitters */
njn4ba5a792002-09-30 10:23:54 +0000877extern void VG_(emit_movv_offregmem_reg) ( Int sz, Int off, Int areg, Int reg );
878extern void VG_(emit_movv_reg_offregmem) ( Int sz, Int reg, Int off, Int areg );
879extern void VG_(emit_movv_reg_reg) ( Int sz, Int reg1, Int reg2 );
880extern void VG_(emit_nonshiftopv_lit_reg)( Int sz, Opcode opc, UInt lit,
881 Int reg );
882extern void VG_(emit_shiftopv_lit_reg) ( Int sz, Opcode opc, UInt lit,
883 Int reg );
884extern void VG_(emit_nonshiftopv_reg_reg)( Int sz, Opcode opc,
885 Int reg1, Int reg2 );
886extern void VG_(emit_movv_lit_reg) ( Int sz, UInt lit, Int reg );
887extern void VG_(emit_unaryopv_reg) ( Int sz, Opcode opc, Int reg );
888extern void VG_(emit_pushv_reg) ( Int sz, Int reg );
889extern void VG_(emit_popv_reg) ( Int sz, Int reg );
njn25e49d8e72002-09-23 09:36:25 +0000890
njn4ba5a792002-09-30 10:23:54 +0000891extern void VG_(emit_pushl_lit32) ( UInt int32 );
892extern void VG_(emit_pushl_lit8) ( Int lit8 );
893extern void VG_(emit_cmpl_zero_reg) ( Int reg );
894extern void VG_(emit_swapl_reg_EAX) ( Int reg );
895extern void VG_(emit_movv_lit_offregmem) ( Int sz, UInt lit, Int off,
896 Int memreg );
njn25e49d8e72002-09-23 09:36:25 +0000897
898/* b-size (1 byte) instruction emitters */
njn4ba5a792002-09-30 10:23:54 +0000899extern void VG_(emit_movb_lit_offregmem) ( UInt lit, Int off, Int memreg );
900extern void VG_(emit_movb_reg_offregmem) ( Int reg, Int off, Int areg );
901extern void VG_(emit_unaryopb_reg) ( Opcode opc, Int reg );
902extern void VG_(emit_testb_lit_reg) ( UInt lit, Int reg );
njn25e49d8e72002-09-23 09:36:25 +0000903
904/* zero-extended load emitters */
njn4ba5a792002-09-30 10:23:54 +0000905extern void VG_(emit_movzbl_offregmem_reg) ( Int off, Int regmem, Int reg );
906extern void VG_(emit_movzwl_offregmem_reg) ( Int off, Int areg, Int reg );
njn25e49d8e72002-09-23 09:36:25 +0000907
908/* misc instruction emitters */
njn4ba5a792002-09-30 10:23:54 +0000909extern void VG_(emit_call_reg) ( Int reg );
910extern void VG_(emit_add_lit_to_esp) ( Int lit );
911extern void VG_(emit_jcondshort_delta) ( Condcode cond, Int delta );
912extern void VG_(emit_pushal) ( void );
913extern void VG_(emit_popal) ( void );
914extern void VG_(emit_AMD_prefetch_reg) ( Int reg );
njn25e49d8e72002-09-23 09:36:25 +0000915
916
917/*====================================================================*/
918/*=== Execution contexts ===*/
919/*====================================================================*/
920
921/* Generic resolution type used in a few different ways, such as deciding
922 how closely to compare two errors for equality. */
923typedef
924 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
925 VgRes;
926
927typedef
928 struct _ExeContext
929 ExeContext;
930
njnd5bb0a52002-09-27 10:24:48 +0000931/* Compare two ExeContexts. Number of callers considered depends on `res':
932 Vg_LowRes: 2
933 Vg_MedRes: 4
934 Vg_HighRes: all */
njn25e49d8e72002-09-23 09:36:25 +0000935extern Bool VG_(eq_ExeContext) ( VgRes res,
936 ExeContext* e1, ExeContext* e2 );
937
938/* Print an ExeContext. */
939extern void VG_(pp_ExeContext) ( ExeContext* );
940
941/* Take a snapshot of the client's stack. Search our collection of
942 ExeContexts to see if we already have it, and if not, allocate a
943 new one. Either way, return a pointer to the context. */
944extern ExeContext* VG_(get_ExeContext) ( ThreadState *tst );
945
946
947/*====================================================================*/
948/*=== Error reporting ===*/
949/*====================================================================*/
950
951/* ------------------------------------------------------------------ */
952/* Suppressions describe errors which we want to suppress, ie, not
953 show the user, usually because it is caused by a problem in a library
954 which we can't fix, replace or work around. Suppressions are read from
njnd5bb0a52002-09-27 10:24:48 +0000955 a file at startup time. This gives flexibility so that new
njn25e49d8e72002-09-23 09:36:25 +0000956 suppressions can be added to the file as and when needed.
957*/
958
959typedef
960 Int /* Do not make this unsigned! */
961 SuppKind;
962
963/* An extensible (via the 'extra' field) suppression record. This holds
964 the suppression details of interest to a skin. Skins can use a normal
965 enum (with element values in the normal range (0..)) for `skind'.
966
967 If VG_(needs).report_errors==True, for each suppression read in by core
968 SKN_(recognised_suppression)() and SKN_(read_extra_suppression_info) will
969 be called. The `skind' field is filled in by the value returned in the
970 argument of the first function; the second function can fill in the
971 `string' and `extra' fields if it wants.
972*/
973typedef
974 struct {
975 /* What kind of suppression. Must use the range (0..) */
976 SuppKind skind;
977 /* String -- use is optional. NULL by default. */
978 Char* string;
979 /* Anything else -- use is optional. NULL by default. */
980 void* extra;
981 }
982 SkinSupp;
983
984
985/* ------------------------------------------------------------------ */
986/* Error records contain enough info to generate an error report. The idea
987 is that (typically) the same few points in the program generate thousands
njnd5bb0a52002-09-27 10:24:48 +0000988 of errors, and we don't want to spew out a fresh error message for each
989 one. Instead, we use these structures to common up duplicates.
njn25e49d8e72002-09-23 09:36:25 +0000990*/
991
992typedef
993 Int /* Do not make this unsigned! */
994 ErrorKind;
995
996/* An extensible (via the 'extra' field) error record. This holds
997 the error details of interest to a skin. Skins can use a normal
998 enum (with element values in the normal range (0..)) for `ekind'.
999
1000 When errors are found and recorded with VG_(maybe_record_error)(), all
1001 the skin must do is pass in the four parameters; core will
1002 allocate/initialise the error record.
1003*/
1004typedef
1005 struct {
1006 /* Used by ALL. Must be in the range (0..) */
1007 Int ekind;
1008 /* Used frequently */
1009 Addr addr;
1010 /* Used frequently */
1011 Char* string;
njnd5bb0a52002-09-27 10:24:48 +00001012 /* For any skin-specific extras */
njn25e49d8e72002-09-23 09:36:25 +00001013 void* extra;
1014 }
1015 SkinError;
1016
1017
1018/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +00001019/* Call this when an error occurs. It will be recorded if it hasn't been
njn25e49d8e72002-09-23 09:36:25 +00001020 seen before. If it has, the existing error record will have its count
1021 incremented.
1022
1023 If the error occurs in generated code, 'tst' should be NULL. If the
1024 error occurs in non-generated code, 'tst' should be non-NULL. The
1025 `extra' field can be stack-allocated; it will be copied (using
1026 SKN_(dup_extra_and_update)()) if needed. But it won't be copied
1027 if it's NULL.
njnd5bb0a52002-09-27 10:24:48 +00001028
1029 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
1030 NULL for them.
njn25e49d8e72002-09-23 09:36:25 +00001031*/
1032extern void VG_(maybe_record_error) ( ThreadState* tst, ErrorKind ekind,
1033 Addr a, Char* s, void* extra );
1034
1035/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
1036 Skips leading spaces on the line. Returns True if EOF was hit instead.
1037 Useful for reading in extra skin-specific suppression lines.
1038*/
njn4ba5a792002-09-30 10:23:54 +00001039extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
njn25e49d8e72002-09-23 09:36:25 +00001040
1041
1042/*====================================================================*/
1043/*=== Obtaining debug information ===*/
1044/*====================================================================*/
1045
1046/* Get the file/function/line number of the instruction at address 'a'.
1047 For these four, if debug info for the address is found, it copies the
1048 info into the buffer/UInt and returns True. If not, it returns False and
1049 nothing is copied. VG_(get_fnname) always demangles C++ function names.
1050*/
1051extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
1052extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
1053extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
1054
1055/* This one is more efficient if getting both filename and line number,
1056 because the two lookups are done together. */
1057extern Bool VG_(get_filename_linenum)
1058 ( Addr a, Char* filename, Int n_filename,
1059 UInt* linenum );
1060
1061/* Succeeds only if we find from debug info that 'a' is the address of the
1062 first instruction in a function -- as opposed to VG_(get_fnname) which
1063 succeeds if we find from debug info that 'a' is the address of any
1064 instruction in a function. Use this to instrument the start of
njnd5bb0a52002-09-27 10:24:48 +00001065 a particular function. Nb: if an executable/shared object is stripped
njn25e49d8e72002-09-23 09:36:25 +00001066 of its symbols, this function will not be able to recognise function
1067 entry points within it. */
1068extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* filename, Int n_filename );
1069
1070/* Succeeds if the address is within a shared object or the main executable.
1071 It doesn't matter if debug info is present or not. */
1072extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
1073
sewardj47104382002-10-20 18:35:48 +00001074/* A way to get information about what segments are mapped */
1075typedef struct _SegInfo SegInfo;
1076
1077extern const SegInfo* VG_(next_seginfo)(const SegInfo *);
1078extern Addr VG_(seg_start)(const SegInfo *);
1079extern UInt VG_(seg_size)(const SegInfo *);
1080extern const UChar* VG_(seg_filename)(const SegInfo *);
1081extern UInt VG_(seg_sym_offset)(const SegInfo *);
1082
1083typedef
1084 enum {
1085 Vg_SectUnknown,
1086 Vg_SectText,
sewardj8fe15a32002-10-20 19:29:21 +00001087 Vg_SectData,
1088 Vg_SectBSS,
sewardj47104382002-10-20 18:35:48 +00001089 Vg_SectGOT,
sewardj8fe15a32002-10-20 19:29:21 +00001090 Vg_SectPLT,
sewardj47104382002-10-20 18:35:48 +00001091 }
1092 VgSectKind;
1093
1094extern VgSectKind VG_(seg_sect_kind)(Addr);
1095
njn25e49d8e72002-09-23 09:36:25 +00001096
1097/*====================================================================*/
1098/*=== Shadow chunks and block-finding ===*/
1099/*====================================================================*/
1100
1101typedef
1102 enum {
1103 Vg_AllocMalloc = 0,
1104 Vg_AllocNew = 1,
1105 Vg_AllocNewVec = 2
1106 }
1107 VgAllocKind;
1108
1109/* Description of a malloc'd chunk. skin_extra[] part can be used by
1110 the skin; size of array is given by VG_(needs).sizeof_shadow_chunk. */
1111typedef
1112 struct _ShadowChunk {
1113 struct _ShadowChunk* next;
1114 UInt size : 30; /* size requested */
1115 VgAllocKind allockind : 2; /* which wrapper did the allocation */
1116 Addr data; /* ptr to actual block */
1117 UInt skin_extra[0]; /* extra skin-specific info */
1118 }
1119 ShadowChunk;
1120
1121/* Use this to free blocks if VG_(needs).alternative_free == True.
1122 It frees the ShadowChunk and the malloc'd block it points to. */
njn4ba5a792002-09-30 10:23:54 +00001123extern void VG_(free_ShadowChunk) ( ShadowChunk* sc );
njn25e49d8e72002-09-23 09:36:25 +00001124
1125/* Makes an array of pointers to all the shadow chunks of malloc'd blocks */
1126extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
1127
1128/* Determines if address 'a' is within the bounds of the block at start.
1129 Allows a little 'slop' round the edges. */
1130extern Bool VG_(addr_is_in_block) ( Addr a, Addr start, UInt size );
1131
1132/* Searches through currently malloc'd blocks until a matching one is found.
1133 Returns NULL if none match. Extra arguments can be implicitly passed to
njnd5bb0a52002-09-27 10:24:48 +00001134 p using nested functions; see memcheck/mc_errcontext.c for an example. */
njn25e49d8e72002-09-23 09:36:25 +00001135extern ShadowChunk* VG_(any_matching_mallocd_ShadowChunks)
1136 ( Bool (*p) ( ShadowChunk* ));
1137
1138/* Searches through all thread's stacks to see if any match. Returns
1139 * VG_INVALID_THREADID if none match. */
1140extern ThreadId VG_(any_matching_thread_stack)
1141 ( Bool (*p) ( Addr stack_min, Addr stack_max ));
1142
1143/*====================================================================*/
1144/*=== Skin-specific stuff ===*/
1145/*====================================================================*/
1146
njnd04b7c62002-10-03 14:05:52 +00001147/* ------------------------------------------------------------------ */
1148/* Details */
1149typedef
1150 struct {
1151 /* Information used in the startup message. `name' also determines the
1152 string used for identifying suppressions in a suppression file as
1153 belonging to this skin. `version' can be NULL, in which case (not
1154 surprisingly) no version info is printed; this mechanism is
1155 designed for skins distributed with Valgrind that share a version
1156 number with Valgrind. Other skins not distributed as part of
1157 Valgrind should probably have their own version number. */
1158 Char* name;
1159 Char* version;
1160 Char* description;
1161 Char* copyright_author;
1162
1163 /* String printed if an `sk_assert' assertion fails or VG_(skin_panic)
1164 is called. Should probably be an email address. */
1165 Char* bug_reports_to;
1166 }
1167 VgDetails;
1168
1169extern VgDetails VG_(details);
1170
1171/* ------------------------------------------------------------------ */
1172/* Needs */
1173
1174/* If new fields are added to this type, update:
njnd5bb0a52002-09-27 10:24:48 +00001175 * - vg_main.c:initialisation of VG_(needs)
njn25e49d8e72002-09-23 09:36:25 +00001176 * - vg_main.c:sanity_check_needs()
1177 *
1178 * If the name of this type or any of its fields change, update:
1179 * - dependent comments (just search for "VG_(needs)").
1180 */
1181typedef
1182 struct {
njnd5bb0a52002-09-27 10:24:48 +00001183 /* Booleans that decide core behaviour, but don't require extra
1184 operations to be defined if `True' */
1185
1186 /* Should __libc_freeres() be run? Bugs in it can crash the skin. */
njnd04b7c62002-10-03 14:05:52 +00001187 Bool libc_freeres;
njn25e49d8e72002-09-23 09:36:25 +00001188
1189 /* Want to have errors detected by Valgrind's core reported? Includes:
1190 - pthread API errors (many; eg. unlocking a non-locked mutex)
1191 - silly arguments to malloc() et al (eg. negative size)
1192 - invalid file descriptors to blocking syscalls read() and write()
1193 - bad signal numbers passed to sigaction()
1194 - attempt to install signal handler for SIGKILL or SIGSTOP */
1195 Bool core_errors;
njn25e49d8e72002-09-23 09:36:25 +00001196
1197 /* Booleans that indicate extra operations are defined; if these are
1198 True, the corresponding template functions (given below) must be
1199 defined. A lot like being a member of a type class. */
1200
njnd5bb0a52002-09-27 10:24:48 +00001201 /* Want to report errors from the skin? This implies use of
1202 suppressions, too. */
1203 Bool skin_errors;
1204
njn25e49d8e72002-09-23 09:36:25 +00001205 /* Is information kept about specific individual basic blocks? (Eg. for
njnd5bb0a52002-09-27 10:24:48 +00001206 cachegrind there are cost-centres for every instruction, stored at a
njn25e49d8e72002-09-23 09:36:25 +00001207 basic block level.) If so, it sometimes has to be discarded, because
1208 .so mmap/munmap-ping or self-modifying code (informed by the
1209 DISCARD_TRANSLATIONS user request) can cause one instruction address
njnd5bb0a52002-09-27 10:24:48 +00001210 to be used for more than one instruction in one program run... */
njn25e49d8e72002-09-23 09:36:25 +00001211 Bool basic_block_discards;
1212
njnd5bb0a52002-09-27 10:24:48 +00001213 /* Skin maintains information about each register? */
njn25e49d8e72002-09-23 09:36:25 +00001214 Bool shadow_regs;
1215
1216 /* Skin defines its own command line options? */
1217 Bool command_line_options;
1218 /* Skin defines its own client requests? */
1219 Bool client_requests;
1220
1221 /* Skin defines its own UInstrs? */
1222 Bool extended_UCode;
1223
1224 /* Skin does stuff before and/or after system calls? */
1225 Bool syscall_wrapper;
1226
1227 /* Size, in words, of extra info about malloc'd blocks recorded by
1228 skin. Be careful to get this right or you'll get seg faults! */
1229 UInt sizeof_shadow_block;
1230
1231 /* Skin does free()s itself? */
1232 Bool alternative_free;
1233
1234 /* Are skin-state sanity checks performed? */
1235 Bool sanity_checks;
sewardj8fe15a32002-10-20 19:29:21 +00001236
1237 /* Do we need to see data symbols? */
1238 Bool data_syms;
njn25e49d8e72002-09-23 09:36:25 +00001239 }
1240 VgNeeds;
1241
1242extern VgNeeds VG_(needs);
1243
1244
1245/* ------------------------------------------------------------------ */
1246/* Core events to track */
1247
1248/* Part of the core from which this call was made. Useful for determining
njnd5bb0a52002-09-27 10:24:48 +00001249 what kind of error message should be emitted. */
njn25e49d8e72002-09-23 09:36:25 +00001250typedef
1251 enum { Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall, Vg_CoreTranslate }
1252 CorePart;
1253
1254/* Events happening in core to track. To be notified, assign a function
njnd5bb0a52002-09-27 10:24:48 +00001255 to the function pointer. To ignore an event, don't do anything
1256 (default assignment is to NULL in which case the call is skipped). */
njn25e49d8e72002-09-23 09:36:25 +00001257typedef
1258 struct {
1259 /* Memory events */
1260 void (*new_mem_startup)( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
1261 void (*new_mem_heap) ( Addr a, UInt len, Bool is_inited );
1262 void (*new_mem_stack) ( Addr a, UInt len );
1263 void (*new_mem_stack_aligned) ( Addr a, UInt len );
1264 void (*new_mem_stack_signal) ( Addr a, UInt len );
1265 void (*new_mem_brk) ( Addr a, UInt len );
1266 void (*new_mem_mmap) ( Addr a, UInt len,
1267 Bool nn, Bool rr, Bool ww, Bool xx );
1268
1269 void (*copy_mem_heap) ( Addr from, Addr to, UInt len );
1270 void (*copy_mem_remap) ( Addr from, Addr to, UInt len );
1271 void (*change_mem_mprotect) ( Addr a, UInt len,
1272 Bool nn, Bool rr, Bool ww, Bool xx );
1273
njnd5bb0a52002-09-27 10:24:48 +00001274 /* Used on redzones around malloc'd blocks and at end of stack */
njn25e49d8e72002-09-23 09:36:25 +00001275 void (*ban_mem_heap) ( Addr a, UInt len );
1276 void (*ban_mem_stack) ( Addr a, UInt len );
1277
1278 void (*die_mem_heap) ( Addr a, UInt len );
1279 void (*die_mem_stack) ( Addr a, UInt len );
1280 void (*die_mem_stack_aligned) ( Addr a, UInt len );
1281 void (*die_mem_stack_signal) ( Addr a, UInt len );
1282 void (*die_mem_brk) ( Addr a, UInt len );
1283 void (*die_mem_munmap) ( Addr a, UInt len );
1284
1285 void (*bad_free) ( ThreadState* tst, Addr a );
1286 void (*mismatched_free) ( ThreadState* tst, Addr a );
1287
1288 void (*pre_mem_read) ( CorePart part, ThreadState* tst,
1289 Char* s, Addr a, UInt size );
1290 void (*pre_mem_read_asciiz) ( CorePart part, ThreadState* tst,
1291 Char* s, Addr a );
1292 void (*pre_mem_write) ( CorePart part, ThreadState* tst,
1293 Char* s, Addr a, UInt size );
1294 /* Not implemented yet -- have to add in lots of places, which is a
1295 pain. Won't bother unless/until there's a need. */
1296 /* void (*post_mem_read) ( ThreadState* tst, Char* s,
1297 Addr a, UInt size ); */
1298 void (*post_mem_write) ( Addr a, UInt size );
1299
1300
njnd5bb0a52002-09-27 10:24:48 +00001301 /* Scheduler events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001302 void (*thread_run) ( ThreadId tid );
1303
1304
njnd5bb0a52002-09-27 10:24:48 +00001305 /* Mutex events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001306 void (*post_mutex_lock) ( ThreadId tid,
1307 void* /*pthread_mutex_t* */ mutex );
1308 void (*post_mutex_unlock) ( ThreadId tid,
1309 void* /*pthread_mutex_t* */ mutex );
njn25e49d8e72002-09-23 09:36:25 +00001310
njnd5bb0a52002-09-27 10:24:48 +00001311
1312 /* Others... thread, condition variable, signal events... */
njn25e49d8e72002-09-23 09:36:25 +00001313 /* ... */
1314 }
1315 VgTrackEvents;
1316
1317/* Declare the struct instance */
1318extern VgTrackEvents VG_(track_events);
1319
1320
1321/* ------------------------------------------------------------------ */
1322/* Template functions */
1323
1324/* These are the parameterised functions in the core. The default definitions
njnd5bb0a52002-09-27 10:24:48 +00001325 are overridden by LD_PRELOADed skin version. At the very least, a skin
1326 must define the fundamental template functions. Depending on what needs
1327 are set, extra template functions will be used too. Functions are
1328 grouped under the needs that govern their use. */
njn25e49d8e72002-09-23 09:36:25 +00001329
1330
1331/* ------------------------------------------------------------------ */
1332/* Fundamental template functions */
1333
1334/* Initialise skin. Must do the following:
njnd04b7c62002-10-03 14:05:52 +00001335 - initialise the `details' struct
njn25e49d8e72002-09-23 09:36:25 +00001336 - register any helpers called by generated code
1337
1338 May do the following:
njnd04b7c62002-10-03 14:05:52 +00001339 - initialise the `needs' struct to indicate certain requirements
1340 - initialise the `track' struct to indicate core events of interest
njn25e49d8e72002-09-23 09:36:25 +00001341 - register any skin-specific profiling events
1342 - any other skin-specific initialisation
1343*/
njnd04b7c62002-10-03 14:05:52 +00001344extern void SK_(pre_clo_init) ( VgDetails* details, VgNeeds* needs,
1345 VgTrackEvents* track );
njn25e49d8e72002-09-23 09:36:25 +00001346
njnd5bb0a52002-09-27 10:24:48 +00001347/* Do initialisation that can only be done after command line processing. */
njn25e49d8e72002-09-23 09:36:25 +00001348extern void SK_(post_clo_init)( void );
1349
1350/* Instrument a basic block. Must be a true function, ie. the same input
1351 always results in the same output, because basic blocks can be
1352 retranslated. Unless you're doing something really strange...
1353 'orig_addr' is the address of the first instruction in the block. */
1354extern UCodeBlock* SK_(instrument) ( UCodeBlock* cb, Addr orig_addr );
1355
1356/* Finish up, print out any results, etc. */
1357extern void SK_(fini) ( void );
1358
1359
1360/* ------------------------------------------------------------------ */
1361/* VG_(needs).report_errors */
1362
1363/* Identify if two errors are equal, or equal enough. `res' indicates how
1364 close is "close enough". `res' should be passed on as necessary, eg. if
1365 the SkinError's extra field contains an ExeContext, `res' should be
1366 passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other
1367 than that, probably don't worry about it unless you have lots of very
1368 similar errors occurring.
1369 */
1370extern Bool SK_(eq_SkinError) ( VgRes res,
1371 SkinError* e1, SkinError* e2 );
1372
1373/* Print error context. The passed function pp_ExeContext() can be (and
1374 probably should be) used to print the location of the error. */
1375extern void SK_(pp_SkinError) ( SkinError* ec, void (*pp_ExeContext)(void) );
1376
1377/* Copy the ec->extra part and replace ec->extra with the new copy. This is
1378 necessary to move from a temporary stack copy to a permanent heap one.
1379
1380 Then fill in any details that could be postponed until after the decision
1381 whether to ignore the error (ie. details not affecting the result of
1382 SK_(eq_SkinError)()). This saves time when errors are ignored.
1383
1384 Yuk.
1385*/
1386extern void SK_(dup_extra_and_update)(SkinError* ec);
1387
1388/* Return value indicates recognition. If recognised, type goes in `skind'. */
1389extern Bool SK_(recognised_suppression) ( Char* name, SuppKind *skind );
1390
1391/* Read any extra info for this suppression kind. For filling up the
1392 `string' and `extra' fields in a `SkinSupp' struct if necessary. */
1393extern Bool SK_(read_extra_suppression_info) ( Int fd, Char* buf,
njnd5bb0a52002-09-27 10:24:48 +00001394 Int nBuf, SkinSupp *s );
njn25e49d8e72002-09-23 09:36:25 +00001395
1396/* This should just check the kinds match and maybe some stuff in the
1397 'extra' field if appropriate */
1398extern Bool SK_(error_matches_suppression)(SkinError* ec, SkinSupp* su);
1399
1400
1401/* ------------------------------------------------------------------ */
1402/* VG_(needs).basic_block_discards */
1403
njnd5bb0a52002-09-27 10:24:48 +00001404/* Should discard any information that pertains to specific basic blocks
1405 or instructions within the address range given. */
njn25e49d8e72002-09-23 09:36:25 +00001406extern void SK_(discard_basic_block_info) ( Addr a, UInt size );
1407
1408
1409/* ------------------------------------------------------------------ */
1410/* VG_(needs).shadow_regs */
1411
1412/* Valid values for general registers and EFLAGS register, for initialising
1413 and updating registers when written in certain places in core. */
1414extern void SK_(written_shadow_regs_values) ( UInt* gen_reg, UInt* eflags );
1415
1416
1417/* ------------------------------------------------------------------ */
1418/* VG_(needs).command_line_options */
1419
njnd5bb0a52002-09-27 10:24:48 +00001420/* Return True if option was recognised. Presumably sets some state to
1421 record the option as well. */
1422extern Bool SK_(process_cmd_line_option) ( Char* argv );
njn25e49d8e72002-09-23 09:36:25 +00001423
1424/* Print out command line usage for skin options */
1425extern Char* SK_(usage) ( void );
1426
1427
1428/* ------------------------------------------------------------------ */
1429/* VG_(needs).client_requests */
1430
1431extern UInt SK_(handle_client_request) ( ThreadState* tst, UInt* arg_block );
1432
1433
1434/* ------------------------------------------------------------------ */
1435/* VG_(needs).extends_UCode */
1436
njn4ba5a792002-09-30 10:23:54 +00001437/* Useful to use in VG_(get_Xreg_usage)() */
njnd5bb0a52002-09-27 10:24:48 +00001438#define VG_UINSTR_READS_REG(ono) \
njn25e49d8e72002-09-23 09:36:25 +00001439 { if (mycat(u->tag,ono) == tag) \
1440 { arr[n].num = mycat(u->val,ono); \
1441 arr[n].isWrite = False; \
1442 n++; \
1443 } \
1444 }
njnd5bb0a52002-09-27 10:24:48 +00001445#define VG_UINSTR_WRITES_REG(ono) \
1446 { if (mycat(u->tag,ono) == tag) \
1447 { arr[n].num = mycat(u->val,ono); \
1448 arr[n].isWrite = True; \
1449 n++; \
1450 } \
njn25e49d8e72002-09-23 09:36:25 +00001451 }
1452
njn4ba5a792002-09-30 10:23:54 +00001453/* 'X' prefix indicates eXtended UCode. */
1454extern Int SK_(get_Xreg_usage) ( UInstr* u, Tag tag, RegUse* arr );
1455extern void SK_(emit_XUInstr) ( UInstr* u, RRegSet regs_live_before );
1456extern Bool SK_(sane_XUInstr) ( Bool beforeRA, Bool beforeLiveness,
njn25e49d8e72002-09-23 09:36:25 +00001457 UInstr* u );
njn4ba5a792002-09-30 10:23:54 +00001458extern Char* SK_(name_XUOpcode) ( Opcode opc );
1459extern void SK_(pp_XUInstr) ( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +00001460
1461
1462/* ------------------------------------------------------------------ */
1463/* VG_(needs).syscall_wrapper */
1464
1465/* If either of the pre_ functions malloc() something to return, the
1466 * corresponding post_ function had better free() it!
1467 */
1468extern void* SK_( pre_syscall) ( ThreadId tid, UInt syscallno,
1469 Bool is_blocking );
1470extern void SK_(post_syscall) ( ThreadId tid, UInt syscallno,
1471 void* pre_result, Int res,
1472 Bool is_blocking );
1473
njnd5bb0a52002-09-27 10:24:48 +00001474
njn25e49d8e72002-09-23 09:36:25 +00001475/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +00001476/* VG_(needs).sizeof_shadow_chunk (if > 0) */
njn25e49d8e72002-09-23 09:36:25 +00001477
1478extern void SK_(complete_shadow_chunk) ( ShadowChunk* sc, ThreadState* tst );
1479
1480
1481/* ------------------------------------------------------------------ */
1482/* VG_(needs).alternative_free */
1483
1484extern void SK_(alt_free) ( ShadowChunk* sc, ThreadState* tst );
1485
njnd5bb0a52002-09-27 10:24:48 +00001486
njn25e49d8e72002-09-23 09:36:25 +00001487/* ---------------------------------------------------------------------
1488 VG_(needs).sanity_checks */
1489
njnd5bb0a52002-09-27 10:24:48 +00001490/* Can be useful for ensuring a skin's correctness. SK_(cheap_sanity_check)
1491 is called very frequently; SK_(expensive_sanity_check) is called less
1492 frequently and can be more involved. */
njn25e49d8e72002-09-23 09:36:25 +00001493extern Bool SK_(cheap_sanity_check) ( void );
1494extern Bool SK_(expensive_sanity_check) ( void );
1495
1496
1497#endif /* NDEF __VG_SKIN_H */
1498
1499/*--------------------------------------------------------------------*/
1500/*--- end vg_skin.h ---*/
1501/*--------------------------------------------------------------------*/
1502