blob: 04a0bd747027b87c786c0acca5bc1f2ab2398043 [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
njn0e1b5142003-04-15 14:58:06 +000011 Copyright (C) 2000-2003 Julian Seward
njn25e49d8e72002-09-23 09:36:25 +000012 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
njn3e884182003-04-15 13:03:23 +0000294/* Searches through all thread's stacks to see if any match. Returns
295 * VG_INVALID_THREADID if none match. */
296extern ThreadId VG_(first_matching_thread_stack)
297 ( Bool (*p) ( Addr stack_min, Addr stack_max ));
298
njn25e49d8e72002-09-23 09:36:25 +0000299
300/*====================================================================*/
301/*=== Valgrind's version of libc ===*/
302/*====================================================================*/
303
304/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
305 are its own versions of C library functions, but with VG_ prefixes. Note
306 that the types of some are slightly different to the real ones. Some
njnf4ce3d32003-02-10 10:17:26 +0000307 additional useful functions are provided too; descriptions of how they
308 work are given below. */
njn25e49d8e72002-09-23 09:36:25 +0000309
310#if !defined(NULL)
311# define NULL ((void*)0)
312#endif
313
314
315/* ------------------------------------------------------------------ */
316/* stdio.h
317 *
318 * Note that they all output to the file descriptor given by the
319 * --logfile-fd=N argument, which defaults to 2 (stderr). Hence no
320 * need for VG_(fprintf)().
njn25e49d8e72002-09-23 09:36:25 +0000321 */
sewardj78e3cd92002-10-22 04:45:48 +0000322extern UInt VG_(printf) ( const char *format, ... );
njn25e49d8e72002-09-23 09:36:25 +0000323/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
sewardj78e3cd92002-10-22 04:45:48 +0000324extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
325extern UInt VG_(vprintf) ( void(*send)(Char),
njn25e49d8e72002-09-23 09:36:25 +0000326 const Char *format, va_list vargs );
327
njn41557122002-10-14 09:25:37 +0000328extern Int VG_(rename) ( Char* old_name, Char* new_name );
329
njn25e49d8e72002-09-23 09:36:25 +0000330/* ------------------------------------------------------------------ */
331/* stdlib.h */
332
333extern void* VG_(malloc) ( Int nbytes );
njnd5bb0a52002-09-27 10:24:48 +0000334extern void VG_(free) ( void* p );
335extern void* VG_(calloc) ( Int n, Int nbytes );
336extern void* VG_(realloc) ( void* p, Int size );
337extern void* VG_(malloc_aligned) ( Int align_bytes, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000338
339extern void VG_(print_malloc_stats) ( void );
340
341
342extern void VG_(exit)( Int status )
343 __attribute__ ((__noreturn__));
njne427a662002-10-02 11:08:25 +0000344/* Prints a panic message (a constant string), appends newline and bug
345 reporting info, aborts. */
346__attribute__ ((__noreturn__))
347extern void VG_(skin_panic) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000348
njnd5bb0a52002-09-27 10:24:48 +0000349/* Looks up VG_(client_envp) */
njn25e49d8e72002-09-23 09:36:25 +0000350extern Char* VG_(getenv) ( Char* name );
351
352/* Crude stand-in for the glibc system() call. */
353extern Int VG_(system) ( Char* cmd );
354
njnd5bb0a52002-09-27 10:24:48 +0000355extern Long VG_(atoll) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000356
357/* Like atoll(), but converts a number of base 2..36 */
358extern Long VG_(atoll36) ( UInt base, Char* str );
359
360
361/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000362/* ctype.h */
njn25e49d8e72002-09-23 09:36:25 +0000363extern Bool VG_(isspace) ( Char c );
364extern Bool VG_(isdigit) ( Char c );
365extern Char VG_(toupper) ( Char c );
366
367
368/* ------------------------------------------------------------------ */
369/* string.h */
370extern Int VG_(strlen) ( const Char* str );
371extern Char* VG_(strcat) ( Char* dest, const Char* src );
372extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
373extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
374extern Char* VG_(strcpy) ( Char* dest, const Char* src );
375extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
376extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
377extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
378extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
379extern Char* VG_(strchr) ( const Char* s, Char c );
380extern Char* VG_(strdup) ( const Char* s);
sewardj7ab2aca2002-10-20 19:40:32 +0000381extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
382extern void* VG_(memset) ( void *s, Int c, Int sz );
njn6d68e792003-02-24 10:49:08 +0000383extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
njn25e49d8e72002-09-23 09:36:25 +0000384
njnd5bb0a52002-09-27 10:24:48 +0000385/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
njn25e49d8e72002-09-23 09:36:25 +0000386extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
njn25e49d8e72002-09-23 09:36:25 +0000387extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
388
njnd5bb0a52002-09-27 10:24:48 +0000389/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
390 last character. */
njn25e49d8e72002-09-23 09:36:25 +0000391extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
392
393/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
394 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
njn4ba5a792002-09-30 10:23:54 +0000395extern Bool VG_(string_match) ( Char* pat, Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000396
397
398/* ------------------------------------------------------------------ */
399/* math.h */
njnd5bb0a52002-09-27 10:24:48 +0000400/* Returns the base-2 logarithm of x. */
njn25e49d8e72002-09-23 09:36:25 +0000401extern Int VG_(log2) ( Int x );
402
403
404/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000405/* unistd.h, fcntl.h, sys/stat.h */
sewardj4cf05692002-10-27 20:28:29 +0000406extern Int VG_(getpid) ( void );
407extern Int VG_(getppid) ( void );
njnd5bb0a52002-09-27 10:24:48 +0000408
njn4aca2d22002-10-04 10:29:38 +0000409extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
410extern Int VG_(read) ( Int fd, void* buf, Int count);
411extern Int VG_(write) ( Int fd, void* buf, Int count);
412extern void VG_(close) ( Int fd );
njnd5bb0a52002-09-27 10:24:48 +0000413
njn41557122002-10-14 09:25:37 +0000414/* Nb: VG_(rename)() declared in stdio.h section above */
njn4aca2d22002-10-04 10:29:38 +0000415extern Int VG_(unlink) ( Char* file_name );
416extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
njn25e49d8e72002-09-23 09:36:25 +0000417
njn13f02932003-04-30 20:23:58 +0000418extern Char* VG_(getcwd) ( Char* buf, Int size );
419
njn25e49d8e72002-09-23 09:36:25 +0000420
421/* ------------------------------------------------------------------ */
422/* assert.h */
423/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
424#define VG__STRING(__str) #__str
425
njne427a662002-10-02 11:08:25 +0000426#define sk_assert(expr) \
njn25e49d8e72002-09-23 09:36:25 +0000427 ((void) ((expr) ? 0 : \
njne427a662002-10-02 11:08:25 +0000428 (VG_(skin_assert_fail) (VG__STRING(expr), \
429 __FILE__, __LINE__, \
430 __PRETTY_FUNCTION__), 0)))
njn25e49d8e72002-09-23 09:36:25 +0000431
njne427a662002-10-02 11:08:25 +0000432__attribute__ ((__noreturn__))
433extern void VG_(skin_assert_fail) ( Char* expr, Char* file,
434 Int line, Char* fn );
njn25e49d8e72002-09-23 09:36:25 +0000435
436
437/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000438/* system/mman.h */
njn25e49d8e72002-09-23 09:36:25 +0000439extern void* VG_(mmap)( void* start, UInt length,
440 UInt prot, UInt flags, UInt fd, UInt offset );
441extern Int VG_(munmap)( void* start, Int length );
442
443/* Get memory by anonymous mmap. */
444extern void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who );
445
446
447/* ------------------------------------------------------------------ */
448/* signal.h.
449
450 Note that these use the vk_ (kernel) structure
451 definitions, which are different in places from those that glibc
452 defines -- hence the 'k' prefix. Since we're operating right at the
453 kernel interface, glibc's view of the world is entirely irrelevant. */
454
455/* --- Signal set ops --- */
njnd5bb0a52002-09-27 10:24:48 +0000456extern Int VG_(ksigfillset) ( vki_ksigset_t* set );
457extern Int VG_(ksigemptyset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000458
njnd5bb0a52002-09-27 10:24:48 +0000459extern Bool VG_(kisfullsigset) ( vki_ksigset_t* set );
460extern Bool VG_(kisemptysigset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000461
njnd5bb0a52002-09-27 10:24:48 +0000462extern Int VG_(ksigaddset) ( vki_ksigset_t* set, Int signum );
463extern Int VG_(ksigdelset) ( vki_ksigset_t* set, Int signum );
njn25e49d8e72002-09-23 09:36:25 +0000464extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
465
njnd5bb0a52002-09-27 10:24:48 +0000466extern void VG_(ksigaddset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
467extern void VG_(ksigdelset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
njn25e49d8e72002-09-23 09:36:25 +0000468
469/* --- Mess with the kernel's sig state --- */
njnd5bb0a52002-09-27 10:24:48 +0000470extern Int VG_(ksigprocmask) ( Int how, const vki_ksigset_t* set,
njn25e49d8e72002-09-23 09:36:25 +0000471 vki_ksigset_t* oldset );
njnd5bb0a52002-09-27 10:24:48 +0000472extern Int VG_(ksigaction) ( Int signum,
473 const vki_ksigaction* act,
474 vki_ksigaction* oldact );
njn25e49d8e72002-09-23 09:36:25 +0000475
njnd5bb0a52002-09-27 10:24:48 +0000476extern Int VG_(ksignal) ( Int signum, void (*sighandler)(Int) );
477extern Int VG_(ksigaltstack) ( const vki_kstack_t* ss, vki_kstack_t* oss );
njn25e49d8e72002-09-23 09:36:25 +0000478
sewardjdcaf3122002-09-30 23:12:33 +0000479extern Int VG_(kkill) ( Int pid, Int signo );
480extern Int VG_(ksigpending) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000481
482
483/*====================================================================*/
484/*=== UCode definition ===*/
485/*====================================================================*/
486
sewardje1042472002-09-30 12:33:11 +0000487/* Tags which describe what operands are. Must fit into 4 bits, which
488 they clearly do. */
njn25e49d8e72002-09-23 09:36:25 +0000489typedef
sewardje1042472002-09-30 12:33:11 +0000490enum { TempReg =0, /* virtual temp-reg */
491 ArchReg =1, /* simulated integer reg */
492 ArchRegS =2, /* simulated segment reg */
493 RealReg =3, /* real machine's real reg */
494 SpillNo =4, /* spill slot location */
495 Literal =5, /* literal; .lit32 field has actual value */
496 Lit16 =6, /* literal; .val[123] field has actual value */
497 NoValue =7 /* operand not in use */
498 }
499 Tag;
njn25e49d8e72002-09-23 09:36:25 +0000500
njnd5bb0a52002-09-27 10:24:48 +0000501/* Invalid register numbers (can't be negative) */
njn25e49d8e72002-09-23 09:36:25 +0000502#define INVALID_TEMPREG 999999999
503#define INVALID_REALREG 999999999
504
505/* Microinstruction opcodes. */
506typedef
507 enum {
njnd5bb0a52002-09-27 10:24:48 +0000508 NOP, /* Null op */
njn25e49d8e72002-09-23 09:36:25 +0000509
sewardj7a5ebcf2002-11-13 22:42:13 +0000510 LOCK, /* Indicate the existance of a LOCK prefix (functionally NOP) */
511
njnd5bb0a52002-09-27 10:24:48 +0000512 /* Moving values around */
513 GET, PUT, /* simulated register <--> TempReg */
514 GETF, PUTF, /* simulated %eflags <--> TempReg */
515 LOAD, STORE, /* memory <--> TempReg */
516 MOV, /* TempReg <--> TempReg */
517 CMOV, /* Used for cmpxchg and cmov */
njn25e49d8e72002-09-23 09:36:25 +0000518
njnd5bb0a52002-09-27 10:24:48 +0000519 /* Arithmetic/logical ops */
520 ADD, ADC, SUB, SBB, /* Add/subtract (w/wo carry) */
521 AND, OR, XOR, NOT, /* Boolean ops */
522 SHL, SHR, SAR, ROL, ROR, RCL, RCR, /* Shift/rotate (w/wo carry) */
523 NEG, /* Negate */
524 INC, DEC, /* Increment/decrement */
525 BSWAP, /* Big-endian <--> little-endian */
526 CC2VAL, /* Condition code --> 0 or 1 */
527 WIDEN, /* Signed or unsigned widening */
njn25e49d8e72002-09-23 09:36:25 +0000528
njnd5bb0a52002-09-27 10:24:48 +0000529 /* Conditional or unconditional jump */
530 JMP,
531
532 /* FPU ops */
533 FPU, /* Doesn't touch memory */
534 FPU_R, FPU_W, /* Reads/writes memory */
535
sewardj3d7c9c82003-03-26 21:08:13 +0000536 /* ------------ MMX ops ------------ */
537
538 /* 1 byte, no memrefs, no iregdefs, copy exactly to the
539 output. Held in val1[7:0]. */
540 MMX1,
541
542 /* 2 bytes, no memrefs, no iregdefs, copy exactly to the
543 output. Held in val1[15:0]. */
544 MMX2,
545
546 /* 3 bytes, no memrefs, no iregdefs, copy exactly to the
547 output. Held in val1[15:0] and val2[7:0]. */
548 MMX3,
549
550 /* 2 bytes, reads/writes mem. Insns of the form
551 bbbbbbbb:mod mmxreg r/m.
552 Held in val1[15:0], and mod and rm are to be replaced
553 at codegen time by a reference to the Temp/RealReg holding
554 the address. Arg2 holds this Temp/Real Reg.
555 Transfer is always at size 8.
556 */
557 MMX2_MemRd,
558 MMX2_MemWr,
559
560 /* 2 bytes, reads/writes an integer register. Insns of the form
561 bbbbbbbb:11 mmxreg ireg.
562 Held in val1[15:0], and ireg is to be replaced
563 at codegen time by a reference to the relevant RealReg.
564 Transfer is always at size 4. Arg2 holds this Temp/Real Reg.
565 */
566 MMX2_RegRd,
567 MMX2_RegWr,
568
569 /* ------------------------ */
570
njnd5bb0a52002-09-27 10:24:48 +0000571 /* Not strictly needed, but improve address calculation translations. */
njn25e49d8e72002-09-23 09:36:25 +0000572 LEA1, /* reg2 := const + reg1 */
573 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
574
njnd5bb0a52002-09-27 10:24:48 +0000575 /* Hack for x86 REP insns. Jump to literal if TempReg/RealReg is zero. */
576 JIFZ,
njn25e49d8e72002-09-23 09:36:25 +0000577
njnd5bb0a52002-09-27 10:24:48 +0000578 /* Advance the simulated %eip by some small (< 128) number. */
579 INCEIP,
njn25e49d8e72002-09-23 09:36:25 +0000580
sewardje1042472002-09-30 12:33:11 +0000581 /* Dealing with segment registers */
582 GETSEG, PUTSEG, /* simulated segment register <--> TempReg */
583 USESEG, /* (LDT/GDT index, virtual addr) --> linear addr */
584
njnd5bb0a52002-09-27 10:24:48 +0000585 /* Not for translating x86 calls -- only to call helpers */
586 CALLM_S, CALLM_E, /* Mark start/end of CALLM push/pop sequence */
587 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers */
588 CALLM, /* Call assembly-code helper */
589
590 /* Not for translating x86 calls -- only to call C helper functions of
591 up to three arguments (or two if the functions has a return value).
592 Arguments and return value must be word-sized. More arguments can
593 be faked with global variables (eg. use VG_(set_global_var)()).
594
595 Seven possibilities: 'arg[123]' show where args go, 'ret' shows
596 where return value goes (if present).
njn25e49d8e72002-09-23 09:36:25 +0000597
598 CCALL(-, -, - ) void f(void)
599 CCALL(arg1, -, - ) void f(UInt arg1)
600 CCALL(arg1, arg2, - ) void f(UInt arg1, UInt arg2)
601 CCALL(arg1, arg2, arg3) void f(UInt arg1, UInt arg2, UInt arg3)
602 CCALL(-, -, ret ) UInt f(UInt)
603 CCALL(arg1, -, ret ) UInt f(UInt arg1)
njnd5bb0a52002-09-27 10:24:48 +0000604 CCALL(arg1, arg2, ret ) UInt f(UInt arg1, UInt arg2) */
njn25e49d8e72002-09-23 09:36:25 +0000605 CCALL,
606
njnd5bb0a52002-09-27 10:24:48 +0000607 /* This opcode makes it easy for skins that extend UCode to do this to
608 avoid opcode overlap:
njn25e49d8e72002-09-23 09:36:25 +0000609
njnd5bb0a52002-09-27 10:24:48 +0000610 enum { EU_OP1 = DUMMY_FINAL_UOPCODE + 1, ... }
njn25e49d8e72002-09-23 09:36:25 +0000611
612 WARNING: Do not add new opcodes after this one! They can be added
613 before, though. */
614 DUMMY_FINAL_UOPCODE
615 }
616 Opcode;
617
618
njnd5bb0a52002-09-27 10:24:48 +0000619/* Condition codes, using the Intel encoding. CondAlways is an extra. */
njn25e49d8e72002-09-23 09:36:25 +0000620typedef
621 enum {
622 CondO = 0, /* overflow */
623 CondNO = 1, /* no overflow */
624 CondB = 2, /* below */
625 CondNB = 3, /* not below */
626 CondZ = 4, /* zero */
627 CondNZ = 5, /* not zero */
628 CondBE = 6, /* below or equal */
629 CondNBE = 7, /* not below or equal */
630 CondS = 8, /* negative */
sewardje1042472002-09-30 12:33:11 +0000631 CondNS = 9, /* not negative */
njn25e49d8e72002-09-23 09:36:25 +0000632 CondP = 10, /* parity even */
633 CondNP = 11, /* not parity even */
634 CondL = 12, /* jump less */
635 CondNL = 13, /* not less */
636 CondLE = 14, /* less or equal */
637 CondNLE = 15, /* not less or equal */
638 CondAlways = 16 /* Jump always */
639 }
640 Condcode;
641
642
643/* Descriptions of additional properties of *unconditional* jumps. */
644typedef
645 enum {
646 JmpBoring=0, /* boring unconditional jump */
647 JmpCall=1, /* jump due to an x86 call insn */
648 JmpRet=2, /* jump due to an x86 ret insn */
649 JmpSyscall=3, /* do a system call, then jump */
650 JmpClientReq=4 /* do a client request, then jump */
651 }
652 JmpKind;
653
654
655/* Flags. User-level code can only read/write O(verflow), S(ign),
656 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
657 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
658 thusly:
659 76543210
660 DOSZACP
661 and bit 7 must always be zero since it is unused.
sewardj2370f3b2002-11-30 15:01:01 +0000662
663 Note: these Flag? values are **not** the positions in the actual
664 %eflags register. */
665
njn25e49d8e72002-09-23 09:36:25 +0000666typedef UChar FlagSet;
667
668#define FlagD (1<<6)
669#define FlagO (1<<5)
670#define FlagS (1<<4)
671#define FlagZ (1<<3)
672#define FlagA (1<<2)
673#define FlagC (1<<1)
674#define FlagP (1<<0)
675
676#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
677#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
678#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
679#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
680#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
681#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
682#define FlagsZCP ( FlagZ | FlagC | FlagP)
683#define FlagsOC (FlagO | FlagC )
684#define FlagsAC ( FlagA | FlagC )
685
686#define FlagsALL (FlagsOSZACP | FlagD)
687#define FlagsEmpty (FlagSet)0
688
689
sewardj2370f3b2002-11-30 15:01:01 +0000690/* flag positions in eflags */
691#define EFlagC (1 << 0) /* carry */
692#define EFlagP (1 << 2) /* parity */
sewardjfa492d42002-12-08 18:20:01 +0000693#define EFlagA (1 << 4) /* aux carry */
sewardj2370f3b2002-11-30 15:01:01 +0000694#define EFlagZ (1 << 6) /* zero */
695#define EFlagS (1 << 7) /* sign */
sewardjfa492d42002-12-08 18:20:01 +0000696#define EFlagD (1 << 10) /* direction */
sewardj2370f3b2002-11-30 15:01:01 +0000697#define EFlagO (1 << 11) /* overflow */
698
njn25e49d8e72002-09-23 09:36:25 +0000699/* Liveness of general purpose registers, useful for code generation.
700 Reg rank order 0..N-1 corresponds to bits 0..N-1, ie. first
701 reg's liveness in bit 0, last reg's in bit N-1. Note that
702 these rankings don't match the Intel register ordering. */
703typedef UInt RRegSet;
704
705#define ALL_RREGS_DEAD 0 /* 0000...00b */
njne7c258c2002-10-03 08:57:01 +0000706#define ALL_RREGS_LIVE ((1 << VG_MAX_REALREGS)-1) /* 0011...11b */
njn25e49d8e72002-09-23 09:36:25 +0000707#define UNIT_RREGSET(rank) (1 << (rank))
708
709#define IS_RREG_LIVE(rank,rregs_live) (rregs_live & UNIT_RREGSET(rank))
710#define SET_RREG_LIVENESS(rank,rregs_live,b) \
711 do { RRegSet unit = UNIT_RREGSET(rank); \
712 if (b) rregs_live |= unit; \
713 else rregs_live &= ~unit; \
714 } while(0)
715
716
717/* A Micro (u)-instruction. */
718typedef
719 struct {
720 /* word 1 */
721 UInt lit32; /* 32-bit literal */
722
723 /* word 2 */
724 UShort val1; /* first operand */
725 UShort val2; /* second operand */
726
727 /* word 3 */
728 UShort val3; /* third operand */
729 UChar opcode; /* opcode */
730 UChar size; /* data transfer size */
731
732 /* word 4 */
733 FlagSet flags_r; /* :: FlagSet */
734 FlagSet flags_w; /* :: FlagSet */
735 UChar tag1:4; /* first operand tag */
736 UChar tag2:4; /* second operand tag */
737 UChar tag3:4; /* third operand tag */
738 UChar extra4b:4; /* Spare field, used by WIDEN for src
739 -size, and by LEA2 for scale (1,2,4 or 8),
740 and by JMPs for original x86 instr size */
741
742 /* word 5 */
743 UChar cond; /* condition, for jumps */
744 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
745 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
746
747 /* Additional properties for UInstrs that call C functions:
748 - CCALL
749 - PUT (when %ESP is the target)
750 - possibly skin-specific UInstrs
751 */
752 UChar argc:2; /* Number of args, max 3 */
753 UChar regparms_n:2; /* Number of args passed in registers */
754 Bool has_ret_val:1; /* Function has return value? */
755
756 /* RealReg liveness; only sensical after reg alloc and liveness
757 analysis done. This info is a little bit arch-specific --
758 VG_MAX_REALREGS can vary on different architectures. Note that
759 to use this information requires converting between register ranks
njn4ba5a792002-09-30 10:23:54 +0000760 and the Intel register numbers, using VG_(realreg_to_rank)()
761 and/or VG_(rank_to_realreg)() */
njn25e49d8e72002-09-23 09:36:25 +0000762 RRegSet regs_live_after:VG_MAX_REALREGS;
763 }
764 UInstr;
765
766
njn25e49d8e72002-09-23 09:36:25 +0000767typedef
njn810086f2002-11-14 12:42:47 +0000768 struct _UCodeBlock
njn25e49d8e72002-09-23 09:36:25 +0000769 UCodeBlock;
770
njn810086f2002-11-14 12:42:47 +0000771extern Int VG_(get_num_instrs) (UCodeBlock* cb);
772extern Int VG_(get_num_temps) (UCodeBlock* cb);
njn25e49d8e72002-09-23 09:36:25 +0000773
njn810086f2002-11-14 12:42:47 +0000774extern UInstr* VG_(get_instr) (UCodeBlock* cb, Int i);
775extern UInstr* VG_(get_last_instr) (UCodeBlock* cb);
776
njn211b6ad2003-02-03 12:33:31 +0000777
njn25e49d8e72002-09-23 09:36:25 +0000778/*====================================================================*/
779/*=== Instrumenting UCode ===*/
780/*====================================================================*/
781
njnf4ce3d32003-02-10 10:17:26 +0000782/* Maximum number of registers read or written by a single UInstruction. */
783#define VG_MAX_REGS_USED 3
njn25e49d8e72002-09-23 09:36:25 +0000784
njnf4ce3d32003-02-10 10:17:26 +0000785/* Find what this instruction does to its regs, useful for
786 analysis/optimisation passes. `tag' indicates whether we're considering
787 TempRegs (pre-reg-alloc) or RealRegs (post-reg-alloc). `regs' is filled
788 with the affected register numbers, `isWrites' parallels it and indicates
789 if the reg is read or written. If a reg is read and written, it will
790 appear twice in `regs'. `regs' and `isWrites' must be able to fit
791 VG_MAX_REGS_USED elements. */
njn810086f2002-11-14 12:42:47 +0000792extern Int VG_(get_reg_usage) ( UInstr* u, Tag tag, Int* regs, Bool* isWrites );
njn25e49d8e72002-09-23 09:36:25 +0000793
794
njnd5bb0a52002-09-27 10:24:48 +0000795/* Used to register helper functions to be called from generated code. A
796 limited number of compact helpers can be registered; the code generated
797 to call them is slightly shorter -- so register the mostly frequently
798 called helpers as compact. */
njn25e49d8e72002-09-23 09:36:25 +0000799extern void VG_(register_compact_helper) ( Addr a );
800extern void VG_(register_noncompact_helper) ( Addr a );
801
802
803/* ------------------------------------------------------------------ */
804/* Virtual register allocation */
805
806/* Get a new virtual register */
njn4ba5a792002-09-30 10:23:54 +0000807extern Int VG_(get_new_temp) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000808
809/* Get a new virtual shadow register */
njn4ba5a792002-09-30 10:23:54 +0000810extern Int VG_(get_new_shadow) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000811
812/* Get a virtual register's corresponding virtual shadow register */
813#define SHADOW(tempreg) ((tempreg)+1)
814
815
816/* ------------------------------------------------------------------ */
817/* Low-level UInstr builders */
njn4ba5a792002-09-30 10:23:54 +0000818extern void VG_(new_NOP) ( UInstr* u );
819extern void VG_(new_UInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
820extern void VG_(new_UInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000821 Tag tag1, UInt val1 );
njn4ba5a792002-09-30 10:23:54 +0000822extern void VG_(new_UInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000823 Tag tag1, UInt val1,
824 Tag tag2, UInt val2 );
njn4ba5a792002-09-30 10:23:54 +0000825extern void VG_(new_UInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000826 Tag tag1, UInt val1,
827 Tag tag2, UInt val2,
828 Tag tag3, UInt val3 );
njn25e49d8e72002-09-23 09:36:25 +0000829
njn810086f2002-11-14 12:42:47 +0000830/* Set read/write/undefined flags. Undefined flags are treaten as written,
831 but it's worth keeping them logically distinct. */
832extern void VG_(set_flag_fields) ( UCodeBlock* cb, FlagSet fr, FlagSet fw,
833 FlagSet fu);
njn4ba5a792002-09-30 10:23:54 +0000834extern void VG_(set_lit_field) ( UCodeBlock* cb, UInt lit32 );
835extern void VG_(set_ccall_fields) ( UCodeBlock* cb, Addr fn, UChar argc,
836 UChar regparms_n, Bool has_ret_val );
njn810086f2002-11-14 12:42:47 +0000837extern void VG_(set_cond_field) ( UCodeBlock* cb, Condcode code );
njn25e49d8e72002-09-23 09:36:25 +0000838
njn4ba5a792002-09-30 10:23:54 +0000839extern void VG_(copy_UInstr) ( UCodeBlock* cb, UInstr* instr );
840
841extern Bool VG_(any_flag_use)( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +0000842
njnac6c1762002-10-04 14:34:15 +0000843/* Macro versions of the above; just shorter to type. */
844#define uInstr0 VG_(new_UInstr0)
845#define uInstr1 VG_(new_UInstr1)
846#define uInstr2 VG_(new_UInstr2)
847#define uInstr3 VG_(new_UInstr3)
848#define uLiteral VG_(set_lit_field)
849#define uCCall VG_(set_ccall_fields)
njn810086f2002-11-14 12:42:47 +0000850#define uCond VG_(set_cond_field)
851#define uFlagsRWU VG_(set_flag_fields)
njnac6c1762002-10-04 14:34:15 +0000852#define newTemp VG_(get_new_temp)
853#define newShadow VG_(get_new_shadow)
854
njn25e49d8e72002-09-23 09:36:25 +0000855/* Refer to `the last instruction stuffed in' (can be lvalue). */
856#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
857
858
859/* ------------------------------------------------------------------ */
860/* Higher-level UInstr sequence builders */
njn4ba5a792002-09-30 10:23:54 +0000861extern void VG_(call_helper_0_0) ( UCodeBlock* cb, Addr f);
862extern void VG_(call_helper_1_0) ( UCodeBlock* cb, Addr f, UInt arg1,
863 UInt regparms_n);
864extern void VG_(call_helper_2_0) ( UCodeBlock* cb, Addr f, UInt arg1, UInt arg2,
865 UInt regparms_n);
njn25e49d8e72002-09-23 09:36:25 +0000866
867/* One way around the 3-arg C function limit is to pass args via global
njn6fefa1b2003-02-24 10:32:51 +0000868 * variables... ugly, but it works. This one puts a literal in there. */
njn4ba5a792002-09-30 10:23:54 +0000869extern void VG_(set_global_var) ( UCodeBlock* cb, Addr globvar_ptr, UInt val);
njn25e49d8e72002-09-23 09:36:25 +0000870
njn6fefa1b2003-02-24 10:32:51 +0000871/* This one puts the contents of a TempReg in the global variable. */
872extern void VG_(set_global_var_tempreg) ( UCodeBlock* cb, Addr globvar_ptr,
873 UInt t_val);
874
njn25e49d8e72002-09-23 09:36:25 +0000875/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000876/* Allocating/freeing basic blocks of UCode */
njn810086f2002-11-14 12:42:47 +0000877extern UCodeBlock* VG_(setup_UCodeBlock) ( UCodeBlock* cb );
njn4ba5a792002-09-30 10:23:54 +0000878extern void VG_(free_UCodeBlock) ( UCodeBlock* cb );
njnd5bb0a52002-09-27 10:24:48 +0000879
880/* ------------------------------------------------------------------ */
881/* UCode pretty/ugly printing. Probably only useful to call from a skin
njn25e49d8e72002-09-23 09:36:25 +0000882 if VG_(needs).extended_UCode == True. */
883
884/* When True, all generated code is/should be printed. */
885extern Bool VG_(print_codegen);
886
njn4ba5a792002-09-30 10:23:54 +0000887/* Pretty/ugly printing functions */
888extern void VG_(pp_UCodeBlock) ( UCodeBlock* cb, Char* title );
889extern void VG_(pp_UInstr) ( Int instrNo, UInstr* u );
890extern void VG_(pp_UInstr_regs) ( Int instrNo, UInstr* u );
891extern void VG_(up_UInstr) ( Int instrNo, UInstr* u );
892extern Char* VG_(name_UOpcode) ( Bool upper, Opcode opc );
njn563f96f2003-02-03 11:17:46 +0000893extern Char* VG_(name_UCondcode) ( Condcode cond );
njn4ba5a792002-09-30 10:23:54 +0000894extern void VG_(pp_UOperand) ( UInstr* u, Int operandNo,
895 Int sz, Bool parens );
njn25e49d8e72002-09-23 09:36:25 +0000896
njnb93d1782003-02-03 12:03:22 +0000897/* ------------------------------------------------------------------ */
njnf4ce3d32003-02-10 10:17:26 +0000898/* Accessing archregs and their shadows */
899extern UInt VG_(get_archreg) ( UInt archreg );
900extern UInt VG_(get_thread_archreg) ( ThreadId tid, UInt archreg );
901
njnb93d1782003-02-03 12:03:22 +0000902extern UInt VG_(get_shadow_archreg) ( UInt archreg );
903extern void VG_(set_shadow_archreg) ( UInt archreg, UInt val );
904extern Addr VG_(shadow_archreg_address) ( UInt archreg );
njn25e49d8e72002-09-23 09:36:25 +0000905
njnf4ce3d32003-02-10 10:17:26 +0000906extern UInt VG_(get_thread_shadow_archreg) ( ThreadId tid, UInt archreg );
907extern void VG_(set_thread_shadow_archreg) ( ThreadId tid, UInt archreg,
908 UInt val );
njn211b6ad2003-02-03 12:33:31 +0000909
910/* ------------------------------------------------------------------ */
911/* Offsets of addresses of helper functions. A "helper" function is one
912 which is called from generated code via CALLM. */
913
914extern Int VGOFF_(helper_idiv_64_32);
915extern Int VGOFF_(helper_div_64_32);
916extern Int VGOFF_(helper_idiv_32_16);
917extern Int VGOFF_(helper_div_32_16);
918extern Int VGOFF_(helper_idiv_16_8);
919extern Int VGOFF_(helper_div_16_8);
920
921extern Int VGOFF_(helper_imul_32_64);
922extern Int VGOFF_(helper_mul_32_64);
923extern Int VGOFF_(helper_imul_16_32);
924extern Int VGOFF_(helper_mul_16_32);
925extern Int VGOFF_(helper_imul_8_16);
926extern Int VGOFF_(helper_mul_8_16);
927
928extern Int VGOFF_(helper_CLD);
929extern Int VGOFF_(helper_STD);
930extern Int VGOFF_(helper_get_dirflag);
931
932extern Int VGOFF_(helper_CLC);
933extern Int VGOFF_(helper_STC);
934
935extern Int VGOFF_(helper_shldl);
936extern Int VGOFF_(helper_shldw);
937extern Int VGOFF_(helper_shrdl);
938extern Int VGOFF_(helper_shrdw);
939
940extern Int VGOFF_(helper_RDTSC);
941extern Int VGOFF_(helper_CPUID);
942
943extern Int VGOFF_(helper_bsf);
944extern Int VGOFF_(helper_bsr);
945
946extern Int VGOFF_(helper_fstsw_AX);
947extern Int VGOFF_(helper_SAHF);
948extern Int VGOFF_(helper_DAS);
949extern Int VGOFF_(helper_DAA);
950
951
njn25e49d8e72002-09-23 09:36:25 +0000952/*====================================================================*/
njnd5bb0a52002-09-27 10:24:48 +0000953/*=== Generating x86 code from UCode ===*/
njn25e49d8e72002-09-23 09:36:25 +0000954/*====================================================================*/
955
njnd5bb0a52002-09-27 10:24:48 +0000956/* All this only necessary for skins with VG_(needs).extends_UCode == True. */
njn25e49d8e72002-09-23 09:36:25 +0000957
sewardje1042472002-09-30 12:33:11 +0000958/* This is the Intel register encoding -- integer regs. */
njn25e49d8e72002-09-23 09:36:25 +0000959#define R_EAX 0
960#define R_ECX 1
961#define R_EDX 2
962#define R_EBX 3
963#define R_ESP 4
964#define R_EBP 5
965#define R_ESI 6
966#define R_EDI 7
967
968#define R_AL (0+R_EAX)
969#define R_CL (0+R_ECX)
970#define R_DL (0+R_EDX)
971#define R_BL (0+R_EBX)
972#define R_AH (4+R_EAX)
973#define R_CH (4+R_ECX)
974#define R_DH (4+R_EDX)
975#define R_BH (4+R_EBX)
976
sewardje1042472002-09-30 12:33:11 +0000977/* This is the Intel register encoding -- segment regs. */
978#define R_ES 0
979#define R_CS 1
980#define R_SS 2
981#define R_DS 3
982#define R_FS 4
983#define R_GS 5
984
njn25e49d8e72002-09-23 09:36:25 +0000985/* For pretty printing x86 code */
sewardj3d7c9c82003-03-26 21:08:13 +0000986extern Char* VG_(name_of_mmx_gran) ( UChar gran );
987extern Char* VG_(name_of_mmx_reg) ( Int mmxreg );
sewardje1042472002-09-30 12:33:11 +0000988extern Char* VG_(name_of_seg_reg) ( Int sreg );
njn4ba5a792002-09-30 10:23:54 +0000989extern Char* VG_(name_of_int_reg) ( Int size, Int reg );
990extern Char VG_(name_of_int_size) ( Int size );
njn25e49d8e72002-09-23 09:36:25 +0000991
njnac6c1762002-10-04 14:34:15 +0000992/* Shorter macros for convenience */
sewardj3d7c9c82003-03-26 21:08:13 +0000993#define nameIReg VG_(name_of_int_reg)
994#define nameISize VG_(name_of_int_size)
995#define nameSReg VG_(name_of_seg_reg)
996#define nameMMXReg VG_(name_of_mmx_reg)
997#define nameMMXGran VG_(name_of_mmx_gran)
njnac6c1762002-10-04 14:34:15 +0000998
njn25e49d8e72002-09-23 09:36:25 +0000999/* Randomly useful things */
1000extern UInt VG_(extend_s_8to32) ( UInt x );
1001
1002/* Code emitters */
njn4ba5a792002-09-30 10:23:54 +00001003extern void VG_(emitB) ( UInt b );
1004extern void VG_(emitW) ( UInt w );
1005extern void VG_(emitL) ( UInt l );
sewardjfa492d42002-12-08 18:20:01 +00001006extern void VG_(new_emit) ( Bool upd_cc, FlagSet uses_flags, FlagSet sets_flags );
njn25e49d8e72002-09-23 09:36:25 +00001007
1008/* Finding offsets */
njn4ba5a792002-09-30 10:23:54 +00001009extern Int VG_(helper_offset) ( Addr a );
1010extern Int VG_(shadow_reg_offset) ( Int arch );
1011extern Int VG_(shadow_flags_offset) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001012
njnd5bb0a52002-09-27 10:24:48 +00001013/* Convert reg ranks <-> Intel register ordering, for using register
1014 liveness information. */
njn4ba5a792002-09-30 10:23:54 +00001015extern Int VG_(realreg_to_rank) ( Int realreg );
1016extern Int VG_(rank_to_realreg) ( Int rank );
njn25e49d8e72002-09-23 09:36:25 +00001017
njnd5bb0a52002-09-27 10:24:48 +00001018/* Call a subroutine. Does no argument passing, stack manipulations, etc. */
sewardjfa492d42002-12-08 18:20:01 +00001019extern void VG_(synth_call) ( Bool ensure_shortform, Int word_offset,
1020 Bool upd_cc, FlagSet use_flags, FlagSet set_flags );
njn25e49d8e72002-09-23 09:36:25 +00001021
njnd5bb0a52002-09-27 10:24:48 +00001022/* For calling C functions -- saves caller save regs, pushes args, calls,
1023 clears the stack, restores caller save regs. `fn' must be registered in
1024 the baseBlock first. Acceptable tags are RealReg and Literal. Optimises
1025 things, eg. by not preserving non-live caller-save registers.
njn25e49d8e72002-09-23 09:36:25 +00001026
njnd5bb0a52002-09-27 10:24:48 +00001027 WARNING: a UInstr should *not* be translated with synth_ccall() followed
1028 by some other x86 assembly code; this will invalidate the results of
1029 vg_realreg_liveness_analysis() and everything will fall over. */
njn4ba5a792002-09-30 10:23:54 +00001030extern void VG_(synth_ccall) ( Addr fn, Int argc, Int regparms_n, UInt argv[],
1031 Tag tagv[], Int ret_reg,
1032 RRegSet regs_live_before,
1033 RRegSet regs_live_after );
njn25e49d8e72002-09-23 09:36:25 +00001034
1035/* Addressing modes */
njn4ba5a792002-09-30 10:23:54 +00001036extern void VG_(emit_amode_offregmem_reg)( Int off, Int regmem, Int reg );
1037extern void VG_(emit_amode_ereg_greg) ( Int e_reg, Int g_reg );
njn25e49d8e72002-09-23 09:36:25 +00001038
1039/* v-size (4, or 2 with OSO) insn emitters */
njn4ba5a792002-09-30 10:23:54 +00001040extern void VG_(emit_movv_offregmem_reg) ( Int sz, Int off, Int areg, Int reg );
1041extern void VG_(emit_movv_reg_offregmem) ( Int sz, Int reg, Int off, Int areg );
1042extern void VG_(emit_movv_reg_reg) ( Int sz, Int reg1, Int reg2 );
sewardjfa492d42002-12-08 18:20:01 +00001043extern void VG_(emit_nonshiftopv_lit_reg)( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001044 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001045extern void VG_(emit_shiftopv_lit_reg) ( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001046 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001047extern void VG_(emit_nonshiftopv_reg_reg)( Bool upd_cc, Int sz, Opcode opc,
njn4ba5a792002-09-30 10:23:54 +00001048 Int reg1, Int reg2 );
1049extern void VG_(emit_movv_lit_reg) ( Int sz, UInt lit, Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001050extern void VG_(emit_unaryopv_reg) ( Bool upd_cc, Int sz, Opcode opc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001051extern void VG_(emit_pushv_reg) ( Int sz, Int reg );
1052extern void VG_(emit_popv_reg) ( Int sz, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001053
njn4ba5a792002-09-30 10:23:54 +00001054extern void VG_(emit_pushl_lit32) ( UInt int32 );
1055extern void VG_(emit_pushl_lit8) ( Int lit8 );
sewardjfa492d42002-12-08 18:20:01 +00001056extern void VG_(emit_cmpl_zero_reg) ( Bool upd_cc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001057extern void VG_(emit_swapl_reg_EAX) ( Int reg );
1058extern void VG_(emit_movv_lit_offregmem) ( Int sz, UInt lit, Int off,
1059 Int memreg );
njn25e49d8e72002-09-23 09:36:25 +00001060
1061/* b-size (1 byte) instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001062extern void VG_(emit_movb_lit_offregmem) ( UInt lit, Int off, Int memreg );
1063extern void VG_(emit_movb_reg_offregmem) ( Int reg, Int off, Int areg );
sewardjfa492d42002-12-08 18:20:01 +00001064extern void VG_(emit_unaryopb_reg) ( Bool upd_cc, Opcode opc, Int reg );
1065extern void VG_(emit_testb_lit_reg) ( Bool upd_cc, UInt lit, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001066
1067/* zero-extended load emitters */
njn4ba5a792002-09-30 10:23:54 +00001068extern void VG_(emit_movzbl_offregmem_reg) ( Int off, Int regmem, Int reg );
1069extern void VG_(emit_movzwl_offregmem_reg) ( Int off, Int areg, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001070
1071/* misc instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001072extern void VG_(emit_call_reg) ( Int reg );
1073extern void VG_(emit_add_lit_to_esp) ( Int lit );
njn4ba5a792002-09-30 10:23:54 +00001074extern void VG_(emit_pushal) ( void );
1075extern void VG_(emit_popal) ( void );
1076extern void VG_(emit_AMD_prefetch_reg) ( Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001077
sewardja2113f92002-12-12 23:42:48 +00001078/* jump emitters */
1079extern void VG_(init_target) ( Int *tgt );
1080
1081extern void VG_(target_back) ( Int *tgt );
1082extern void VG_(target_forward) ( Int *tgt );
1083extern void VG_(emit_target_delta) ( Int *tgt );
1084
1085extern void VG_(emit_jcondshort_delta) ( Bool simd_cc, Condcode cond, Int delta );
1086extern void VG_(emit_jcondshort_target)( Bool simd_cc, Condcode cond, Int *tgt );
1087
njn25e49d8e72002-09-23 09:36:25 +00001088
1089/*====================================================================*/
1090/*=== Execution contexts ===*/
1091/*====================================================================*/
1092
1093/* Generic resolution type used in a few different ways, such as deciding
1094 how closely to compare two errors for equality. */
1095typedef
1096 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
1097 VgRes;
1098
1099typedef
1100 struct _ExeContext
1101 ExeContext;
1102
njnd5bb0a52002-09-27 10:24:48 +00001103/* Compare two ExeContexts. Number of callers considered depends on `res':
1104 Vg_LowRes: 2
1105 Vg_MedRes: 4
1106 Vg_HighRes: all */
njn25e49d8e72002-09-23 09:36:25 +00001107extern Bool VG_(eq_ExeContext) ( VgRes res,
1108 ExeContext* e1, ExeContext* e2 );
1109
1110/* Print an ExeContext. */
1111extern void VG_(pp_ExeContext) ( ExeContext* );
1112
1113/* Take a snapshot of the client's stack. Search our collection of
1114 ExeContexts to see if we already have it, and if not, allocate a
1115 new one. Either way, return a pointer to the context. */
1116extern ExeContext* VG_(get_ExeContext) ( ThreadState *tst );
1117
sewardj499e3de2002-11-13 22:22:25 +00001118/* Just grab the client's EIP, as a much smaller and cheaper
1119 indication of where they are. */
1120extern Addr VG_(get_EIP)( ThreadState *tst );
njn25e49d8e72002-09-23 09:36:25 +00001121
njn211b6ad2003-02-03 12:33:31 +00001122
njn25e49d8e72002-09-23 09:36:25 +00001123/*====================================================================*/
1124/*=== Error reporting ===*/
1125/*====================================================================*/
1126
1127/* ------------------------------------------------------------------ */
1128/* Suppressions describe errors which we want to suppress, ie, not
1129 show the user, usually because it is caused by a problem in a library
1130 which we can't fix, replace or work around. Suppressions are read from
njnd5bb0a52002-09-27 10:24:48 +00001131 a file at startup time. This gives flexibility so that new
njn25e49d8e72002-09-23 09:36:25 +00001132 suppressions can be added to the file as and when needed.
1133*/
1134
1135typedef
1136 Int /* Do not make this unsigned! */
1137 SuppKind;
1138
njn810086f2002-11-14 12:42:47 +00001139/* The skin-relevant parts of a suppression are:
1140 kind: what kind of suppression; must be in the range (0..)
1141 string: use is optional. NULL by default.
1142 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001143*/
1144typedef
njn810086f2002-11-14 12:42:47 +00001145 struct _Supp
1146 Supp;
1147
1148/* Useful in SK_(error_matches_suppression)() */
1149SuppKind VG_(get_supp_kind) ( Supp* su );
1150Char* VG_(get_supp_string) ( Supp* su );
1151void* VG_(get_supp_extra) ( Supp* su );
1152
1153/* Must be used in VG_(recognised_suppression)() */
1154void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
1155/* May be used in VG_(read_extra_suppression_info)() */
1156void VG_(set_supp_string) ( Supp* su, Char* string );
1157void VG_(set_supp_extra) ( Supp* su, void* extra );
njn25e49d8e72002-09-23 09:36:25 +00001158
1159
1160/* ------------------------------------------------------------------ */
1161/* Error records contain enough info to generate an error report. The idea
1162 is that (typically) the same few points in the program generate thousands
njnd5bb0a52002-09-27 10:24:48 +00001163 of errors, and we don't want to spew out a fresh error message for each
1164 one. Instead, we use these structures to common up duplicates.
njn25e49d8e72002-09-23 09:36:25 +00001165*/
1166
1167typedef
1168 Int /* Do not make this unsigned! */
1169 ErrorKind;
1170
njn810086f2002-11-14 12:42:47 +00001171/* The skin-relevant parts of an Error are:
1172 kind: what kind of error; must be in the range (0..)
1173 addr: use is optional. 0 by default.
1174 string: use is optional. NULL by default.
1175 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001176*/
1177typedef
njn810086f2002-11-14 12:42:47 +00001178 struct _Error
1179 Error;
njn25e49d8e72002-09-23 09:36:25 +00001180
njn810086f2002-11-14 12:42:47 +00001181/* Useful in SK_(error_matches_suppression)(), SK_(pp_SkinError)(), etc */
njnb877d492003-01-28 20:40:57 +00001182ExeContext* VG_(get_error_where) ( Error* err );
1183SuppKind VG_(get_error_kind) ( Error* err );
1184Addr VG_(get_error_address) ( Error* err );
1185Char* VG_(get_error_string) ( Error* err );
1186void* VG_(get_error_extra) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001187
njnd5bb0a52002-09-27 10:24:48 +00001188/* Call this when an error occurs. It will be recorded if it hasn't been
njn25e49d8e72002-09-23 09:36:25 +00001189 seen before. If it has, the existing error record will have its count
1190 incremented.
1191
1192 If the error occurs in generated code, 'tst' should be NULL. If the
1193 error occurs in non-generated code, 'tst' should be non-NULL. The
njn43c799e2003-04-08 00:08:52 +00001194 `extra' field can be stack-allocated; it will be copied by the core
1195 if needed. But it won't be copied if it's NULL.
njnd5bb0a52002-09-27 10:24:48 +00001196
1197 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
njn3e884182003-04-15 13:03:23 +00001198 NULL for them. */
njn25e49d8e72002-09-23 09:36:25 +00001199extern void VG_(maybe_record_error) ( ThreadState* tst, ErrorKind ekind,
1200 Addr a, Char* s, void* extra );
1201
njn43c799e2003-04-08 00:08:52 +00001202/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
1203 error -- useful for errors that can only happen once. The errors can be
1204 suppressed, though. Return value is True if it was suppressed.
1205 `print_error' dictates whether to print the error, which is a bit of a
1206 hack that's useful sometimes if you just want to know if the error would
njn47363ab2003-04-21 13:24:40 +00001207 be suppressed without possibly printing it. `count_error' dictates
1208 whether to add the error in the error total count (another mild hack). */
njn43c799e2003-04-08 00:08:52 +00001209extern Bool VG_(unique_error) ( ThreadState* tst, ErrorKind ekind,
1210 Addr a, Char* s, void* extra,
njn3e884182003-04-15 13:03:23 +00001211 ExeContext* where, Bool print_error,
njn47363ab2003-04-21 13:24:40 +00001212 Bool allow_GDB_attach, Bool count_error );
njn43c799e2003-04-08 00:08:52 +00001213
njn25e49d8e72002-09-23 09:36:25 +00001214/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
1215 Skips leading spaces on the line. Returns True if EOF was hit instead.
njn3e884182003-04-15 13:03:23 +00001216 Useful for reading in extra skin-specific suppression lines. */
njn4ba5a792002-09-30 10:23:54 +00001217extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
njn25e49d8e72002-09-23 09:36:25 +00001218
njn3e884182003-04-15 13:03:23 +00001219/* Client request: write a string to the logging sink. */
1220#define VG_USERREQ__LOGMESSAGE 0x3103
1221
njn25e49d8e72002-09-23 09:36:25 +00001222
1223/*====================================================================*/
1224/*=== Obtaining debug information ===*/
1225/*====================================================================*/
1226
sewardj6e008cb2002-12-15 13:11:39 +00001227/* Get the file/function/line number of the instruction at address
1228 'a'. For these four, if debug info for the address is found, it
1229 copies the info into the buffer/UInt and returns True. If not, it
1230 returns False and nothing is copied. VG_(get_fnname) always
1231 demangles C++ function names. VG_(get_fnname_w_offset) is the
njn3e884182003-04-15 13:03:23 +00001232 same, except it appends "+N" to symbol names to indicate offsets. */
njn25e49d8e72002-09-23 09:36:25 +00001233extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
1234extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
1235extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
sewardj6e008cb2002-12-15 13:11:39 +00001236extern Bool VG_(get_fnname_w_offset)
1237 ( Addr a, Char* fnname, Int n_fnname );
njn25e49d8e72002-09-23 09:36:25 +00001238
1239/* This one is more efficient if getting both filename and line number,
1240 because the two lookups are done together. */
1241extern Bool VG_(get_filename_linenum)
1242 ( Addr a, Char* filename, Int n_filename,
1243 UInt* linenum );
1244
1245/* Succeeds only if we find from debug info that 'a' is the address of the
1246 first instruction in a function -- as opposed to VG_(get_fnname) which
1247 succeeds if we find from debug info that 'a' is the address of any
1248 instruction in a function. Use this to instrument the start of
njnd5bb0a52002-09-27 10:24:48 +00001249 a particular function. Nb: if an executable/shared object is stripped
njn25e49d8e72002-09-23 09:36:25 +00001250 of its symbols, this function will not be able to recognise function
1251 entry points within it. */
1252extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* filename, Int n_filename );
1253
1254/* Succeeds if the address is within a shared object or the main executable.
1255 It doesn't matter if debug info is present or not. */
1256extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
1257
sewardj47104382002-10-20 18:35:48 +00001258/* A way to get information about what segments are mapped */
1259typedef struct _SegInfo SegInfo;
1260
njnb877d492003-01-28 20:40:57 +00001261/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
1262 is present or not. */
1263extern SegInfo* VG_(get_obj) ( Addr a );
1264
1265extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
1266extern Addr VG_(seg_start) ( const SegInfo *seg );
1267extern UInt VG_(seg_size) ( const SegInfo *seg );
1268extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
1269extern UInt VG_(seg_sym_offset)( const SegInfo *seg );
sewardj47104382002-10-20 18:35:48 +00001270
1271typedef
1272 enum {
1273 Vg_SectUnknown,
1274 Vg_SectText,
sewardj8fe15a32002-10-20 19:29:21 +00001275 Vg_SectData,
1276 Vg_SectBSS,
sewardj47104382002-10-20 18:35:48 +00001277 Vg_SectGOT,
sewardj8fe15a32002-10-20 19:29:21 +00001278 Vg_SectPLT,
sewardj47104382002-10-20 18:35:48 +00001279 }
1280 VgSectKind;
1281
1282extern VgSectKind VG_(seg_sect_kind)(Addr);
1283
njn25e49d8e72002-09-23 09:36:25 +00001284
1285/*====================================================================*/
njn3e884182003-04-15 13:03:23 +00001286/*=== Generic hash table ===*/
njn25e49d8e72002-09-23 09:36:25 +00001287/*====================================================================*/
1288
njn3e884182003-04-15 13:03:23 +00001289/* Generic type for a separately-chained hash table. Via a kind of dodgy
1290 C-as-C++ style inheritance, skins can extend the VgHashNode type, so long
1291 as the first two fields match the sizes of these two fields. Requires
1292 a bit of casting by the skin. */
njn25e49d8e72002-09-23 09:36:25 +00001293typedef
njn3e884182003-04-15 13:03:23 +00001294 struct _VgHashNode {
1295 struct _VgHashNode * next;
1296 UInt key;
1297 }
1298 VgHashNode;
njn25e49d8e72002-09-23 09:36:25 +00001299
njn3e884182003-04-15 13:03:23 +00001300typedef
1301 VgHashNode**
1302 VgHashTable;
njn810086f2002-11-14 12:42:47 +00001303
njn3e884182003-04-15 13:03:23 +00001304/* Make a new table. */
1305extern VgHashTable VG_(HT_construct) ( void );
1306
1307/* Add a node to the table. */
1308extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
1309
1310/* Looks up a node in the hash table. Also returns the address of the
1311 previous node's `next' pointer which allows it to be removed from the
1312 list later without having to look it up again. */
1313extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UInt key,
1314 /*OUT*/VgHashNode*** next_ptr );
1315
1316/* Allocates a sorted array of pointers to all the shadow chunks of malloc'd
1317 blocks. */
1318extern VgHashNode** VG_(HT_to_sorted_array) ( VgHashTable t,
1319 /*OUT*/ UInt* n_shadows );
1320
1321/* Returns first node that matches predicate `p', or NULL if none do.
1322 Extra arguments can be implicitly passed to `p' using nested functions;
1323 see memcheck/mc_errcontext.c for an example. */
1324extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
1325 Bool (*p)(VgHashNode*) );
1326
1327/* Applies a function f() once to each node. Again, nested functions
1328 can be very useful. */
1329extern void VG_(HT_apply_to_all_nodes)( VgHashTable t, void (*f)(VgHashNode*) );
1330
1331/* Destroy a table. */
1332extern void VG_(HT_destruct) ( VgHashTable t );
njn810086f2002-11-14 12:42:47 +00001333
1334
njn3e884182003-04-15 13:03:23 +00001335/*====================================================================*/
1336/*=== General stuff for replacing functions ===*/
1337/*====================================================================*/
njn25e49d8e72002-09-23 09:36:25 +00001338
njn3e884182003-04-15 13:03:23 +00001339/* Some skins need to replace the standard definitions of some functions. */
njn25e49d8e72002-09-23 09:36:25 +00001340
njn3e884182003-04-15 13:03:23 +00001341/* ------------------------------------------------------------------ */
1342/* General stuff, for replacing any functions */
njn25e49d8e72002-09-23 09:36:25 +00001343
njn3e884182003-04-15 13:03:23 +00001344/* Is the client running on the simulated CPU or the real one?
njn25e49d8e72002-09-23 09:36:25 +00001345
njn3e884182003-04-15 13:03:23 +00001346 Nb: If it is, and you want to call a function to be run on the real CPU,
njn057c65f2003-04-21 13:30:55 +00001347 use one of the VALGRIND_NON_SIMD_CALL[123] macros in valgrind.h to call it.
njn25e49d8e72002-09-23 09:36:25 +00001348
njn3e884182003-04-15 13:03:23 +00001349 Nb: don't forget the function parentheses when using this in a
1350 condition... write this:
1351
1352 if (VG_(is_running_on_simd_CPU)()) { ... } // calls function
1353
1354 not this:
1355
1356 if (VG_(is_running_on_simd_CPU)) { ... } // address of var!
1357*/
1358extern Bool VG_(is_running_on_simd_CPU) ( void );
1359
1360
1361/*====================================================================*/
1362/*=== Specific stuff for replacing malloc() and friends ===*/
1363/*====================================================================*/
1364
1365/* ------------------------------------------------------------------ */
1366/* Replacing malloc() and friends */
1367
1368/* If a skin replaces malloc() et al, the easiest way to do so is to link
1369 with coregrind/vg_replace_malloc.c, and follow the following instructions.
1370 You can do it from scratch, though, if you enjoy that sort of thing. */
1371
1372/* Arena size for valgrind's own malloc(); default value is 0, but can
1373 be overridden by skin -- but must be done so *statically*, eg:
1374
1375 Int VG_(vg_malloc_redzone_szB) = 4;
1376
1377 It can't be done from a function like SK_(pre_clo_init)(). So it can't,
1378 for example, be controlled with a command line option, unfortunately. */
1379extern UInt VG_(vg_malloc_redzone_szB);
1380
1381/* If a skin links with vg_replace_malloc.c, the following functions will be
1382 called appropriately when malloc() et al are called. */
1383extern void* SK_(malloc) ( ThreadState* tst, Int n );
1384extern void* SK_(__builtin_new) ( ThreadState* tst, Int n );
1385extern void* SK_(__builtin_vec_new) ( ThreadState* tst, Int n );
1386extern void* SK_(memalign) ( ThreadState* tst, Int align, Int n );
1387extern void* SK_(calloc) ( ThreadState* tst, Int nmemb, Int n );
1388extern void SK_(free) ( ThreadState* tst, void* p );
1389extern void SK_(__builtin_delete) ( ThreadState* tst, void* p );
1390extern void SK_(__builtin_vec_delete) ( ThreadState* tst, void* p );
1391extern void* SK_(realloc) ( ThreadState* tst, void* p, Int size );
1392
1393/* Can be called from SK_(malloc) et al to do the actual alloc/freeing. */
1394extern void* VG_(cli_malloc) ( UInt align, Int nbytes );
1395extern void VG_(cli_free) ( void* p );
1396
1397/* Check if an address is within a range, allowing for redzones at edges */
1398extern Bool VG_(addr_is_in_block)( Addr a, Addr start, UInt size );
1399
1400/* ------------------------------------------------------------------ */
1401/* Some options that can be used by a skin if malloc() et al are replaced.
1402 The skin should use the VG_(process...)() and VG_(print...)() functions
1403 to give control over these aspects of Valgrind's version of malloc(). */
1404
1405/* Round malloc sizes upwards to integral number of words? default: NO */
1406extern Bool VG_(clo_sloppy_malloc);
1407/* DEBUG: print malloc details? default: NO */
1408extern Bool VG_(clo_trace_malloc);
1409/* Minimum alignment in functions that don't specify alignment explicitly.
1410 default: 0, i.e. use default of the machine (== 4) */
1411extern Int VG_(clo_alignment);
1412
1413extern Bool VG_(replacement_malloc_process_cmd_line_option) ( Char* arg );
1414extern void VG_(replacement_malloc_print_usage) ( void );
1415extern void VG_(replacement_malloc_print_debug_usage) ( void );
sewardja4495682002-10-21 07:29:59 +00001416
1417
njn25e49d8e72002-09-23 09:36:25 +00001418/*====================================================================*/
1419/*=== Skin-specific stuff ===*/
1420/*====================================================================*/
1421
njnd04b7c62002-10-03 14:05:52 +00001422/* ------------------------------------------------------------------ */
1423/* Details */
njnd04b7c62002-10-03 14:05:52 +00001424
njn120281f2003-02-03 12:20:07 +00001425/* Default value for avg_translations_sizeB (in bytes), indicating typical
1426 code expansion of about 6:1. */
1427#define VG_DEFAULT_TRANS_SIZEB 100
1428
njn810086f2002-11-14 12:42:47 +00001429/* Information used in the startup message. `name' also determines the
1430 string used for identifying suppressions in a suppression file as
1431 belonging to this skin. `version' can be NULL, in which case (not
1432 surprisingly) no version info is printed; this mechanism is designed for
1433 skins distributed with Valgrind that share a version number with
1434 Valgrind. Other skins not distributed as part of Valgrind should
sewardjc0d8f682002-11-30 00:49:43 +00001435 probably have their own version number. */
1436extern void VG_(details_name) ( Char* name );
1437extern void VG_(details_version) ( Char* version );
1438extern void VG_(details_description) ( Char* description );
1439extern void VG_(details_copyright_author) ( Char* copyright_author );
1440
1441/* Average size of a translation, in bytes, so that the translation
njn120281f2003-02-03 12:20:07 +00001442 storage machinery can allocate memory appropriately. Not critical,
1443 setting is optional. */
1444extern void VG_(details_avg_translation_sizeB) ( UInt size );
njnd04b7c62002-10-03 14:05:52 +00001445
njn810086f2002-11-14 12:42:47 +00001446/* String printed if an `sk_assert' assertion fails or VG_(skin_panic)
1447 is called. Should probably be an email address. */
1448extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
njnd04b7c62002-10-03 14:05:52 +00001449
1450/* ------------------------------------------------------------------ */
1451/* Needs */
1452
njn810086f2002-11-14 12:42:47 +00001453/* Booleans that decide core behaviour, but don't require extra
1454 operations to be defined if `True' */
njnd5bb0a52002-09-27 10:24:48 +00001455
njn810086f2002-11-14 12:42:47 +00001456/* Should __libc_freeres() be run? Bugs in it can crash the skin. */
1457extern void VG_(needs_libc_freeres) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001458
njn810086f2002-11-14 12:42:47 +00001459/* Want to have errors detected by Valgrind's core reported? Includes:
1460 - pthread API errors (many; eg. unlocking a non-locked mutex)
njn810086f2002-11-14 12:42:47 +00001461 - invalid file descriptors to blocking syscalls read() and write()
1462 - bad signal numbers passed to sigaction()
1463 - attempt to install signal handler for SIGKILL or SIGSTOP */
1464extern void VG_(needs_core_errors) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001465
njn810086f2002-11-14 12:42:47 +00001466/* Booleans that indicate extra operations are defined; if these are True,
1467 the corresponding template functions (given below) must be defined. A
1468 lot like being a member of a type class. */
njn25e49d8e72002-09-23 09:36:25 +00001469
njn810086f2002-11-14 12:42:47 +00001470/* Want to report errors from skin? This implies use of suppressions, too. */
1471extern void VG_(needs_skin_errors) ( void );
njnd5bb0a52002-09-27 10:24:48 +00001472
njn810086f2002-11-14 12:42:47 +00001473/* Is information kept about specific individual basic blocks? (Eg. for
1474 cachegrind there are cost-centres for every instruction, stored at a
1475 basic block level.) If so, it sometimes has to be discarded, because
1476 .so mmap/munmap-ping or self-modifying code (informed by the
1477 DISCARD_TRANSLATIONS user request) can cause one instruction address
1478 to be used for more than one instruction in one program run... */
1479extern void VG_(needs_basic_block_discards) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001480
njn810086f2002-11-14 12:42:47 +00001481/* Skin maintains information about each register? */
1482extern void VG_(needs_shadow_regs) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001483
njn810086f2002-11-14 12:42:47 +00001484/* Skin defines its own command line options? */
1485extern void VG_(needs_command_line_options) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001486
njn810086f2002-11-14 12:42:47 +00001487/* Skin defines its own client requests? */
1488extern void VG_(needs_client_requests) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001489
njn810086f2002-11-14 12:42:47 +00001490/* Skin defines its own UInstrs? */
1491extern void VG_(needs_extended_UCode) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001492
njn810086f2002-11-14 12:42:47 +00001493/* Skin does stuff before and/or after system calls? */
1494extern void VG_(needs_syscall_wrapper) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001495
njn810086f2002-11-14 12:42:47 +00001496/* Are skin-state sanity checks performed? */
1497extern void VG_(needs_sanity_checks) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001498
njn810086f2002-11-14 12:42:47 +00001499/* Do we need to see data symbols? */
1500extern void VG_(needs_data_syms) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001501
1502/* ------------------------------------------------------------------ */
1503/* Core events to track */
1504
1505/* Part of the core from which this call was made. Useful for determining
njnd5bb0a52002-09-27 10:24:48 +00001506 what kind of error message should be emitted. */
njn25e49d8e72002-09-23 09:36:25 +00001507typedef
1508 enum { Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall, Vg_CoreTranslate }
1509 CorePart;
1510
njn810086f2002-11-14 12:42:47 +00001511#define EV extern void
njn25e49d8e72002-09-23 09:36:25 +00001512
njn810086f2002-11-14 12:42:47 +00001513/* Events happening in core to track. To be notified, pass a callback
1514 function to the appropriate function. To ignore an event, don't do
1515 anything (default is for events to be ignored). */
1516
njn810086f2002-11-14 12:42:47 +00001517
njn3e884182003-04-15 13:03:23 +00001518/* Memory events (Nb: to track heap allocation/freeing, a skin must replace
1519 malloc() et al. See above how to do this.) */
1520
1521/* These ones occur at startup, upon some signals, and upon some syscalls */
njn810086f2002-11-14 12:42:47 +00001522EV VG_(track_new_mem_startup) ( void (*f)(Addr a, UInt len,
1523 Bool rr, Bool ww, Bool xx) );
njn810086f2002-11-14 12:42:47 +00001524EV VG_(track_new_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1525EV VG_(track_new_mem_brk) ( void (*f)(Addr a, UInt len) );
1526EV VG_(track_new_mem_mmap) ( void (*f)(Addr a, UInt len,
1527 Bool rr, Bool ww, Bool xx) );
1528
njn3e884182003-04-15 13:03:23 +00001529EV VG_(track_copy_mem_remap) ( void (*f)(Addr from, Addr to, UInt len) );
1530EV VG_(track_change_mem_mprotect) ( void (*f)(Addr a, UInt len,
1531 Bool rr, Bool ww, Bool xx) );
1532EV VG_(track_die_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1533EV VG_(track_die_mem_brk) ( void (*f)(Addr a, UInt len) );
1534EV VG_(track_die_mem_munmap) ( void (*f)(Addr a, UInt len) );
1535
1536
1537/* These ones are called when %esp changes. A skin could track these itself
1538 (except for ban_mem_stack) but it's much easier to use the core's help.
1539
1540 The specialised ones are called in preference to the general one, if they
njn9b007f62003-04-07 14:40:25 +00001541 are defined. These functions are called a lot if they are used, so
1542 specialising can optimise things significantly. If any of the
1543 specialised cases are defined, the general case must be defined too.
1544
1545 Nb: they must all use the __attribute__((regparm(n))) attribute. */
1546EV VG_(track_new_mem_stack_4) ( void (*f)(Addr new_ESP) );
1547EV VG_(track_new_mem_stack_8) ( void (*f)(Addr new_ESP) );
1548EV VG_(track_new_mem_stack_12) ( void (*f)(Addr new_ESP) );
1549EV VG_(track_new_mem_stack_16) ( void (*f)(Addr new_ESP) );
1550EV VG_(track_new_mem_stack_32) ( void (*f)(Addr new_ESP) );
1551EV VG_(track_new_mem_stack) ( void (*f)(Addr a, UInt len) );
1552
njn9b007f62003-04-07 14:40:25 +00001553EV VG_(track_die_mem_stack_4) ( void (*f)(Addr die_ESP) );
1554EV VG_(track_die_mem_stack_8) ( void (*f)(Addr die_ESP) );
1555EV VG_(track_die_mem_stack_12) ( void (*f)(Addr die_ESP) );
1556EV VG_(track_die_mem_stack_16) ( void (*f)(Addr die_ESP) );
1557EV VG_(track_die_mem_stack_32) ( void (*f)(Addr die_ESP) );
1558EV VG_(track_die_mem_stack) ( void (*f)(Addr a, UInt len) );
1559
njn3e884182003-04-15 13:03:23 +00001560/* Used for redzone at end of thread stacks */
1561EV VG_(track_ban_mem_stack) ( void (*f)(Addr a, UInt len) );
njn25e49d8e72002-09-23 09:36:25 +00001562
njn3e884182003-04-15 13:03:23 +00001563/* These ones occur around syscalls, signal handling, etc */
njn810086f2002-11-14 12:42:47 +00001564EV VG_(track_pre_mem_read) ( void (*f)(CorePart part, ThreadState* tst,
1565 Char* s, Addr a, UInt size) );
1566EV VG_(track_pre_mem_read_asciiz) ( void (*f)(CorePart part, ThreadState* tst,
1567 Char* s, Addr a) );
1568EV VG_(track_pre_mem_write) ( void (*f)(CorePart part, ThreadState* tst,
1569 Char* s, Addr a, UInt size) );
1570/* Not implemented yet -- have to add in lots of places, which is a
1571 pain. Won't bother unless/until there's a need. */
1572/* EV VG_(track_post_mem_read) ( void (*f)(ThreadState* tst, Char* s,
1573 Addr a, UInt size) ); */
1574EV VG_(track_post_mem_write) ( void (*f)(Addr a, UInt size) );
njn25e49d8e72002-09-23 09:36:25 +00001575
1576
njn810086f2002-11-14 12:42:47 +00001577/* Scheduler events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001578
njn810086f2002-11-14 12:42:47 +00001579EV VG_(track_thread_run) ( void (*f)(ThreadId tid) );
njn25e49d8e72002-09-23 09:36:25 +00001580
njn810086f2002-11-14 12:42:47 +00001581/* Thread events (not exhaustive) */
sewardjdca84112002-11-13 22:29:34 +00001582
njn810086f2002-11-14 12:42:47 +00001583/* Called during thread create, before the new thread has run any
1584 instructions (or touched any memory). */
1585EV VG_(track_post_thread_create)( void (*f)(ThreadId tid, ThreadId child) );
1586/* Called once the joinee thread is terminated and the joining thread is
1587 about to resume. */
1588EV VG_(track_post_thread_join) ( void (*f)(ThreadId joiner, ThreadId joinee) );
njn25e49d8e72002-09-23 09:36:25 +00001589
njnd5bb0a52002-09-27 10:24:48 +00001590
njn810086f2002-11-14 12:42:47 +00001591/* Mutex events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001592
njn810086f2002-11-14 12:42:47 +00001593/* Called before a thread can block while waiting for a mutex (called
1594 regardless of whether the thread will block or not). */
1595EV VG_(track_pre_mutex_lock) ( void (*f)(ThreadId tid,
1596 void* /*pthread_mutex_t* */ mutex) );
1597/* Called once the thread actually holds the mutex (always paired with
1598 pre_mutex_lock). */
1599EV VG_(track_post_mutex_lock) ( void (*f)(ThreadId tid,
1600 void* /*pthread_mutex_t* */ mutex) );
1601/* Called after a thread has released a mutex (no need for a corresponding
1602 pre_mutex_unlock, because unlocking can't block). */
1603EV VG_(track_post_mutex_unlock) ( void (*f)(ThreadId tid,
1604 void* /*pthread_mutex_t* */ mutex) );
njn25e49d8e72002-09-23 09:36:25 +00001605
njn1045b0a2003-02-24 10:42:47 +00001606
1607/* Signal events (not exhaustive) */
1608
1609/* Called before a signal is delivered; `alt_stack' indicates if it is
1610 delivered on an alternative stack. */
1611EV VG_(track_pre_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum,
1612 Bool alt_stack) );
1613/* Called after a signal is delivered. */
1614EV VG_(track_post_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum ) );
1615
1616
1617/* Others... condition variables... */
njn810086f2002-11-14 12:42:47 +00001618/* ... */
1619
1620#undef EV
njn25e49d8e72002-09-23 09:36:25 +00001621
1622/* ------------------------------------------------------------------ */
1623/* Template functions */
1624
1625/* These are the parameterised functions in the core. The default definitions
njnd5bb0a52002-09-27 10:24:48 +00001626 are overridden by LD_PRELOADed skin version. At the very least, a skin
1627 must define the fundamental template functions. Depending on what needs
1628 are set, extra template functions will be used too. Functions are
1629 grouped under the needs that govern their use. */
njn25e49d8e72002-09-23 09:36:25 +00001630
1631
1632/* ------------------------------------------------------------------ */
1633/* Fundamental template functions */
1634
1635/* Initialise skin. Must do the following:
njn810086f2002-11-14 12:42:47 +00001636 - initialise the `details' struct, via the VG_(details_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001637 - register any helpers called by generated code
1638
1639 May do the following:
njn810086f2002-11-14 12:42:47 +00001640 - initialise the `needs' struct to indicate certain requirements, via
1641 the VG_(needs_*)() functions
1642 - initialise the `track' struct to indicate core events of interest, via
1643 the VG_(track_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001644 - register any skin-specific profiling events
1645 - any other skin-specific initialisation
1646*/
njn810086f2002-11-14 12:42:47 +00001647extern void SK_(pre_clo_init) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001648
njnd5bb0a52002-09-27 10:24:48 +00001649/* Do initialisation that can only be done after command line processing. */
njn25e49d8e72002-09-23 09:36:25 +00001650extern void SK_(post_clo_init)( void );
1651
1652/* Instrument a basic block. Must be a true function, ie. the same input
1653 always results in the same output, because basic blocks can be
1654 retranslated. Unless you're doing something really strange...
1655 'orig_addr' is the address of the first instruction in the block. */
1656extern UCodeBlock* SK_(instrument) ( UCodeBlock* cb, Addr orig_addr );
1657
njn7d9f94d2003-04-22 21:41:40 +00001658/* Finish up, print out any results, etc. `exitcode' is program's exit
1659 code. The shadow (if the `shadow_regs' need is set) can be found with
1660 VG_(get_shadow_archreg)(R_EBX), since %ebx holds the argument to the
1661 exit() syscall. */
1662extern void SK_(fini) ( Int exitcode );
njn25e49d8e72002-09-23 09:36:25 +00001663
1664
1665/* ------------------------------------------------------------------ */
1666/* VG_(needs).report_errors */
1667
1668/* Identify if two errors are equal, or equal enough. `res' indicates how
1669 close is "close enough". `res' should be passed on as necessary, eg. if
njn810086f2002-11-14 12:42:47 +00001670 the Error's `extra' part contains an ExeContext, `res' should be
njn25e49d8e72002-09-23 09:36:25 +00001671 passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other
1672 than that, probably don't worry about it unless you have lots of very
1673 similar errors occurring.
1674 */
njn810086f2002-11-14 12:42:47 +00001675extern Bool SK_(eq_SkinError) ( VgRes res, Error* e1, Error* e2 );
njn25e49d8e72002-09-23 09:36:25 +00001676
njn43c799e2003-04-08 00:08:52 +00001677/* Print error context. */
1678extern void SK_(pp_SkinError) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001679
njn43c799e2003-04-08 00:08:52 +00001680/* Should fill in any details that could be postponed until after the
njn810086f2002-11-14 12:42:47 +00001681 decision whether to ignore the error (ie. details not affecting the
1682 result of SK_(eq_SkinError)()). This saves time when errors are ignored.
njn25e49d8e72002-09-23 09:36:25 +00001683 Yuk.
njn43c799e2003-04-08 00:08:52 +00001684
1685 Return value: must be the size of the `extra' part in bytes -- used by
1686 the core to make a copy.
njn25e49d8e72002-09-23 09:36:25 +00001687*/
njn43c799e2003-04-08 00:08:52 +00001688extern UInt SK_(update_extra) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001689
njn810086f2002-11-14 12:42:47 +00001690/* Return value indicates recognition. If recognised, must set skind using
1691 VG_(set_supp_kind)(). */
1692extern Bool SK_(recognised_suppression) ( Char* name, Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001693
njn810086f2002-11-14 12:42:47 +00001694/* Read any extra info for this suppression kind. Most likely for filling
1695 in the `extra' and `string' parts (with VG_(set_supp_{extra,string})())
1696 of a suppression if necessary. Should return False if a syntax error
1697 occurred, True otherwise. */
1698extern Bool SK_(read_extra_suppression_info) ( Int fd, Char* buf, Int nBuf,
1699 Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001700
1701/* This should just check the kinds match and maybe some stuff in the
njn810086f2002-11-14 12:42:47 +00001702 `string' and `extra' field if appropriate (using VG_(get_supp_*)() to
1703 get the relevant suppression parts). */
njn43c799e2003-04-08 00:08:52 +00001704extern Bool SK_(error_matches_suppression) ( Error* err, Supp* su );
1705
1706/* This should return the suppression name, for --gen-suppressions, or NULL
1707 if that error type cannot be suppressed. This is the inverse of
1708 SK_(recognised_suppression)(). */
1709extern Char* SK_(get_error_name) ( Error* err );
1710
1711/* This should print any extra info for the error, for --gen-suppressions,
1712 including the newline. This is the inverse of
1713 SK_(read_extra_suppression_info)(). */
1714extern void SK_(print_extra_suppression_info) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001715
1716
1717/* ------------------------------------------------------------------ */
1718/* VG_(needs).basic_block_discards */
1719
njnd5bb0a52002-09-27 10:24:48 +00001720/* Should discard any information that pertains to specific basic blocks
1721 or instructions within the address range given. */
njn25e49d8e72002-09-23 09:36:25 +00001722extern void SK_(discard_basic_block_info) ( Addr a, UInt size );
1723
1724
1725/* ------------------------------------------------------------------ */
1726/* VG_(needs).shadow_regs */
1727
1728/* Valid values for general registers and EFLAGS register, for initialising
1729 and updating registers when written in certain places in core. */
1730extern void SK_(written_shadow_regs_values) ( UInt* gen_reg, UInt* eflags );
1731
1732
1733/* ------------------------------------------------------------------ */
1734/* VG_(needs).command_line_options */
1735
njnd5bb0a52002-09-27 10:24:48 +00001736/* Return True if option was recognised. Presumably sets some state to
1737 record the option as well. */
1738extern Bool SK_(process_cmd_line_option) ( Char* argv );
njn25e49d8e72002-09-23 09:36:25 +00001739
njn3e884182003-04-15 13:03:23 +00001740/* Print out command line usage for options for normal skin operation. */
1741extern void SK_(print_usage) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001742
njn3e884182003-04-15 13:03:23 +00001743/* Print out command line usage for options for debugging the skin. */
1744extern void SK_(print_debug_usage) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001745
1746/* ------------------------------------------------------------------ */
1747/* VG_(needs).client_requests */
1748
sewardj34042512002-10-22 04:14:35 +00001749extern Bool SK_(handle_client_request) ( ThreadState* tst, UInt* arg_block, UInt *ret );
njn25e49d8e72002-09-23 09:36:25 +00001750
1751
1752/* ------------------------------------------------------------------ */
1753/* VG_(needs).extends_UCode */
1754
njn4ba5a792002-09-30 10:23:54 +00001755/* Useful to use in VG_(get_Xreg_usage)() */
njn810086f2002-11-14 12:42:47 +00001756#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
njn25e49d8e72002-09-23 09:36:25 +00001757 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00001758 { regs[n] = mycat(u->val,ono); \
1759 isWrites[n] = False; \
njn25e49d8e72002-09-23 09:36:25 +00001760 n++; \
1761 } \
1762 }
njn810086f2002-11-14 12:42:47 +00001763#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
njnd5bb0a52002-09-27 10:24:48 +00001764 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00001765 { regs[n] = mycat(u->val,ono); \
1766 isWrites[n] = True; \
njnd5bb0a52002-09-27 10:24:48 +00001767 n++; \
1768 } \
njn25e49d8e72002-09-23 09:36:25 +00001769 }
1770
njn4ba5a792002-09-30 10:23:54 +00001771/* 'X' prefix indicates eXtended UCode. */
njn810086f2002-11-14 12:42:47 +00001772extern Int SK_(get_Xreg_usage) ( UInstr* u, Tag tag, Int* regs,
1773 Bool* isWrites );
njn4ba5a792002-09-30 10:23:54 +00001774extern void SK_(emit_XUInstr) ( UInstr* u, RRegSet regs_live_before );
1775extern Bool SK_(sane_XUInstr) ( Bool beforeRA, Bool beforeLiveness,
njn25e49d8e72002-09-23 09:36:25 +00001776 UInstr* u );
njn4ba5a792002-09-30 10:23:54 +00001777extern Char* SK_(name_XUOpcode) ( Opcode opc );
1778extern void SK_(pp_XUInstr) ( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +00001779
1780
1781/* ------------------------------------------------------------------ */
1782/* VG_(needs).syscall_wrapper */
1783
1784/* If either of the pre_ functions malloc() something to return, the
1785 * corresponding post_ function had better free() it!
1786 */
1787extern void* SK_( pre_syscall) ( ThreadId tid, UInt syscallno,
1788 Bool is_blocking );
1789extern void SK_(post_syscall) ( ThreadId tid, UInt syscallno,
1790 void* pre_result, Int res,
1791 Bool is_blocking );
1792
njnd5bb0a52002-09-27 10:24:48 +00001793
njn25e49d8e72002-09-23 09:36:25 +00001794/* ---------------------------------------------------------------------
1795 VG_(needs).sanity_checks */
1796
njnd5bb0a52002-09-27 10:24:48 +00001797/* Can be useful for ensuring a skin's correctness. SK_(cheap_sanity_check)
1798 is called very frequently; SK_(expensive_sanity_check) is called less
1799 frequently and can be more involved. */
njn25e49d8e72002-09-23 09:36:25 +00001800extern Bool SK_(cheap_sanity_check) ( void );
1801extern Bool SK_(expensive_sanity_check) ( void );
1802
1803
1804#endif /* NDEF __VG_SKIN_H */
1805
1806/*--------------------------------------------------------------------*/
1807/*--- end vg_skin.h ---*/
1808/*--------------------------------------------------------------------*/
1809