blob: 723555f4e4db7c2695eb7ebdb4578705504e51f0 [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
njn211b6ad2003-02-03 12:33:31 +000062 If you increase 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)
njn211b6ad2003-02-03 12:33:31 +000068
69 You can decrease it, and performance will drop because more spills will
70 occur. If you decrease it too much, everything will fall over.
njn25e49d8e72002-09-23 09:36:25 +000071
72 Do not change this unless you really know what you are doing! */
73#define VG_MAX_REALREGS 6
74
75
76/*====================================================================*/
njn1a1dd8b2002-09-27 10:42:20 +000077/*=== Basic types, useful macros ===*/
njn25e49d8e72002-09-23 09:36:25 +000078/*====================================================================*/
79
njn25e49d8e72002-09-23 09:36:25 +000080typedef unsigned char UChar;
81typedef unsigned short UShort;
82typedef unsigned int UInt;
83typedef unsigned long long int ULong;
84
85typedef signed char Char;
86typedef signed short Short;
87typedef signed int Int;
88typedef signed long long int Long;
89
90typedef unsigned int Addr;
91
92typedef unsigned char Bool;
93#define False ((Bool)0)
94#define True ((Bool)1)
95
96
njn1a1dd8b2002-09-27 10:42:20 +000097#define mycat_wrk(aaa,bbb) aaa##bbb
98#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
99
100/* No, really. I _am_ that strange. */
101#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
102
njn25e49d8e72002-09-23 09:36:25 +0000103/* ---------------------------------------------------------------------
104 Now the basic types are set up, we can haul in the kernel-interface
105 definitions.
106 ------------------------------------------------------------------ */
107
njn2574bb4762002-09-24 11:23:50 +0000108#include "../coregrind/vg_kerneliface.h"
njn25e49d8e72002-09-23 09:36:25 +0000109
110
111/*====================================================================*/
njn27f1a382002-11-08 15:48:16 +0000112/*=== Core/skin interface version ===*/
113/*====================================================================*/
114
115/* The major version number indicates binary-incompatible changes to the
116 interface; if the core and skin major versions don't match, Valgrind
117 will abort. The minor version indicates binary-compatible changes.
njn27f1a382002-11-08 15:48:16 +0000118*/
njn9b007f62003-04-07 14:40:25 +0000119#define VG_CORE_INTERFACE_MAJOR_VERSION 2
120#define VG_CORE_INTERFACE_MINOR_VERSION 0
njn27f1a382002-11-08 15:48:16 +0000121
122extern const Int VG_(skin_interface_major_version);
123extern const Int VG_(skin_interface_minor_version);
124
njn563f96f2003-02-03 11:17:46 +0000125/* Every skin must include this macro somewhere, exactly once. */
njn27f1a382002-11-08 15:48:16 +0000126#define VG_DETERMINE_INTERFACE_VERSION \
127const Int VG_(skin_interface_major_version) = VG_CORE_INTERFACE_MAJOR_VERSION; \
128const Int VG_(skin_interface_minor_version) = VG_CORE_INTERFACE_MINOR_VERSION;
129
njn211b6ad2003-02-03 12:33:31 +0000130
njn27f1a382002-11-08 15:48:16 +0000131/*====================================================================*/
njn25e49d8e72002-09-23 09:36:25 +0000132/*=== Command-line options ===*/
133/*====================================================================*/
134
njn43c799e2003-04-08 00:08:52 +0000135/* Use this for normal null-termination-style string comparison */
136#define VG_STREQ(s1,s2) (s1 != NULL && s2 != NULL \
137 && VG_(strcmp)((s1),(s2))==0)
138
139/* Use these for recognising skin command line options -- stops comparing
140 once whitespace is reached. */
141# define VG_CLO_STREQ(s1,s2) (0==VG_(strcmp_ws)((s1),(s2)))
142# define VG_CLO_STREQN(nn,s1,s2) (0==VG_(strncmp_ws)((s1),(s2),(nn)))
143
njn25e49d8e72002-09-23 09:36:25 +0000144/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
145extern Int VG_(clo_verbosity);
146
147/* Profile? */
148extern Bool VG_(clo_profile);
149
njn25e49d8e72002-09-23 09:36:25 +0000150/* Call this if a recognised option was bad for some reason.
151 Note: don't use it just because an option was unrecognised -- return 'False'
152 from SKN_(process_cmd_line_option) to indicate that. */
153extern void VG_(bad_option) ( Char* opt );
154
155/* Client args */
156extern Int VG_(client_argc);
157extern Char** VG_(client_argv);
158
njnd5bb0a52002-09-27 10:24:48 +0000159/* Client environment. Can be inspected with VG_(getenv)() */
njn25e49d8e72002-09-23 09:36:25 +0000160extern Char** VG_(client_envp);
161
162
163/*====================================================================*/
164/*=== Printing messages for the user ===*/
165/*====================================================================*/
166
167/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
168 Should be used for all user output. */
169
170typedef
171 enum { Vg_UserMsg, /* '?' == '=' */
172 Vg_DebugMsg, /* '?' == '-' */
173 Vg_DebugExtraMsg /* '?' == '+' */
174 }
175 VgMsgKind;
176
177/* Functions for building a message from multiple parts. */
178extern void VG_(start_msg) ( VgMsgKind kind );
179extern void VG_(add_to_msg) ( Char* format, ... );
180/* Ends and prints the message. Appends a newline. */
181extern void VG_(end_msg) ( void );
182
njnd5bb0a52002-09-27 10:24:48 +0000183/* Send a single-part message. Appends a newline. */
njn25e49d8e72002-09-23 09:36:25 +0000184extern void VG_(message) ( VgMsgKind kind, Char* format, ... );
185
186
187/*====================================================================*/
188/*=== Profiling ===*/
189/*====================================================================*/
190
191/* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */
192#define VGP_CORE_LIST \
193 /* These ones depend on the core */ \
194 VGP_PAIR(VgpUnc, "unclassified"), \
195 VGP_PAIR(VgpRun, "running"), \
196 VGP_PAIR(VgpSched, "scheduler"), \
197 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
198 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
njn25e49d8e72002-09-23 09:36:25 +0000199 VGP_PAIR(VgpTranslate, "translate-main"), \
200 VGP_PAIR(VgpToUCode, "to-ucode"), \
201 VGP_PAIR(VgpFromUcode, "from-ucode"), \
202 VGP_PAIR(VgpImprove, "improve"), \
njn9b007f62003-04-07 14:40:25 +0000203 VGP_PAIR(VgpESPUpdate, "ESP-update"), \
njn25e49d8e72002-09-23 09:36:25 +0000204 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
205 VGP_PAIR(VgpLiveness, "liveness-analysis"), \
206 VGP_PAIR(VgpDoLRU, "do-lru"), \
207 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
208 VGP_PAIR(VgpInitMem, "init-memory"), \
209 VGP_PAIR(VgpExeContext, "exe-context"), \
210 VGP_PAIR(VgpReadSyms, "read-syms"), \
211 VGP_PAIR(VgpSearchSyms, "search-syms"), \
212 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
213 VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
214 VGP_PAIR(VgpDemangle, "demangle"), \
njn37cea302002-09-30 11:24:00 +0000215 VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
216 VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000217 /* These ones depend on the skin */ \
218 VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
219 VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
220 VGP_PAIR(VgpInstrument, "instrument"), \
221 VGP_PAIR(VgpSkinSysWrap, "skin-syscall-wrapper"), \
njn37cea302002-09-30 11:24:00 +0000222 VGP_PAIR(VgpSkinCheapSanity, "skin-cheap-sanity"), \
223 VGP_PAIR(VgpSkinExpensiveSanity, "skin-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000224 VGP_PAIR(VgpFini, "fini")
225
226#define VGP_PAIR(n,name) n
227typedef enum { VGP_CORE_LIST } VgpCoreCC;
228#undef VGP_PAIR
229
230/* When registering skin profiling events, ensure that the 'n' value is in
231 * the range (VgpFini+1..) */
232extern void VGP_(register_profile_event) ( Int n, Char* name );
233
234extern void VGP_(pushcc) ( UInt cc );
235extern void VGP_(popcc) ( UInt cc );
236
237/* Define them only if they haven't already been defined by vg_profile.c */
238#ifndef VGP_PUSHCC
239# define VGP_PUSHCC(x)
240#endif
241#ifndef VGP_POPCC
242# define VGP_POPCC(x)
243#endif
244
245
246/*====================================================================*/
247/*=== Useful stuff to call from generated code ===*/
248/*====================================================================*/
249
250/* ------------------------------------------------------------------ */
251/* General stuff */
252
njn41557122002-10-14 09:25:37 +0000253/* 64-bit counter for the number of basic blocks done. */
254extern ULong VG_(bbs_done);
255
njn25e49d8e72002-09-23 09:36:25 +0000256/* Get the simulated %esp */
257extern Addr VG_(get_stack_pointer) ( void );
258
njnd5bb0a52002-09-27 10:24:48 +0000259/* Detect if an address is within Valgrind's stack or Valgrind's
260 m_state_static; useful for memory leak detectors to tell if a block
261 is used by Valgrind (and thus can be ignored). */
njn25e49d8e72002-09-23 09:36:25 +0000262extern Bool VG_(within_stack)(Addr a);
njn25e49d8e72002-09-23 09:36:25 +0000263extern Bool VG_(within_m_state_static)(Addr a);
264
265/* Check if an address is 4-byte aligned */
266#define IS_ALIGNED4_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 3))
njn9b007f62003-04-07 14:40:25 +0000267#define IS_ALIGNED8_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 7))
njn25e49d8e72002-09-23 09:36:25 +0000268
269
270/* ------------------------------------------------------------------ */
271/* Thread-related stuff */
272
273/* Special magic value for an invalid ThreadId. It corresponds to
274 LinuxThreads using zero as the initial value for
275 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
276#define VG_INVALID_THREADID ((ThreadId)(0))
277
278/* ThreadIds are simply indices into the vg_threads[] array. */
279typedef
280 UInt
281 ThreadId;
282
njnd5bb0a52002-09-27 10:24:48 +0000283/* struct _ThreadState defined elsewhere; ThreadState is abstract as its
284 definition is not important for skins. */
njn25e49d8e72002-09-23 09:36:25 +0000285typedef
286 struct _ThreadState
287 ThreadState;
288
sewardj7ab2aca2002-10-20 19:40:32 +0000289extern ThreadId VG_(get_current_tid) ( void );
sewardjb52a1b02002-10-23 21:38:22 +0000290extern ThreadId VG_(get_current_or_recent_tid) ( void );
sewardj7ab2aca2002-10-20 19:40:32 +0000291extern ThreadId VG_(get_tid_from_ThreadState) ( ThreadState* );
njn25e49d8e72002-09-23 09:36:25 +0000292extern ThreadState* VG_(get_ThreadState) ( ThreadId tid );
293
294
295/*====================================================================*/
296/*=== Valgrind's version of libc ===*/
297/*====================================================================*/
298
299/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
300 are its own versions of C library functions, but with VG_ prefixes. Note
301 that the types of some are slightly different to the real ones. Some
njnf4ce3d32003-02-10 10:17:26 +0000302 additional useful functions are provided too; descriptions of how they
303 work are given below. */
njn25e49d8e72002-09-23 09:36:25 +0000304
305#if !defined(NULL)
306# define NULL ((void*)0)
307#endif
308
309
310/* ------------------------------------------------------------------ */
311/* stdio.h
312 *
313 * Note that they all output to the file descriptor given by the
314 * --logfile-fd=N argument, which defaults to 2 (stderr). Hence no
315 * need for VG_(fprintf)().
njn25e49d8e72002-09-23 09:36:25 +0000316 */
sewardj78e3cd92002-10-22 04:45:48 +0000317extern UInt VG_(printf) ( const char *format, ... );
njn25e49d8e72002-09-23 09:36:25 +0000318/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
sewardj78e3cd92002-10-22 04:45:48 +0000319extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
320extern UInt VG_(vprintf) ( void(*send)(Char),
njn25e49d8e72002-09-23 09:36:25 +0000321 const Char *format, va_list vargs );
322
njn41557122002-10-14 09:25:37 +0000323extern Int VG_(rename) ( Char* old_name, Char* new_name );
324
njn25e49d8e72002-09-23 09:36:25 +0000325/* ------------------------------------------------------------------ */
326/* stdlib.h */
327
328extern void* VG_(malloc) ( Int nbytes );
njnd5bb0a52002-09-27 10:24:48 +0000329extern void VG_(free) ( void* p );
330extern void* VG_(calloc) ( Int n, Int nbytes );
331extern void* VG_(realloc) ( void* p, Int size );
332extern void* VG_(malloc_aligned) ( Int align_bytes, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000333
334extern void VG_(print_malloc_stats) ( void );
335
336
337extern void VG_(exit)( Int status )
338 __attribute__ ((__noreturn__));
njne427a662002-10-02 11:08:25 +0000339/* Prints a panic message (a constant string), appends newline and bug
340 reporting info, aborts. */
341__attribute__ ((__noreturn__))
342extern void VG_(skin_panic) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000343
njnd5bb0a52002-09-27 10:24:48 +0000344/* Looks up VG_(client_envp) */
njn25e49d8e72002-09-23 09:36:25 +0000345extern Char* VG_(getenv) ( Char* name );
346
347/* Crude stand-in for the glibc system() call. */
348extern Int VG_(system) ( Char* cmd );
349
njnd5bb0a52002-09-27 10:24:48 +0000350extern Long VG_(atoll) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000351
352/* Like atoll(), but converts a number of base 2..36 */
353extern Long VG_(atoll36) ( UInt base, Char* str );
354
355
356/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000357/* ctype.h */
njn25e49d8e72002-09-23 09:36:25 +0000358extern Bool VG_(isspace) ( Char c );
359extern Bool VG_(isdigit) ( Char c );
360extern Char VG_(toupper) ( Char c );
361
362
363/* ------------------------------------------------------------------ */
364/* string.h */
365extern Int VG_(strlen) ( const Char* str );
366extern Char* VG_(strcat) ( Char* dest, const Char* src );
367extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
368extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
369extern Char* VG_(strcpy) ( Char* dest, const Char* src );
370extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
371extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
372extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
373extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
374extern Char* VG_(strchr) ( const Char* s, Char c );
375extern Char* VG_(strdup) ( const Char* s);
sewardj7ab2aca2002-10-20 19:40:32 +0000376extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
377extern void* VG_(memset) ( void *s, Int c, Int sz );
njn6d68e792003-02-24 10:49:08 +0000378extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
njn25e49d8e72002-09-23 09:36:25 +0000379
njnd5bb0a52002-09-27 10:24:48 +0000380/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
njn25e49d8e72002-09-23 09:36:25 +0000381extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
njn25e49d8e72002-09-23 09:36:25 +0000382extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
383
njnd5bb0a52002-09-27 10:24:48 +0000384/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
385 last character. */
njn25e49d8e72002-09-23 09:36:25 +0000386extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
387
388/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
389 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
njn4ba5a792002-09-30 10:23:54 +0000390extern Bool VG_(string_match) ( Char* pat, Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000391
392
393/* ------------------------------------------------------------------ */
394/* math.h */
njnd5bb0a52002-09-27 10:24:48 +0000395/* Returns the base-2 logarithm of x. */
njn25e49d8e72002-09-23 09:36:25 +0000396extern Int VG_(log2) ( Int x );
397
398
399/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000400/* unistd.h, fcntl.h, sys/stat.h */
sewardj4cf05692002-10-27 20:28:29 +0000401extern Int VG_(getpid) ( void );
402extern Int VG_(getppid) ( void );
njnd5bb0a52002-09-27 10:24:48 +0000403
njn4aca2d22002-10-04 10:29:38 +0000404extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
405extern Int VG_(read) ( Int fd, void* buf, Int count);
406extern Int VG_(write) ( Int fd, void* buf, Int count);
407extern void VG_(close) ( Int fd );
njnd5bb0a52002-09-27 10:24:48 +0000408
njn41557122002-10-14 09:25:37 +0000409/* Nb: VG_(rename)() declared in stdio.h section above */
njn4aca2d22002-10-04 10:29:38 +0000410extern Int VG_(unlink) ( Char* file_name );
411extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
njn25e49d8e72002-09-23 09:36:25 +0000412
413
414/* ------------------------------------------------------------------ */
415/* assert.h */
416/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
417#define VG__STRING(__str) #__str
418
njne427a662002-10-02 11:08:25 +0000419#define sk_assert(expr) \
njn25e49d8e72002-09-23 09:36:25 +0000420 ((void) ((expr) ? 0 : \
njne427a662002-10-02 11:08:25 +0000421 (VG_(skin_assert_fail) (VG__STRING(expr), \
422 __FILE__, __LINE__, \
423 __PRETTY_FUNCTION__), 0)))
njn25e49d8e72002-09-23 09:36:25 +0000424
njne427a662002-10-02 11:08:25 +0000425__attribute__ ((__noreturn__))
426extern void VG_(skin_assert_fail) ( Char* expr, Char* file,
427 Int line, Char* fn );
njn25e49d8e72002-09-23 09:36:25 +0000428
429
430/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000431/* system/mman.h */
njn25e49d8e72002-09-23 09:36:25 +0000432extern void* VG_(mmap)( void* start, UInt length,
433 UInt prot, UInt flags, UInt fd, UInt offset );
434extern Int VG_(munmap)( void* start, Int length );
435
436/* Get memory by anonymous mmap. */
437extern void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who );
438
439
440/* ------------------------------------------------------------------ */
441/* signal.h.
442
443 Note that these use the vk_ (kernel) structure
444 definitions, which are different in places from those that glibc
445 defines -- hence the 'k' prefix. Since we're operating right at the
446 kernel interface, glibc's view of the world is entirely irrelevant. */
447
448/* --- Signal set ops --- */
njnd5bb0a52002-09-27 10:24:48 +0000449extern Int VG_(ksigfillset) ( vki_ksigset_t* set );
450extern Int VG_(ksigemptyset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000451
njnd5bb0a52002-09-27 10:24:48 +0000452extern Bool VG_(kisfullsigset) ( vki_ksigset_t* set );
453extern Bool VG_(kisemptysigset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000454
njnd5bb0a52002-09-27 10:24:48 +0000455extern Int VG_(ksigaddset) ( vki_ksigset_t* set, Int signum );
456extern Int VG_(ksigdelset) ( vki_ksigset_t* set, Int signum );
njn25e49d8e72002-09-23 09:36:25 +0000457extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
458
njnd5bb0a52002-09-27 10:24:48 +0000459extern void VG_(ksigaddset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
460extern void VG_(ksigdelset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
njn25e49d8e72002-09-23 09:36:25 +0000461
462/* --- Mess with the kernel's sig state --- */
njnd5bb0a52002-09-27 10:24:48 +0000463extern Int VG_(ksigprocmask) ( Int how, const vki_ksigset_t* set,
njn25e49d8e72002-09-23 09:36:25 +0000464 vki_ksigset_t* oldset );
njnd5bb0a52002-09-27 10:24:48 +0000465extern Int VG_(ksigaction) ( Int signum,
466 const vki_ksigaction* act,
467 vki_ksigaction* oldact );
njn25e49d8e72002-09-23 09:36:25 +0000468
njnd5bb0a52002-09-27 10:24:48 +0000469extern Int VG_(ksignal) ( Int signum, void (*sighandler)(Int) );
470extern Int VG_(ksigaltstack) ( const vki_kstack_t* ss, vki_kstack_t* oss );
njn25e49d8e72002-09-23 09:36:25 +0000471
sewardjdcaf3122002-09-30 23:12:33 +0000472extern Int VG_(kkill) ( Int pid, Int signo );
473extern Int VG_(ksigpending) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000474
475
476/*====================================================================*/
477/*=== UCode definition ===*/
478/*====================================================================*/
479
sewardje1042472002-09-30 12:33:11 +0000480/* Tags which describe what operands are. Must fit into 4 bits, which
481 they clearly do. */
njn25e49d8e72002-09-23 09:36:25 +0000482typedef
sewardje1042472002-09-30 12:33:11 +0000483enum { TempReg =0, /* virtual temp-reg */
484 ArchReg =1, /* simulated integer reg */
485 ArchRegS =2, /* simulated segment reg */
486 RealReg =3, /* real machine's real reg */
487 SpillNo =4, /* spill slot location */
488 Literal =5, /* literal; .lit32 field has actual value */
489 Lit16 =6, /* literal; .val[123] field has actual value */
490 NoValue =7 /* operand not in use */
491 }
492 Tag;
njn25e49d8e72002-09-23 09:36:25 +0000493
njnd5bb0a52002-09-27 10:24:48 +0000494/* Invalid register numbers (can't be negative) */
njn25e49d8e72002-09-23 09:36:25 +0000495#define INVALID_TEMPREG 999999999
496#define INVALID_REALREG 999999999
497
498/* Microinstruction opcodes. */
499typedef
500 enum {
njnd5bb0a52002-09-27 10:24:48 +0000501 NOP, /* Null op */
njn25e49d8e72002-09-23 09:36:25 +0000502
sewardj7a5ebcf2002-11-13 22:42:13 +0000503 LOCK, /* Indicate the existance of a LOCK prefix (functionally NOP) */
504
njnd5bb0a52002-09-27 10:24:48 +0000505 /* Moving values around */
506 GET, PUT, /* simulated register <--> TempReg */
507 GETF, PUTF, /* simulated %eflags <--> TempReg */
508 LOAD, STORE, /* memory <--> TempReg */
509 MOV, /* TempReg <--> TempReg */
510 CMOV, /* Used for cmpxchg and cmov */
njn25e49d8e72002-09-23 09:36:25 +0000511
njnd5bb0a52002-09-27 10:24:48 +0000512 /* Arithmetic/logical ops */
513 ADD, ADC, SUB, SBB, /* Add/subtract (w/wo carry) */
514 AND, OR, XOR, NOT, /* Boolean ops */
515 SHL, SHR, SAR, ROL, ROR, RCL, RCR, /* Shift/rotate (w/wo carry) */
516 NEG, /* Negate */
517 INC, DEC, /* Increment/decrement */
518 BSWAP, /* Big-endian <--> little-endian */
519 CC2VAL, /* Condition code --> 0 or 1 */
520 WIDEN, /* Signed or unsigned widening */
njn25e49d8e72002-09-23 09:36:25 +0000521
njnd5bb0a52002-09-27 10:24:48 +0000522 /* Conditional or unconditional jump */
523 JMP,
524
525 /* FPU ops */
526 FPU, /* Doesn't touch memory */
527 FPU_R, FPU_W, /* Reads/writes memory */
528
sewardj3d7c9c82003-03-26 21:08:13 +0000529 /* ------------ MMX ops ------------ */
530
531 /* 1 byte, no memrefs, no iregdefs, copy exactly to the
532 output. Held in val1[7:0]. */
533 MMX1,
534
535 /* 2 bytes, no memrefs, no iregdefs, copy exactly to the
536 output. Held in val1[15:0]. */
537 MMX2,
538
539 /* 3 bytes, no memrefs, no iregdefs, copy exactly to the
540 output. Held in val1[15:0] and val2[7:0]. */
541 MMX3,
542
543 /* 2 bytes, reads/writes mem. Insns of the form
544 bbbbbbbb:mod mmxreg r/m.
545 Held in val1[15:0], and mod and rm are to be replaced
546 at codegen time by a reference to the Temp/RealReg holding
547 the address. Arg2 holds this Temp/Real Reg.
548 Transfer is always at size 8.
549 */
550 MMX2_MemRd,
551 MMX2_MemWr,
552
553 /* 2 bytes, reads/writes an integer register. Insns of the form
554 bbbbbbbb:11 mmxreg ireg.
555 Held in val1[15:0], and ireg is to be replaced
556 at codegen time by a reference to the relevant RealReg.
557 Transfer is always at size 4. Arg2 holds this Temp/Real Reg.
558 */
559 MMX2_RegRd,
560 MMX2_RegWr,
561
562 /* ------------------------ */
563
njnd5bb0a52002-09-27 10:24:48 +0000564 /* Not strictly needed, but improve address calculation translations. */
njn25e49d8e72002-09-23 09:36:25 +0000565 LEA1, /* reg2 := const + reg1 */
566 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
567
njnd5bb0a52002-09-27 10:24:48 +0000568 /* Hack for x86 REP insns. Jump to literal if TempReg/RealReg is zero. */
569 JIFZ,
njn25e49d8e72002-09-23 09:36:25 +0000570
njnd5bb0a52002-09-27 10:24:48 +0000571 /* Advance the simulated %eip by some small (< 128) number. */
572 INCEIP,
njn25e49d8e72002-09-23 09:36:25 +0000573
sewardje1042472002-09-30 12:33:11 +0000574 /* Dealing with segment registers */
575 GETSEG, PUTSEG, /* simulated segment register <--> TempReg */
576 USESEG, /* (LDT/GDT index, virtual addr) --> linear addr */
577
njnd5bb0a52002-09-27 10:24:48 +0000578 /* Not for translating x86 calls -- only to call helpers */
579 CALLM_S, CALLM_E, /* Mark start/end of CALLM push/pop sequence */
580 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers */
581 CALLM, /* Call assembly-code helper */
582
583 /* Not for translating x86 calls -- only to call C helper functions of
584 up to three arguments (or two if the functions has a return value).
585 Arguments and return value must be word-sized. More arguments can
586 be faked with global variables (eg. use VG_(set_global_var)()).
587
588 Seven possibilities: 'arg[123]' show where args go, 'ret' shows
589 where return value goes (if present).
njn25e49d8e72002-09-23 09:36:25 +0000590
591 CCALL(-, -, - ) void f(void)
592 CCALL(arg1, -, - ) void f(UInt arg1)
593 CCALL(arg1, arg2, - ) void f(UInt arg1, UInt arg2)
594 CCALL(arg1, arg2, arg3) void f(UInt arg1, UInt arg2, UInt arg3)
595 CCALL(-, -, ret ) UInt f(UInt)
596 CCALL(arg1, -, ret ) UInt f(UInt arg1)
njnd5bb0a52002-09-27 10:24:48 +0000597 CCALL(arg1, arg2, ret ) UInt f(UInt arg1, UInt arg2) */
njn25e49d8e72002-09-23 09:36:25 +0000598 CCALL,
599
njnd5bb0a52002-09-27 10:24:48 +0000600 /* This opcode makes it easy for skins that extend UCode to do this to
601 avoid opcode overlap:
njn25e49d8e72002-09-23 09:36:25 +0000602
njnd5bb0a52002-09-27 10:24:48 +0000603 enum { EU_OP1 = DUMMY_FINAL_UOPCODE + 1, ... }
njn25e49d8e72002-09-23 09:36:25 +0000604
605 WARNING: Do not add new opcodes after this one! They can be added
606 before, though. */
607 DUMMY_FINAL_UOPCODE
608 }
609 Opcode;
610
611
njnd5bb0a52002-09-27 10:24:48 +0000612/* Condition codes, using the Intel encoding. CondAlways is an extra. */
njn25e49d8e72002-09-23 09:36:25 +0000613typedef
614 enum {
615 CondO = 0, /* overflow */
616 CondNO = 1, /* no overflow */
617 CondB = 2, /* below */
618 CondNB = 3, /* not below */
619 CondZ = 4, /* zero */
620 CondNZ = 5, /* not zero */
621 CondBE = 6, /* below or equal */
622 CondNBE = 7, /* not below or equal */
623 CondS = 8, /* negative */
sewardje1042472002-09-30 12:33:11 +0000624 CondNS = 9, /* not negative */
njn25e49d8e72002-09-23 09:36:25 +0000625 CondP = 10, /* parity even */
626 CondNP = 11, /* not parity even */
627 CondL = 12, /* jump less */
628 CondNL = 13, /* not less */
629 CondLE = 14, /* less or equal */
630 CondNLE = 15, /* not less or equal */
631 CondAlways = 16 /* Jump always */
632 }
633 Condcode;
634
635
636/* Descriptions of additional properties of *unconditional* jumps. */
637typedef
638 enum {
639 JmpBoring=0, /* boring unconditional jump */
640 JmpCall=1, /* jump due to an x86 call insn */
641 JmpRet=2, /* jump due to an x86 ret insn */
642 JmpSyscall=3, /* do a system call, then jump */
643 JmpClientReq=4 /* do a client request, then jump */
644 }
645 JmpKind;
646
647
648/* Flags. User-level code can only read/write O(verflow), S(ign),
649 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
650 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
651 thusly:
652 76543210
653 DOSZACP
654 and bit 7 must always be zero since it is unused.
sewardj2370f3b2002-11-30 15:01:01 +0000655
656 Note: these Flag? values are **not** the positions in the actual
657 %eflags register. */
658
njn25e49d8e72002-09-23 09:36:25 +0000659typedef UChar FlagSet;
660
661#define FlagD (1<<6)
662#define FlagO (1<<5)
663#define FlagS (1<<4)
664#define FlagZ (1<<3)
665#define FlagA (1<<2)
666#define FlagC (1<<1)
667#define FlagP (1<<0)
668
669#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
670#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
671#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
672#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
673#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
674#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
675#define FlagsZCP ( FlagZ | FlagC | FlagP)
676#define FlagsOC (FlagO | FlagC )
677#define FlagsAC ( FlagA | FlagC )
678
679#define FlagsALL (FlagsOSZACP | FlagD)
680#define FlagsEmpty (FlagSet)0
681
682
sewardj2370f3b2002-11-30 15:01:01 +0000683/* flag positions in eflags */
684#define EFlagC (1 << 0) /* carry */
685#define EFlagP (1 << 2) /* parity */
sewardjfa492d42002-12-08 18:20:01 +0000686#define EFlagA (1 << 4) /* aux carry */
sewardj2370f3b2002-11-30 15:01:01 +0000687#define EFlagZ (1 << 6) /* zero */
688#define EFlagS (1 << 7) /* sign */
sewardjfa492d42002-12-08 18:20:01 +0000689#define EFlagD (1 << 10) /* direction */
sewardj2370f3b2002-11-30 15:01:01 +0000690#define EFlagO (1 << 11) /* overflow */
691
njn25e49d8e72002-09-23 09:36:25 +0000692/* Liveness of general purpose registers, useful for code generation.
693 Reg rank order 0..N-1 corresponds to bits 0..N-1, ie. first
694 reg's liveness in bit 0, last reg's in bit N-1. Note that
695 these rankings don't match the Intel register ordering. */
696typedef UInt RRegSet;
697
698#define ALL_RREGS_DEAD 0 /* 0000...00b */
njne7c258c2002-10-03 08:57:01 +0000699#define ALL_RREGS_LIVE ((1 << VG_MAX_REALREGS)-1) /* 0011...11b */
njn25e49d8e72002-09-23 09:36:25 +0000700#define UNIT_RREGSET(rank) (1 << (rank))
701
702#define IS_RREG_LIVE(rank,rregs_live) (rregs_live & UNIT_RREGSET(rank))
703#define SET_RREG_LIVENESS(rank,rregs_live,b) \
704 do { RRegSet unit = UNIT_RREGSET(rank); \
705 if (b) rregs_live |= unit; \
706 else rregs_live &= ~unit; \
707 } while(0)
708
709
710/* A Micro (u)-instruction. */
711typedef
712 struct {
713 /* word 1 */
714 UInt lit32; /* 32-bit literal */
715
716 /* word 2 */
717 UShort val1; /* first operand */
718 UShort val2; /* second operand */
719
720 /* word 3 */
721 UShort val3; /* third operand */
722 UChar opcode; /* opcode */
723 UChar size; /* data transfer size */
724
725 /* word 4 */
726 FlagSet flags_r; /* :: FlagSet */
727 FlagSet flags_w; /* :: FlagSet */
728 UChar tag1:4; /* first operand tag */
729 UChar tag2:4; /* second operand tag */
730 UChar tag3:4; /* third operand tag */
731 UChar extra4b:4; /* Spare field, used by WIDEN for src
732 -size, and by LEA2 for scale (1,2,4 or 8),
733 and by JMPs for original x86 instr size */
734
735 /* word 5 */
736 UChar cond; /* condition, for jumps */
737 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
738 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
739
740 /* Additional properties for UInstrs that call C functions:
741 - CCALL
742 - PUT (when %ESP is the target)
743 - possibly skin-specific UInstrs
744 */
745 UChar argc:2; /* Number of args, max 3 */
746 UChar regparms_n:2; /* Number of args passed in registers */
747 Bool has_ret_val:1; /* Function has return value? */
748
749 /* RealReg liveness; only sensical after reg alloc and liveness
750 analysis done. This info is a little bit arch-specific --
751 VG_MAX_REALREGS can vary on different architectures. Note that
752 to use this information requires converting between register ranks
njn4ba5a792002-09-30 10:23:54 +0000753 and the Intel register numbers, using VG_(realreg_to_rank)()
754 and/or VG_(rank_to_realreg)() */
njn25e49d8e72002-09-23 09:36:25 +0000755 RRegSet regs_live_after:VG_MAX_REALREGS;
756 }
757 UInstr;
758
759
njn25e49d8e72002-09-23 09:36:25 +0000760typedef
njn810086f2002-11-14 12:42:47 +0000761 struct _UCodeBlock
njn25e49d8e72002-09-23 09:36:25 +0000762 UCodeBlock;
763
njn810086f2002-11-14 12:42:47 +0000764extern Int VG_(get_num_instrs) (UCodeBlock* cb);
765extern Int VG_(get_num_temps) (UCodeBlock* cb);
njn25e49d8e72002-09-23 09:36:25 +0000766
njn810086f2002-11-14 12:42:47 +0000767extern UInstr* VG_(get_instr) (UCodeBlock* cb, Int i);
768extern UInstr* VG_(get_last_instr) (UCodeBlock* cb);
769
njn211b6ad2003-02-03 12:33:31 +0000770
njn25e49d8e72002-09-23 09:36:25 +0000771/*====================================================================*/
772/*=== Instrumenting UCode ===*/
773/*====================================================================*/
774
njnf4ce3d32003-02-10 10:17:26 +0000775/* Maximum number of registers read or written by a single UInstruction. */
776#define VG_MAX_REGS_USED 3
njn25e49d8e72002-09-23 09:36:25 +0000777
njnf4ce3d32003-02-10 10:17:26 +0000778/* Find what this instruction does to its regs, useful for
779 analysis/optimisation passes. `tag' indicates whether we're considering
780 TempRegs (pre-reg-alloc) or RealRegs (post-reg-alloc). `regs' is filled
781 with the affected register numbers, `isWrites' parallels it and indicates
782 if the reg is read or written. If a reg is read and written, it will
783 appear twice in `regs'. `regs' and `isWrites' must be able to fit
784 VG_MAX_REGS_USED elements. */
njn810086f2002-11-14 12:42:47 +0000785extern Int VG_(get_reg_usage) ( UInstr* u, Tag tag, Int* regs, Bool* isWrites );
njn25e49d8e72002-09-23 09:36:25 +0000786
787
njnd5bb0a52002-09-27 10:24:48 +0000788/* Used to register helper functions to be called from generated code. A
789 limited number of compact helpers can be registered; the code generated
790 to call them is slightly shorter -- so register the mostly frequently
791 called helpers as compact. */
njn25e49d8e72002-09-23 09:36:25 +0000792extern void VG_(register_compact_helper) ( Addr a );
793extern void VG_(register_noncompact_helper) ( Addr a );
794
795
796/* ------------------------------------------------------------------ */
797/* Virtual register allocation */
798
799/* Get a new virtual register */
njn4ba5a792002-09-30 10:23:54 +0000800extern Int VG_(get_new_temp) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000801
802/* Get a new virtual shadow register */
njn4ba5a792002-09-30 10:23:54 +0000803extern Int VG_(get_new_shadow) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000804
805/* Get a virtual register's corresponding virtual shadow register */
806#define SHADOW(tempreg) ((tempreg)+1)
807
808
809/* ------------------------------------------------------------------ */
810/* Low-level UInstr builders */
njn4ba5a792002-09-30 10:23:54 +0000811extern void VG_(new_NOP) ( UInstr* u );
812extern void VG_(new_UInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
813extern void VG_(new_UInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000814 Tag tag1, UInt val1 );
njn4ba5a792002-09-30 10:23:54 +0000815extern void VG_(new_UInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000816 Tag tag1, UInt val1,
817 Tag tag2, UInt val2 );
njn4ba5a792002-09-30 10:23:54 +0000818extern void VG_(new_UInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000819 Tag tag1, UInt val1,
820 Tag tag2, UInt val2,
821 Tag tag3, UInt val3 );
njn25e49d8e72002-09-23 09:36:25 +0000822
njn810086f2002-11-14 12:42:47 +0000823/* Set read/write/undefined flags. Undefined flags are treaten as written,
824 but it's worth keeping them logically distinct. */
825extern void VG_(set_flag_fields) ( UCodeBlock* cb, FlagSet fr, FlagSet fw,
826 FlagSet fu);
njn4ba5a792002-09-30 10:23:54 +0000827extern void VG_(set_lit_field) ( UCodeBlock* cb, UInt lit32 );
828extern void VG_(set_ccall_fields) ( UCodeBlock* cb, Addr fn, UChar argc,
829 UChar regparms_n, Bool has_ret_val );
njn810086f2002-11-14 12:42:47 +0000830extern void VG_(set_cond_field) ( UCodeBlock* cb, Condcode code );
njn25e49d8e72002-09-23 09:36:25 +0000831
njn4ba5a792002-09-30 10:23:54 +0000832extern void VG_(copy_UInstr) ( UCodeBlock* cb, UInstr* instr );
833
834extern Bool VG_(any_flag_use)( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +0000835
njnac6c1762002-10-04 14:34:15 +0000836/* Macro versions of the above; just shorter to type. */
837#define uInstr0 VG_(new_UInstr0)
838#define uInstr1 VG_(new_UInstr1)
839#define uInstr2 VG_(new_UInstr2)
840#define uInstr3 VG_(new_UInstr3)
841#define uLiteral VG_(set_lit_field)
842#define uCCall VG_(set_ccall_fields)
njn810086f2002-11-14 12:42:47 +0000843#define uCond VG_(set_cond_field)
844#define uFlagsRWU VG_(set_flag_fields)
njnac6c1762002-10-04 14:34:15 +0000845#define newTemp VG_(get_new_temp)
846#define newShadow VG_(get_new_shadow)
847
njn25e49d8e72002-09-23 09:36:25 +0000848/* Refer to `the last instruction stuffed in' (can be lvalue). */
849#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
850
851
852/* ------------------------------------------------------------------ */
853/* Higher-level UInstr sequence builders */
njn4ba5a792002-09-30 10:23:54 +0000854extern void VG_(call_helper_0_0) ( UCodeBlock* cb, Addr f);
855extern void VG_(call_helper_1_0) ( UCodeBlock* cb, Addr f, UInt arg1,
856 UInt regparms_n);
857extern void VG_(call_helper_2_0) ( UCodeBlock* cb, Addr f, UInt arg1, UInt arg2,
858 UInt regparms_n);
njn25e49d8e72002-09-23 09:36:25 +0000859
860/* One way around the 3-arg C function limit is to pass args via global
njn6fefa1b2003-02-24 10:32:51 +0000861 * variables... ugly, but it works. This one puts a literal in there. */
njn4ba5a792002-09-30 10:23:54 +0000862extern void VG_(set_global_var) ( UCodeBlock* cb, Addr globvar_ptr, UInt val);
njn25e49d8e72002-09-23 09:36:25 +0000863
njn6fefa1b2003-02-24 10:32:51 +0000864/* This one puts the contents of a TempReg in the global variable. */
865extern void VG_(set_global_var_tempreg) ( UCodeBlock* cb, Addr globvar_ptr,
866 UInt t_val);
867
njn25e49d8e72002-09-23 09:36:25 +0000868/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000869/* Allocating/freeing basic blocks of UCode */
njn810086f2002-11-14 12:42:47 +0000870extern UCodeBlock* VG_(setup_UCodeBlock) ( UCodeBlock* cb );
njn4ba5a792002-09-30 10:23:54 +0000871extern void VG_(free_UCodeBlock) ( UCodeBlock* cb );
njnd5bb0a52002-09-27 10:24:48 +0000872
873/* ------------------------------------------------------------------ */
874/* UCode pretty/ugly printing. Probably only useful to call from a skin
njn25e49d8e72002-09-23 09:36:25 +0000875 if VG_(needs).extended_UCode == True. */
876
877/* When True, all generated code is/should be printed. */
878extern Bool VG_(print_codegen);
879
njn4ba5a792002-09-30 10:23:54 +0000880/* Pretty/ugly printing functions */
881extern void VG_(pp_UCodeBlock) ( UCodeBlock* cb, Char* title );
882extern void VG_(pp_UInstr) ( Int instrNo, UInstr* u );
883extern void VG_(pp_UInstr_regs) ( Int instrNo, UInstr* u );
884extern void VG_(up_UInstr) ( Int instrNo, UInstr* u );
885extern Char* VG_(name_UOpcode) ( Bool upper, Opcode opc );
njn563f96f2003-02-03 11:17:46 +0000886extern Char* VG_(name_UCondcode) ( Condcode cond );
njn4ba5a792002-09-30 10:23:54 +0000887extern void VG_(pp_UOperand) ( UInstr* u, Int operandNo,
888 Int sz, Bool parens );
njn25e49d8e72002-09-23 09:36:25 +0000889
njnb93d1782003-02-03 12:03:22 +0000890/* ------------------------------------------------------------------ */
njnf4ce3d32003-02-10 10:17:26 +0000891/* Accessing archregs and their shadows */
892extern UInt VG_(get_archreg) ( UInt archreg );
893extern UInt VG_(get_thread_archreg) ( ThreadId tid, UInt archreg );
894
njnb93d1782003-02-03 12:03:22 +0000895extern UInt VG_(get_shadow_archreg) ( UInt archreg );
896extern void VG_(set_shadow_archreg) ( UInt archreg, UInt val );
897extern Addr VG_(shadow_archreg_address) ( UInt archreg );
njn25e49d8e72002-09-23 09:36:25 +0000898
njnf4ce3d32003-02-10 10:17:26 +0000899extern UInt VG_(get_thread_shadow_archreg) ( ThreadId tid, UInt archreg );
900extern void VG_(set_thread_shadow_archreg) ( ThreadId tid, UInt archreg,
901 UInt val );
njn211b6ad2003-02-03 12:33:31 +0000902
903/* ------------------------------------------------------------------ */
904/* Offsets of addresses of helper functions. A "helper" function is one
905 which is called from generated code via CALLM. */
906
907extern Int VGOFF_(helper_idiv_64_32);
908extern Int VGOFF_(helper_div_64_32);
909extern Int VGOFF_(helper_idiv_32_16);
910extern Int VGOFF_(helper_div_32_16);
911extern Int VGOFF_(helper_idiv_16_8);
912extern Int VGOFF_(helper_div_16_8);
913
914extern Int VGOFF_(helper_imul_32_64);
915extern Int VGOFF_(helper_mul_32_64);
916extern Int VGOFF_(helper_imul_16_32);
917extern Int VGOFF_(helper_mul_16_32);
918extern Int VGOFF_(helper_imul_8_16);
919extern Int VGOFF_(helper_mul_8_16);
920
921extern Int VGOFF_(helper_CLD);
922extern Int VGOFF_(helper_STD);
923extern Int VGOFF_(helper_get_dirflag);
924
925extern Int VGOFF_(helper_CLC);
926extern Int VGOFF_(helper_STC);
927
928extern Int VGOFF_(helper_shldl);
929extern Int VGOFF_(helper_shldw);
930extern Int VGOFF_(helper_shrdl);
931extern Int VGOFF_(helper_shrdw);
932
933extern Int VGOFF_(helper_RDTSC);
934extern Int VGOFF_(helper_CPUID);
935
936extern Int VGOFF_(helper_bsf);
937extern Int VGOFF_(helper_bsr);
938
939extern Int VGOFF_(helper_fstsw_AX);
940extern Int VGOFF_(helper_SAHF);
941extern Int VGOFF_(helper_DAS);
942extern Int VGOFF_(helper_DAA);
943
944
njn25e49d8e72002-09-23 09:36:25 +0000945/*====================================================================*/
njnd5bb0a52002-09-27 10:24:48 +0000946/*=== Generating x86 code from UCode ===*/
njn25e49d8e72002-09-23 09:36:25 +0000947/*====================================================================*/
948
njnd5bb0a52002-09-27 10:24:48 +0000949/* All this only necessary for skins with VG_(needs).extends_UCode == True. */
njn25e49d8e72002-09-23 09:36:25 +0000950
sewardje1042472002-09-30 12:33:11 +0000951/* This is the Intel register encoding -- integer regs. */
njn25e49d8e72002-09-23 09:36:25 +0000952#define R_EAX 0
953#define R_ECX 1
954#define R_EDX 2
955#define R_EBX 3
956#define R_ESP 4
957#define R_EBP 5
958#define R_ESI 6
959#define R_EDI 7
960
961#define R_AL (0+R_EAX)
962#define R_CL (0+R_ECX)
963#define R_DL (0+R_EDX)
964#define R_BL (0+R_EBX)
965#define R_AH (4+R_EAX)
966#define R_CH (4+R_ECX)
967#define R_DH (4+R_EDX)
968#define R_BH (4+R_EBX)
969
sewardje1042472002-09-30 12:33:11 +0000970/* This is the Intel register encoding -- segment regs. */
971#define R_ES 0
972#define R_CS 1
973#define R_SS 2
974#define R_DS 3
975#define R_FS 4
976#define R_GS 5
977
njn25e49d8e72002-09-23 09:36:25 +0000978/* For pretty printing x86 code */
sewardj3d7c9c82003-03-26 21:08:13 +0000979extern Char* VG_(name_of_mmx_gran) ( UChar gran );
980extern Char* VG_(name_of_mmx_reg) ( Int mmxreg );
sewardje1042472002-09-30 12:33:11 +0000981extern Char* VG_(name_of_seg_reg) ( Int sreg );
njn4ba5a792002-09-30 10:23:54 +0000982extern Char* VG_(name_of_int_reg) ( Int size, Int reg );
983extern Char VG_(name_of_int_size) ( Int size );
njn25e49d8e72002-09-23 09:36:25 +0000984
njnac6c1762002-10-04 14:34:15 +0000985/* Shorter macros for convenience */
sewardj3d7c9c82003-03-26 21:08:13 +0000986#define nameIReg VG_(name_of_int_reg)
987#define nameISize VG_(name_of_int_size)
988#define nameSReg VG_(name_of_seg_reg)
989#define nameMMXReg VG_(name_of_mmx_reg)
990#define nameMMXGran VG_(name_of_mmx_gran)
njnac6c1762002-10-04 14:34:15 +0000991
njn25e49d8e72002-09-23 09:36:25 +0000992/* Randomly useful things */
993extern UInt VG_(extend_s_8to32) ( UInt x );
994
995/* Code emitters */
njn4ba5a792002-09-30 10:23:54 +0000996extern void VG_(emitB) ( UInt b );
997extern void VG_(emitW) ( UInt w );
998extern void VG_(emitL) ( UInt l );
sewardjfa492d42002-12-08 18:20:01 +0000999extern void VG_(new_emit) ( Bool upd_cc, FlagSet uses_flags, FlagSet sets_flags );
njn25e49d8e72002-09-23 09:36:25 +00001000
1001/* Finding offsets */
njn4ba5a792002-09-30 10:23:54 +00001002extern Int VG_(helper_offset) ( Addr a );
1003extern Int VG_(shadow_reg_offset) ( Int arch );
1004extern Int VG_(shadow_flags_offset) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001005
njnd5bb0a52002-09-27 10:24:48 +00001006/* Convert reg ranks <-> Intel register ordering, for using register
1007 liveness information. */
njn4ba5a792002-09-30 10:23:54 +00001008extern Int VG_(realreg_to_rank) ( Int realreg );
1009extern Int VG_(rank_to_realreg) ( Int rank );
njn25e49d8e72002-09-23 09:36:25 +00001010
njnd5bb0a52002-09-27 10:24:48 +00001011/* Call a subroutine. Does no argument passing, stack manipulations, etc. */
sewardjfa492d42002-12-08 18:20:01 +00001012extern void VG_(synth_call) ( Bool ensure_shortform, Int word_offset,
1013 Bool upd_cc, FlagSet use_flags, FlagSet set_flags );
njn25e49d8e72002-09-23 09:36:25 +00001014
njnd5bb0a52002-09-27 10:24:48 +00001015/* For calling C functions -- saves caller save regs, pushes args, calls,
1016 clears the stack, restores caller save regs. `fn' must be registered in
1017 the baseBlock first. Acceptable tags are RealReg and Literal. Optimises
1018 things, eg. by not preserving non-live caller-save registers.
njn25e49d8e72002-09-23 09:36:25 +00001019
njnd5bb0a52002-09-27 10:24:48 +00001020 WARNING: a UInstr should *not* be translated with synth_ccall() followed
1021 by some other x86 assembly code; this will invalidate the results of
1022 vg_realreg_liveness_analysis() and everything will fall over. */
njn4ba5a792002-09-30 10:23:54 +00001023extern void VG_(synth_ccall) ( Addr fn, Int argc, Int regparms_n, UInt argv[],
1024 Tag tagv[], Int ret_reg,
1025 RRegSet regs_live_before,
1026 RRegSet regs_live_after );
njn25e49d8e72002-09-23 09:36:25 +00001027
1028/* Addressing modes */
njn4ba5a792002-09-30 10:23:54 +00001029extern void VG_(emit_amode_offregmem_reg)( Int off, Int regmem, Int reg );
1030extern void VG_(emit_amode_ereg_greg) ( Int e_reg, Int g_reg );
njn25e49d8e72002-09-23 09:36:25 +00001031
1032/* v-size (4, or 2 with OSO) insn emitters */
njn4ba5a792002-09-30 10:23:54 +00001033extern void VG_(emit_movv_offregmem_reg) ( Int sz, Int off, Int areg, Int reg );
1034extern void VG_(emit_movv_reg_offregmem) ( Int sz, Int reg, Int off, Int areg );
1035extern void VG_(emit_movv_reg_reg) ( Int sz, Int reg1, Int reg2 );
sewardjfa492d42002-12-08 18:20:01 +00001036extern void VG_(emit_nonshiftopv_lit_reg)( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001037 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001038extern void VG_(emit_shiftopv_lit_reg) ( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001039 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001040extern void VG_(emit_nonshiftopv_reg_reg)( Bool upd_cc, Int sz, Opcode opc,
njn4ba5a792002-09-30 10:23:54 +00001041 Int reg1, Int reg2 );
1042extern void VG_(emit_movv_lit_reg) ( Int sz, UInt lit, Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001043extern void VG_(emit_unaryopv_reg) ( Bool upd_cc, Int sz, Opcode opc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001044extern void VG_(emit_pushv_reg) ( Int sz, Int reg );
1045extern void VG_(emit_popv_reg) ( Int sz, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001046
njn4ba5a792002-09-30 10:23:54 +00001047extern void VG_(emit_pushl_lit32) ( UInt int32 );
1048extern void VG_(emit_pushl_lit8) ( Int lit8 );
sewardjfa492d42002-12-08 18:20:01 +00001049extern void VG_(emit_cmpl_zero_reg) ( Bool upd_cc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001050extern void VG_(emit_swapl_reg_EAX) ( Int reg );
1051extern void VG_(emit_movv_lit_offregmem) ( Int sz, UInt lit, Int off,
1052 Int memreg );
njn25e49d8e72002-09-23 09:36:25 +00001053
1054/* b-size (1 byte) instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001055extern void VG_(emit_movb_lit_offregmem) ( UInt lit, Int off, Int memreg );
1056extern void VG_(emit_movb_reg_offregmem) ( Int reg, Int off, Int areg );
sewardjfa492d42002-12-08 18:20:01 +00001057extern void VG_(emit_unaryopb_reg) ( Bool upd_cc, Opcode opc, Int reg );
1058extern void VG_(emit_testb_lit_reg) ( Bool upd_cc, UInt lit, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001059
1060/* zero-extended load emitters */
njn4ba5a792002-09-30 10:23:54 +00001061extern void VG_(emit_movzbl_offregmem_reg) ( Int off, Int regmem, Int reg );
1062extern void VG_(emit_movzwl_offregmem_reg) ( Int off, Int areg, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001063
1064/* misc instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001065extern void VG_(emit_call_reg) ( Int reg );
1066extern void VG_(emit_add_lit_to_esp) ( Int lit );
njn4ba5a792002-09-30 10:23:54 +00001067extern void VG_(emit_pushal) ( void );
1068extern void VG_(emit_popal) ( void );
1069extern void VG_(emit_AMD_prefetch_reg) ( Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001070
sewardja2113f92002-12-12 23:42:48 +00001071/* jump emitters */
1072extern void VG_(init_target) ( Int *tgt );
1073
1074extern void VG_(target_back) ( Int *tgt );
1075extern void VG_(target_forward) ( Int *tgt );
1076extern void VG_(emit_target_delta) ( Int *tgt );
1077
1078extern void VG_(emit_jcondshort_delta) ( Bool simd_cc, Condcode cond, Int delta );
1079extern void VG_(emit_jcondshort_target)( Bool simd_cc, Condcode cond, Int *tgt );
1080
njn25e49d8e72002-09-23 09:36:25 +00001081
1082/*====================================================================*/
1083/*=== Execution contexts ===*/
1084/*====================================================================*/
1085
1086/* Generic resolution type used in a few different ways, such as deciding
1087 how closely to compare two errors for equality. */
1088typedef
1089 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
1090 VgRes;
1091
1092typedef
1093 struct _ExeContext
1094 ExeContext;
1095
njnd5bb0a52002-09-27 10:24:48 +00001096/* Compare two ExeContexts. Number of callers considered depends on `res':
1097 Vg_LowRes: 2
1098 Vg_MedRes: 4
1099 Vg_HighRes: all */
njn25e49d8e72002-09-23 09:36:25 +00001100extern Bool VG_(eq_ExeContext) ( VgRes res,
1101 ExeContext* e1, ExeContext* e2 );
1102
1103/* Print an ExeContext. */
1104extern void VG_(pp_ExeContext) ( ExeContext* );
1105
1106/* Take a snapshot of the client's stack. Search our collection of
1107 ExeContexts to see if we already have it, and if not, allocate a
1108 new one. Either way, return a pointer to the context. */
1109extern ExeContext* VG_(get_ExeContext) ( ThreadState *tst );
1110
sewardj499e3de2002-11-13 22:22:25 +00001111/* Just grab the client's EIP, as a much smaller and cheaper
1112 indication of where they are. */
1113extern Addr VG_(get_EIP)( ThreadState *tst );
njn25e49d8e72002-09-23 09:36:25 +00001114
njn211b6ad2003-02-03 12:33:31 +00001115
njn25e49d8e72002-09-23 09:36:25 +00001116/*====================================================================*/
1117/*=== Error reporting ===*/
1118/*====================================================================*/
1119
1120/* ------------------------------------------------------------------ */
1121/* Suppressions describe errors which we want to suppress, ie, not
1122 show the user, usually because it is caused by a problem in a library
1123 which we can't fix, replace or work around. Suppressions are read from
njnd5bb0a52002-09-27 10:24:48 +00001124 a file at startup time. This gives flexibility so that new
njn25e49d8e72002-09-23 09:36:25 +00001125 suppressions can be added to the file as and when needed.
1126*/
1127
1128typedef
1129 Int /* Do not make this unsigned! */
1130 SuppKind;
1131
njn810086f2002-11-14 12:42:47 +00001132/* The skin-relevant parts of a suppression are:
1133 kind: what kind of suppression; must be in the range (0..)
1134 string: use is optional. NULL by default.
1135 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001136*/
1137typedef
njn810086f2002-11-14 12:42:47 +00001138 struct _Supp
1139 Supp;
1140
1141/* Useful in SK_(error_matches_suppression)() */
1142SuppKind VG_(get_supp_kind) ( Supp* su );
1143Char* VG_(get_supp_string) ( Supp* su );
1144void* VG_(get_supp_extra) ( Supp* su );
1145
1146/* Must be used in VG_(recognised_suppression)() */
1147void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
1148/* May be used in VG_(read_extra_suppression_info)() */
1149void VG_(set_supp_string) ( Supp* su, Char* string );
1150void VG_(set_supp_extra) ( Supp* su, void* extra );
njn25e49d8e72002-09-23 09:36:25 +00001151
1152
1153/* ------------------------------------------------------------------ */
1154/* Error records contain enough info to generate an error report. The idea
1155 is that (typically) the same few points in the program generate thousands
njnd5bb0a52002-09-27 10:24:48 +00001156 of errors, and we don't want to spew out a fresh error message for each
1157 one. Instead, we use these structures to common up duplicates.
njn25e49d8e72002-09-23 09:36:25 +00001158*/
1159
1160typedef
1161 Int /* Do not make this unsigned! */
1162 ErrorKind;
1163
njn810086f2002-11-14 12:42:47 +00001164/* The skin-relevant parts of an Error are:
1165 kind: what kind of error; must be in the range (0..)
1166 addr: use is optional. 0 by default.
1167 string: use is optional. NULL by default.
1168 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001169*/
1170typedef
njn810086f2002-11-14 12:42:47 +00001171 struct _Error
1172 Error;
njn25e49d8e72002-09-23 09:36:25 +00001173
njn810086f2002-11-14 12:42:47 +00001174/* Useful in SK_(error_matches_suppression)(), SK_(pp_SkinError)(), etc */
njnb877d492003-01-28 20:40:57 +00001175ExeContext* VG_(get_error_where) ( Error* err );
1176SuppKind VG_(get_error_kind) ( Error* err );
1177Addr VG_(get_error_address) ( Error* err );
1178Char* VG_(get_error_string) ( Error* err );
1179void* VG_(get_error_extra) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001180
njnd5bb0a52002-09-27 10:24:48 +00001181/* Call this when an error occurs. It will be recorded if it hasn't been
njn25e49d8e72002-09-23 09:36:25 +00001182 seen before. If it has, the existing error record will have its count
1183 incremented.
1184
1185 If the error occurs in generated code, 'tst' should be NULL. If the
1186 error occurs in non-generated code, 'tst' should be non-NULL. The
njn43c799e2003-04-08 00:08:52 +00001187 `extra' field can be stack-allocated; it will be copied by the core
1188 if needed. But it won't be copied if it's NULL.
njnd5bb0a52002-09-27 10:24:48 +00001189
1190 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
1191 NULL for them.
njn25e49d8e72002-09-23 09:36:25 +00001192*/
1193extern void VG_(maybe_record_error) ( ThreadState* tst, ErrorKind ekind,
1194 Addr a, Char* s, void* extra );
1195
njn43c799e2003-04-08 00:08:52 +00001196/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
1197 error -- useful for errors that can only happen once. The errors can be
1198 suppressed, though. Return value is True if it was suppressed.
1199 `print_error' dictates whether to print the error, which is a bit of a
1200 hack that's useful sometimes if you just want to know if the error would
1201 be suppressed without possibly printing it. */
1202extern Bool VG_(unique_error) ( ThreadState* tst, ErrorKind ekind,
1203 Addr a, Char* s, void* extra,
1204 ExeContext* where, Bool print_error );
1205
njn25e49d8e72002-09-23 09:36:25 +00001206/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
1207 Skips leading spaces on the line. Returns True if EOF was hit instead.
1208 Useful for reading in extra skin-specific suppression lines.
1209*/
njn4ba5a792002-09-30 10:23:54 +00001210extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
njn25e49d8e72002-09-23 09:36:25 +00001211
1212
1213/*====================================================================*/
1214/*=== Obtaining debug information ===*/
1215/*====================================================================*/
1216
sewardj6e008cb2002-12-15 13:11:39 +00001217/* Get the file/function/line number of the instruction at address
1218 'a'. For these four, if debug info for the address is found, it
1219 copies the info into the buffer/UInt and returns True. If not, it
1220 returns False and nothing is copied. VG_(get_fnname) always
1221 demangles C++ function names. VG_(get_fnname_w_offset) is the
1222 same, except it appends "+N" to symbol names to indicate offsets.
njn25e49d8e72002-09-23 09:36:25 +00001223*/
1224extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
1225extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
1226extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
sewardj6e008cb2002-12-15 13:11:39 +00001227extern Bool VG_(get_fnname_w_offset)
1228 ( Addr a, Char* fnname, Int n_fnname );
njn25e49d8e72002-09-23 09:36:25 +00001229
1230/* This one is more efficient if getting both filename and line number,
1231 because the two lookups are done together. */
1232extern Bool VG_(get_filename_linenum)
1233 ( Addr a, Char* filename, Int n_filename,
1234 UInt* linenum );
1235
1236/* Succeeds only if we find from debug info that 'a' is the address of the
1237 first instruction in a function -- as opposed to VG_(get_fnname) which
1238 succeeds if we find from debug info that 'a' is the address of any
1239 instruction in a function. Use this to instrument the start of
njnd5bb0a52002-09-27 10:24:48 +00001240 a particular function. Nb: if an executable/shared object is stripped
njn25e49d8e72002-09-23 09:36:25 +00001241 of its symbols, this function will not be able to recognise function
1242 entry points within it. */
1243extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* filename, Int n_filename );
1244
1245/* Succeeds if the address is within a shared object or the main executable.
1246 It doesn't matter if debug info is present or not. */
1247extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
1248
sewardj47104382002-10-20 18:35:48 +00001249/* A way to get information about what segments are mapped */
1250typedef struct _SegInfo SegInfo;
1251
njnb877d492003-01-28 20:40:57 +00001252/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
1253 is present or not. */
1254extern SegInfo* VG_(get_obj) ( Addr a );
1255
1256extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
1257extern Addr VG_(seg_start) ( const SegInfo *seg );
1258extern UInt VG_(seg_size) ( const SegInfo *seg );
1259extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
1260extern UInt VG_(seg_sym_offset)( const SegInfo *seg );
sewardj47104382002-10-20 18:35:48 +00001261
1262typedef
1263 enum {
1264 Vg_SectUnknown,
1265 Vg_SectText,
sewardj8fe15a32002-10-20 19:29:21 +00001266 Vg_SectData,
1267 Vg_SectBSS,
sewardj47104382002-10-20 18:35:48 +00001268 Vg_SectGOT,
sewardj8fe15a32002-10-20 19:29:21 +00001269 Vg_SectPLT,
sewardj47104382002-10-20 18:35:48 +00001270 }
1271 VgSectKind;
1272
1273extern VgSectKind VG_(seg_sect_kind)(Addr);
1274
njn25e49d8e72002-09-23 09:36:25 +00001275
1276/*====================================================================*/
1277/*=== Shadow chunks and block-finding ===*/
1278/*====================================================================*/
1279
njn810086f2002-11-14 12:42:47 +00001280/* The skin-relevant parts of a ShadowChunk are:
1281 size: size of the block in bytes
1282 addr: addr of the block
1283 extra: anything extra kept by the skin; size is determined by
1284 VG_(needs).sizeof_shadow_chunk
1285*/
njn25e49d8e72002-09-23 09:36:25 +00001286typedef
njn810086f2002-11-14 12:42:47 +00001287 struct _ShadowChunk
njn25e49d8e72002-09-23 09:36:25 +00001288 ShadowChunk;
1289
njn810086f2002-11-14 12:42:47 +00001290extern UInt VG_(get_sc_size) ( ShadowChunk* sc );
1291extern Addr VG_(get_sc_data) ( ShadowChunk* sc );
1292/* Gets the ith word of the `extra' field. */
1293extern UInt VG_(get_sc_extra) ( ShadowChunk* sc, UInt i );
1294/* Sets the ith word of the `extra' field to `word'. */
1295extern void VG_(set_sc_extra) ( ShadowChunk* sc, UInt i, UInt word );
1296
1297/* These two should only be used if the `alternative_free' need is set, once
1298 we reach the point where the block would have been free'd. */
1299extern ShadowChunk* VG_(get_sc_next) ( ShadowChunk* sc );
1300extern void VG_(set_sc_next) ( ShadowChunk* sc, ShadowChunk* next );
1301
1302
njn25e49d8e72002-09-23 09:36:25 +00001303/* Use this to free blocks if VG_(needs).alternative_free == True.
1304 It frees the ShadowChunk and the malloc'd block it points to. */
njn4ba5a792002-09-30 10:23:54 +00001305extern void VG_(free_ShadowChunk) ( ShadowChunk* sc );
njn25e49d8e72002-09-23 09:36:25 +00001306
1307/* Makes an array of pointers to all the shadow chunks of malloc'd blocks */
1308extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
1309
1310/* Determines if address 'a' is within the bounds of the block at start.
1311 Allows a little 'slop' round the edges. */
1312extern Bool VG_(addr_is_in_block) ( Addr a, Addr start, UInt size );
1313
1314/* Searches through currently malloc'd blocks until a matching one is found.
1315 Returns NULL if none match. Extra arguments can be implicitly passed to
njnd5bb0a52002-09-27 10:24:48 +00001316 p using nested functions; see memcheck/mc_errcontext.c for an example. */
njn43c799e2003-04-08 00:08:52 +00001317extern ShadowChunk* VG_(first_matching_mallocd_ShadowChunk)
njn25e49d8e72002-09-23 09:36:25 +00001318 ( Bool (*p) ( ShadowChunk* ));
1319
1320/* Searches through all thread's stacks to see if any match. Returns
1321 * VG_INVALID_THREADID if none match. */
njn43c799e2003-04-08 00:08:52 +00001322extern ThreadId VG_(first_matching_thread_stack)
njn25e49d8e72002-09-23 09:36:25 +00001323 ( Bool (*p) ( Addr stack_min, Addr stack_max ));
1324
sewardja4495682002-10-21 07:29:59 +00001325/* Do memory leak detection. */
1326extern void VG_(generic_detect_memory_leaks) (
1327 Bool is_valid_64k_chunk ( UInt ),
1328 Bool is_valid_address ( Addr ),
1329 ExeContext* get_where ( ShadowChunk* ),
1330 VgRes leak_resolution,
sewardj99aac972002-12-26 01:53:45 +00001331 Bool show_reachable,
1332 UInt /*CoreErrorKind*/ leakSupp
sewardja4495682002-10-21 07:29:59 +00001333 );
1334
1335
njn25e49d8e72002-09-23 09:36:25 +00001336/*====================================================================*/
1337/*=== Skin-specific stuff ===*/
1338/*====================================================================*/
1339
njnd04b7c62002-10-03 14:05:52 +00001340/* ------------------------------------------------------------------ */
1341/* Details */
njnd04b7c62002-10-03 14:05:52 +00001342
njn120281f2003-02-03 12:20:07 +00001343/* Default value for avg_translations_sizeB (in bytes), indicating typical
1344 code expansion of about 6:1. */
1345#define VG_DEFAULT_TRANS_SIZEB 100
1346
njn810086f2002-11-14 12:42:47 +00001347/* Information used in the startup message. `name' also determines the
1348 string used for identifying suppressions in a suppression file as
1349 belonging to this skin. `version' can be NULL, in which case (not
1350 surprisingly) no version info is printed; this mechanism is designed for
1351 skins distributed with Valgrind that share a version number with
1352 Valgrind. Other skins not distributed as part of Valgrind should
sewardjc0d8f682002-11-30 00:49:43 +00001353 probably have their own version number. */
1354extern void VG_(details_name) ( Char* name );
1355extern void VG_(details_version) ( Char* version );
1356extern void VG_(details_description) ( Char* description );
1357extern void VG_(details_copyright_author) ( Char* copyright_author );
1358
1359/* Average size of a translation, in bytes, so that the translation
njn120281f2003-02-03 12:20:07 +00001360 storage machinery can allocate memory appropriately. Not critical,
1361 setting is optional. */
1362extern void VG_(details_avg_translation_sizeB) ( UInt size );
njnd04b7c62002-10-03 14:05:52 +00001363
njn810086f2002-11-14 12:42:47 +00001364/* String printed if an `sk_assert' assertion fails or VG_(skin_panic)
1365 is called. Should probably be an email address. */
1366extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
njnd04b7c62002-10-03 14:05:52 +00001367
1368/* ------------------------------------------------------------------ */
1369/* Needs */
1370
njn810086f2002-11-14 12:42:47 +00001371/* Booleans that decide core behaviour, but don't require extra
1372 operations to be defined if `True' */
njnd5bb0a52002-09-27 10:24:48 +00001373
njn810086f2002-11-14 12:42:47 +00001374/* Should __libc_freeres() be run? Bugs in it can crash the skin. */
1375extern void VG_(needs_libc_freeres) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001376
njn810086f2002-11-14 12:42:47 +00001377/* Want to have errors detected by Valgrind's core reported? Includes:
1378 - pthread API errors (many; eg. unlocking a non-locked mutex)
1379 - silly arguments to malloc() et al (eg. negative size)
1380 - invalid file descriptors to blocking syscalls read() and write()
1381 - bad signal numbers passed to sigaction()
1382 - attempt to install signal handler for SIGKILL or SIGSTOP */
1383extern void VG_(needs_core_errors) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001384
njn810086f2002-11-14 12:42:47 +00001385/* Booleans that indicate extra operations are defined; if these are True,
1386 the corresponding template functions (given below) must be defined. A
1387 lot like being a member of a type class. */
njn25e49d8e72002-09-23 09:36:25 +00001388
njn810086f2002-11-14 12:42:47 +00001389/* Want to report errors from skin? This implies use of suppressions, too. */
1390extern void VG_(needs_skin_errors) ( void );
njnd5bb0a52002-09-27 10:24:48 +00001391
njn810086f2002-11-14 12:42:47 +00001392/* Is information kept about specific individual basic blocks? (Eg. for
1393 cachegrind there are cost-centres for every instruction, stored at a
1394 basic block level.) If so, it sometimes has to be discarded, because
1395 .so mmap/munmap-ping or self-modifying code (informed by the
1396 DISCARD_TRANSLATIONS user request) can cause one instruction address
1397 to be used for more than one instruction in one program run... */
1398extern void VG_(needs_basic_block_discards) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001399
njn810086f2002-11-14 12:42:47 +00001400/* Skin maintains information about each register? */
1401extern void VG_(needs_shadow_regs) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001402
njn810086f2002-11-14 12:42:47 +00001403/* Skin defines its own command line options? */
1404extern void VG_(needs_command_line_options) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001405
njn810086f2002-11-14 12:42:47 +00001406/* Skin defines its own client requests? */
1407extern void VG_(needs_client_requests) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001408
njn810086f2002-11-14 12:42:47 +00001409/* Skin defines its own UInstrs? */
1410extern void VG_(needs_extended_UCode) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001411
njn810086f2002-11-14 12:42:47 +00001412/* Skin does stuff before and/or after system calls? */
1413extern void VG_(needs_syscall_wrapper) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001414
njn810086f2002-11-14 12:42:47 +00001415/* Size, in words, of extra info about malloc'd blocks recorded by
1416 skin. Be careful to get this right or you'll get seg faults! */
1417extern void VG_(needs_sizeof_shadow_block) ( Int size );
njn25e49d8e72002-09-23 09:36:25 +00001418
njn810086f2002-11-14 12:42:47 +00001419/* Skin does free()s itself? Useful if a skin needs to keep track of
1420 blocks in some way after they're free'd.
1421 WARNING: don't forget to call VG_(free_ShadowChunk)() for each block
1422 eventually! */
1423extern void VG_(needs_alternative_free) ( void );
sewardj8fe15a32002-10-20 19:29:21 +00001424
njn810086f2002-11-14 12:42:47 +00001425/* Are skin-state sanity checks performed? */
1426extern void VG_(needs_sanity_checks) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001427
njn810086f2002-11-14 12:42:47 +00001428/* Do we need to see data symbols? */
1429extern void VG_(needs_data_syms) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001430
1431/* ------------------------------------------------------------------ */
1432/* Core events to track */
1433
1434/* Part of the core from which this call was made. Useful for determining
njnd5bb0a52002-09-27 10:24:48 +00001435 what kind of error message should be emitted. */
njn25e49d8e72002-09-23 09:36:25 +00001436typedef
1437 enum { Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall, Vg_CoreTranslate }
1438 CorePart;
1439
njn810086f2002-11-14 12:42:47 +00001440#define EV extern void
njn25e49d8e72002-09-23 09:36:25 +00001441
njn810086f2002-11-14 12:42:47 +00001442/* Events happening in core to track. To be notified, pass a callback
1443 function to the appropriate function. To ignore an event, don't do
1444 anything (default is for events to be ignored). */
1445
1446/* Memory events */
1447
1448EV VG_(track_new_mem_startup) ( void (*f)(Addr a, UInt len,
1449 Bool rr, Bool ww, Bool xx) );
1450EV VG_(track_new_mem_heap) ( void (*f)(Addr a, UInt len, Bool is_inited) );
njn810086f2002-11-14 12:42:47 +00001451EV VG_(track_new_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1452EV VG_(track_new_mem_brk) ( void (*f)(Addr a, UInt len) );
1453EV VG_(track_new_mem_mmap) ( void (*f)(Addr a, UInt len,
1454 Bool rr, Bool ww, Bool xx) );
1455
njn9b007f62003-04-07 14:40:25 +00001456/* The specialised ones are called in preference to the general one, if they
1457 are defined. These functions are called a lot if they are used, so
1458 specialising can optimise things significantly. If any of the
1459 specialised cases are defined, the general case must be defined too.
1460
1461 Nb: they must all use the __attribute__((regparm(n))) attribute. */
1462EV VG_(track_new_mem_stack_4) ( void (*f)(Addr new_ESP) );
1463EV VG_(track_new_mem_stack_8) ( void (*f)(Addr new_ESP) );
1464EV VG_(track_new_mem_stack_12) ( void (*f)(Addr new_ESP) );
1465EV VG_(track_new_mem_stack_16) ( void (*f)(Addr new_ESP) );
1466EV VG_(track_new_mem_stack_32) ( void (*f)(Addr new_ESP) );
1467EV VG_(track_new_mem_stack) ( void (*f)(Addr a, UInt len) );
1468
1469EV VG_(track_change_mem_stack) ( void (*f)(Addr new_ESP) );
1470
njn810086f2002-11-14 12:42:47 +00001471EV VG_(track_copy_mem_heap) ( void (*f)(Addr from, Addr to, UInt len) );
1472EV VG_(track_copy_mem_remap) ( void (*f)(Addr from, Addr to, UInt len) );
1473EV VG_(track_change_mem_mprotect) ( void (*f)(Addr a, UInt len,
1474 Bool rr, Bool ww, Bool xx) );
njn25e49d8e72002-09-23 09:36:25 +00001475
njn810086f2002-11-14 12:42:47 +00001476/* Used on redzones around malloc'd blocks and at end of stack */
1477EV VG_(track_ban_mem_heap) ( void (*f)(Addr a, UInt len) );
1478EV VG_(track_ban_mem_stack) ( void (*f)(Addr a, UInt len) );
njn25e49d8e72002-09-23 09:36:25 +00001479
njn810086f2002-11-14 12:42:47 +00001480EV VG_(track_die_mem_heap) ( void (*f)(Addr a, UInt len) );
njn810086f2002-11-14 12:42:47 +00001481EV VG_(track_die_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1482EV VG_(track_die_mem_brk) ( void (*f)(Addr a, UInt len) );
1483EV VG_(track_die_mem_munmap) ( void (*f)(Addr a, UInt len) );
njn25e49d8e72002-09-23 09:36:25 +00001484
njn9b007f62003-04-07 14:40:25 +00001485/* See comments for VG_(track_new_mem_stack_4) et al above */
1486EV VG_(track_die_mem_stack_4) ( void (*f)(Addr die_ESP) );
1487EV VG_(track_die_mem_stack_8) ( void (*f)(Addr die_ESP) );
1488EV VG_(track_die_mem_stack_12) ( void (*f)(Addr die_ESP) );
1489EV VG_(track_die_mem_stack_16) ( void (*f)(Addr die_ESP) );
1490EV VG_(track_die_mem_stack_32) ( void (*f)(Addr die_ESP) );
1491EV VG_(track_die_mem_stack) ( void (*f)(Addr a, UInt len) );
1492
njn810086f2002-11-14 12:42:47 +00001493EV VG_(track_bad_free) ( void (*f)(ThreadState* tst, Addr a) );
1494EV VG_(track_mismatched_free) ( void (*f)(ThreadState* tst, Addr a) );
njn25e49d8e72002-09-23 09:36:25 +00001495
njn810086f2002-11-14 12:42:47 +00001496EV VG_(track_pre_mem_read) ( void (*f)(CorePart part, ThreadState* tst,
1497 Char* s, Addr a, UInt size) );
1498EV VG_(track_pre_mem_read_asciiz) ( void (*f)(CorePart part, ThreadState* tst,
1499 Char* s, Addr a) );
1500EV VG_(track_pre_mem_write) ( void (*f)(CorePart part, ThreadState* tst,
1501 Char* s, Addr a, UInt size) );
1502/* Not implemented yet -- have to add in lots of places, which is a
1503 pain. Won't bother unless/until there's a need. */
1504/* EV VG_(track_post_mem_read) ( void (*f)(ThreadState* tst, Char* s,
1505 Addr a, UInt size) ); */
1506EV VG_(track_post_mem_write) ( void (*f)(Addr a, UInt size) );
njn25e49d8e72002-09-23 09:36:25 +00001507
1508
njn810086f2002-11-14 12:42:47 +00001509/* Scheduler events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001510
njn810086f2002-11-14 12:42:47 +00001511EV VG_(track_thread_run) ( void (*f)(ThreadId tid) );
njn25e49d8e72002-09-23 09:36:25 +00001512
njn810086f2002-11-14 12:42:47 +00001513/* Thread events (not exhaustive) */
sewardjdca84112002-11-13 22:29:34 +00001514
njn810086f2002-11-14 12:42:47 +00001515/* Called during thread create, before the new thread has run any
1516 instructions (or touched any memory). */
1517EV VG_(track_post_thread_create)( void (*f)(ThreadId tid, ThreadId child) );
1518/* Called once the joinee thread is terminated and the joining thread is
1519 about to resume. */
1520EV VG_(track_post_thread_join) ( void (*f)(ThreadId joiner, ThreadId joinee) );
njn25e49d8e72002-09-23 09:36:25 +00001521
njnd5bb0a52002-09-27 10:24:48 +00001522
njn810086f2002-11-14 12:42:47 +00001523/* Mutex events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001524
njn810086f2002-11-14 12:42:47 +00001525/* Called before a thread can block while waiting for a mutex (called
1526 regardless of whether the thread will block or not). */
1527EV VG_(track_pre_mutex_lock) ( void (*f)(ThreadId tid,
1528 void* /*pthread_mutex_t* */ mutex) );
1529/* Called once the thread actually holds the mutex (always paired with
1530 pre_mutex_lock). */
1531EV VG_(track_post_mutex_lock) ( void (*f)(ThreadId tid,
1532 void* /*pthread_mutex_t* */ mutex) );
1533/* Called after a thread has released a mutex (no need for a corresponding
1534 pre_mutex_unlock, because unlocking can't block). */
1535EV VG_(track_post_mutex_unlock) ( void (*f)(ThreadId tid,
1536 void* /*pthread_mutex_t* */ mutex) );
njn25e49d8e72002-09-23 09:36:25 +00001537
njn1045b0a2003-02-24 10:42:47 +00001538
1539/* Signal events (not exhaustive) */
1540
1541/* Called before a signal is delivered; `alt_stack' indicates if it is
1542 delivered on an alternative stack. */
1543EV VG_(track_pre_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum,
1544 Bool alt_stack) );
1545/* Called after a signal is delivered. */
1546EV VG_(track_post_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum ) );
1547
1548
1549/* Others... condition variables... */
njn810086f2002-11-14 12:42:47 +00001550/* ... */
1551
1552#undef EV
njn25e49d8e72002-09-23 09:36:25 +00001553
1554/* ------------------------------------------------------------------ */
1555/* Template functions */
1556
1557/* These are the parameterised functions in the core. The default definitions
njnd5bb0a52002-09-27 10:24:48 +00001558 are overridden by LD_PRELOADed skin version. At the very least, a skin
1559 must define the fundamental template functions. Depending on what needs
1560 are set, extra template functions will be used too. Functions are
1561 grouped under the needs that govern their use. */
njn25e49d8e72002-09-23 09:36:25 +00001562
1563
1564/* ------------------------------------------------------------------ */
1565/* Fundamental template functions */
1566
1567/* Initialise skin. Must do the following:
njn810086f2002-11-14 12:42:47 +00001568 - initialise the `details' struct, via the VG_(details_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001569 - register any helpers called by generated code
1570
1571 May do the following:
njn810086f2002-11-14 12:42:47 +00001572 - initialise the `needs' struct to indicate certain requirements, via
1573 the VG_(needs_*)() functions
1574 - initialise the `track' struct to indicate core events of interest, via
1575 the VG_(track_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001576 - register any skin-specific profiling events
1577 - any other skin-specific initialisation
1578*/
njn810086f2002-11-14 12:42:47 +00001579extern void SK_(pre_clo_init) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001580
njnd5bb0a52002-09-27 10:24:48 +00001581/* Do initialisation that can only be done after command line processing. */
njn25e49d8e72002-09-23 09:36:25 +00001582extern void SK_(post_clo_init)( void );
1583
1584/* Instrument a basic block. Must be a true function, ie. the same input
1585 always results in the same output, because basic blocks can be
1586 retranslated. Unless you're doing something really strange...
1587 'orig_addr' is the address of the first instruction in the block. */
1588extern UCodeBlock* SK_(instrument) ( UCodeBlock* cb, Addr orig_addr );
1589
1590/* Finish up, print out any results, etc. */
1591extern void SK_(fini) ( void );
1592
1593
1594/* ------------------------------------------------------------------ */
1595/* VG_(needs).report_errors */
1596
1597/* Identify if two errors are equal, or equal enough. `res' indicates how
1598 close is "close enough". `res' should be passed on as necessary, eg. if
njn810086f2002-11-14 12:42:47 +00001599 the Error's `extra' part contains an ExeContext, `res' should be
njn25e49d8e72002-09-23 09:36:25 +00001600 passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other
1601 than that, probably don't worry about it unless you have lots of very
1602 similar errors occurring.
1603 */
njn810086f2002-11-14 12:42:47 +00001604extern Bool SK_(eq_SkinError) ( VgRes res, Error* e1, Error* e2 );
njn25e49d8e72002-09-23 09:36:25 +00001605
njn43c799e2003-04-08 00:08:52 +00001606/* Print error context. */
1607extern void SK_(pp_SkinError) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001608
njn43c799e2003-04-08 00:08:52 +00001609/* Should fill in any details that could be postponed until after the
njn810086f2002-11-14 12:42:47 +00001610 decision whether to ignore the error (ie. details not affecting the
1611 result of SK_(eq_SkinError)()). This saves time when errors are ignored.
njn25e49d8e72002-09-23 09:36:25 +00001612 Yuk.
njn43c799e2003-04-08 00:08:52 +00001613
1614 Return value: must be the size of the `extra' part in bytes -- used by
1615 the core to make a copy.
njn25e49d8e72002-09-23 09:36:25 +00001616*/
njn43c799e2003-04-08 00:08:52 +00001617extern UInt SK_(update_extra) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001618
njn810086f2002-11-14 12:42:47 +00001619/* Return value indicates recognition. If recognised, must set skind using
1620 VG_(set_supp_kind)(). */
1621extern Bool SK_(recognised_suppression) ( Char* name, Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001622
njn810086f2002-11-14 12:42:47 +00001623/* Read any extra info for this suppression kind. Most likely for filling
1624 in the `extra' and `string' parts (with VG_(set_supp_{extra,string})())
1625 of a suppression if necessary. Should return False if a syntax error
1626 occurred, True otherwise. */
1627extern Bool SK_(read_extra_suppression_info) ( Int fd, Char* buf, Int nBuf,
1628 Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001629
1630/* This should just check the kinds match and maybe some stuff in the
njn810086f2002-11-14 12:42:47 +00001631 `string' and `extra' field if appropriate (using VG_(get_supp_*)() to
1632 get the relevant suppression parts). */
njn43c799e2003-04-08 00:08:52 +00001633extern Bool SK_(error_matches_suppression) ( Error* err, Supp* su );
1634
1635/* This should return the suppression name, for --gen-suppressions, or NULL
1636 if that error type cannot be suppressed. This is the inverse of
1637 SK_(recognised_suppression)(). */
1638extern Char* SK_(get_error_name) ( Error* err );
1639
1640/* This should print any extra info for the error, for --gen-suppressions,
1641 including the newline. This is the inverse of
1642 SK_(read_extra_suppression_info)(). */
1643extern void SK_(print_extra_suppression_info) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001644
1645
1646/* ------------------------------------------------------------------ */
1647/* VG_(needs).basic_block_discards */
1648
njnd5bb0a52002-09-27 10:24:48 +00001649/* Should discard any information that pertains to specific basic blocks
1650 or instructions within the address range given. */
njn25e49d8e72002-09-23 09:36:25 +00001651extern void SK_(discard_basic_block_info) ( Addr a, UInt size );
1652
1653
1654/* ------------------------------------------------------------------ */
1655/* VG_(needs).shadow_regs */
1656
1657/* Valid values for general registers and EFLAGS register, for initialising
1658 and updating registers when written in certain places in core. */
1659extern void SK_(written_shadow_regs_values) ( UInt* gen_reg, UInt* eflags );
1660
1661
1662/* ------------------------------------------------------------------ */
1663/* VG_(needs).command_line_options */
1664
njnd5bb0a52002-09-27 10:24:48 +00001665/* Return True if option was recognised. Presumably sets some state to
1666 record the option as well. */
1667extern Bool SK_(process_cmd_line_option) ( Char* argv );
njn25e49d8e72002-09-23 09:36:25 +00001668
1669/* Print out command line usage for skin options */
1670extern Char* SK_(usage) ( void );
1671
1672
1673/* ------------------------------------------------------------------ */
1674/* VG_(needs).client_requests */
1675
sewardj34042512002-10-22 04:14:35 +00001676extern Bool SK_(handle_client_request) ( ThreadState* tst, UInt* arg_block, UInt *ret );
njn25e49d8e72002-09-23 09:36:25 +00001677
1678
1679/* ------------------------------------------------------------------ */
1680/* VG_(needs).extends_UCode */
1681
njn4ba5a792002-09-30 10:23:54 +00001682/* Useful to use in VG_(get_Xreg_usage)() */
njn810086f2002-11-14 12:42:47 +00001683#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
njn25e49d8e72002-09-23 09:36:25 +00001684 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00001685 { regs[n] = mycat(u->val,ono); \
1686 isWrites[n] = False; \
njn25e49d8e72002-09-23 09:36:25 +00001687 n++; \
1688 } \
1689 }
njn810086f2002-11-14 12:42:47 +00001690#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
njnd5bb0a52002-09-27 10:24:48 +00001691 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00001692 { regs[n] = mycat(u->val,ono); \
1693 isWrites[n] = True; \
njnd5bb0a52002-09-27 10:24:48 +00001694 n++; \
1695 } \
njn25e49d8e72002-09-23 09:36:25 +00001696 }
1697
njn4ba5a792002-09-30 10:23:54 +00001698/* 'X' prefix indicates eXtended UCode. */
njn810086f2002-11-14 12:42:47 +00001699extern Int SK_(get_Xreg_usage) ( UInstr* u, Tag tag, Int* regs,
1700 Bool* isWrites );
njn4ba5a792002-09-30 10:23:54 +00001701extern void SK_(emit_XUInstr) ( UInstr* u, RRegSet regs_live_before );
1702extern Bool SK_(sane_XUInstr) ( Bool beforeRA, Bool beforeLiveness,
njn25e49d8e72002-09-23 09:36:25 +00001703 UInstr* u );
njn4ba5a792002-09-30 10:23:54 +00001704extern Char* SK_(name_XUOpcode) ( Opcode opc );
1705extern void SK_(pp_XUInstr) ( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +00001706
1707
1708/* ------------------------------------------------------------------ */
1709/* VG_(needs).syscall_wrapper */
1710
1711/* If either of the pre_ functions malloc() something to return, the
1712 * corresponding post_ function had better free() it!
1713 */
1714extern void* SK_( pre_syscall) ( ThreadId tid, UInt syscallno,
1715 Bool is_blocking );
1716extern void SK_(post_syscall) ( ThreadId tid, UInt syscallno,
1717 void* pre_result, Int res,
1718 Bool is_blocking );
1719
njnd5bb0a52002-09-27 10:24:48 +00001720
njn25e49d8e72002-09-23 09:36:25 +00001721/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +00001722/* VG_(needs).sizeof_shadow_chunk (if > 0) */
njn25e49d8e72002-09-23 09:36:25 +00001723
njn810086f2002-11-14 12:42:47 +00001724/* Must fill in the `extra' part, using VG_(set_sc_extra)(). */
njn25e49d8e72002-09-23 09:36:25 +00001725extern void SK_(complete_shadow_chunk) ( ShadowChunk* sc, ThreadState* tst );
1726
1727
1728/* ------------------------------------------------------------------ */
1729/* VG_(needs).alternative_free */
1730
njn810086f2002-11-14 12:42:47 +00001731/* If this need is set, when a dynamic block would normally be free'd, this
1732 is called instead. The block is contained inside the ShadowChunk; use
1733 the VG_(get_sc_*)() functions to access it. */
njn25e49d8e72002-09-23 09:36:25 +00001734extern void SK_(alt_free) ( ShadowChunk* sc, ThreadState* tst );
1735
njnd5bb0a52002-09-27 10:24:48 +00001736
njn25e49d8e72002-09-23 09:36:25 +00001737/* ---------------------------------------------------------------------
1738 VG_(needs).sanity_checks */
1739
njnd5bb0a52002-09-27 10:24:48 +00001740/* Can be useful for ensuring a skin's correctness. SK_(cheap_sanity_check)
1741 is called very frequently; SK_(expensive_sanity_check) is called less
1742 frequently and can be more involved. */
njn25e49d8e72002-09-23 09:36:25 +00001743extern Bool SK_(cheap_sanity_check) ( void );
1744extern Bool SK_(expensive_sanity_check) ( void );
1745
1746
1747#endif /* NDEF __VG_SKIN_H */
1748
1749/*--------------------------------------------------------------------*/
1750/*--- end vg_skin.h ---*/
1751/*--------------------------------------------------------------------*/
1752