blob: 986b8f321c81c52a8da5a327f89fc32a2290e631 [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
135/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
136extern Int VG_(clo_verbosity);
137
138/* Profile? */
139extern Bool VG_(clo_profile);
140
njn25e49d8e72002-09-23 09:36:25 +0000141/* Call this if a recognised option was bad for some reason.
142 Note: don't use it just because an option was unrecognised -- return 'False'
143 from SKN_(process_cmd_line_option) to indicate that. */
144extern void VG_(bad_option) ( Char* opt );
145
146/* Client args */
147extern Int VG_(client_argc);
148extern Char** VG_(client_argv);
149
njnd5bb0a52002-09-27 10:24:48 +0000150/* Client environment. Can be inspected with VG_(getenv)() */
njn25e49d8e72002-09-23 09:36:25 +0000151extern Char** VG_(client_envp);
152
153
154/*====================================================================*/
155/*=== Printing messages for the user ===*/
156/*====================================================================*/
157
158/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
159 Should be used for all user output. */
160
161typedef
162 enum { Vg_UserMsg, /* '?' == '=' */
163 Vg_DebugMsg, /* '?' == '-' */
164 Vg_DebugExtraMsg /* '?' == '+' */
165 }
166 VgMsgKind;
167
168/* Functions for building a message from multiple parts. */
169extern void VG_(start_msg) ( VgMsgKind kind );
170extern void VG_(add_to_msg) ( Char* format, ... );
171/* Ends and prints the message. Appends a newline. */
172extern void VG_(end_msg) ( void );
173
njnd5bb0a52002-09-27 10:24:48 +0000174/* Send a single-part message. Appends a newline. */
njn25e49d8e72002-09-23 09:36:25 +0000175extern void VG_(message) ( VgMsgKind kind, Char* format, ... );
176
177
178/*====================================================================*/
179/*=== Profiling ===*/
180/*====================================================================*/
181
182/* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */
183#define VGP_CORE_LIST \
184 /* These ones depend on the core */ \
185 VGP_PAIR(VgpUnc, "unclassified"), \
186 VGP_PAIR(VgpRun, "running"), \
187 VGP_PAIR(VgpSched, "scheduler"), \
188 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
189 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
njn25e49d8e72002-09-23 09:36:25 +0000190 VGP_PAIR(VgpTranslate, "translate-main"), \
191 VGP_PAIR(VgpToUCode, "to-ucode"), \
192 VGP_PAIR(VgpFromUcode, "from-ucode"), \
193 VGP_PAIR(VgpImprove, "improve"), \
njn9b007f62003-04-07 14:40:25 +0000194 VGP_PAIR(VgpESPUpdate, "ESP-update"), \
njn25e49d8e72002-09-23 09:36:25 +0000195 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
196 VGP_PAIR(VgpLiveness, "liveness-analysis"), \
197 VGP_PAIR(VgpDoLRU, "do-lru"), \
198 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
199 VGP_PAIR(VgpInitMem, "init-memory"), \
200 VGP_PAIR(VgpExeContext, "exe-context"), \
201 VGP_PAIR(VgpReadSyms, "read-syms"), \
202 VGP_PAIR(VgpSearchSyms, "search-syms"), \
203 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
204 VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
205 VGP_PAIR(VgpDemangle, "demangle"), \
njn37cea302002-09-30 11:24:00 +0000206 VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
207 VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000208 /* These ones depend on the skin */ \
209 VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
210 VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
211 VGP_PAIR(VgpInstrument, "instrument"), \
212 VGP_PAIR(VgpSkinSysWrap, "skin-syscall-wrapper"), \
njn37cea302002-09-30 11:24:00 +0000213 VGP_PAIR(VgpSkinCheapSanity, "skin-cheap-sanity"), \
214 VGP_PAIR(VgpSkinExpensiveSanity, "skin-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000215 VGP_PAIR(VgpFini, "fini")
216
217#define VGP_PAIR(n,name) n
218typedef enum { VGP_CORE_LIST } VgpCoreCC;
219#undef VGP_PAIR
220
221/* When registering skin profiling events, ensure that the 'n' value is in
222 * the range (VgpFini+1..) */
223extern void VGP_(register_profile_event) ( Int n, Char* name );
224
225extern void VGP_(pushcc) ( UInt cc );
226extern void VGP_(popcc) ( UInt cc );
227
228/* Define them only if they haven't already been defined by vg_profile.c */
229#ifndef VGP_PUSHCC
230# define VGP_PUSHCC(x)
231#endif
232#ifndef VGP_POPCC
233# define VGP_POPCC(x)
234#endif
235
236
237/*====================================================================*/
238/*=== Useful stuff to call from generated code ===*/
239/*====================================================================*/
240
241/* ------------------------------------------------------------------ */
242/* General stuff */
243
njn41557122002-10-14 09:25:37 +0000244/* 64-bit counter for the number of basic blocks done. */
245extern ULong VG_(bbs_done);
246
njn25e49d8e72002-09-23 09:36:25 +0000247/* Get the simulated %esp */
248extern Addr VG_(get_stack_pointer) ( void );
249
njnd5bb0a52002-09-27 10:24:48 +0000250/* Detect if an address is within Valgrind's stack or Valgrind's
251 m_state_static; useful for memory leak detectors to tell if a block
252 is used by Valgrind (and thus can be ignored). */
njn25e49d8e72002-09-23 09:36:25 +0000253extern Bool VG_(within_stack)(Addr a);
njn25e49d8e72002-09-23 09:36:25 +0000254extern Bool VG_(within_m_state_static)(Addr a);
255
256/* Check if an address is 4-byte aligned */
257#define IS_ALIGNED4_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 3))
njn9b007f62003-04-07 14:40:25 +0000258#define IS_ALIGNED8_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 7))
njn25e49d8e72002-09-23 09:36:25 +0000259
260
261/* ------------------------------------------------------------------ */
262/* Thread-related stuff */
263
264/* Special magic value for an invalid ThreadId. It corresponds to
265 LinuxThreads using zero as the initial value for
266 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
267#define VG_INVALID_THREADID ((ThreadId)(0))
268
269/* ThreadIds are simply indices into the vg_threads[] array. */
270typedef
271 UInt
272 ThreadId;
273
njnd5bb0a52002-09-27 10:24:48 +0000274/* struct _ThreadState defined elsewhere; ThreadState is abstract as its
275 definition is not important for skins. */
njn25e49d8e72002-09-23 09:36:25 +0000276typedef
277 struct _ThreadState
278 ThreadState;
279
sewardj7ab2aca2002-10-20 19:40:32 +0000280extern ThreadId VG_(get_current_tid) ( void );
sewardjb52a1b02002-10-23 21:38:22 +0000281extern ThreadId VG_(get_current_or_recent_tid) ( void );
sewardj7ab2aca2002-10-20 19:40:32 +0000282extern ThreadId VG_(get_tid_from_ThreadState) ( ThreadState* );
njn25e49d8e72002-09-23 09:36:25 +0000283extern ThreadState* VG_(get_ThreadState) ( ThreadId tid );
284
285
286/*====================================================================*/
287/*=== Valgrind's version of libc ===*/
288/*====================================================================*/
289
290/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
291 are its own versions of C library functions, but with VG_ prefixes. Note
292 that the types of some are slightly different to the real ones. Some
njnf4ce3d32003-02-10 10:17:26 +0000293 additional useful functions are provided too; descriptions of how they
294 work are given below. */
njn25e49d8e72002-09-23 09:36:25 +0000295
296#if !defined(NULL)
297# define NULL ((void*)0)
298#endif
299
300
301/* ------------------------------------------------------------------ */
302/* stdio.h
303 *
304 * Note that they all output to the file descriptor given by the
305 * --logfile-fd=N argument, which defaults to 2 (stderr). Hence no
306 * need for VG_(fprintf)().
njn25e49d8e72002-09-23 09:36:25 +0000307 */
sewardj78e3cd92002-10-22 04:45:48 +0000308extern UInt VG_(printf) ( const char *format, ... );
njn25e49d8e72002-09-23 09:36:25 +0000309/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
sewardj78e3cd92002-10-22 04:45:48 +0000310extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
311extern UInt VG_(vprintf) ( void(*send)(Char),
njn25e49d8e72002-09-23 09:36:25 +0000312 const Char *format, va_list vargs );
313
njn41557122002-10-14 09:25:37 +0000314extern Int VG_(rename) ( Char* old_name, Char* new_name );
315
njn25e49d8e72002-09-23 09:36:25 +0000316/* ------------------------------------------------------------------ */
317/* stdlib.h */
318
319extern void* VG_(malloc) ( Int nbytes );
njnd5bb0a52002-09-27 10:24:48 +0000320extern void VG_(free) ( void* p );
321extern void* VG_(calloc) ( Int n, Int nbytes );
322extern void* VG_(realloc) ( void* p, Int size );
323extern void* VG_(malloc_aligned) ( Int align_bytes, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000324
325extern void VG_(print_malloc_stats) ( void );
326
327
328extern void VG_(exit)( Int status )
329 __attribute__ ((__noreturn__));
njne427a662002-10-02 11:08:25 +0000330/* Prints a panic message (a constant string), appends newline and bug
331 reporting info, aborts. */
332__attribute__ ((__noreturn__))
333extern void VG_(skin_panic) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000334
njnd5bb0a52002-09-27 10:24:48 +0000335/* Looks up VG_(client_envp) */
njn25e49d8e72002-09-23 09:36:25 +0000336extern Char* VG_(getenv) ( Char* name );
337
338/* Crude stand-in for the glibc system() call. */
339extern Int VG_(system) ( Char* cmd );
340
njnd5bb0a52002-09-27 10:24:48 +0000341extern Long VG_(atoll) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000342
343/* Like atoll(), but converts a number of base 2..36 */
344extern Long VG_(atoll36) ( UInt base, Char* str );
345
346
347/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000348/* ctype.h */
njn25e49d8e72002-09-23 09:36:25 +0000349extern Bool VG_(isspace) ( Char c );
350extern Bool VG_(isdigit) ( Char c );
351extern Char VG_(toupper) ( Char c );
352
353
354/* ------------------------------------------------------------------ */
355/* string.h */
356extern Int VG_(strlen) ( const Char* str );
357extern Char* VG_(strcat) ( Char* dest, const Char* src );
358extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
359extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
360extern Char* VG_(strcpy) ( Char* dest, const Char* src );
361extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
362extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
363extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
364extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
365extern Char* VG_(strchr) ( const Char* s, Char c );
366extern Char* VG_(strdup) ( const Char* s);
sewardj7ab2aca2002-10-20 19:40:32 +0000367extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
368extern void* VG_(memset) ( void *s, Int c, Int sz );
njn6d68e792003-02-24 10:49:08 +0000369extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
njn25e49d8e72002-09-23 09:36:25 +0000370
njnd5bb0a52002-09-27 10:24:48 +0000371/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
njn25e49d8e72002-09-23 09:36:25 +0000372extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
njn25e49d8e72002-09-23 09:36:25 +0000373extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
374
njnd5bb0a52002-09-27 10:24:48 +0000375/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
376 last character. */
njn25e49d8e72002-09-23 09:36:25 +0000377extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
378
379/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
380 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
njn4ba5a792002-09-30 10:23:54 +0000381extern Bool VG_(string_match) ( Char* pat, Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000382
383
384/* ------------------------------------------------------------------ */
385/* math.h */
njnd5bb0a52002-09-27 10:24:48 +0000386/* Returns the base-2 logarithm of x. */
njn25e49d8e72002-09-23 09:36:25 +0000387extern Int VG_(log2) ( Int x );
388
389
390/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000391/* unistd.h, fcntl.h, sys/stat.h */
sewardj4cf05692002-10-27 20:28:29 +0000392extern Int VG_(getpid) ( void );
393extern Int VG_(getppid) ( void );
njnd5bb0a52002-09-27 10:24:48 +0000394
njn4aca2d22002-10-04 10:29:38 +0000395extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
396extern Int VG_(read) ( Int fd, void* buf, Int count);
397extern Int VG_(write) ( Int fd, void* buf, Int count);
398extern void VG_(close) ( Int fd );
njnd5bb0a52002-09-27 10:24:48 +0000399
njn41557122002-10-14 09:25:37 +0000400/* Nb: VG_(rename)() declared in stdio.h section above */
njn4aca2d22002-10-04 10:29:38 +0000401extern Int VG_(unlink) ( Char* file_name );
402extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
njn25e49d8e72002-09-23 09:36:25 +0000403
404
405/* ------------------------------------------------------------------ */
406/* assert.h */
407/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
408#define VG__STRING(__str) #__str
409
njne427a662002-10-02 11:08:25 +0000410#define sk_assert(expr) \
njn25e49d8e72002-09-23 09:36:25 +0000411 ((void) ((expr) ? 0 : \
njne427a662002-10-02 11:08:25 +0000412 (VG_(skin_assert_fail) (VG__STRING(expr), \
413 __FILE__, __LINE__, \
414 __PRETTY_FUNCTION__), 0)))
njn25e49d8e72002-09-23 09:36:25 +0000415
njne427a662002-10-02 11:08:25 +0000416__attribute__ ((__noreturn__))
417extern void VG_(skin_assert_fail) ( Char* expr, Char* file,
418 Int line, Char* fn );
njn25e49d8e72002-09-23 09:36:25 +0000419
420
421/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000422/* system/mman.h */
njn25e49d8e72002-09-23 09:36:25 +0000423extern void* VG_(mmap)( void* start, UInt length,
424 UInt prot, UInt flags, UInt fd, UInt offset );
425extern Int VG_(munmap)( void* start, Int length );
426
427/* Get memory by anonymous mmap. */
428extern void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who );
429
430
431/* ------------------------------------------------------------------ */
432/* signal.h.
433
434 Note that these use the vk_ (kernel) structure
435 definitions, which are different in places from those that glibc
436 defines -- hence the 'k' prefix. Since we're operating right at the
437 kernel interface, glibc's view of the world is entirely irrelevant. */
438
439/* --- Signal set ops --- */
njnd5bb0a52002-09-27 10:24:48 +0000440extern Int VG_(ksigfillset) ( vki_ksigset_t* set );
441extern Int VG_(ksigemptyset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000442
njnd5bb0a52002-09-27 10:24:48 +0000443extern Bool VG_(kisfullsigset) ( vki_ksigset_t* set );
444extern Bool VG_(kisemptysigset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000445
njnd5bb0a52002-09-27 10:24:48 +0000446extern Int VG_(ksigaddset) ( vki_ksigset_t* set, Int signum );
447extern Int VG_(ksigdelset) ( vki_ksigset_t* set, Int signum );
njn25e49d8e72002-09-23 09:36:25 +0000448extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
449
njnd5bb0a52002-09-27 10:24:48 +0000450extern void VG_(ksigaddset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
451extern void VG_(ksigdelset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
njn25e49d8e72002-09-23 09:36:25 +0000452
453/* --- Mess with the kernel's sig state --- */
njnd5bb0a52002-09-27 10:24:48 +0000454extern Int VG_(ksigprocmask) ( Int how, const vki_ksigset_t* set,
njn25e49d8e72002-09-23 09:36:25 +0000455 vki_ksigset_t* oldset );
njnd5bb0a52002-09-27 10:24:48 +0000456extern Int VG_(ksigaction) ( Int signum,
457 const vki_ksigaction* act,
458 vki_ksigaction* oldact );
njn25e49d8e72002-09-23 09:36:25 +0000459
njnd5bb0a52002-09-27 10:24:48 +0000460extern Int VG_(ksignal) ( Int signum, void (*sighandler)(Int) );
461extern Int VG_(ksigaltstack) ( const vki_kstack_t* ss, vki_kstack_t* oss );
njn25e49d8e72002-09-23 09:36:25 +0000462
sewardjdcaf3122002-09-30 23:12:33 +0000463extern Int VG_(kkill) ( Int pid, Int signo );
464extern Int VG_(ksigpending) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000465
466
467/*====================================================================*/
468/*=== UCode definition ===*/
469/*====================================================================*/
470
sewardje1042472002-09-30 12:33:11 +0000471/* Tags which describe what operands are. Must fit into 4 bits, which
472 they clearly do. */
njn25e49d8e72002-09-23 09:36:25 +0000473typedef
sewardje1042472002-09-30 12:33:11 +0000474enum { TempReg =0, /* virtual temp-reg */
475 ArchReg =1, /* simulated integer reg */
476 ArchRegS =2, /* simulated segment reg */
477 RealReg =3, /* real machine's real reg */
478 SpillNo =4, /* spill slot location */
479 Literal =5, /* literal; .lit32 field has actual value */
480 Lit16 =6, /* literal; .val[123] field has actual value */
481 NoValue =7 /* operand not in use */
482 }
483 Tag;
njn25e49d8e72002-09-23 09:36:25 +0000484
njnd5bb0a52002-09-27 10:24:48 +0000485/* Invalid register numbers (can't be negative) */
njn25e49d8e72002-09-23 09:36:25 +0000486#define INVALID_TEMPREG 999999999
487#define INVALID_REALREG 999999999
488
489/* Microinstruction opcodes. */
490typedef
491 enum {
njnd5bb0a52002-09-27 10:24:48 +0000492 NOP, /* Null op */
njn25e49d8e72002-09-23 09:36:25 +0000493
sewardj7a5ebcf2002-11-13 22:42:13 +0000494 LOCK, /* Indicate the existance of a LOCK prefix (functionally NOP) */
495
njnd5bb0a52002-09-27 10:24:48 +0000496 /* Moving values around */
497 GET, PUT, /* simulated register <--> TempReg */
498 GETF, PUTF, /* simulated %eflags <--> TempReg */
499 LOAD, STORE, /* memory <--> TempReg */
500 MOV, /* TempReg <--> TempReg */
501 CMOV, /* Used for cmpxchg and cmov */
njn25e49d8e72002-09-23 09:36:25 +0000502
njnd5bb0a52002-09-27 10:24:48 +0000503 /* Arithmetic/logical ops */
504 ADD, ADC, SUB, SBB, /* Add/subtract (w/wo carry) */
505 AND, OR, XOR, NOT, /* Boolean ops */
506 SHL, SHR, SAR, ROL, ROR, RCL, RCR, /* Shift/rotate (w/wo carry) */
507 NEG, /* Negate */
508 INC, DEC, /* Increment/decrement */
509 BSWAP, /* Big-endian <--> little-endian */
510 CC2VAL, /* Condition code --> 0 or 1 */
511 WIDEN, /* Signed or unsigned widening */
njn25e49d8e72002-09-23 09:36:25 +0000512
njnd5bb0a52002-09-27 10:24:48 +0000513 /* Conditional or unconditional jump */
514 JMP,
515
516 /* FPU ops */
517 FPU, /* Doesn't touch memory */
518 FPU_R, FPU_W, /* Reads/writes memory */
519
sewardj3d7c9c82003-03-26 21:08:13 +0000520 /* ------------ MMX ops ------------ */
521
522 /* 1 byte, no memrefs, no iregdefs, copy exactly to the
523 output. Held in val1[7:0]. */
524 MMX1,
525
526 /* 2 bytes, no memrefs, no iregdefs, copy exactly to the
527 output. Held in val1[15:0]. */
528 MMX2,
529
530 /* 3 bytes, no memrefs, no iregdefs, copy exactly to the
531 output. Held in val1[15:0] and val2[7:0]. */
532 MMX3,
533
534 /* 2 bytes, reads/writes mem. Insns of the form
535 bbbbbbbb:mod mmxreg r/m.
536 Held in val1[15:0], and mod and rm are to be replaced
537 at codegen time by a reference to the Temp/RealReg holding
538 the address. Arg2 holds this Temp/Real Reg.
539 Transfer is always at size 8.
540 */
541 MMX2_MemRd,
542 MMX2_MemWr,
543
544 /* 2 bytes, reads/writes an integer register. Insns of the form
545 bbbbbbbb:11 mmxreg ireg.
546 Held in val1[15:0], and ireg is to be replaced
547 at codegen time by a reference to the relevant RealReg.
548 Transfer is always at size 4. Arg2 holds this Temp/Real Reg.
549 */
550 MMX2_RegRd,
551 MMX2_RegWr,
552
553 /* ------------------------ */
554
njnd5bb0a52002-09-27 10:24:48 +0000555 /* Not strictly needed, but improve address calculation translations. */
njn25e49d8e72002-09-23 09:36:25 +0000556 LEA1, /* reg2 := const + reg1 */
557 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
558
njnd5bb0a52002-09-27 10:24:48 +0000559 /* Hack for x86 REP insns. Jump to literal if TempReg/RealReg is zero. */
560 JIFZ,
njn25e49d8e72002-09-23 09:36:25 +0000561
njnd5bb0a52002-09-27 10:24:48 +0000562 /* Advance the simulated %eip by some small (< 128) number. */
563 INCEIP,
njn25e49d8e72002-09-23 09:36:25 +0000564
sewardje1042472002-09-30 12:33:11 +0000565 /* Dealing with segment registers */
566 GETSEG, PUTSEG, /* simulated segment register <--> TempReg */
567 USESEG, /* (LDT/GDT index, virtual addr) --> linear addr */
568
njnd5bb0a52002-09-27 10:24:48 +0000569 /* Not for translating x86 calls -- only to call helpers */
570 CALLM_S, CALLM_E, /* Mark start/end of CALLM push/pop sequence */
571 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers */
572 CALLM, /* Call assembly-code helper */
573
574 /* Not for translating x86 calls -- only to call C helper functions of
575 up to three arguments (or two if the functions has a return value).
576 Arguments and return value must be word-sized. More arguments can
577 be faked with global variables (eg. use VG_(set_global_var)()).
578
579 Seven possibilities: 'arg[123]' show where args go, 'ret' shows
580 where return value goes (if present).
njn25e49d8e72002-09-23 09:36:25 +0000581
582 CCALL(-, -, - ) void f(void)
583 CCALL(arg1, -, - ) void f(UInt arg1)
584 CCALL(arg1, arg2, - ) void f(UInt arg1, UInt arg2)
585 CCALL(arg1, arg2, arg3) void f(UInt arg1, UInt arg2, UInt arg3)
586 CCALL(-, -, ret ) UInt f(UInt)
587 CCALL(arg1, -, ret ) UInt f(UInt arg1)
njnd5bb0a52002-09-27 10:24:48 +0000588 CCALL(arg1, arg2, ret ) UInt f(UInt arg1, UInt arg2) */
njn25e49d8e72002-09-23 09:36:25 +0000589 CCALL,
590
njnd5bb0a52002-09-27 10:24:48 +0000591 /* This opcode makes it easy for skins that extend UCode to do this to
592 avoid opcode overlap:
njn25e49d8e72002-09-23 09:36:25 +0000593
njnd5bb0a52002-09-27 10:24:48 +0000594 enum { EU_OP1 = DUMMY_FINAL_UOPCODE + 1, ... }
njn25e49d8e72002-09-23 09:36:25 +0000595
596 WARNING: Do not add new opcodes after this one! They can be added
597 before, though. */
598 DUMMY_FINAL_UOPCODE
599 }
600 Opcode;
601
602
njnd5bb0a52002-09-27 10:24:48 +0000603/* Condition codes, using the Intel encoding. CondAlways is an extra. */
njn25e49d8e72002-09-23 09:36:25 +0000604typedef
605 enum {
606 CondO = 0, /* overflow */
607 CondNO = 1, /* no overflow */
608 CondB = 2, /* below */
609 CondNB = 3, /* not below */
610 CondZ = 4, /* zero */
611 CondNZ = 5, /* not zero */
612 CondBE = 6, /* below or equal */
613 CondNBE = 7, /* not below or equal */
614 CondS = 8, /* negative */
sewardje1042472002-09-30 12:33:11 +0000615 CondNS = 9, /* not negative */
njn25e49d8e72002-09-23 09:36:25 +0000616 CondP = 10, /* parity even */
617 CondNP = 11, /* not parity even */
618 CondL = 12, /* jump less */
619 CondNL = 13, /* not less */
620 CondLE = 14, /* less or equal */
621 CondNLE = 15, /* not less or equal */
622 CondAlways = 16 /* Jump always */
623 }
624 Condcode;
625
626
627/* Descriptions of additional properties of *unconditional* jumps. */
628typedef
629 enum {
630 JmpBoring=0, /* boring unconditional jump */
631 JmpCall=1, /* jump due to an x86 call insn */
632 JmpRet=2, /* jump due to an x86 ret insn */
633 JmpSyscall=3, /* do a system call, then jump */
634 JmpClientReq=4 /* do a client request, then jump */
635 }
636 JmpKind;
637
638
639/* Flags. User-level code can only read/write O(verflow), S(ign),
640 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
641 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
642 thusly:
643 76543210
644 DOSZACP
645 and bit 7 must always be zero since it is unused.
sewardj2370f3b2002-11-30 15:01:01 +0000646
647 Note: these Flag? values are **not** the positions in the actual
648 %eflags register. */
649
njn25e49d8e72002-09-23 09:36:25 +0000650typedef UChar FlagSet;
651
652#define FlagD (1<<6)
653#define FlagO (1<<5)
654#define FlagS (1<<4)
655#define FlagZ (1<<3)
656#define FlagA (1<<2)
657#define FlagC (1<<1)
658#define FlagP (1<<0)
659
660#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
661#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
662#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
663#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
664#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
665#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
666#define FlagsZCP ( FlagZ | FlagC | FlagP)
667#define FlagsOC (FlagO | FlagC )
668#define FlagsAC ( FlagA | FlagC )
669
670#define FlagsALL (FlagsOSZACP | FlagD)
671#define FlagsEmpty (FlagSet)0
672
673
sewardj2370f3b2002-11-30 15:01:01 +0000674/* flag positions in eflags */
675#define EFlagC (1 << 0) /* carry */
676#define EFlagP (1 << 2) /* parity */
sewardjfa492d42002-12-08 18:20:01 +0000677#define EFlagA (1 << 4) /* aux carry */
sewardj2370f3b2002-11-30 15:01:01 +0000678#define EFlagZ (1 << 6) /* zero */
679#define EFlagS (1 << 7) /* sign */
sewardjfa492d42002-12-08 18:20:01 +0000680#define EFlagD (1 << 10) /* direction */
sewardj2370f3b2002-11-30 15:01:01 +0000681#define EFlagO (1 << 11) /* overflow */
682
njn25e49d8e72002-09-23 09:36:25 +0000683/* Liveness of general purpose registers, useful for code generation.
684 Reg rank order 0..N-1 corresponds to bits 0..N-1, ie. first
685 reg's liveness in bit 0, last reg's in bit N-1. Note that
686 these rankings don't match the Intel register ordering. */
687typedef UInt RRegSet;
688
689#define ALL_RREGS_DEAD 0 /* 0000...00b */
njne7c258c2002-10-03 08:57:01 +0000690#define ALL_RREGS_LIVE ((1 << VG_MAX_REALREGS)-1) /* 0011...11b */
njn25e49d8e72002-09-23 09:36:25 +0000691#define UNIT_RREGSET(rank) (1 << (rank))
692
693#define IS_RREG_LIVE(rank,rregs_live) (rregs_live & UNIT_RREGSET(rank))
694#define SET_RREG_LIVENESS(rank,rregs_live,b) \
695 do { RRegSet unit = UNIT_RREGSET(rank); \
696 if (b) rregs_live |= unit; \
697 else rregs_live &= ~unit; \
698 } while(0)
699
700
701/* A Micro (u)-instruction. */
702typedef
703 struct {
704 /* word 1 */
705 UInt lit32; /* 32-bit literal */
706
707 /* word 2 */
708 UShort val1; /* first operand */
709 UShort val2; /* second operand */
710
711 /* word 3 */
712 UShort val3; /* third operand */
713 UChar opcode; /* opcode */
714 UChar size; /* data transfer size */
715
716 /* word 4 */
717 FlagSet flags_r; /* :: FlagSet */
718 FlagSet flags_w; /* :: FlagSet */
719 UChar tag1:4; /* first operand tag */
720 UChar tag2:4; /* second operand tag */
721 UChar tag3:4; /* third operand tag */
722 UChar extra4b:4; /* Spare field, used by WIDEN for src
723 -size, and by LEA2 for scale (1,2,4 or 8),
724 and by JMPs for original x86 instr size */
725
726 /* word 5 */
727 UChar cond; /* condition, for jumps */
728 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
729 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
730
731 /* Additional properties for UInstrs that call C functions:
732 - CCALL
733 - PUT (when %ESP is the target)
734 - possibly skin-specific UInstrs
735 */
736 UChar argc:2; /* Number of args, max 3 */
737 UChar regparms_n:2; /* Number of args passed in registers */
738 Bool has_ret_val:1; /* Function has return value? */
739
740 /* RealReg liveness; only sensical after reg alloc and liveness
741 analysis done. This info is a little bit arch-specific --
742 VG_MAX_REALREGS can vary on different architectures. Note that
743 to use this information requires converting between register ranks
njn4ba5a792002-09-30 10:23:54 +0000744 and the Intel register numbers, using VG_(realreg_to_rank)()
745 and/or VG_(rank_to_realreg)() */
njn25e49d8e72002-09-23 09:36:25 +0000746 RRegSet regs_live_after:VG_MAX_REALREGS;
747 }
748 UInstr;
749
750
njn25e49d8e72002-09-23 09:36:25 +0000751typedef
njn810086f2002-11-14 12:42:47 +0000752 struct _UCodeBlock
njn25e49d8e72002-09-23 09:36:25 +0000753 UCodeBlock;
754
njn810086f2002-11-14 12:42:47 +0000755extern Int VG_(get_num_instrs) (UCodeBlock* cb);
756extern Int VG_(get_num_temps) (UCodeBlock* cb);
njn25e49d8e72002-09-23 09:36:25 +0000757
njn810086f2002-11-14 12:42:47 +0000758extern UInstr* VG_(get_instr) (UCodeBlock* cb, Int i);
759extern UInstr* VG_(get_last_instr) (UCodeBlock* cb);
760
njn211b6ad2003-02-03 12:33:31 +0000761
njn25e49d8e72002-09-23 09:36:25 +0000762/*====================================================================*/
763/*=== Instrumenting UCode ===*/
764/*====================================================================*/
765
njnf4ce3d32003-02-10 10:17:26 +0000766/* Maximum number of registers read or written by a single UInstruction. */
767#define VG_MAX_REGS_USED 3
njn25e49d8e72002-09-23 09:36:25 +0000768
njnf4ce3d32003-02-10 10:17:26 +0000769/* Find what this instruction does to its regs, useful for
770 analysis/optimisation passes. `tag' indicates whether we're considering
771 TempRegs (pre-reg-alloc) or RealRegs (post-reg-alloc). `regs' is filled
772 with the affected register numbers, `isWrites' parallels it and indicates
773 if the reg is read or written. If a reg is read and written, it will
774 appear twice in `regs'. `regs' and `isWrites' must be able to fit
775 VG_MAX_REGS_USED elements. */
njn810086f2002-11-14 12:42:47 +0000776extern Int VG_(get_reg_usage) ( UInstr* u, Tag tag, Int* regs, Bool* isWrites );
njn25e49d8e72002-09-23 09:36:25 +0000777
778
njnd5bb0a52002-09-27 10:24:48 +0000779/* Used to register helper functions to be called from generated code. A
780 limited number of compact helpers can be registered; the code generated
781 to call them is slightly shorter -- so register the mostly frequently
782 called helpers as compact. */
njn25e49d8e72002-09-23 09:36:25 +0000783extern void VG_(register_compact_helper) ( Addr a );
784extern void VG_(register_noncompact_helper) ( Addr a );
785
786
787/* ------------------------------------------------------------------ */
788/* Virtual register allocation */
789
790/* Get a new virtual register */
njn4ba5a792002-09-30 10:23:54 +0000791extern Int VG_(get_new_temp) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000792
793/* Get a new virtual shadow register */
njn4ba5a792002-09-30 10:23:54 +0000794extern Int VG_(get_new_shadow) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000795
796/* Get a virtual register's corresponding virtual shadow register */
797#define SHADOW(tempreg) ((tempreg)+1)
798
799
800/* ------------------------------------------------------------------ */
801/* Low-level UInstr builders */
njn4ba5a792002-09-30 10:23:54 +0000802extern void VG_(new_NOP) ( UInstr* u );
803extern void VG_(new_UInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
804extern void VG_(new_UInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000805 Tag tag1, UInt val1 );
njn4ba5a792002-09-30 10:23:54 +0000806extern void VG_(new_UInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000807 Tag tag1, UInt val1,
808 Tag tag2, UInt val2 );
njn4ba5a792002-09-30 10:23:54 +0000809extern void VG_(new_UInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000810 Tag tag1, UInt val1,
811 Tag tag2, UInt val2,
812 Tag tag3, UInt val3 );
njn25e49d8e72002-09-23 09:36:25 +0000813
njn810086f2002-11-14 12:42:47 +0000814/* Set read/write/undefined flags. Undefined flags are treaten as written,
815 but it's worth keeping them logically distinct. */
816extern void VG_(set_flag_fields) ( UCodeBlock* cb, FlagSet fr, FlagSet fw,
817 FlagSet fu);
njn4ba5a792002-09-30 10:23:54 +0000818extern void VG_(set_lit_field) ( UCodeBlock* cb, UInt lit32 );
819extern void VG_(set_ccall_fields) ( UCodeBlock* cb, Addr fn, UChar argc,
820 UChar regparms_n, Bool has_ret_val );
njn810086f2002-11-14 12:42:47 +0000821extern void VG_(set_cond_field) ( UCodeBlock* cb, Condcode code );
njn25e49d8e72002-09-23 09:36:25 +0000822
njn4ba5a792002-09-30 10:23:54 +0000823extern void VG_(copy_UInstr) ( UCodeBlock* cb, UInstr* instr );
824
825extern Bool VG_(any_flag_use)( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +0000826
njnac6c1762002-10-04 14:34:15 +0000827/* Macro versions of the above; just shorter to type. */
828#define uInstr0 VG_(new_UInstr0)
829#define uInstr1 VG_(new_UInstr1)
830#define uInstr2 VG_(new_UInstr2)
831#define uInstr3 VG_(new_UInstr3)
832#define uLiteral VG_(set_lit_field)
833#define uCCall VG_(set_ccall_fields)
njn810086f2002-11-14 12:42:47 +0000834#define uCond VG_(set_cond_field)
835#define uFlagsRWU VG_(set_flag_fields)
njnac6c1762002-10-04 14:34:15 +0000836#define newTemp VG_(get_new_temp)
837#define newShadow VG_(get_new_shadow)
838
njn25e49d8e72002-09-23 09:36:25 +0000839/* Refer to `the last instruction stuffed in' (can be lvalue). */
840#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
841
842
843/* ------------------------------------------------------------------ */
844/* Higher-level UInstr sequence builders */
njn4ba5a792002-09-30 10:23:54 +0000845extern void VG_(call_helper_0_0) ( UCodeBlock* cb, Addr f);
846extern void VG_(call_helper_1_0) ( UCodeBlock* cb, Addr f, UInt arg1,
847 UInt regparms_n);
848extern void VG_(call_helper_2_0) ( UCodeBlock* cb, Addr f, UInt arg1, UInt arg2,
849 UInt regparms_n);
njn25e49d8e72002-09-23 09:36:25 +0000850
851/* One way around the 3-arg C function limit is to pass args via global
njn6fefa1b2003-02-24 10:32:51 +0000852 * variables... ugly, but it works. This one puts a literal in there. */
njn4ba5a792002-09-30 10:23:54 +0000853extern void VG_(set_global_var) ( UCodeBlock* cb, Addr globvar_ptr, UInt val);
njn25e49d8e72002-09-23 09:36:25 +0000854
njn6fefa1b2003-02-24 10:32:51 +0000855/* This one puts the contents of a TempReg in the global variable. */
856extern void VG_(set_global_var_tempreg) ( UCodeBlock* cb, Addr globvar_ptr,
857 UInt t_val);
858
njn25e49d8e72002-09-23 09:36:25 +0000859/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000860/* Allocating/freeing basic blocks of UCode */
njn810086f2002-11-14 12:42:47 +0000861extern UCodeBlock* VG_(setup_UCodeBlock) ( UCodeBlock* cb );
njn4ba5a792002-09-30 10:23:54 +0000862extern void VG_(free_UCodeBlock) ( UCodeBlock* cb );
njnd5bb0a52002-09-27 10:24:48 +0000863
864/* ------------------------------------------------------------------ */
865/* UCode pretty/ugly printing. Probably only useful to call from a skin
njn25e49d8e72002-09-23 09:36:25 +0000866 if VG_(needs).extended_UCode == True. */
867
868/* When True, all generated code is/should be printed. */
869extern Bool VG_(print_codegen);
870
njn4ba5a792002-09-30 10:23:54 +0000871/* Pretty/ugly printing functions */
872extern void VG_(pp_UCodeBlock) ( UCodeBlock* cb, Char* title );
873extern void VG_(pp_UInstr) ( Int instrNo, UInstr* u );
874extern void VG_(pp_UInstr_regs) ( Int instrNo, UInstr* u );
875extern void VG_(up_UInstr) ( Int instrNo, UInstr* u );
876extern Char* VG_(name_UOpcode) ( Bool upper, Opcode opc );
njn563f96f2003-02-03 11:17:46 +0000877extern Char* VG_(name_UCondcode) ( Condcode cond );
njn4ba5a792002-09-30 10:23:54 +0000878extern void VG_(pp_UOperand) ( UInstr* u, Int operandNo,
879 Int sz, Bool parens );
njn25e49d8e72002-09-23 09:36:25 +0000880
njnb93d1782003-02-03 12:03:22 +0000881/* ------------------------------------------------------------------ */
njnf4ce3d32003-02-10 10:17:26 +0000882/* Accessing archregs and their shadows */
883extern UInt VG_(get_archreg) ( UInt archreg );
884extern UInt VG_(get_thread_archreg) ( ThreadId tid, UInt archreg );
885
njnb93d1782003-02-03 12:03:22 +0000886extern UInt VG_(get_shadow_archreg) ( UInt archreg );
887extern void VG_(set_shadow_archreg) ( UInt archreg, UInt val );
888extern Addr VG_(shadow_archreg_address) ( UInt archreg );
njn25e49d8e72002-09-23 09:36:25 +0000889
njnf4ce3d32003-02-10 10:17:26 +0000890extern UInt VG_(get_thread_shadow_archreg) ( ThreadId tid, UInt archreg );
891extern void VG_(set_thread_shadow_archreg) ( ThreadId tid, UInt archreg,
892 UInt val );
njn211b6ad2003-02-03 12:33:31 +0000893
894/* ------------------------------------------------------------------ */
895/* Offsets of addresses of helper functions. A "helper" function is one
896 which is called from generated code via CALLM. */
897
898extern Int VGOFF_(helper_idiv_64_32);
899extern Int VGOFF_(helper_div_64_32);
900extern Int VGOFF_(helper_idiv_32_16);
901extern Int VGOFF_(helper_div_32_16);
902extern Int VGOFF_(helper_idiv_16_8);
903extern Int VGOFF_(helper_div_16_8);
904
905extern Int VGOFF_(helper_imul_32_64);
906extern Int VGOFF_(helper_mul_32_64);
907extern Int VGOFF_(helper_imul_16_32);
908extern Int VGOFF_(helper_mul_16_32);
909extern Int VGOFF_(helper_imul_8_16);
910extern Int VGOFF_(helper_mul_8_16);
911
912extern Int VGOFF_(helper_CLD);
913extern Int VGOFF_(helper_STD);
914extern Int VGOFF_(helper_get_dirflag);
915
916extern Int VGOFF_(helper_CLC);
917extern Int VGOFF_(helper_STC);
918
919extern Int VGOFF_(helper_shldl);
920extern Int VGOFF_(helper_shldw);
921extern Int VGOFF_(helper_shrdl);
922extern Int VGOFF_(helper_shrdw);
923
924extern Int VGOFF_(helper_RDTSC);
925extern Int VGOFF_(helper_CPUID);
926
927extern Int VGOFF_(helper_bsf);
928extern Int VGOFF_(helper_bsr);
929
930extern Int VGOFF_(helper_fstsw_AX);
931extern Int VGOFF_(helper_SAHF);
932extern Int VGOFF_(helper_DAS);
933extern Int VGOFF_(helper_DAA);
934
935
njn25e49d8e72002-09-23 09:36:25 +0000936/*====================================================================*/
njnd5bb0a52002-09-27 10:24:48 +0000937/*=== Generating x86 code from UCode ===*/
njn25e49d8e72002-09-23 09:36:25 +0000938/*====================================================================*/
939
njnd5bb0a52002-09-27 10:24:48 +0000940/* All this only necessary for skins with VG_(needs).extends_UCode == True. */
njn25e49d8e72002-09-23 09:36:25 +0000941
sewardje1042472002-09-30 12:33:11 +0000942/* This is the Intel register encoding -- integer regs. */
njn25e49d8e72002-09-23 09:36:25 +0000943#define R_EAX 0
944#define R_ECX 1
945#define R_EDX 2
946#define R_EBX 3
947#define R_ESP 4
948#define R_EBP 5
949#define R_ESI 6
950#define R_EDI 7
951
952#define R_AL (0+R_EAX)
953#define R_CL (0+R_ECX)
954#define R_DL (0+R_EDX)
955#define R_BL (0+R_EBX)
956#define R_AH (4+R_EAX)
957#define R_CH (4+R_ECX)
958#define R_DH (4+R_EDX)
959#define R_BH (4+R_EBX)
960
sewardje1042472002-09-30 12:33:11 +0000961/* This is the Intel register encoding -- segment regs. */
962#define R_ES 0
963#define R_CS 1
964#define R_SS 2
965#define R_DS 3
966#define R_FS 4
967#define R_GS 5
968
njn25e49d8e72002-09-23 09:36:25 +0000969/* For pretty printing x86 code */
sewardj3d7c9c82003-03-26 21:08:13 +0000970extern Char* VG_(name_of_mmx_gran) ( UChar gran );
971extern Char* VG_(name_of_mmx_reg) ( Int mmxreg );
sewardje1042472002-09-30 12:33:11 +0000972extern Char* VG_(name_of_seg_reg) ( Int sreg );
njn4ba5a792002-09-30 10:23:54 +0000973extern Char* VG_(name_of_int_reg) ( Int size, Int reg );
974extern Char VG_(name_of_int_size) ( Int size );
njn25e49d8e72002-09-23 09:36:25 +0000975
njnac6c1762002-10-04 14:34:15 +0000976/* Shorter macros for convenience */
sewardj3d7c9c82003-03-26 21:08:13 +0000977#define nameIReg VG_(name_of_int_reg)
978#define nameISize VG_(name_of_int_size)
979#define nameSReg VG_(name_of_seg_reg)
980#define nameMMXReg VG_(name_of_mmx_reg)
981#define nameMMXGran VG_(name_of_mmx_gran)
njnac6c1762002-10-04 14:34:15 +0000982
njn25e49d8e72002-09-23 09:36:25 +0000983/* Randomly useful things */
984extern UInt VG_(extend_s_8to32) ( UInt x );
985
986/* Code emitters */
njn4ba5a792002-09-30 10:23:54 +0000987extern void VG_(emitB) ( UInt b );
988extern void VG_(emitW) ( UInt w );
989extern void VG_(emitL) ( UInt l );
sewardjfa492d42002-12-08 18:20:01 +0000990extern void VG_(new_emit) ( Bool upd_cc, FlagSet uses_flags, FlagSet sets_flags );
njn25e49d8e72002-09-23 09:36:25 +0000991
992/* Finding offsets */
njn4ba5a792002-09-30 10:23:54 +0000993extern Int VG_(helper_offset) ( Addr a );
994extern Int VG_(shadow_reg_offset) ( Int arch );
995extern Int VG_(shadow_flags_offset) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000996
njnd5bb0a52002-09-27 10:24:48 +0000997/* Convert reg ranks <-> Intel register ordering, for using register
998 liveness information. */
njn4ba5a792002-09-30 10:23:54 +0000999extern Int VG_(realreg_to_rank) ( Int realreg );
1000extern Int VG_(rank_to_realreg) ( Int rank );
njn25e49d8e72002-09-23 09:36:25 +00001001
njnd5bb0a52002-09-27 10:24:48 +00001002/* Call a subroutine. Does no argument passing, stack manipulations, etc. */
sewardjfa492d42002-12-08 18:20:01 +00001003extern void VG_(synth_call) ( Bool ensure_shortform, Int word_offset,
1004 Bool upd_cc, FlagSet use_flags, FlagSet set_flags );
njn25e49d8e72002-09-23 09:36:25 +00001005
njnd5bb0a52002-09-27 10:24:48 +00001006/* For calling C functions -- saves caller save regs, pushes args, calls,
1007 clears the stack, restores caller save regs. `fn' must be registered in
1008 the baseBlock first. Acceptable tags are RealReg and Literal. Optimises
1009 things, eg. by not preserving non-live caller-save registers.
njn25e49d8e72002-09-23 09:36:25 +00001010
njnd5bb0a52002-09-27 10:24:48 +00001011 WARNING: a UInstr should *not* be translated with synth_ccall() followed
1012 by some other x86 assembly code; this will invalidate the results of
1013 vg_realreg_liveness_analysis() and everything will fall over. */
njn4ba5a792002-09-30 10:23:54 +00001014extern void VG_(synth_ccall) ( Addr fn, Int argc, Int regparms_n, UInt argv[],
1015 Tag tagv[], Int ret_reg,
1016 RRegSet regs_live_before,
1017 RRegSet regs_live_after );
njn25e49d8e72002-09-23 09:36:25 +00001018
1019/* Addressing modes */
njn4ba5a792002-09-30 10:23:54 +00001020extern void VG_(emit_amode_offregmem_reg)( Int off, Int regmem, Int reg );
1021extern void VG_(emit_amode_ereg_greg) ( Int e_reg, Int g_reg );
njn25e49d8e72002-09-23 09:36:25 +00001022
1023/* v-size (4, or 2 with OSO) insn emitters */
njn4ba5a792002-09-30 10:23:54 +00001024extern void VG_(emit_movv_offregmem_reg) ( Int sz, Int off, Int areg, Int reg );
1025extern void VG_(emit_movv_reg_offregmem) ( Int sz, Int reg, Int off, Int areg );
1026extern void VG_(emit_movv_reg_reg) ( Int sz, Int reg1, Int reg2 );
sewardjfa492d42002-12-08 18:20:01 +00001027extern void VG_(emit_nonshiftopv_lit_reg)( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001028 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001029extern void VG_(emit_shiftopv_lit_reg) ( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001030 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001031extern void VG_(emit_nonshiftopv_reg_reg)( Bool upd_cc, Int sz, Opcode opc,
njn4ba5a792002-09-30 10:23:54 +00001032 Int reg1, Int reg2 );
1033extern void VG_(emit_movv_lit_reg) ( Int sz, UInt lit, Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001034extern void VG_(emit_unaryopv_reg) ( Bool upd_cc, Int sz, Opcode opc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001035extern void VG_(emit_pushv_reg) ( Int sz, Int reg );
1036extern void VG_(emit_popv_reg) ( Int sz, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001037
njn4ba5a792002-09-30 10:23:54 +00001038extern void VG_(emit_pushl_lit32) ( UInt int32 );
1039extern void VG_(emit_pushl_lit8) ( Int lit8 );
sewardjfa492d42002-12-08 18:20:01 +00001040extern void VG_(emit_cmpl_zero_reg) ( Bool upd_cc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001041extern void VG_(emit_swapl_reg_EAX) ( Int reg );
1042extern void VG_(emit_movv_lit_offregmem) ( Int sz, UInt lit, Int off,
1043 Int memreg );
njn25e49d8e72002-09-23 09:36:25 +00001044
1045/* b-size (1 byte) instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001046extern void VG_(emit_movb_lit_offregmem) ( UInt lit, Int off, Int memreg );
1047extern void VG_(emit_movb_reg_offregmem) ( Int reg, Int off, Int areg );
sewardjfa492d42002-12-08 18:20:01 +00001048extern void VG_(emit_unaryopb_reg) ( Bool upd_cc, Opcode opc, Int reg );
1049extern void VG_(emit_testb_lit_reg) ( Bool upd_cc, UInt lit, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001050
1051/* zero-extended load emitters */
njn4ba5a792002-09-30 10:23:54 +00001052extern void VG_(emit_movzbl_offregmem_reg) ( Int off, Int regmem, Int reg );
1053extern void VG_(emit_movzwl_offregmem_reg) ( Int off, Int areg, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001054
1055/* misc instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001056extern void VG_(emit_call_reg) ( Int reg );
1057extern void VG_(emit_add_lit_to_esp) ( Int lit );
njn4ba5a792002-09-30 10:23:54 +00001058extern void VG_(emit_pushal) ( void );
1059extern void VG_(emit_popal) ( void );
1060extern void VG_(emit_AMD_prefetch_reg) ( Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001061
sewardja2113f92002-12-12 23:42:48 +00001062/* jump emitters */
1063extern void VG_(init_target) ( Int *tgt );
1064
1065extern void VG_(target_back) ( Int *tgt );
1066extern void VG_(target_forward) ( Int *tgt );
1067extern void VG_(emit_target_delta) ( Int *tgt );
1068
1069extern void VG_(emit_jcondshort_delta) ( Bool simd_cc, Condcode cond, Int delta );
1070extern void VG_(emit_jcondshort_target)( Bool simd_cc, Condcode cond, Int *tgt );
1071
njn25e49d8e72002-09-23 09:36:25 +00001072
1073/*====================================================================*/
1074/*=== Execution contexts ===*/
1075/*====================================================================*/
1076
1077/* Generic resolution type used in a few different ways, such as deciding
1078 how closely to compare two errors for equality. */
1079typedef
1080 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
1081 VgRes;
1082
1083typedef
1084 struct _ExeContext
1085 ExeContext;
1086
njnd5bb0a52002-09-27 10:24:48 +00001087/* Compare two ExeContexts. Number of callers considered depends on `res':
1088 Vg_LowRes: 2
1089 Vg_MedRes: 4
1090 Vg_HighRes: all */
njn25e49d8e72002-09-23 09:36:25 +00001091extern Bool VG_(eq_ExeContext) ( VgRes res,
1092 ExeContext* e1, ExeContext* e2 );
1093
1094/* Print an ExeContext. */
1095extern void VG_(pp_ExeContext) ( ExeContext* );
1096
1097/* Take a snapshot of the client's stack. Search our collection of
1098 ExeContexts to see if we already have it, and if not, allocate a
1099 new one. Either way, return a pointer to the context. */
1100extern ExeContext* VG_(get_ExeContext) ( ThreadState *tst );
1101
sewardj499e3de2002-11-13 22:22:25 +00001102/* Just grab the client's EIP, as a much smaller and cheaper
1103 indication of where they are. */
1104extern Addr VG_(get_EIP)( ThreadState *tst );
njn25e49d8e72002-09-23 09:36:25 +00001105
njn211b6ad2003-02-03 12:33:31 +00001106
njn25e49d8e72002-09-23 09:36:25 +00001107/*====================================================================*/
1108/*=== Error reporting ===*/
1109/*====================================================================*/
1110
1111/* ------------------------------------------------------------------ */
1112/* Suppressions describe errors which we want to suppress, ie, not
1113 show the user, usually because it is caused by a problem in a library
1114 which we can't fix, replace or work around. Suppressions are read from
njnd5bb0a52002-09-27 10:24:48 +00001115 a file at startup time. This gives flexibility so that new
njn25e49d8e72002-09-23 09:36:25 +00001116 suppressions can be added to the file as and when needed.
1117*/
1118
1119typedef
1120 Int /* Do not make this unsigned! */
1121 SuppKind;
1122
njn810086f2002-11-14 12:42:47 +00001123/* The skin-relevant parts of a suppression are:
1124 kind: what kind of suppression; must be in the range (0..)
1125 string: use is optional. NULL by default.
1126 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001127*/
1128typedef
njn810086f2002-11-14 12:42:47 +00001129 struct _Supp
1130 Supp;
1131
1132/* Useful in SK_(error_matches_suppression)() */
1133SuppKind VG_(get_supp_kind) ( Supp* su );
1134Char* VG_(get_supp_string) ( Supp* su );
1135void* VG_(get_supp_extra) ( Supp* su );
1136
1137/* Must be used in VG_(recognised_suppression)() */
1138void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
1139/* May be used in VG_(read_extra_suppression_info)() */
1140void VG_(set_supp_string) ( Supp* su, Char* string );
1141void VG_(set_supp_extra) ( Supp* su, void* extra );
njn25e49d8e72002-09-23 09:36:25 +00001142
1143
1144/* ------------------------------------------------------------------ */
1145/* Error records contain enough info to generate an error report. The idea
1146 is that (typically) the same few points in the program generate thousands
njnd5bb0a52002-09-27 10:24:48 +00001147 of errors, and we don't want to spew out a fresh error message for each
1148 one. Instead, we use these structures to common up duplicates.
njn25e49d8e72002-09-23 09:36:25 +00001149*/
1150
1151typedef
1152 Int /* Do not make this unsigned! */
1153 ErrorKind;
1154
njn810086f2002-11-14 12:42:47 +00001155/* The skin-relevant parts of an Error are:
1156 kind: what kind of error; must be in the range (0..)
1157 addr: use is optional. 0 by default.
1158 string: use is optional. NULL by default.
1159 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001160*/
1161typedef
njn810086f2002-11-14 12:42:47 +00001162 struct _Error
1163 Error;
njn25e49d8e72002-09-23 09:36:25 +00001164
njn810086f2002-11-14 12:42:47 +00001165/* Useful in SK_(error_matches_suppression)(), SK_(pp_SkinError)(), etc */
njnb877d492003-01-28 20:40:57 +00001166ExeContext* VG_(get_error_where) ( Error* err );
1167SuppKind VG_(get_error_kind) ( Error* err );
1168Addr VG_(get_error_address) ( Error* err );
1169Char* VG_(get_error_string) ( Error* err );
1170void* VG_(get_error_extra) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001171
njnd5bb0a52002-09-27 10:24:48 +00001172/* Call this when an error occurs. It will be recorded if it hasn't been
njn25e49d8e72002-09-23 09:36:25 +00001173 seen before. If it has, the existing error record will have its count
1174 incremented.
1175
1176 If the error occurs in generated code, 'tst' should be NULL. If the
1177 error occurs in non-generated code, 'tst' should be non-NULL. The
1178 `extra' field can be stack-allocated; it will be copied (using
1179 SKN_(dup_extra_and_update)()) if needed. But it won't be copied
1180 if it's NULL.
njnd5bb0a52002-09-27 10:24:48 +00001181
1182 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
1183 NULL for them.
njn25e49d8e72002-09-23 09:36:25 +00001184*/
1185extern void VG_(maybe_record_error) ( ThreadState* tst, ErrorKind ekind,
1186 Addr a, Char* s, void* extra );
1187
1188/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
1189 Skips leading spaces on the line. Returns True if EOF was hit instead.
1190 Useful for reading in extra skin-specific suppression lines.
1191*/
njn4ba5a792002-09-30 10:23:54 +00001192extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
njn25e49d8e72002-09-23 09:36:25 +00001193
1194
1195/*====================================================================*/
1196/*=== Obtaining debug information ===*/
1197/*====================================================================*/
1198
sewardj6e008cb2002-12-15 13:11:39 +00001199/* Get the file/function/line number of the instruction at address
1200 'a'. For these four, if debug info for the address is found, it
1201 copies the info into the buffer/UInt and returns True. If not, it
1202 returns False and nothing is copied. VG_(get_fnname) always
1203 demangles C++ function names. VG_(get_fnname_w_offset) is the
1204 same, except it appends "+N" to symbol names to indicate offsets.
njn25e49d8e72002-09-23 09:36:25 +00001205*/
1206extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
1207extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
1208extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
sewardj6e008cb2002-12-15 13:11:39 +00001209extern Bool VG_(get_fnname_w_offset)
1210 ( Addr a, Char* fnname, Int n_fnname );
njn25e49d8e72002-09-23 09:36:25 +00001211
1212/* This one is more efficient if getting both filename and line number,
1213 because the two lookups are done together. */
1214extern Bool VG_(get_filename_linenum)
1215 ( Addr a, Char* filename, Int n_filename,
1216 UInt* linenum );
1217
1218/* Succeeds only if we find from debug info that 'a' is the address of the
1219 first instruction in a function -- as opposed to VG_(get_fnname) which
1220 succeeds if we find from debug info that 'a' is the address of any
1221 instruction in a function. Use this to instrument the start of
njnd5bb0a52002-09-27 10:24:48 +00001222 a particular function. Nb: if an executable/shared object is stripped
njn25e49d8e72002-09-23 09:36:25 +00001223 of its symbols, this function will not be able to recognise function
1224 entry points within it. */
1225extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* filename, Int n_filename );
1226
1227/* Succeeds if the address is within a shared object or the main executable.
1228 It doesn't matter if debug info is present or not. */
1229extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
1230
sewardj47104382002-10-20 18:35:48 +00001231/* A way to get information about what segments are mapped */
1232typedef struct _SegInfo SegInfo;
1233
njnb877d492003-01-28 20:40:57 +00001234/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
1235 is present or not. */
1236extern SegInfo* VG_(get_obj) ( Addr a );
1237
1238extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
1239extern Addr VG_(seg_start) ( const SegInfo *seg );
1240extern UInt VG_(seg_size) ( const SegInfo *seg );
1241extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
1242extern UInt VG_(seg_sym_offset)( const SegInfo *seg );
sewardj47104382002-10-20 18:35:48 +00001243
1244typedef
1245 enum {
1246 Vg_SectUnknown,
1247 Vg_SectText,
sewardj8fe15a32002-10-20 19:29:21 +00001248 Vg_SectData,
1249 Vg_SectBSS,
sewardj47104382002-10-20 18:35:48 +00001250 Vg_SectGOT,
sewardj8fe15a32002-10-20 19:29:21 +00001251 Vg_SectPLT,
sewardj47104382002-10-20 18:35:48 +00001252 }
1253 VgSectKind;
1254
1255extern VgSectKind VG_(seg_sect_kind)(Addr);
1256
njn25e49d8e72002-09-23 09:36:25 +00001257
1258/*====================================================================*/
1259/*=== Shadow chunks and block-finding ===*/
1260/*====================================================================*/
1261
njn810086f2002-11-14 12:42:47 +00001262/* The skin-relevant parts of a ShadowChunk are:
1263 size: size of the block in bytes
1264 addr: addr of the block
1265 extra: anything extra kept by the skin; size is determined by
1266 VG_(needs).sizeof_shadow_chunk
1267*/
njn25e49d8e72002-09-23 09:36:25 +00001268typedef
njn810086f2002-11-14 12:42:47 +00001269 struct _ShadowChunk
njn25e49d8e72002-09-23 09:36:25 +00001270 ShadowChunk;
1271
njn810086f2002-11-14 12:42:47 +00001272extern UInt VG_(get_sc_size) ( ShadowChunk* sc );
1273extern Addr VG_(get_sc_data) ( ShadowChunk* sc );
1274/* Gets the ith word of the `extra' field. */
1275extern UInt VG_(get_sc_extra) ( ShadowChunk* sc, UInt i );
1276/* Sets the ith word of the `extra' field to `word'. */
1277extern void VG_(set_sc_extra) ( ShadowChunk* sc, UInt i, UInt word );
1278
1279/* These two should only be used if the `alternative_free' need is set, once
1280 we reach the point where the block would have been free'd. */
1281extern ShadowChunk* VG_(get_sc_next) ( ShadowChunk* sc );
1282extern void VG_(set_sc_next) ( ShadowChunk* sc, ShadowChunk* next );
1283
1284
njn25e49d8e72002-09-23 09:36:25 +00001285/* Use this to free blocks if VG_(needs).alternative_free == True.
1286 It frees the ShadowChunk and the malloc'd block it points to. */
njn4ba5a792002-09-30 10:23:54 +00001287extern void VG_(free_ShadowChunk) ( ShadowChunk* sc );
njn25e49d8e72002-09-23 09:36:25 +00001288
1289/* Makes an array of pointers to all the shadow chunks of malloc'd blocks */
1290extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
1291
1292/* Determines if address 'a' is within the bounds of the block at start.
1293 Allows a little 'slop' round the edges. */
1294extern Bool VG_(addr_is_in_block) ( Addr a, Addr start, UInt size );
1295
1296/* Searches through currently malloc'd blocks until a matching one is found.
1297 Returns NULL if none match. Extra arguments can be implicitly passed to
njnd5bb0a52002-09-27 10:24:48 +00001298 p using nested functions; see memcheck/mc_errcontext.c for an example. */
njn25e49d8e72002-09-23 09:36:25 +00001299extern ShadowChunk* VG_(any_matching_mallocd_ShadowChunks)
1300 ( Bool (*p) ( ShadowChunk* ));
1301
1302/* Searches through all thread's stacks to see if any match. Returns
1303 * VG_INVALID_THREADID if none match. */
1304extern ThreadId VG_(any_matching_thread_stack)
1305 ( Bool (*p) ( Addr stack_min, Addr stack_max ));
1306
sewardja4495682002-10-21 07:29:59 +00001307/* Do memory leak detection. */
1308extern void VG_(generic_detect_memory_leaks) (
1309 Bool is_valid_64k_chunk ( UInt ),
1310 Bool is_valid_address ( Addr ),
1311 ExeContext* get_where ( ShadowChunk* ),
1312 VgRes leak_resolution,
sewardj99aac972002-12-26 01:53:45 +00001313 Bool show_reachable,
1314 UInt /*CoreErrorKind*/ leakSupp
sewardja4495682002-10-21 07:29:59 +00001315 );
1316
1317
njn25e49d8e72002-09-23 09:36:25 +00001318/*====================================================================*/
1319/*=== Skin-specific stuff ===*/
1320/*====================================================================*/
1321
njnd04b7c62002-10-03 14:05:52 +00001322/* ------------------------------------------------------------------ */
1323/* Details */
njnd04b7c62002-10-03 14:05:52 +00001324
njn120281f2003-02-03 12:20:07 +00001325/* Default value for avg_translations_sizeB (in bytes), indicating typical
1326 code expansion of about 6:1. */
1327#define VG_DEFAULT_TRANS_SIZEB 100
1328
njn810086f2002-11-14 12:42:47 +00001329/* Information used in the startup message. `name' also determines the
1330 string used for identifying suppressions in a suppression file as
1331 belonging to this skin. `version' can be NULL, in which case (not
1332 surprisingly) no version info is printed; this mechanism is designed for
1333 skins distributed with Valgrind that share a version number with
1334 Valgrind. Other skins not distributed as part of Valgrind should
sewardjc0d8f682002-11-30 00:49:43 +00001335 probably have their own version number. */
1336extern void VG_(details_name) ( Char* name );
1337extern void VG_(details_version) ( Char* version );
1338extern void VG_(details_description) ( Char* description );
1339extern void VG_(details_copyright_author) ( Char* copyright_author );
1340
1341/* Average size of a translation, in bytes, so that the translation
njn120281f2003-02-03 12:20:07 +00001342 storage machinery can allocate memory appropriately. Not critical,
1343 setting is optional. */
1344extern void VG_(details_avg_translation_sizeB) ( UInt size );
njnd04b7c62002-10-03 14:05:52 +00001345
njn810086f2002-11-14 12:42:47 +00001346/* String printed if an `sk_assert' assertion fails or VG_(skin_panic)
1347 is called. Should probably be an email address. */
1348extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
njnd04b7c62002-10-03 14:05:52 +00001349
1350/* ------------------------------------------------------------------ */
1351/* Needs */
1352
njn810086f2002-11-14 12:42:47 +00001353/* Booleans that decide core behaviour, but don't require extra
1354 operations to be defined if `True' */
njnd5bb0a52002-09-27 10:24:48 +00001355
njn810086f2002-11-14 12:42:47 +00001356/* Should __libc_freeres() be run? Bugs in it can crash the skin. */
1357extern void VG_(needs_libc_freeres) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001358
njn810086f2002-11-14 12:42:47 +00001359/* Want to have errors detected by Valgrind's core reported? Includes:
1360 - pthread API errors (many; eg. unlocking a non-locked mutex)
1361 - silly arguments to malloc() et al (eg. negative size)
1362 - invalid file descriptors to blocking syscalls read() and write()
1363 - bad signal numbers passed to sigaction()
1364 - attempt to install signal handler for SIGKILL or SIGSTOP */
1365extern void VG_(needs_core_errors) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001366
njn810086f2002-11-14 12:42:47 +00001367/* Booleans that indicate extra operations are defined; if these are True,
1368 the corresponding template functions (given below) must be defined. A
1369 lot like being a member of a type class. */
njn25e49d8e72002-09-23 09:36:25 +00001370
njn810086f2002-11-14 12:42:47 +00001371/* Want to report errors from skin? This implies use of suppressions, too. */
1372extern void VG_(needs_skin_errors) ( void );
njnd5bb0a52002-09-27 10:24:48 +00001373
njn810086f2002-11-14 12:42:47 +00001374/* Is information kept about specific individual basic blocks? (Eg. for
1375 cachegrind there are cost-centres for every instruction, stored at a
1376 basic block level.) If so, it sometimes has to be discarded, because
1377 .so mmap/munmap-ping or self-modifying code (informed by the
1378 DISCARD_TRANSLATIONS user request) can cause one instruction address
1379 to be used for more than one instruction in one program run... */
1380extern void VG_(needs_basic_block_discards) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001381
njn810086f2002-11-14 12:42:47 +00001382/* Skin maintains information about each register? */
1383extern void VG_(needs_shadow_regs) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001384
njn810086f2002-11-14 12:42:47 +00001385/* Skin defines its own command line options? */
1386extern void VG_(needs_command_line_options) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001387
njn810086f2002-11-14 12:42:47 +00001388/* Skin defines its own client requests? */
1389extern void VG_(needs_client_requests) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001390
njn810086f2002-11-14 12:42:47 +00001391/* Skin defines its own UInstrs? */
1392extern void VG_(needs_extended_UCode) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001393
njn810086f2002-11-14 12:42:47 +00001394/* Skin does stuff before and/or after system calls? */
1395extern void VG_(needs_syscall_wrapper) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001396
njn810086f2002-11-14 12:42:47 +00001397/* Size, in words, of extra info about malloc'd blocks recorded by
1398 skin. Be careful to get this right or you'll get seg faults! */
1399extern void VG_(needs_sizeof_shadow_block) ( Int size );
njn25e49d8e72002-09-23 09:36:25 +00001400
njn810086f2002-11-14 12:42:47 +00001401/* Skin does free()s itself? Useful if a skin needs to keep track of
1402 blocks in some way after they're free'd.
1403 WARNING: don't forget to call VG_(free_ShadowChunk)() for each block
1404 eventually! */
1405extern void VG_(needs_alternative_free) ( void );
sewardj8fe15a32002-10-20 19:29:21 +00001406
njn810086f2002-11-14 12:42:47 +00001407/* Are skin-state sanity checks performed? */
1408extern void VG_(needs_sanity_checks) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001409
njn810086f2002-11-14 12:42:47 +00001410/* Do we need to see data symbols? */
1411extern void VG_(needs_data_syms) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001412
1413/* ------------------------------------------------------------------ */
1414/* Core events to track */
1415
1416/* Part of the core from which this call was made. Useful for determining
njnd5bb0a52002-09-27 10:24:48 +00001417 what kind of error message should be emitted. */
njn25e49d8e72002-09-23 09:36:25 +00001418typedef
1419 enum { Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall, Vg_CoreTranslate }
1420 CorePart;
1421
njn810086f2002-11-14 12:42:47 +00001422#define EV extern void
njn25e49d8e72002-09-23 09:36:25 +00001423
njn810086f2002-11-14 12:42:47 +00001424/* Events happening in core to track. To be notified, pass a callback
1425 function to the appropriate function. To ignore an event, don't do
1426 anything (default is for events to be ignored). */
1427
1428/* Memory events */
1429
1430EV VG_(track_new_mem_startup) ( void (*f)(Addr a, UInt len,
1431 Bool rr, Bool ww, Bool xx) );
1432EV VG_(track_new_mem_heap) ( void (*f)(Addr a, UInt len, Bool is_inited) );
njn810086f2002-11-14 12:42:47 +00001433EV VG_(track_new_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1434EV VG_(track_new_mem_brk) ( void (*f)(Addr a, UInt len) );
1435EV VG_(track_new_mem_mmap) ( void (*f)(Addr a, UInt len,
1436 Bool rr, Bool ww, Bool xx) );
1437
njn9b007f62003-04-07 14:40:25 +00001438/* The specialised ones are called in preference to the general one, if they
1439 are defined. These functions are called a lot if they are used, so
1440 specialising can optimise things significantly. If any of the
1441 specialised cases are defined, the general case must be defined too.
1442
1443 Nb: they must all use the __attribute__((regparm(n))) attribute. */
1444EV VG_(track_new_mem_stack_4) ( void (*f)(Addr new_ESP) );
1445EV VG_(track_new_mem_stack_8) ( void (*f)(Addr new_ESP) );
1446EV VG_(track_new_mem_stack_12) ( void (*f)(Addr new_ESP) );
1447EV VG_(track_new_mem_stack_16) ( void (*f)(Addr new_ESP) );
1448EV VG_(track_new_mem_stack_32) ( void (*f)(Addr new_ESP) );
1449EV VG_(track_new_mem_stack) ( void (*f)(Addr a, UInt len) );
1450
1451EV VG_(track_change_mem_stack) ( void (*f)(Addr new_ESP) );
1452
njn810086f2002-11-14 12:42:47 +00001453EV VG_(track_copy_mem_heap) ( void (*f)(Addr from, Addr to, UInt len) );
1454EV VG_(track_copy_mem_remap) ( void (*f)(Addr from, Addr to, UInt len) );
1455EV VG_(track_change_mem_mprotect) ( void (*f)(Addr a, UInt len,
1456 Bool rr, Bool ww, Bool xx) );
njn25e49d8e72002-09-23 09:36:25 +00001457
njn810086f2002-11-14 12:42:47 +00001458/* Used on redzones around malloc'd blocks and at end of stack */
1459EV VG_(track_ban_mem_heap) ( void (*f)(Addr a, UInt len) );
1460EV VG_(track_ban_mem_stack) ( void (*f)(Addr a, UInt len) );
njn25e49d8e72002-09-23 09:36:25 +00001461
njn810086f2002-11-14 12:42:47 +00001462EV VG_(track_die_mem_heap) ( void (*f)(Addr a, UInt len) );
njn810086f2002-11-14 12:42:47 +00001463EV VG_(track_die_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1464EV VG_(track_die_mem_brk) ( void (*f)(Addr a, UInt len) );
1465EV VG_(track_die_mem_munmap) ( void (*f)(Addr a, UInt len) );
njn25e49d8e72002-09-23 09:36:25 +00001466
njn9b007f62003-04-07 14:40:25 +00001467/* See comments for VG_(track_new_mem_stack_4) et al above */
1468EV VG_(track_die_mem_stack_4) ( void (*f)(Addr die_ESP) );
1469EV VG_(track_die_mem_stack_8) ( void (*f)(Addr die_ESP) );
1470EV VG_(track_die_mem_stack_12) ( void (*f)(Addr die_ESP) );
1471EV VG_(track_die_mem_stack_16) ( void (*f)(Addr die_ESP) );
1472EV VG_(track_die_mem_stack_32) ( void (*f)(Addr die_ESP) );
1473EV VG_(track_die_mem_stack) ( void (*f)(Addr a, UInt len) );
1474
njn810086f2002-11-14 12:42:47 +00001475EV VG_(track_bad_free) ( void (*f)(ThreadState* tst, Addr a) );
1476EV VG_(track_mismatched_free) ( void (*f)(ThreadState* tst, Addr a) );
njn25e49d8e72002-09-23 09:36:25 +00001477
njn810086f2002-11-14 12:42:47 +00001478EV VG_(track_pre_mem_read) ( void (*f)(CorePart part, ThreadState* tst,
1479 Char* s, Addr a, UInt size) );
1480EV VG_(track_pre_mem_read_asciiz) ( void (*f)(CorePart part, ThreadState* tst,
1481 Char* s, Addr a) );
1482EV VG_(track_pre_mem_write) ( void (*f)(CorePart part, ThreadState* tst,
1483 Char* s, Addr a, UInt size) );
1484/* Not implemented yet -- have to add in lots of places, which is a
1485 pain. Won't bother unless/until there's a need. */
1486/* EV VG_(track_post_mem_read) ( void (*f)(ThreadState* tst, Char* s,
1487 Addr a, UInt size) ); */
1488EV VG_(track_post_mem_write) ( void (*f)(Addr a, UInt size) );
njn25e49d8e72002-09-23 09:36:25 +00001489
1490
njn810086f2002-11-14 12:42:47 +00001491/* Scheduler events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001492
njn810086f2002-11-14 12:42:47 +00001493EV VG_(track_thread_run) ( void (*f)(ThreadId tid) );
njn25e49d8e72002-09-23 09:36:25 +00001494
njn810086f2002-11-14 12:42:47 +00001495/* Thread events (not exhaustive) */
sewardjdca84112002-11-13 22:29:34 +00001496
njn810086f2002-11-14 12:42:47 +00001497/* Called during thread create, before the new thread has run any
1498 instructions (or touched any memory). */
1499EV VG_(track_post_thread_create)( void (*f)(ThreadId tid, ThreadId child) );
1500/* Called once the joinee thread is terminated and the joining thread is
1501 about to resume. */
1502EV VG_(track_post_thread_join) ( void (*f)(ThreadId joiner, ThreadId joinee) );
njn25e49d8e72002-09-23 09:36:25 +00001503
njnd5bb0a52002-09-27 10:24:48 +00001504
njn810086f2002-11-14 12:42:47 +00001505/* Mutex events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001506
njn810086f2002-11-14 12:42:47 +00001507/* Called before a thread can block while waiting for a mutex (called
1508 regardless of whether the thread will block or not). */
1509EV VG_(track_pre_mutex_lock) ( void (*f)(ThreadId tid,
1510 void* /*pthread_mutex_t* */ mutex) );
1511/* Called once the thread actually holds the mutex (always paired with
1512 pre_mutex_lock). */
1513EV VG_(track_post_mutex_lock) ( void (*f)(ThreadId tid,
1514 void* /*pthread_mutex_t* */ mutex) );
1515/* Called after a thread has released a mutex (no need for a corresponding
1516 pre_mutex_unlock, because unlocking can't block). */
1517EV VG_(track_post_mutex_unlock) ( void (*f)(ThreadId tid,
1518 void* /*pthread_mutex_t* */ mutex) );
njn25e49d8e72002-09-23 09:36:25 +00001519
njn1045b0a2003-02-24 10:42:47 +00001520
1521/* Signal events (not exhaustive) */
1522
1523/* Called before a signal is delivered; `alt_stack' indicates if it is
1524 delivered on an alternative stack. */
1525EV VG_(track_pre_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum,
1526 Bool alt_stack) );
1527/* Called after a signal is delivered. */
1528EV VG_(track_post_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum ) );
1529
1530
1531/* Others... condition variables... */
njn810086f2002-11-14 12:42:47 +00001532/* ... */
1533
1534#undef EV
njn25e49d8e72002-09-23 09:36:25 +00001535
1536/* ------------------------------------------------------------------ */
1537/* Template functions */
1538
1539/* These are the parameterised functions in the core. The default definitions
njnd5bb0a52002-09-27 10:24:48 +00001540 are overridden by LD_PRELOADed skin version. At the very least, a skin
1541 must define the fundamental template functions. Depending on what needs
1542 are set, extra template functions will be used too. Functions are
1543 grouped under the needs that govern their use. */
njn25e49d8e72002-09-23 09:36:25 +00001544
1545
1546/* ------------------------------------------------------------------ */
1547/* Fundamental template functions */
1548
1549/* Initialise skin. Must do the following:
njn810086f2002-11-14 12:42:47 +00001550 - initialise the `details' struct, via the VG_(details_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001551 - register any helpers called by generated code
1552
1553 May do the following:
njn810086f2002-11-14 12:42:47 +00001554 - initialise the `needs' struct to indicate certain requirements, via
1555 the VG_(needs_*)() functions
1556 - initialise the `track' struct to indicate core events of interest, via
1557 the VG_(track_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001558 - register any skin-specific profiling events
1559 - any other skin-specific initialisation
1560*/
njn810086f2002-11-14 12:42:47 +00001561extern void SK_(pre_clo_init) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001562
njnd5bb0a52002-09-27 10:24:48 +00001563/* Do initialisation that can only be done after command line processing. */
njn25e49d8e72002-09-23 09:36:25 +00001564extern void SK_(post_clo_init)( void );
1565
1566/* Instrument a basic block. Must be a true function, ie. the same input
1567 always results in the same output, because basic blocks can be
1568 retranslated. Unless you're doing something really strange...
1569 'orig_addr' is the address of the first instruction in the block. */
1570extern UCodeBlock* SK_(instrument) ( UCodeBlock* cb, Addr orig_addr );
1571
1572/* Finish up, print out any results, etc. */
1573extern void SK_(fini) ( void );
1574
1575
1576/* ------------------------------------------------------------------ */
1577/* VG_(needs).report_errors */
1578
1579/* Identify if two errors are equal, or equal enough. `res' indicates how
1580 close is "close enough". `res' should be passed on as necessary, eg. if
njn810086f2002-11-14 12:42:47 +00001581 the Error's `extra' part contains an ExeContext, `res' should be
njn25e49d8e72002-09-23 09:36:25 +00001582 passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other
1583 than that, probably don't worry about it unless you have lots of very
1584 similar errors occurring.
1585 */
njn810086f2002-11-14 12:42:47 +00001586extern Bool SK_(eq_SkinError) ( VgRes res, Error* e1, Error* e2 );
njn25e49d8e72002-09-23 09:36:25 +00001587
1588/* Print error context. The passed function pp_ExeContext() can be (and
1589 probably should be) used to print the location of the error. */
njn810086f2002-11-14 12:42:47 +00001590extern void SK_(pp_SkinError) ( Error* err, void (*pp_ExeContext)(void) );
njn25e49d8e72002-09-23 09:36:25 +00001591
njn810086f2002-11-14 12:42:47 +00001592/* Should copy the `extra' part which the core uses to override the old
1593 version. This is necessary to move from a temporary stack copy to a
1594 permanent heap one.
njn25e49d8e72002-09-23 09:36:25 +00001595
njn810086f2002-11-14 12:42:47 +00001596 Then should fill in any details that could be postponed until after the
1597 decision whether to ignore the error (ie. details not affecting the
1598 result of SK_(eq_SkinError)()). This saves time when errors are ignored.
njn25e49d8e72002-09-23 09:36:25 +00001599
1600 Yuk.
1601*/
njn810086f2002-11-14 12:42:47 +00001602extern void* SK_(dup_extra_and_update) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001603
njn810086f2002-11-14 12:42:47 +00001604/* Return value indicates recognition. If recognised, must set skind using
1605 VG_(set_supp_kind)(). */
1606extern Bool SK_(recognised_suppression) ( Char* name, Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001607
njn810086f2002-11-14 12:42:47 +00001608/* Read any extra info for this suppression kind. Most likely for filling
1609 in the `extra' and `string' parts (with VG_(set_supp_{extra,string})())
1610 of a suppression if necessary. Should return False if a syntax error
1611 occurred, True otherwise. */
1612extern Bool SK_(read_extra_suppression_info) ( Int fd, Char* buf, Int nBuf,
1613 Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001614
1615/* This should just check the kinds match and maybe some stuff in the
njn810086f2002-11-14 12:42:47 +00001616 `string' and `extra' field if appropriate (using VG_(get_supp_*)() to
1617 get the relevant suppression parts). */
1618extern Bool SK_(error_matches_suppression)(Error* err, Supp* su);
njn25e49d8e72002-09-23 09:36:25 +00001619
1620
1621/* ------------------------------------------------------------------ */
1622/* VG_(needs).basic_block_discards */
1623
njnd5bb0a52002-09-27 10:24:48 +00001624/* Should discard any information that pertains to specific basic blocks
1625 or instructions within the address range given. */
njn25e49d8e72002-09-23 09:36:25 +00001626extern void SK_(discard_basic_block_info) ( Addr a, UInt size );
1627
1628
1629/* ------------------------------------------------------------------ */
1630/* VG_(needs).shadow_regs */
1631
1632/* Valid values for general registers and EFLAGS register, for initialising
1633 and updating registers when written in certain places in core. */
1634extern void SK_(written_shadow_regs_values) ( UInt* gen_reg, UInt* eflags );
1635
1636
1637/* ------------------------------------------------------------------ */
1638/* VG_(needs).command_line_options */
1639
njnd5bb0a52002-09-27 10:24:48 +00001640/* Return True if option was recognised. Presumably sets some state to
1641 record the option as well. */
1642extern Bool SK_(process_cmd_line_option) ( Char* argv );
njn25e49d8e72002-09-23 09:36:25 +00001643
1644/* Print out command line usage for skin options */
1645extern Char* SK_(usage) ( void );
1646
1647
1648/* ------------------------------------------------------------------ */
1649/* VG_(needs).client_requests */
1650
sewardj34042512002-10-22 04:14:35 +00001651extern Bool SK_(handle_client_request) ( ThreadState* tst, UInt* arg_block, UInt *ret );
njn25e49d8e72002-09-23 09:36:25 +00001652
1653
1654/* ------------------------------------------------------------------ */
1655/* VG_(needs).extends_UCode */
1656
njn4ba5a792002-09-30 10:23:54 +00001657/* Useful to use in VG_(get_Xreg_usage)() */
njn810086f2002-11-14 12:42:47 +00001658#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
njn25e49d8e72002-09-23 09:36:25 +00001659 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00001660 { regs[n] = mycat(u->val,ono); \
1661 isWrites[n] = False; \
njn25e49d8e72002-09-23 09:36:25 +00001662 n++; \
1663 } \
1664 }
njn810086f2002-11-14 12:42:47 +00001665#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
njnd5bb0a52002-09-27 10:24:48 +00001666 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00001667 { regs[n] = mycat(u->val,ono); \
1668 isWrites[n] = True; \
njnd5bb0a52002-09-27 10:24:48 +00001669 n++; \
1670 } \
njn25e49d8e72002-09-23 09:36:25 +00001671 }
1672
njn4ba5a792002-09-30 10:23:54 +00001673/* 'X' prefix indicates eXtended UCode. */
njn810086f2002-11-14 12:42:47 +00001674extern Int SK_(get_Xreg_usage) ( UInstr* u, Tag tag, Int* regs,
1675 Bool* isWrites );
njn4ba5a792002-09-30 10:23:54 +00001676extern void SK_(emit_XUInstr) ( UInstr* u, RRegSet regs_live_before );
1677extern Bool SK_(sane_XUInstr) ( Bool beforeRA, Bool beforeLiveness,
njn25e49d8e72002-09-23 09:36:25 +00001678 UInstr* u );
njn4ba5a792002-09-30 10:23:54 +00001679extern Char* SK_(name_XUOpcode) ( Opcode opc );
1680extern void SK_(pp_XUInstr) ( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +00001681
1682
1683/* ------------------------------------------------------------------ */
1684/* VG_(needs).syscall_wrapper */
1685
1686/* If either of the pre_ functions malloc() something to return, the
1687 * corresponding post_ function had better free() it!
1688 */
1689extern void* SK_( pre_syscall) ( ThreadId tid, UInt syscallno,
1690 Bool is_blocking );
1691extern void SK_(post_syscall) ( ThreadId tid, UInt syscallno,
1692 void* pre_result, Int res,
1693 Bool is_blocking );
1694
njnd5bb0a52002-09-27 10:24:48 +00001695
njn25e49d8e72002-09-23 09:36:25 +00001696/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +00001697/* VG_(needs).sizeof_shadow_chunk (if > 0) */
njn25e49d8e72002-09-23 09:36:25 +00001698
njn810086f2002-11-14 12:42:47 +00001699/* Must fill in the `extra' part, using VG_(set_sc_extra)(). */
njn25e49d8e72002-09-23 09:36:25 +00001700extern void SK_(complete_shadow_chunk) ( ShadowChunk* sc, ThreadState* tst );
1701
1702
1703/* ------------------------------------------------------------------ */
1704/* VG_(needs).alternative_free */
1705
njn810086f2002-11-14 12:42:47 +00001706/* If this need is set, when a dynamic block would normally be free'd, this
1707 is called instead. The block is contained inside the ShadowChunk; use
1708 the VG_(get_sc_*)() functions to access it. */
njn25e49d8e72002-09-23 09:36:25 +00001709extern void SK_(alt_free) ( ShadowChunk* sc, ThreadState* tst );
1710
njnd5bb0a52002-09-27 10:24:48 +00001711
njn25e49d8e72002-09-23 09:36:25 +00001712/* ---------------------------------------------------------------------
1713 VG_(needs).sanity_checks */
1714
njnd5bb0a52002-09-27 10:24:48 +00001715/* Can be useful for ensuring a skin's correctness. SK_(cheap_sanity_check)
1716 is called very frequently; SK_(expensive_sanity_check) is called less
1717 frequently and can be more involved. */
njn25e49d8e72002-09-23 09:36:25 +00001718extern Bool SK_(cheap_sanity_check) ( void );
1719extern Bool SK_(expensive_sanity_check) ( void );
1720
1721
1722#endif /* NDEF __VG_SKIN_H */
1723
1724/*--------------------------------------------------------------------*/
1725/*--- end vg_skin.h ---*/
1726/*--------------------------------------------------------------------*/
1727