blob: ab191b766c0fbcddef299fbb993de5bcf9979191 [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
sewardj7ab2aca2002-10-20 19:40:32 +0000256extern ThreadId VG_(get_current_tid) ( void );
sewardjb52a1b02002-10-23 21:38:22 +0000257extern ThreadId VG_(get_current_or_recent_tid) ( void );
sewardj7ab2aca2002-10-20 19:40:32 +0000258extern ThreadId VG_(get_tid_from_ThreadState) ( ThreadState* );
njn25e49d8e72002-09-23 09:36:25 +0000259extern ThreadState* VG_(get_ThreadState) ( ThreadId tid );
260
261
262/*====================================================================*/
263/*=== Valgrind's version of libc ===*/
264/*====================================================================*/
265
266/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
267 are its own versions of C library functions, but with VG_ prefixes. Note
268 that the types of some are slightly different to the real ones. Some
269 extra useful functions are provided too; descriptions of how they work
270 are given below. */
271
272#if !defined(NULL)
273# define NULL ((void*)0)
274#endif
275
276
277/* ------------------------------------------------------------------ */
278/* stdio.h
279 *
280 * Note that they all output to the file descriptor given by the
281 * --logfile-fd=N argument, which defaults to 2 (stderr). Hence no
282 * need for VG_(fprintf)().
njn25e49d8e72002-09-23 09:36:25 +0000283 */
sewardj78e3cd92002-10-22 04:45:48 +0000284extern UInt VG_(printf) ( const char *format, ... );
njn25e49d8e72002-09-23 09:36:25 +0000285/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
sewardj78e3cd92002-10-22 04:45:48 +0000286extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
287extern UInt VG_(vprintf) ( void(*send)(Char),
njn25e49d8e72002-09-23 09:36:25 +0000288 const Char *format, va_list vargs );
289
njn41557122002-10-14 09:25:37 +0000290extern Int VG_(rename) ( Char* old_name, Char* new_name );
291
njn25e49d8e72002-09-23 09:36:25 +0000292/* ------------------------------------------------------------------ */
293/* stdlib.h */
294
295extern void* VG_(malloc) ( Int nbytes );
njnd5bb0a52002-09-27 10:24:48 +0000296extern void VG_(free) ( void* p );
297extern void* VG_(calloc) ( Int n, Int nbytes );
298extern void* VG_(realloc) ( void* p, Int size );
299extern void* VG_(malloc_aligned) ( Int align_bytes, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000300
301extern void VG_(print_malloc_stats) ( void );
302
303
304extern void VG_(exit)( Int status )
305 __attribute__ ((__noreturn__));
njne427a662002-10-02 11:08:25 +0000306/* Prints a panic message (a constant string), appends newline and bug
307 reporting info, aborts. */
308__attribute__ ((__noreturn__))
309extern void VG_(skin_panic) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000310
njnd5bb0a52002-09-27 10:24:48 +0000311/* Looks up VG_(client_envp) */
njn25e49d8e72002-09-23 09:36:25 +0000312extern Char* VG_(getenv) ( Char* name );
313
314/* Crude stand-in for the glibc system() call. */
315extern Int VG_(system) ( Char* cmd );
316
njnd5bb0a52002-09-27 10:24:48 +0000317extern Long VG_(atoll) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000318
319/* Like atoll(), but converts a number of base 2..36 */
320extern Long VG_(atoll36) ( UInt base, Char* str );
321
322
323/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000324/* ctype.h */
njn25e49d8e72002-09-23 09:36:25 +0000325extern Bool VG_(isspace) ( Char c );
326extern Bool VG_(isdigit) ( Char c );
327extern Char VG_(toupper) ( Char c );
328
329
330/* ------------------------------------------------------------------ */
331/* string.h */
332extern Int VG_(strlen) ( const Char* str );
333extern Char* VG_(strcat) ( Char* dest, const Char* src );
334extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
335extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
336extern Char* VG_(strcpy) ( Char* dest, const Char* src );
337extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
338extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
339extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
340extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
341extern Char* VG_(strchr) ( const Char* s, Char c );
342extern Char* VG_(strdup) ( const Char* s);
sewardj7ab2aca2002-10-20 19:40:32 +0000343extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
344extern void* VG_(memset) ( void *s, Int c, Int sz );
njn25e49d8e72002-09-23 09:36:25 +0000345
njnd5bb0a52002-09-27 10:24:48 +0000346/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
njn25e49d8e72002-09-23 09:36:25 +0000347extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
njn25e49d8e72002-09-23 09:36:25 +0000348extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
349
njnd5bb0a52002-09-27 10:24:48 +0000350/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
351 last character. */
njn25e49d8e72002-09-23 09:36:25 +0000352extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
353
354/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
355 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
njn4ba5a792002-09-30 10:23:54 +0000356extern Bool VG_(string_match) ( Char* pat, Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000357
358
359/* ------------------------------------------------------------------ */
360/* math.h */
njnd5bb0a52002-09-27 10:24:48 +0000361/* Returns the base-2 logarithm of x. */
njn25e49d8e72002-09-23 09:36:25 +0000362extern Int VG_(log2) ( Int x );
363
364
365/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000366/* unistd.h, fcntl.h, sys/stat.h */
sewardj4cf05692002-10-27 20:28:29 +0000367extern Int VG_(getpid) ( void );
368extern Int VG_(getppid) ( void );
njnd5bb0a52002-09-27 10:24:48 +0000369
njn4aca2d22002-10-04 10:29:38 +0000370extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
371extern Int VG_(read) ( Int fd, void* buf, Int count);
372extern Int VG_(write) ( Int fd, void* buf, Int count);
373extern void VG_(close) ( Int fd );
njnd5bb0a52002-09-27 10:24:48 +0000374
njn41557122002-10-14 09:25:37 +0000375/* Nb: VG_(rename)() declared in stdio.h section above */
njn4aca2d22002-10-04 10:29:38 +0000376extern Int VG_(unlink) ( Char* file_name );
377extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
njn25e49d8e72002-09-23 09:36:25 +0000378
379
380/* ------------------------------------------------------------------ */
381/* assert.h */
382/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
383#define VG__STRING(__str) #__str
384
njne427a662002-10-02 11:08:25 +0000385#define sk_assert(expr) \
njn25e49d8e72002-09-23 09:36:25 +0000386 ((void) ((expr) ? 0 : \
njne427a662002-10-02 11:08:25 +0000387 (VG_(skin_assert_fail) (VG__STRING(expr), \
388 __FILE__, __LINE__, \
389 __PRETTY_FUNCTION__), 0)))
njn25e49d8e72002-09-23 09:36:25 +0000390
njne427a662002-10-02 11:08:25 +0000391__attribute__ ((__noreturn__))
392extern void VG_(skin_assert_fail) ( Char* expr, Char* file,
393 Int line, Char* fn );
njn25e49d8e72002-09-23 09:36:25 +0000394
395
396/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000397/* system/mman.h */
njn25e49d8e72002-09-23 09:36:25 +0000398extern void* VG_(mmap)( void* start, UInt length,
399 UInt prot, UInt flags, UInt fd, UInt offset );
400extern Int VG_(munmap)( void* start, Int length );
401
402/* Get memory by anonymous mmap. */
403extern void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who );
404
405
406/* ------------------------------------------------------------------ */
407/* signal.h.
408
409 Note that these use the vk_ (kernel) structure
410 definitions, which are different in places from those that glibc
411 defines -- hence the 'k' prefix. Since we're operating right at the
412 kernel interface, glibc's view of the world is entirely irrelevant. */
413
414/* --- Signal set ops --- */
njnd5bb0a52002-09-27 10:24:48 +0000415extern Int VG_(ksigfillset) ( vki_ksigset_t* set );
416extern Int VG_(ksigemptyset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000417
njnd5bb0a52002-09-27 10:24:48 +0000418extern Bool VG_(kisfullsigset) ( vki_ksigset_t* set );
419extern Bool VG_(kisemptysigset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000420
njnd5bb0a52002-09-27 10:24:48 +0000421extern Int VG_(ksigaddset) ( vki_ksigset_t* set, Int signum );
422extern Int VG_(ksigdelset) ( vki_ksigset_t* set, Int signum );
njn25e49d8e72002-09-23 09:36:25 +0000423extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
424
njnd5bb0a52002-09-27 10:24:48 +0000425extern void VG_(ksigaddset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
426extern void VG_(ksigdelset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
njn25e49d8e72002-09-23 09:36:25 +0000427
428/* --- Mess with the kernel's sig state --- */
njnd5bb0a52002-09-27 10:24:48 +0000429extern Int VG_(ksigprocmask) ( Int how, const vki_ksigset_t* set,
njn25e49d8e72002-09-23 09:36:25 +0000430 vki_ksigset_t* oldset );
njnd5bb0a52002-09-27 10:24:48 +0000431extern Int VG_(ksigaction) ( Int signum,
432 const vki_ksigaction* act,
433 vki_ksigaction* oldact );
njn25e49d8e72002-09-23 09:36:25 +0000434
njnd5bb0a52002-09-27 10:24:48 +0000435extern Int VG_(ksignal) ( Int signum, void (*sighandler)(Int) );
436extern Int VG_(ksigaltstack) ( const vki_kstack_t* ss, vki_kstack_t* oss );
njn25e49d8e72002-09-23 09:36:25 +0000437
sewardjdcaf3122002-09-30 23:12:33 +0000438extern Int VG_(kkill) ( Int pid, Int signo );
439extern Int VG_(ksigpending) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000440
441
442/*====================================================================*/
443/*=== UCode definition ===*/
444/*====================================================================*/
445
sewardje1042472002-09-30 12:33:11 +0000446/* Tags which describe what operands are. Must fit into 4 bits, which
447 they clearly do. */
njn25e49d8e72002-09-23 09:36:25 +0000448typedef
sewardje1042472002-09-30 12:33:11 +0000449enum { TempReg =0, /* virtual temp-reg */
450 ArchReg =1, /* simulated integer reg */
451 ArchRegS =2, /* simulated segment reg */
452 RealReg =3, /* real machine's real reg */
453 SpillNo =4, /* spill slot location */
454 Literal =5, /* literal; .lit32 field has actual value */
455 Lit16 =6, /* literal; .val[123] field has actual value */
456 NoValue =7 /* operand not in use */
457 }
458 Tag;
njn25e49d8e72002-09-23 09:36:25 +0000459
njnd5bb0a52002-09-27 10:24:48 +0000460/* Invalid register numbers (can't be negative) */
njn25e49d8e72002-09-23 09:36:25 +0000461#define INVALID_TEMPREG 999999999
462#define INVALID_REALREG 999999999
463
464/* Microinstruction opcodes. */
465typedef
466 enum {
njnd5bb0a52002-09-27 10:24:48 +0000467 NOP, /* Null op */
njn25e49d8e72002-09-23 09:36:25 +0000468
njnd5bb0a52002-09-27 10:24:48 +0000469 /* Moving values around */
470 GET, PUT, /* simulated register <--> TempReg */
471 GETF, PUTF, /* simulated %eflags <--> TempReg */
472 LOAD, STORE, /* memory <--> TempReg */
473 MOV, /* TempReg <--> TempReg */
474 CMOV, /* Used for cmpxchg and cmov */
njn25e49d8e72002-09-23 09:36:25 +0000475
njnd5bb0a52002-09-27 10:24:48 +0000476 /* Arithmetic/logical ops */
477 ADD, ADC, SUB, SBB, /* Add/subtract (w/wo carry) */
478 AND, OR, XOR, NOT, /* Boolean ops */
479 SHL, SHR, SAR, ROL, ROR, RCL, RCR, /* Shift/rotate (w/wo carry) */
480 NEG, /* Negate */
481 INC, DEC, /* Increment/decrement */
482 BSWAP, /* Big-endian <--> little-endian */
483 CC2VAL, /* Condition code --> 0 or 1 */
484 WIDEN, /* Signed or unsigned widening */
njn25e49d8e72002-09-23 09:36:25 +0000485
njnd5bb0a52002-09-27 10:24:48 +0000486 /* Conditional or unconditional jump */
487 JMP,
488
489 /* FPU ops */
490 FPU, /* Doesn't touch memory */
491 FPU_R, FPU_W, /* Reads/writes memory */
492
493 /* Not strictly needed, but improve address calculation translations. */
njn25e49d8e72002-09-23 09:36:25 +0000494 LEA1, /* reg2 := const + reg1 */
495 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
496
njnd5bb0a52002-09-27 10:24:48 +0000497 /* Hack for x86 REP insns. Jump to literal if TempReg/RealReg is zero. */
498 JIFZ,
njn25e49d8e72002-09-23 09:36:25 +0000499
njnd5bb0a52002-09-27 10:24:48 +0000500 /* Advance the simulated %eip by some small (< 128) number. */
501 INCEIP,
njn25e49d8e72002-09-23 09:36:25 +0000502
sewardje1042472002-09-30 12:33:11 +0000503 /* Dealing with segment registers */
504 GETSEG, PUTSEG, /* simulated segment register <--> TempReg */
505 USESEG, /* (LDT/GDT index, virtual addr) --> linear addr */
506
njnd5bb0a52002-09-27 10:24:48 +0000507 /* Not for translating x86 calls -- only to call helpers */
508 CALLM_S, CALLM_E, /* Mark start/end of CALLM push/pop sequence */
509 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers */
510 CALLM, /* Call assembly-code helper */
511
512 /* Not for translating x86 calls -- only to call C helper functions of
513 up to three arguments (or two if the functions has a return value).
514 Arguments and return value must be word-sized. More arguments can
515 be faked with global variables (eg. use VG_(set_global_var)()).
516
517 Seven possibilities: 'arg[123]' show where args go, 'ret' shows
518 where return value goes (if present).
njn25e49d8e72002-09-23 09:36:25 +0000519
520 CCALL(-, -, - ) void f(void)
521 CCALL(arg1, -, - ) void f(UInt arg1)
522 CCALL(arg1, arg2, - ) void f(UInt arg1, UInt arg2)
523 CCALL(arg1, arg2, arg3) void f(UInt arg1, UInt arg2, UInt arg3)
524 CCALL(-, -, ret ) UInt f(UInt)
525 CCALL(arg1, -, ret ) UInt f(UInt arg1)
njnd5bb0a52002-09-27 10:24:48 +0000526 CCALL(arg1, arg2, ret ) UInt f(UInt arg1, UInt arg2) */
njn25e49d8e72002-09-23 09:36:25 +0000527 CCALL,
528
njnd5bb0a52002-09-27 10:24:48 +0000529 /* This opcode makes it easy for skins that extend UCode to do this to
530 avoid opcode overlap:
njn25e49d8e72002-09-23 09:36:25 +0000531
njnd5bb0a52002-09-27 10:24:48 +0000532 enum { EU_OP1 = DUMMY_FINAL_UOPCODE + 1, ... }
njn25e49d8e72002-09-23 09:36:25 +0000533
534 WARNING: Do not add new opcodes after this one! They can be added
535 before, though. */
536 DUMMY_FINAL_UOPCODE
537 }
538 Opcode;
539
540
njnd5bb0a52002-09-27 10:24:48 +0000541/* Condition codes, using the Intel encoding. CondAlways is an extra. */
njn25e49d8e72002-09-23 09:36:25 +0000542typedef
543 enum {
544 CondO = 0, /* overflow */
545 CondNO = 1, /* no overflow */
546 CondB = 2, /* below */
547 CondNB = 3, /* not below */
548 CondZ = 4, /* zero */
549 CondNZ = 5, /* not zero */
550 CondBE = 6, /* below or equal */
551 CondNBE = 7, /* not below or equal */
552 CondS = 8, /* negative */
sewardje1042472002-09-30 12:33:11 +0000553 CondNS = 9, /* not negative */
njn25e49d8e72002-09-23 09:36:25 +0000554 CondP = 10, /* parity even */
555 CondNP = 11, /* not parity even */
556 CondL = 12, /* jump less */
557 CondNL = 13, /* not less */
558 CondLE = 14, /* less or equal */
559 CondNLE = 15, /* not less or equal */
560 CondAlways = 16 /* Jump always */
561 }
562 Condcode;
563
564
565/* Descriptions of additional properties of *unconditional* jumps. */
566typedef
567 enum {
568 JmpBoring=0, /* boring unconditional jump */
569 JmpCall=1, /* jump due to an x86 call insn */
570 JmpRet=2, /* jump due to an x86 ret insn */
571 JmpSyscall=3, /* do a system call, then jump */
572 JmpClientReq=4 /* do a client request, then jump */
573 }
574 JmpKind;
575
576
577/* Flags. User-level code can only read/write O(verflow), S(ign),
578 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
579 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
580 thusly:
581 76543210
582 DOSZACP
583 and bit 7 must always be zero since it is unused.
584*/
585typedef UChar FlagSet;
586
587#define FlagD (1<<6)
588#define FlagO (1<<5)
589#define FlagS (1<<4)
590#define FlagZ (1<<3)
591#define FlagA (1<<2)
592#define FlagC (1<<1)
593#define FlagP (1<<0)
594
595#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
596#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
597#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
598#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
599#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
600#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
601#define FlagsZCP ( FlagZ | FlagC | FlagP)
602#define FlagsOC (FlagO | FlagC )
603#define FlagsAC ( FlagA | FlagC )
604
605#define FlagsALL (FlagsOSZACP | FlagD)
606#define FlagsEmpty (FlagSet)0
607
608
609/* Liveness of general purpose registers, useful for code generation.
610 Reg rank order 0..N-1 corresponds to bits 0..N-1, ie. first
611 reg's liveness in bit 0, last reg's in bit N-1. Note that
612 these rankings don't match the Intel register ordering. */
613typedef UInt RRegSet;
614
615#define ALL_RREGS_DEAD 0 /* 0000...00b */
njne7c258c2002-10-03 08:57:01 +0000616#define ALL_RREGS_LIVE ((1 << VG_MAX_REALREGS)-1) /* 0011...11b */
njn25e49d8e72002-09-23 09:36:25 +0000617#define UNIT_RREGSET(rank) (1 << (rank))
618
619#define IS_RREG_LIVE(rank,rregs_live) (rregs_live & UNIT_RREGSET(rank))
620#define SET_RREG_LIVENESS(rank,rregs_live,b) \
621 do { RRegSet unit = UNIT_RREGSET(rank); \
622 if (b) rregs_live |= unit; \
623 else rregs_live &= ~unit; \
624 } while(0)
625
626
627/* A Micro (u)-instruction. */
628typedef
629 struct {
630 /* word 1 */
631 UInt lit32; /* 32-bit literal */
632
633 /* word 2 */
634 UShort val1; /* first operand */
635 UShort val2; /* second operand */
636
637 /* word 3 */
638 UShort val3; /* third operand */
639 UChar opcode; /* opcode */
640 UChar size; /* data transfer size */
641
642 /* word 4 */
643 FlagSet flags_r; /* :: FlagSet */
644 FlagSet flags_w; /* :: FlagSet */
645 UChar tag1:4; /* first operand tag */
646 UChar tag2:4; /* second operand tag */
647 UChar tag3:4; /* third operand tag */
648 UChar extra4b:4; /* Spare field, used by WIDEN for src
649 -size, and by LEA2 for scale (1,2,4 or 8),
650 and by JMPs for original x86 instr size */
651
652 /* word 5 */
653 UChar cond; /* condition, for jumps */
654 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
655 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
656
657 /* Additional properties for UInstrs that call C functions:
658 - CCALL
659 - PUT (when %ESP is the target)
660 - possibly skin-specific UInstrs
661 */
662 UChar argc:2; /* Number of args, max 3 */
663 UChar regparms_n:2; /* Number of args passed in registers */
664 Bool has_ret_val:1; /* Function has return value? */
665
666 /* RealReg liveness; only sensical after reg alloc and liveness
667 analysis done. This info is a little bit arch-specific --
668 VG_MAX_REALREGS can vary on different architectures. Note that
669 to use this information requires converting between register ranks
njn4ba5a792002-09-30 10:23:54 +0000670 and the Intel register numbers, using VG_(realreg_to_rank)()
671 and/or VG_(rank_to_realreg)() */
njn25e49d8e72002-09-23 09:36:25 +0000672 RRegSet regs_live_after:VG_MAX_REALREGS;
673 }
674 UInstr;
675
676
677/* Expandable arrays of uinstrs. */
678typedef
679 struct {
680 Int used;
681 Int size;
682 UInstr* instrs;
683 Int nextTemp;
684 }
685 UCodeBlock;
686
687
688/*====================================================================*/
689/*=== Instrumenting UCode ===*/
690/*====================================================================*/
691
692/* A structure for communicating TempReg and RealReg uses of UInstrs. */
693typedef
694 struct {
695 Int num;
696 Bool isWrite;
697 }
698 RegUse;
699
700/* Find what this instruction does to its regs. Tag indicates whether we're
701 * considering TempRegs (pre-reg-alloc) or RealRegs (post-reg-alloc).
702 * Useful for analysis/optimisation passes. */
njn4ba5a792002-09-30 10:23:54 +0000703extern Int VG_(get_reg_usage) ( UInstr* u, Tag tag, RegUse* arr );
njn25e49d8e72002-09-23 09:36:25 +0000704
705
706/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000707/* Used to register helper functions to be called from generated code. A
708 limited number of compact helpers can be registered; the code generated
709 to call them is slightly shorter -- so register the mostly frequently
710 called helpers as compact. */
njn25e49d8e72002-09-23 09:36:25 +0000711extern void VG_(register_compact_helper) ( Addr a );
712extern void VG_(register_noncompact_helper) ( Addr a );
713
714
715/* ------------------------------------------------------------------ */
716/* Virtual register allocation */
717
718/* Get a new virtual register */
njn4ba5a792002-09-30 10:23:54 +0000719extern Int VG_(get_new_temp) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000720
721/* Get a new virtual shadow register */
njn4ba5a792002-09-30 10:23:54 +0000722extern Int VG_(get_new_shadow) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000723
724/* Get a virtual register's corresponding virtual shadow register */
725#define SHADOW(tempreg) ((tempreg)+1)
726
727
728/* ------------------------------------------------------------------ */
729/* Low-level UInstr builders */
njn4ba5a792002-09-30 10:23:54 +0000730extern void VG_(new_NOP) ( UInstr* u );
731extern void VG_(new_UInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
732extern void VG_(new_UInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000733 Tag tag1, UInt val1 );
njn4ba5a792002-09-30 10:23:54 +0000734extern void VG_(new_UInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000735 Tag tag1, UInt val1,
736 Tag tag2, UInt val2 );
njn4ba5a792002-09-30 10:23:54 +0000737extern void VG_(new_UInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000738 Tag tag1, UInt val1,
739 Tag tag2, UInt val2,
740 Tag tag3, UInt val3 );
njn25e49d8e72002-09-23 09:36:25 +0000741
njn4ba5a792002-09-30 10:23:54 +0000742extern void VG_(set_flag_RW) ( UInstr* u, FlagSet fr, FlagSet fw );
743extern void VG_(set_lit_field) ( UCodeBlock* cb, UInt lit32 );
744extern void VG_(set_ccall_fields) ( UCodeBlock* cb, Addr fn, UChar argc,
745 UChar regparms_n, Bool has_ret_val );
njn25e49d8e72002-09-23 09:36:25 +0000746
njn4ba5a792002-09-30 10:23:54 +0000747extern void VG_(copy_UInstr) ( UCodeBlock* cb, UInstr* instr );
748
749extern Bool VG_(any_flag_use)( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +0000750
njnac6c1762002-10-04 14:34:15 +0000751/* Macro versions of the above; just shorter to type. */
752#define uInstr0 VG_(new_UInstr0)
753#define uInstr1 VG_(new_UInstr1)
754#define uInstr2 VG_(new_UInstr2)
755#define uInstr3 VG_(new_UInstr3)
756#define uLiteral VG_(set_lit_field)
757#define uCCall VG_(set_ccall_fields)
758#define newTemp VG_(get_new_temp)
759#define newShadow VG_(get_new_shadow)
760
njn25e49d8e72002-09-23 09:36:25 +0000761/* Refer to `the last instruction stuffed in' (can be lvalue). */
762#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
763
764
765/* ------------------------------------------------------------------ */
766/* Higher-level UInstr sequence builders */
njn4ba5a792002-09-30 10:23:54 +0000767extern void VG_(call_helper_0_0) ( UCodeBlock* cb, Addr f);
768extern void VG_(call_helper_1_0) ( UCodeBlock* cb, Addr f, UInt arg1,
769 UInt regparms_n);
770extern void VG_(call_helper_2_0) ( UCodeBlock* cb, Addr f, UInt arg1, UInt arg2,
771 UInt regparms_n);
njn25e49d8e72002-09-23 09:36:25 +0000772
773/* One way around the 3-arg C function limit is to pass args via global
774 * variables... ugly, but it works. */
njn4ba5a792002-09-30 10:23:54 +0000775extern void VG_(set_global_var) ( UCodeBlock* cb, Addr globvar_ptr, UInt val);
njn25e49d8e72002-09-23 09:36:25 +0000776
777/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000778/* Allocating/freeing basic blocks of UCode */
njn4ba5a792002-09-30 10:23:54 +0000779extern UCodeBlock* VG_(alloc_UCodeBlock) ( void );
780extern void VG_(free_UCodeBlock) ( UCodeBlock* cb );
njnd5bb0a52002-09-27 10:24:48 +0000781
782/* ------------------------------------------------------------------ */
783/* UCode pretty/ugly printing. Probably only useful to call from a skin
njn25e49d8e72002-09-23 09:36:25 +0000784 if VG_(needs).extended_UCode == True. */
785
786/* When True, all generated code is/should be printed. */
787extern Bool VG_(print_codegen);
788
njn4ba5a792002-09-30 10:23:54 +0000789/* Pretty/ugly printing functions */
790extern void VG_(pp_UCodeBlock) ( UCodeBlock* cb, Char* title );
791extern void VG_(pp_UInstr) ( Int instrNo, UInstr* u );
792extern void VG_(pp_UInstr_regs) ( Int instrNo, UInstr* u );
793extern void VG_(up_UInstr) ( Int instrNo, UInstr* u );
794extern Char* VG_(name_UOpcode) ( Bool upper, Opcode opc );
795extern void VG_(pp_UOperand) ( UInstr* u, Int operandNo,
796 Int sz, Bool parens );
njn25e49d8e72002-09-23 09:36:25 +0000797
njn25e49d8e72002-09-23 09:36:25 +0000798
799/*====================================================================*/
njnd5bb0a52002-09-27 10:24:48 +0000800/*=== Generating x86 code from UCode ===*/
njn25e49d8e72002-09-23 09:36:25 +0000801/*====================================================================*/
802
njnd5bb0a52002-09-27 10:24:48 +0000803/* All this only necessary for skins with VG_(needs).extends_UCode == True. */
njn25e49d8e72002-09-23 09:36:25 +0000804
sewardje1042472002-09-30 12:33:11 +0000805/* This is the Intel register encoding -- integer regs. */
njn25e49d8e72002-09-23 09:36:25 +0000806#define R_EAX 0
807#define R_ECX 1
808#define R_EDX 2
809#define R_EBX 3
810#define R_ESP 4
811#define R_EBP 5
812#define R_ESI 6
813#define R_EDI 7
814
815#define R_AL (0+R_EAX)
816#define R_CL (0+R_ECX)
817#define R_DL (0+R_EDX)
818#define R_BL (0+R_EBX)
819#define R_AH (4+R_EAX)
820#define R_CH (4+R_ECX)
821#define R_DH (4+R_EDX)
822#define R_BH (4+R_EBX)
823
sewardje1042472002-09-30 12:33:11 +0000824/* This is the Intel register encoding -- segment regs. */
825#define R_ES 0
826#define R_CS 1
827#define R_SS 2
828#define R_DS 3
829#define R_FS 4
830#define R_GS 5
831
njn25e49d8e72002-09-23 09:36:25 +0000832/* For pretty printing x86 code */
sewardje1042472002-09-30 12:33:11 +0000833extern Char* VG_(name_of_seg_reg) ( Int sreg );
njn4ba5a792002-09-30 10:23:54 +0000834extern Char* VG_(name_of_int_reg) ( Int size, Int reg );
835extern Char VG_(name_of_int_size) ( Int size );
njn25e49d8e72002-09-23 09:36:25 +0000836
njnac6c1762002-10-04 14:34:15 +0000837/* Shorter macros for convenience */
838#define nameIReg VG_(name_of_int_reg)
839#define nameISize VG_(name_of_int_size)
840#define nameSReg VG_(name_of_seg_reg)
841
njn25e49d8e72002-09-23 09:36:25 +0000842/* Randomly useful things */
843extern UInt VG_(extend_s_8to32) ( UInt x );
844
845/* Code emitters */
njn4ba5a792002-09-30 10:23:54 +0000846extern void VG_(emitB) ( UInt b );
847extern void VG_(emitW) ( UInt w );
848extern void VG_(emitL) ( UInt l );
849extern void VG_(new_emit) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000850
851/* Finding offsets */
njn4ba5a792002-09-30 10:23:54 +0000852extern Int VG_(helper_offset) ( Addr a );
853extern Int VG_(shadow_reg_offset) ( Int arch );
854extern Int VG_(shadow_flags_offset) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000855
njnd5bb0a52002-09-27 10:24:48 +0000856/* Convert reg ranks <-> Intel register ordering, for using register
857 liveness information. */
njn4ba5a792002-09-30 10:23:54 +0000858extern Int VG_(realreg_to_rank) ( Int realreg );
859extern Int VG_(rank_to_realreg) ( Int rank );
njn25e49d8e72002-09-23 09:36:25 +0000860
njnd5bb0a52002-09-27 10:24:48 +0000861/* Call a subroutine. Does no argument passing, stack manipulations, etc. */
njn4ba5a792002-09-30 10:23:54 +0000862extern void VG_(synth_call) ( Bool ensure_shortform, Int word_offset );
njn25e49d8e72002-09-23 09:36:25 +0000863
njnd5bb0a52002-09-27 10:24:48 +0000864/* For calling C functions -- saves caller save regs, pushes args, calls,
865 clears the stack, restores caller save regs. `fn' must be registered in
866 the baseBlock first. Acceptable tags are RealReg and Literal. Optimises
867 things, eg. by not preserving non-live caller-save registers.
njn25e49d8e72002-09-23 09:36:25 +0000868
njnd5bb0a52002-09-27 10:24:48 +0000869 WARNING: a UInstr should *not* be translated with synth_ccall() followed
870 by some other x86 assembly code; this will invalidate the results of
871 vg_realreg_liveness_analysis() and everything will fall over. */
njn4ba5a792002-09-30 10:23:54 +0000872extern void VG_(synth_ccall) ( Addr fn, Int argc, Int regparms_n, UInt argv[],
873 Tag tagv[], Int ret_reg,
874 RRegSet regs_live_before,
875 RRegSet regs_live_after );
njn25e49d8e72002-09-23 09:36:25 +0000876
877/* Addressing modes */
njn4ba5a792002-09-30 10:23:54 +0000878extern void VG_(emit_amode_offregmem_reg)( Int off, Int regmem, Int reg );
879extern void VG_(emit_amode_ereg_greg) ( Int e_reg, Int g_reg );
njn25e49d8e72002-09-23 09:36:25 +0000880
881/* v-size (4, or 2 with OSO) insn emitters */
njn4ba5a792002-09-30 10:23:54 +0000882extern void VG_(emit_movv_offregmem_reg) ( Int sz, Int off, Int areg, Int reg );
883extern void VG_(emit_movv_reg_offregmem) ( Int sz, Int reg, Int off, Int areg );
884extern void VG_(emit_movv_reg_reg) ( Int sz, Int reg1, Int reg2 );
885extern void VG_(emit_nonshiftopv_lit_reg)( Int sz, Opcode opc, UInt lit,
886 Int reg );
887extern void VG_(emit_shiftopv_lit_reg) ( Int sz, Opcode opc, UInt lit,
888 Int reg );
889extern void VG_(emit_nonshiftopv_reg_reg)( Int sz, Opcode opc,
890 Int reg1, Int reg2 );
891extern void VG_(emit_movv_lit_reg) ( Int sz, UInt lit, Int reg );
892extern void VG_(emit_unaryopv_reg) ( Int sz, Opcode opc, Int reg );
893extern void VG_(emit_pushv_reg) ( Int sz, Int reg );
894extern void VG_(emit_popv_reg) ( Int sz, Int reg );
njn25e49d8e72002-09-23 09:36:25 +0000895
njn4ba5a792002-09-30 10:23:54 +0000896extern void VG_(emit_pushl_lit32) ( UInt int32 );
897extern void VG_(emit_pushl_lit8) ( Int lit8 );
898extern void VG_(emit_cmpl_zero_reg) ( Int reg );
899extern void VG_(emit_swapl_reg_EAX) ( Int reg );
900extern void VG_(emit_movv_lit_offregmem) ( Int sz, UInt lit, Int off,
901 Int memreg );
njn25e49d8e72002-09-23 09:36:25 +0000902
903/* b-size (1 byte) instruction emitters */
njn4ba5a792002-09-30 10:23:54 +0000904extern void VG_(emit_movb_lit_offregmem) ( UInt lit, Int off, Int memreg );
905extern void VG_(emit_movb_reg_offregmem) ( Int reg, Int off, Int areg );
906extern void VG_(emit_unaryopb_reg) ( Opcode opc, Int reg );
907extern void VG_(emit_testb_lit_reg) ( UInt lit, Int reg );
njn25e49d8e72002-09-23 09:36:25 +0000908
909/* zero-extended load emitters */
njn4ba5a792002-09-30 10:23:54 +0000910extern void VG_(emit_movzbl_offregmem_reg) ( Int off, Int regmem, Int reg );
911extern void VG_(emit_movzwl_offregmem_reg) ( Int off, Int areg, Int reg );
njn25e49d8e72002-09-23 09:36:25 +0000912
913/* misc instruction emitters */
njn4ba5a792002-09-30 10:23:54 +0000914extern void VG_(emit_call_reg) ( Int reg );
915extern void VG_(emit_add_lit_to_esp) ( Int lit );
916extern void VG_(emit_jcondshort_delta) ( Condcode cond, Int delta );
917extern void VG_(emit_pushal) ( void );
918extern void VG_(emit_popal) ( void );
919extern void VG_(emit_AMD_prefetch_reg) ( Int reg );
njn25e49d8e72002-09-23 09:36:25 +0000920
921
922/*====================================================================*/
923/*=== Execution contexts ===*/
924/*====================================================================*/
925
926/* Generic resolution type used in a few different ways, such as deciding
927 how closely to compare two errors for equality. */
928typedef
929 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
930 VgRes;
931
932typedef
933 struct _ExeContext
934 ExeContext;
935
njnd5bb0a52002-09-27 10:24:48 +0000936/* Compare two ExeContexts. Number of callers considered depends on `res':
937 Vg_LowRes: 2
938 Vg_MedRes: 4
939 Vg_HighRes: all */
njn25e49d8e72002-09-23 09:36:25 +0000940extern Bool VG_(eq_ExeContext) ( VgRes res,
941 ExeContext* e1, ExeContext* e2 );
942
943/* Print an ExeContext. */
944extern void VG_(pp_ExeContext) ( ExeContext* );
945
946/* Take a snapshot of the client's stack. Search our collection of
947 ExeContexts to see if we already have it, and if not, allocate a
948 new one. Either way, return a pointer to the context. */
949extern ExeContext* VG_(get_ExeContext) ( ThreadState *tst );
950
951
952/*====================================================================*/
953/*=== Error reporting ===*/
954/*====================================================================*/
955
956/* ------------------------------------------------------------------ */
957/* Suppressions describe errors which we want to suppress, ie, not
958 show the user, usually because it is caused by a problem in a library
959 which we can't fix, replace or work around. Suppressions are read from
njnd5bb0a52002-09-27 10:24:48 +0000960 a file at startup time. This gives flexibility so that new
njn25e49d8e72002-09-23 09:36:25 +0000961 suppressions can be added to the file as and when needed.
962*/
963
964typedef
965 Int /* Do not make this unsigned! */
966 SuppKind;
967
968/* An extensible (via the 'extra' field) suppression record. This holds
969 the suppression details of interest to a skin. Skins can use a normal
970 enum (with element values in the normal range (0..)) for `skind'.
971
972 If VG_(needs).report_errors==True, for each suppression read in by core
973 SKN_(recognised_suppression)() and SKN_(read_extra_suppression_info) will
974 be called. The `skind' field is filled in by the value returned in the
975 argument of the first function; the second function can fill in the
976 `string' and `extra' fields if it wants.
977*/
978typedef
979 struct {
980 /* What kind of suppression. Must use the range (0..) */
981 SuppKind skind;
982 /* String -- use is optional. NULL by default. */
983 Char* string;
984 /* Anything else -- use is optional. NULL by default. */
985 void* extra;
986 }
987 SkinSupp;
988
989
990/* ------------------------------------------------------------------ */
991/* Error records contain enough info to generate an error report. The idea
992 is that (typically) the same few points in the program generate thousands
njnd5bb0a52002-09-27 10:24:48 +0000993 of errors, and we don't want to spew out a fresh error message for each
994 one. Instead, we use these structures to common up duplicates.
njn25e49d8e72002-09-23 09:36:25 +0000995*/
996
997typedef
998 Int /* Do not make this unsigned! */
999 ErrorKind;
1000
1001/* An extensible (via the 'extra' field) error record. This holds
1002 the error details of interest to a skin. Skins can use a normal
1003 enum (with element values in the normal range (0..)) for `ekind'.
1004
1005 When errors are found and recorded with VG_(maybe_record_error)(), all
1006 the skin must do is pass in the four parameters; core will
1007 allocate/initialise the error record.
1008*/
1009typedef
1010 struct {
1011 /* Used by ALL. Must be in the range (0..) */
1012 Int ekind;
1013 /* Used frequently */
1014 Addr addr;
1015 /* Used frequently */
1016 Char* string;
njnd5bb0a52002-09-27 10:24:48 +00001017 /* For any skin-specific extras */
njn25e49d8e72002-09-23 09:36:25 +00001018 void* extra;
1019 }
1020 SkinError;
1021
1022
1023/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +00001024/* Call this when an error occurs. It will be recorded if it hasn't been
njn25e49d8e72002-09-23 09:36:25 +00001025 seen before. If it has, the existing error record will have its count
1026 incremented.
1027
1028 If the error occurs in generated code, 'tst' should be NULL. If the
1029 error occurs in non-generated code, 'tst' should be non-NULL. The
1030 `extra' field can be stack-allocated; it will be copied (using
1031 SKN_(dup_extra_and_update)()) if needed. But it won't be copied
1032 if it's NULL.
njnd5bb0a52002-09-27 10:24:48 +00001033
1034 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
1035 NULL for them.
njn25e49d8e72002-09-23 09:36:25 +00001036*/
1037extern void VG_(maybe_record_error) ( ThreadState* tst, ErrorKind ekind,
1038 Addr a, Char* s, void* extra );
1039
1040/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
1041 Skips leading spaces on the line. Returns True if EOF was hit instead.
1042 Useful for reading in extra skin-specific suppression lines.
1043*/
njn4ba5a792002-09-30 10:23:54 +00001044extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
njn25e49d8e72002-09-23 09:36:25 +00001045
1046
1047/*====================================================================*/
1048/*=== Obtaining debug information ===*/
1049/*====================================================================*/
1050
1051/* Get the file/function/line number of the instruction at address 'a'.
1052 For these four, if debug info for the address is found, it copies the
1053 info into the buffer/UInt and returns True. If not, it returns False and
1054 nothing is copied. VG_(get_fnname) always demangles C++ function names.
1055*/
1056extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
1057extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
1058extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
1059
1060/* This one is more efficient if getting both filename and line number,
1061 because the two lookups are done together. */
1062extern Bool VG_(get_filename_linenum)
1063 ( Addr a, Char* filename, Int n_filename,
1064 UInt* linenum );
1065
1066/* Succeeds only if we find from debug info that 'a' is the address of the
1067 first instruction in a function -- as opposed to VG_(get_fnname) which
1068 succeeds if we find from debug info that 'a' is the address of any
1069 instruction in a function. Use this to instrument the start of
njnd5bb0a52002-09-27 10:24:48 +00001070 a particular function. Nb: if an executable/shared object is stripped
njn25e49d8e72002-09-23 09:36:25 +00001071 of its symbols, this function will not be able to recognise function
1072 entry points within it. */
1073extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* filename, Int n_filename );
1074
1075/* Succeeds if the address is within a shared object or the main executable.
1076 It doesn't matter if debug info is present or not. */
1077extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
1078
sewardj47104382002-10-20 18:35:48 +00001079/* A way to get information about what segments are mapped */
1080typedef struct _SegInfo SegInfo;
1081
1082extern const SegInfo* VG_(next_seginfo)(const SegInfo *);
1083extern Addr VG_(seg_start)(const SegInfo *);
1084extern UInt VG_(seg_size)(const SegInfo *);
1085extern const UChar* VG_(seg_filename)(const SegInfo *);
1086extern UInt VG_(seg_sym_offset)(const SegInfo *);
1087
1088typedef
1089 enum {
1090 Vg_SectUnknown,
1091 Vg_SectText,
sewardj8fe15a32002-10-20 19:29:21 +00001092 Vg_SectData,
1093 Vg_SectBSS,
sewardj47104382002-10-20 18:35:48 +00001094 Vg_SectGOT,
sewardj8fe15a32002-10-20 19:29:21 +00001095 Vg_SectPLT,
sewardj47104382002-10-20 18:35:48 +00001096 }
1097 VgSectKind;
1098
1099extern VgSectKind VG_(seg_sect_kind)(Addr);
1100
njn25e49d8e72002-09-23 09:36:25 +00001101
1102/*====================================================================*/
1103/*=== Shadow chunks and block-finding ===*/
1104/*====================================================================*/
1105
1106typedef
1107 enum {
1108 Vg_AllocMalloc = 0,
1109 Vg_AllocNew = 1,
1110 Vg_AllocNewVec = 2
1111 }
1112 VgAllocKind;
1113
1114/* Description of a malloc'd chunk. skin_extra[] part can be used by
1115 the skin; size of array is given by VG_(needs).sizeof_shadow_chunk. */
1116typedef
1117 struct _ShadowChunk {
1118 struct _ShadowChunk* next;
1119 UInt size : 30; /* size requested */
1120 VgAllocKind allockind : 2; /* which wrapper did the allocation */
1121 Addr data; /* ptr to actual block */
1122 UInt skin_extra[0]; /* extra skin-specific info */
1123 }
1124 ShadowChunk;
1125
1126/* Use this to free blocks if VG_(needs).alternative_free == True.
1127 It frees the ShadowChunk and the malloc'd block it points to. */
njn4ba5a792002-09-30 10:23:54 +00001128extern void VG_(free_ShadowChunk) ( ShadowChunk* sc );
njn25e49d8e72002-09-23 09:36:25 +00001129
1130/* Makes an array of pointers to all the shadow chunks of malloc'd blocks */
1131extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
1132
1133/* Determines if address 'a' is within the bounds of the block at start.
1134 Allows a little 'slop' round the edges. */
1135extern Bool VG_(addr_is_in_block) ( Addr a, Addr start, UInt size );
1136
1137/* Searches through currently malloc'd blocks until a matching one is found.
1138 Returns NULL if none match. Extra arguments can be implicitly passed to
njnd5bb0a52002-09-27 10:24:48 +00001139 p using nested functions; see memcheck/mc_errcontext.c for an example. */
njn25e49d8e72002-09-23 09:36:25 +00001140extern ShadowChunk* VG_(any_matching_mallocd_ShadowChunks)
1141 ( Bool (*p) ( ShadowChunk* ));
1142
1143/* Searches through all thread's stacks to see if any match. Returns
1144 * VG_INVALID_THREADID if none match. */
1145extern ThreadId VG_(any_matching_thread_stack)
1146 ( Bool (*p) ( Addr stack_min, Addr stack_max ));
1147
sewardja4495682002-10-21 07:29:59 +00001148/* Do memory leak detection. */
1149extern void VG_(generic_detect_memory_leaks) (
1150 Bool is_valid_64k_chunk ( UInt ),
1151 Bool is_valid_address ( Addr ),
1152 ExeContext* get_where ( ShadowChunk* ),
1153 VgRes leak_resolution,
1154 Bool show_reachable
1155 );
1156
1157
njn25e49d8e72002-09-23 09:36:25 +00001158/*====================================================================*/
1159/*=== Skin-specific stuff ===*/
1160/*====================================================================*/
1161
njnd04b7c62002-10-03 14:05:52 +00001162/* ------------------------------------------------------------------ */
1163/* Details */
1164typedef
1165 struct {
1166 /* Information used in the startup message. `name' also determines the
1167 string used for identifying suppressions in a suppression file as
1168 belonging to this skin. `version' can be NULL, in which case (not
1169 surprisingly) no version info is printed; this mechanism is
1170 designed for skins distributed with Valgrind that share a version
1171 number with Valgrind. Other skins not distributed as part of
1172 Valgrind should probably have their own version number. */
1173 Char* name;
1174 Char* version;
1175 Char* description;
1176 Char* copyright_author;
1177
1178 /* String printed if an `sk_assert' assertion fails or VG_(skin_panic)
1179 is called. Should probably be an email address. */
1180 Char* bug_reports_to;
1181 }
1182 VgDetails;
1183
1184extern VgDetails VG_(details);
1185
1186/* ------------------------------------------------------------------ */
1187/* Needs */
1188
1189/* If new fields are added to this type, update:
njnd5bb0a52002-09-27 10:24:48 +00001190 * - vg_main.c:initialisation of VG_(needs)
njn25e49d8e72002-09-23 09:36:25 +00001191 * - vg_main.c:sanity_check_needs()
1192 *
1193 * If the name of this type or any of its fields change, update:
1194 * - dependent comments (just search for "VG_(needs)").
1195 */
1196typedef
1197 struct {
njnd5bb0a52002-09-27 10:24:48 +00001198 /* Booleans that decide core behaviour, but don't require extra
1199 operations to be defined if `True' */
1200
1201 /* Should __libc_freeres() be run? Bugs in it can crash the skin. */
njnd04b7c62002-10-03 14:05:52 +00001202 Bool libc_freeres;
njn25e49d8e72002-09-23 09:36:25 +00001203
1204 /* Want to have errors detected by Valgrind's core reported? Includes:
1205 - pthread API errors (many; eg. unlocking a non-locked mutex)
1206 - silly arguments to malloc() et al (eg. negative size)
1207 - invalid file descriptors to blocking syscalls read() and write()
1208 - bad signal numbers passed to sigaction()
1209 - attempt to install signal handler for SIGKILL or SIGSTOP */
1210 Bool core_errors;
njn25e49d8e72002-09-23 09:36:25 +00001211
1212 /* Booleans that indicate extra operations are defined; if these are
1213 True, the corresponding template functions (given below) must be
1214 defined. A lot like being a member of a type class. */
1215
njnd5bb0a52002-09-27 10:24:48 +00001216 /* Want to report errors from the skin? This implies use of
1217 suppressions, too. */
1218 Bool skin_errors;
1219
njn25e49d8e72002-09-23 09:36:25 +00001220 /* Is information kept about specific individual basic blocks? (Eg. for
njnd5bb0a52002-09-27 10:24:48 +00001221 cachegrind there are cost-centres for every instruction, stored at a
njn25e49d8e72002-09-23 09:36:25 +00001222 basic block level.) If so, it sometimes has to be discarded, because
1223 .so mmap/munmap-ping or self-modifying code (informed by the
1224 DISCARD_TRANSLATIONS user request) can cause one instruction address
njnd5bb0a52002-09-27 10:24:48 +00001225 to be used for more than one instruction in one program run... */
njn25e49d8e72002-09-23 09:36:25 +00001226 Bool basic_block_discards;
1227
njnd5bb0a52002-09-27 10:24:48 +00001228 /* Skin maintains information about each register? */
njn25e49d8e72002-09-23 09:36:25 +00001229 Bool shadow_regs;
1230
1231 /* Skin defines its own command line options? */
1232 Bool command_line_options;
1233 /* Skin defines its own client requests? */
1234 Bool client_requests;
1235
1236 /* Skin defines its own UInstrs? */
1237 Bool extended_UCode;
1238
1239 /* Skin does stuff before and/or after system calls? */
1240 Bool syscall_wrapper;
1241
1242 /* Size, in words, of extra info about malloc'd blocks recorded by
1243 skin. Be careful to get this right or you'll get seg faults! */
1244 UInt sizeof_shadow_block;
1245
1246 /* Skin does free()s itself? */
1247 Bool alternative_free;
1248
1249 /* Are skin-state sanity checks performed? */
1250 Bool sanity_checks;
sewardj8fe15a32002-10-20 19:29:21 +00001251
1252 /* Do we need to see data symbols? */
1253 Bool data_syms;
njn25e49d8e72002-09-23 09:36:25 +00001254 }
1255 VgNeeds;
1256
1257extern VgNeeds VG_(needs);
1258
1259
1260/* ------------------------------------------------------------------ */
1261/* Core events to track */
1262
1263/* Part of the core from which this call was made. Useful for determining
njnd5bb0a52002-09-27 10:24:48 +00001264 what kind of error message should be emitted. */
njn25e49d8e72002-09-23 09:36:25 +00001265typedef
1266 enum { Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall, Vg_CoreTranslate }
1267 CorePart;
1268
1269/* Events happening in core to track. To be notified, assign a function
njnd5bb0a52002-09-27 10:24:48 +00001270 to the function pointer. To ignore an event, don't do anything
1271 (default assignment is to NULL in which case the call is skipped). */
njn25e49d8e72002-09-23 09:36:25 +00001272typedef
1273 struct {
1274 /* Memory events */
1275 void (*new_mem_startup)( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
1276 void (*new_mem_heap) ( Addr a, UInt len, Bool is_inited );
1277 void (*new_mem_stack) ( Addr a, UInt len );
1278 void (*new_mem_stack_aligned) ( Addr a, UInt len );
1279 void (*new_mem_stack_signal) ( Addr a, UInt len );
1280 void (*new_mem_brk) ( Addr a, UInt len );
sewardj40f8ebe2002-10-23 21:46:13 +00001281 void (*new_mem_mmap) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
njn25e49d8e72002-09-23 09:36:25 +00001282
1283 void (*copy_mem_heap) ( Addr from, Addr to, UInt len );
1284 void (*copy_mem_remap) ( Addr from, Addr to, UInt len );
sewardj40f8ebe2002-10-23 21:46:13 +00001285 void (*change_mem_mprotect) ( Addr a, UInt len, Bool rr, Bool ww, Bool xx );
njn25e49d8e72002-09-23 09:36:25 +00001286
njnd5bb0a52002-09-27 10:24:48 +00001287 /* Used on redzones around malloc'd blocks and at end of stack */
njn25e49d8e72002-09-23 09:36:25 +00001288 void (*ban_mem_heap) ( Addr a, UInt len );
1289 void (*ban_mem_stack) ( Addr a, UInt len );
1290
1291 void (*die_mem_heap) ( Addr a, UInt len );
1292 void (*die_mem_stack) ( Addr a, UInt len );
1293 void (*die_mem_stack_aligned) ( Addr a, UInt len );
1294 void (*die_mem_stack_signal) ( Addr a, UInt len );
1295 void (*die_mem_brk) ( Addr a, UInt len );
1296 void (*die_mem_munmap) ( Addr a, UInt len );
1297
1298 void (*bad_free) ( ThreadState* tst, Addr a );
1299 void (*mismatched_free) ( ThreadState* tst, Addr a );
1300
1301 void (*pre_mem_read) ( CorePart part, ThreadState* tst,
1302 Char* s, Addr a, UInt size );
1303 void (*pre_mem_read_asciiz) ( CorePart part, ThreadState* tst,
1304 Char* s, Addr a );
1305 void (*pre_mem_write) ( CorePart part, ThreadState* tst,
1306 Char* s, Addr a, UInt size );
1307 /* Not implemented yet -- have to add in lots of places, which is a
1308 pain. Won't bother unless/until there's a need. */
1309 /* void (*post_mem_read) ( ThreadState* tst, Char* s,
1310 Addr a, UInt size ); */
1311 void (*post_mem_write) ( Addr a, UInt size );
1312
1313
njnd5bb0a52002-09-27 10:24:48 +00001314 /* Scheduler events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001315 void (*thread_run) ( ThreadId tid );
1316
1317
njnd5bb0a52002-09-27 10:24:48 +00001318 /* Mutex events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001319 void (*post_mutex_lock) ( ThreadId tid,
1320 void* /*pthread_mutex_t* */ mutex );
1321 void (*post_mutex_unlock) ( ThreadId tid,
1322 void* /*pthread_mutex_t* */ mutex );
njn25e49d8e72002-09-23 09:36:25 +00001323
njnd5bb0a52002-09-27 10:24:48 +00001324
1325 /* Others... thread, condition variable, signal events... */
njn25e49d8e72002-09-23 09:36:25 +00001326 /* ... */
1327 }
1328 VgTrackEvents;
1329
1330/* Declare the struct instance */
1331extern VgTrackEvents VG_(track_events);
1332
1333
1334/* ------------------------------------------------------------------ */
1335/* Template functions */
1336
1337/* These are the parameterised functions in the core. The default definitions
njnd5bb0a52002-09-27 10:24:48 +00001338 are overridden by LD_PRELOADed skin version. At the very least, a skin
1339 must define the fundamental template functions. Depending on what needs
1340 are set, extra template functions will be used too. Functions are
1341 grouped under the needs that govern their use. */
njn25e49d8e72002-09-23 09:36:25 +00001342
1343
1344/* ------------------------------------------------------------------ */
1345/* Fundamental template functions */
1346
1347/* Initialise skin. Must do the following:
njnd04b7c62002-10-03 14:05:52 +00001348 - initialise the `details' struct
njn25e49d8e72002-09-23 09:36:25 +00001349 - register any helpers called by generated code
1350
1351 May do the following:
njnd04b7c62002-10-03 14:05:52 +00001352 - initialise the `needs' struct to indicate certain requirements
1353 - initialise the `track' struct to indicate core events of interest
njn25e49d8e72002-09-23 09:36:25 +00001354 - register any skin-specific profiling events
1355 - any other skin-specific initialisation
1356*/
njnd04b7c62002-10-03 14:05:52 +00001357extern void SK_(pre_clo_init) ( VgDetails* details, VgNeeds* needs,
1358 VgTrackEvents* track );
njn25e49d8e72002-09-23 09:36:25 +00001359
njnd5bb0a52002-09-27 10:24:48 +00001360/* Do initialisation that can only be done after command line processing. */
njn25e49d8e72002-09-23 09:36:25 +00001361extern void SK_(post_clo_init)( void );
1362
1363/* Instrument a basic block. Must be a true function, ie. the same input
1364 always results in the same output, because basic blocks can be
1365 retranslated. Unless you're doing something really strange...
1366 'orig_addr' is the address of the first instruction in the block. */
1367extern UCodeBlock* SK_(instrument) ( UCodeBlock* cb, Addr orig_addr );
1368
1369/* Finish up, print out any results, etc. */
1370extern void SK_(fini) ( void );
1371
1372
1373/* ------------------------------------------------------------------ */
1374/* VG_(needs).report_errors */
1375
1376/* Identify if two errors are equal, or equal enough. `res' indicates how
1377 close is "close enough". `res' should be passed on as necessary, eg. if
1378 the SkinError's extra field contains an ExeContext, `res' should be
1379 passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other
1380 than that, probably don't worry about it unless you have lots of very
1381 similar errors occurring.
1382 */
1383extern Bool SK_(eq_SkinError) ( VgRes res,
1384 SkinError* e1, SkinError* e2 );
1385
1386/* Print error context. The passed function pp_ExeContext() can be (and
1387 probably should be) used to print the location of the error. */
1388extern void SK_(pp_SkinError) ( SkinError* ec, void (*pp_ExeContext)(void) );
1389
1390/* Copy the ec->extra part and replace ec->extra with the new copy. This is
1391 necessary to move from a temporary stack copy to a permanent heap one.
1392
1393 Then fill in any details that could be postponed until after the decision
1394 whether to ignore the error (ie. details not affecting the result of
1395 SK_(eq_SkinError)()). This saves time when errors are ignored.
1396
1397 Yuk.
1398*/
1399extern void SK_(dup_extra_and_update)(SkinError* ec);
1400
1401/* Return value indicates recognition. If recognised, type goes in `skind'. */
1402extern Bool SK_(recognised_suppression) ( Char* name, SuppKind *skind );
1403
1404/* Read any extra info for this suppression kind. For filling up the
1405 `string' and `extra' fields in a `SkinSupp' struct if necessary. */
1406extern Bool SK_(read_extra_suppression_info) ( Int fd, Char* buf,
njnd5bb0a52002-09-27 10:24:48 +00001407 Int nBuf, SkinSupp *s );
njn25e49d8e72002-09-23 09:36:25 +00001408
1409/* This should just check the kinds match and maybe some stuff in the
1410 'extra' field if appropriate */
1411extern Bool SK_(error_matches_suppression)(SkinError* ec, SkinSupp* su);
1412
1413
1414/* ------------------------------------------------------------------ */
1415/* VG_(needs).basic_block_discards */
1416
njnd5bb0a52002-09-27 10:24:48 +00001417/* Should discard any information that pertains to specific basic blocks
1418 or instructions within the address range given. */
njn25e49d8e72002-09-23 09:36:25 +00001419extern void SK_(discard_basic_block_info) ( Addr a, UInt size );
1420
1421
1422/* ------------------------------------------------------------------ */
1423/* VG_(needs).shadow_regs */
1424
1425/* Valid values for general registers and EFLAGS register, for initialising
1426 and updating registers when written in certain places in core. */
1427extern void SK_(written_shadow_regs_values) ( UInt* gen_reg, UInt* eflags );
1428
1429
1430/* ------------------------------------------------------------------ */
1431/* VG_(needs).command_line_options */
1432
njnd5bb0a52002-09-27 10:24:48 +00001433/* Return True if option was recognised. Presumably sets some state to
1434 record the option as well. */
1435extern Bool SK_(process_cmd_line_option) ( Char* argv );
njn25e49d8e72002-09-23 09:36:25 +00001436
1437/* Print out command line usage for skin options */
1438extern Char* SK_(usage) ( void );
1439
1440
1441/* ------------------------------------------------------------------ */
1442/* VG_(needs).client_requests */
1443
sewardj34042512002-10-22 04:14:35 +00001444extern Bool SK_(handle_client_request) ( ThreadState* tst, UInt* arg_block, UInt *ret );
njn25e49d8e72002-09-23 09:36:25 +00001445
1446
1447/* ------------------------------------------------------------------ */
1448/* VG_(needs).extends_UCode */
1449
njn4ba5a792002-09-30 10:23:54 +00001450/* Useful to use in VG_(get_Xreg_usage)() */
njnd5bb0a52002-09-27 10:24:48 +00001451#define VG_UINSTR_READS_REG(ono) \
njn25e49d8e72002-09-23 09:36:25 +00001452 { if (mycat(u->tag,ono) == tag) \
1453 { arr[n].num = mycat(u->val,ono); \
1454 arr[n].isWrite = False; \
1455 n++; \
1456 } \
1457 }
njnd5bb0a52002-09-27 10:24:48 +00001458#define VG_UINSTR_WRITES_REG(ono) \
1459 { if (mycat(u->tag,ono) == tag) \
1460 { arr[n].num = mycat(u->val,ono); \
1461 arr[n].isWrite = True; \
1462 n++; \
1463 } \
njn25e49d8e72002-09-23 09:36:25 +00001464 }
1465
njn4ba5a792002-09-30 10:23:54 +00001466/* 'X' prefix indicates eXtended UCode. */
1467extern Int SK_(get_Xreg_usage) ( UInstr* u, Tag tag, RegUse* arr );
1468extern void SK_(emit_XUInstr) ( UInstr* u, RRegSet regs_live_before );
1469extern Bool SK_(sane_XUInstr) ( Bool beforeRA, Bool beforeLiveness,
njn25e49d8e72002-09-23 09:36:25 +00001470 UInstr* u );
njn4ba5a792002-09-30 10:23:54 +00001471extern Char* SK_(name_XUOpcode) ( Opcode opc );
1472extern void SK_(pp_XUInstr) ( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +00001473
1474
1475/* ------------------------------------------------------------------ */
1476/* VG_(needs).syscall_wrapper */
1477
1478/* If either of the pre_ functions malloc() something to return, the
1479 * corresponding post_ function had better free() it!
1480 */
1481extern void* SK_( pre_syscall) ( ThreadId tid, UInt syscallno,
1482 Bool is_blocking );
1483extern void SK_(post_syscall) ( ThreadId tid, UInt syscallno,
1484 void* pre_result, Int res,
1485 Bool is_blocking );
1486
njnd5bb0a52002-09-27 10:24:48 +00001487
njn25e49d8e72002-09-23 09:36:25 +00001488/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +00001489/* VG_(needs).sizeof_shadow_chunk (if > 0) */
njn25e49d8e72002-09-23 09:36:25 +00001490
1491extern void SK_(complete_shadow_chunk) ( ShadowChunk* sc, ThreadState* tst );
1492
1493
1494/* ------------------------------------------------------------------ */
1495/* VG_(needs).alternative_free */
1496
1497extern void SK_(alt_free) ( ShadowChunk* sc, ThreadState* tst );
1498
njnd5bb0a52002-09-27 10:24:48 +00001499
njn25e49d8e72002-09-23 09:36:25 +00001500/* ---------------------------------------------------------------------
1501 VG_(needs).sanity_checks */
1502
njnd5bb0a52002-09-27 10:24:48 +00001503/* Can be useful for ensuring a skin's correctness. SK_(cheap_sanity_check)
1504 is called very frequently; SK_(expensive_sanity_check) is called less
1505 frequently and can be more involved. */
njn25e49d8e72002-09-23 09:36:25 +00001506extern Bool SK_(cheap_sanity_check) ( void );
1507extern Bool SK_(expensive_sanity_check) ( void );
1508
1509
1510#endif /* NDEF __VG_SKIN_H */
1511
1512/*--------------------------------------------------------------------*/
1513/*--- end vg_skin.h ---*/
1514/*--------------------------------------------------------------------*/
1515