blob: 0101eaa248b96d035cf5c5231a3528f2634fe175 [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
daywalker5d945de2003-09-26 00:32:53 +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
daywalker5d945de2003-09-26 00:32:53 +000045/* You should be able to change these options or sizes, recompile, and
njn25e49d8e72002-09-23 09:36:25 +000046 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. */
sewardj989dad92003-07-06 01:52:32 +000053#define VG_N_THREADS 100
njn25e49d8e72002-09-23 09:36:25 +000054
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).
daywalker5d945de2003-09-26 00:32:53 +000061
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.
daywalker5d945de2003-09-26 00:32:53 +000071
njn25e49d8e72002-09-23 09:36:25 +000072 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
njn78adbf42003-07-24 19:35:00 +0000108#include "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*/
jseward157689b2003-11-05 23:59:21 +0000119#define VG_CORE_INTERFACE_MAJOR_VERSION 5
njn9b007f62003-04-07 14:40:25 +0000120#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, /* '?' == '-' */
fitzhardinge39de4b42003-10-31 07:12:21 +0000173 Vg_DebugExtraMsg, /* '?' == '+' */
174 Vg_ClientMsg, /* '?' == '*' */
njn25e49d8e72002-09-23 09:36:25 +0000175 }
176 VgMsgKind;
177
178/* Functions for building a message from multiple parts. */
fitzhardinge39de4b42003-10-31 07:12:21 +0000179extern int VG_(start_msg) ( VgMsgKind kind );
180extern int VG_(add_to_msg) ( Char* format, ... );
njn25e49d8e72002-09-23 09:36:25 +0000181/* Ends and prints the message. Appends a newline. */
fitzhardinge39de4b42003-10-31 07:12:21 +0000182extern int VG_(end_msg) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000183
njnd5bb0a52002-09-27 10:24:48 +0000184/* Send a single-part message. Appends a newline. */
fitzhardinge39de4b42003-10-31 07:12:21 +0000185extern int VG_(message) ( VgMsgKind kind, Char* format, ... );
186extern int VG_(vmessage) ( VgMsgKind kind, Char* format, va_list vargs );
njn25e49d8e72002-09-23 09:36:25 +0000187
188
189/*====================================================================*/
190/*=== Profiling ===*/
191/*====================================================================*/
192
193/* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */
194#define VGP_CORE_LIST \
195 /* These ones depend on the core */ \
196 VGP_PAIR(VgpUnc, "unclassified"), \
197 VGP_PAIR(VgpRun, "running"), \
198 VGP_PAIR(VgpSched, "scheduler"), \
199 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
200 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
njn25e49d8e72002-09-23 09:36:25 +0000201 VGP_PAIR(VgpTranslate, "translate-main"), \
202 VGP_PAIR(VgpToUCode, "to-ucode"), \
203 VGP_PAIR(VgpFromUcode, "from-ucode"), \
204 VGP_PAIR(VgpImprove, "improve"), \
njn9b007f62003-04-07 14:40:25 +0000205 VGP_PAIR(VgpESPUpdate, "ESP-update"), \
njn25e49d8e72002-09-23 09:36:25 +0000206 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
207 VGP_PAIR(VgpLiveness, "liveness-analysis"), \
208 VGP_PAIR(VgpDoLRU, "do-lru"), \
209 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
210 VGP_PAIR(VgpInitMem, "init-memory"), \
211 VGP_PAIR(VgpExeContext, "exe-context"), \
212 VGP_PAIR(VgpReadSyms, "read-syms"), \
213 VGP_PAIR(VgpSearchSyms, "search-syms"), \
214 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
215 VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
216 VGP_PAIR(VgpDemangle, "demangle"), \
njn37cea302002-09-30 11:24:00 +0000217 VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
218 VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000219 /* These ones depend on the skin */ \
220 VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
221 VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
222 VGP_PAIR(VgpInstrument, "instrument"), \
223 VGP_PAIR(VgpSkinSysWrap, "skin-syscall-wrapper"), \
njn37cea302002-09-30 11:24:00 +0000224 VGP_PAIR(VgpSkinCheapSanity, "skin-cheap-sanity"), \
225 VGP_PAIR(VgpSkinExpensiveSanity, "skin-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000226 VGP_PAIR(VgpFini, "fini")
227
228#define VGP_PAIR(n,name) n
229typedef enum { VGP_CORE_LIST } VgpCoreCC;
230#undef VGP_PAIR
231
232/* When registering skin profiling events, ensure that the 'n' value is in
233 * the range (VgpFini+1..) */
234extern void VGP_(register_profile_event) ( Int n, Char* name );
235
236extern void VGP_(pushcc) ( UInt cc );
237extern void VGP_(popcc) ( UInt cc );
238
239/* Define them only if they haven't already been defined by vg_profile.c */
240#ifndef VGP_PUSHCC
241# define VGP_PUSHCC(x)
242#endif
243#ifndef VGP_POPCC
244# define VGP_POPCC(x)
245#endif
246
247
248/*====================================================================*/
249/*=== Useful stuff to call from generated code ===*/
250/*====================================================================*/
251
252/* ------------------------------------------------------------------ */
253/* General stuff */
254
njn41557122002-10-14 09:25:37 +0000255/* 64-bit counter for the number of basic blocks done. */
256extern ULong VG_(bbs_done);
257
njn25e49d8e72002-09-23 09:36:25 +0000258/* Get the simulated %esp */
259extern Addr VG_(get_stack_pointer) ( void );
260
sewardjecf8e102003-07-12 12:11:39 +0000261/* Detect if an address is within Valgrind's stack, Valgrind's
262 m_state_static, or the VG_(threads) array. This is useful for
263 memory leak detectors to rule out spurious pointers to a block. */
njn25e49d8e72002-09-23 09:36:25 +0000264extern Bool VG_(within_stack)(Addr a);
sewardjecf8e102003-07-12 12:11:39 +0000265extern Bool VG_(within_m_state_static_OR_threads)(Addr a);
njn25e49d8e72002-09-23 09:36:25 +0000266
267/* Check if an address is 4-byte aligned */
268#define IS_ALIGNED4_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 3))
njn9b007f62003-04-07 14:40:25 +0000269#define IS_ALIGNED8_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 7))
njn25e49d8e72002-09-23 09:36:25 +0000270
271
272/* ------------------------------------------------------------------ */
273/* Thread-related stuff */
274
275/* Special magic value for an invalid ThreadId. It corresponds to
276 LinuxThreads using zero as the initial value for
277 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
278#define VG_INVALID_THREADID ((ThreadId)(0))
279
njn72718642003-07-24 08:45:32 +0000280/* ThreadIds are simply indices into the VG_(threads)[] array. */
daywalker5d945de2003-09-26 00:32:53 +0000281typedef
282 UInt
njn25e49d8e72002-09-23 09:36:25 +0000283 ThreadId;
284
njn72718642003-07-24 08:45:32 +0000285/* When looking for the current ThreadId, this is the safe option and
286 probably the one you want.
daywalker5d945de2003-09-26 00:32:53 +0000287
njn72718642003-07-24 08:45:32 +0000288 Details: Use this one from non-generated code, eg. from functions called
289 on events like 'new_mem_heap'. In such a case, the "current" thread is
290 temporarily suspended as Valgrind's dispatcher is running. This function
291 is also suitable to be called from generated code (ie. from UCode, or a C
292 function called directly from UCode).
daywalker5d945de2003-09-26 00:32:53 +0000293
njn72718642003-07-24 08:45:32 +0000294 If you use VG_(get_current_tid)() from non-generated code, it will return
295 0 signifying the invalid thread, which is probably not what you want. */
296extern ThreadId VG_(get_current_or_recent_tid) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000297
njn72718642003-07-24 08:45:32 +0000298/* When looking for the current ThreadId, only use this one if you know what
299 you are doing.
daywalker5d945de2003-09-26 00:32:53 +0000300
njn72718642003-07-24 08:45:32 +0000301 Details: Use this one from generated code, eg. from C functions called
302 from UCode. (VG_(get_current_or_recent_tid)() is also suitable in that
303 case.) If you use this function from non-generated code, it will return
304 0 signifying the invalid thread, which is probably not what you want. */
305extern ThreadId VG_(get_current_tid) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000306
njn3e884182003-04-15 13:03:23 +0000307/* Searches through all thread's stacks to see if any match. Returns
njn72718642003-07-24 08:45:32 +0000308 VG_INVALID_THREADID if none match. */
njn3e884182003-04-15 13:03:23 +0000309extern ThreadId VG_(first_matching_thread_stack)
310 ( Bool (*p) ( Addr stack_min, Addr stack_max ));
311
njn25e49d8e72002-09-23 09:36:25 +0000312
313/*====================================================================*/
314/*=== Valgrind's version of libc ===*/
315/*====================================================================*/
316
317/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
318 are its own versions of C library functions, but with VG_ prefixes. Note
319 that the types of some are slightly different to the real ones. Some
njnf4ce3d32003-02-10 10:17:26 +0000320 additional useful functions are provided too; descriptions of how they
321 work are given below. */
njn25e49d8e72002-09-23 09:36:25 +0000322
323#if !defined(NULL)
324# define NULL ((void*)0)
325#endif
326
327
328/* ------------------------------------------------------------------ */
329/* stdio.h
330 *
331 * Note that they all output to the file descriptor given by the
332 * --logfile-fd=N argument, which defaults to 2 (stderr). Hence no
daywalker5d945de2003-09-26 00:32:53 +0000333 * need for VG_(fprintf)().
njn25e49d8e72002-09-23 09:36:25 +0000334 */
sewardj78e3cd92002-10-22 04:45:48 +0000335extern UInt VG_(printf) ( const char *format, ... );
njn25e49d8e72002-09-23 09:36:25 +0000336/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
sewardj78e3cd92002-10-22 04:45:48 +0000337extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
daywalker5d945de2003-09-26 00:32:53 +0000338extern UInt VG_(vprintf) ( void(*send)(Char),
njn25e49d8e72002-09-23 09:36:25 +0000339 const Char *format, va_list vargs );
340
njn41557122002-10-14 09:25:37 +0000341extern Int VG_(rename) ( Char* old_name, Char* new_name );
342
njn25e49d8e72002-09-23 09:36:25 +0000343/* ------------------------------------------------------------------ */
344/* stdlib.h */
345
346extern void* VG_(malloc) ( Int nbytes );
njnd5bb0a52002-09-27 10:24:48 +0000347extern void VG_(free) ( void* p );
348extern void* VG_(calloc) ( Int n, Int nbytes );
349extern void* VG_(realloc) ( void* p, Int size );
350extern void* VG_(malloc_aligned) ( Int align_bytes, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000351
352extern void VG_(print_malloc_stats) ( void );
353
354
355extern void VG_(exit)( Int status )
356 __attribute__ ((__noreturn__));
njne427a662002-10-02 11:08:25 +0000357/* Prints a panic message (a constant string), appends newline and bug
358 reporting info, aborts. */
359__attribute__ ((__noreturn__))
360extern void VG_(skin_panic) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000361
njnd5bb0a52002-09-27 10:24:48 +0000362/* Looks up VG_(client_envp) */
njn25e49d8e72002-09-23 09:36:25 +0000363extern Char* VG_(getenv) ( Char* name );
364
365/* Crude stand-in for the glibc system() call. */
366extern Int VG_(system) ( Char* cmd );
367
njnd5bb0a52002-09-27 10:24:48 +0000368extern Long VG_(atoll) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000369
370/* Like atoll(), but converts a number of base 2..36 */
371extern Long VG_(atoll36) ( UInt base, Char* str );
372
njne36543a2003-09-30 15:37:24 +0000373/* Like qsort(), but does shell-sort. The size==1/2/4 cases are specialised. */
njnd3b0c5f2003-09-30 14:43:54 +0000374extern void VG_(ssort)( void* base, UInt nmemb, UInt size,
375 Int (*compar)(void*, void*) );
376
njn25e49d8e72002-09-23 09:36:25 +0000377
378/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000379/* ctype.h */
njn25e49d8e72002-09-23 09:36:25 +0000380extern Bool VG_(isspace) ( Char c );
381extern Bool VG_(isdigit) ( Char c );
382extern Char VG_(toupper) ( Char c );
383
384
385/* ------------------------------------------------------------------ */
386/* string.h */
387extern Int VG_(strlen) ( const Char* str );
388extern Char* VG_(strcat) ( Char* dest, const Char* src );
389extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
390extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
391extern Char* VG_(strcpy) ( Char* dest, const Char* src );
392extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
393extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
394extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
395extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
396extern Char* VG_(strchr) ( const Char* s, Char c );
397extern Char* VG_(strdup) ( const Char* s);
sewardj7ab2aca2002-10-20 19:40:32 +0000398extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
399extern void* VG_(memset) ( void *s, Int c, Int sz );
njn6d68e792003-02-24 10:49:08 +0000400extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
njn25e49d8e72002-09-23 09:36:25 +0000401
njnd5bb0a52002-09-27 10:24:48 +0000402/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
njn25e49d8e72002-09-23 09:36:25 +0000403extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
njn25e49d8e72002-09-23 09:36:25 +0000404extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
405
daywalker5d945de2003-09-26 00:32:53 +0000406/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
njnd5bb0a52002-09-27 10:24:48 +0000407 last character. */
njn25e49d8e72002-09-23 09:36:25 +0000408extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
409
410/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
411 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
njn4ba5a792002-09-30 10:23:54 +0000412extern Bool VG_(string_match) ( Char* pat, Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000413
414
415/* ------------------------------------------------------------------ */
416/* math.h */
njnd5bb0a52002-09-27 10:24:48 +0000417/* Returns the base-2 logarithm of x. */
njn25e49d8e72002-09-23 09:36:25 +0000418extern Int VG_(log2) ( Int x );
419
420
421/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000422/* unistd.h, fcntl.h, sys/stat.h */
sewardj4cf05692002-10-27 20:28:29 +0000423extern Int VG_(getpid) ( void );
424extern Int VG_(getppid) ( void );
jsgf855d93d2003-10-13 22:26:55 +0000425extern Int VG_(getpgrp) ( void );
426extern Int VG_(gettid) ( void );
427extern Int VG_(setpgid) ( Int pid, Int pgrp );
njnd5bb0a52002-09-27 10:24:48 +0000428
njn4aca2d22002-10-04 10:29:38 +0000429extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
430extern Int VG_(read) ( Int fd, void* buf, Int count);
jsgf855d93d2003-10-13 22:26:55 +0000431extern Int VG_(write) ( Int fd, const void* buf, Int count);
njn4aca2d22002-10-04 10:29:38 +0000432extern void VG_(close) ( Int fd );
njnd5bb0a52002-09-27 10:24:48 +0000433
jsgf855d93d2003-10-13 22:26:55 +0000434extern Int VG_(pipe) ( Int fd[2] );
435
njn41557122002-10-14 09:25:37 +0000436/* Nb: VG_(rename)() declared in stdio.h section above */
njn4aca2d22002-10-04 10:29:38 +0000437extern Int VG_(unlink) ( Char* file_name );
438extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
njnc9d4ba72003-10-15 10:34:03 +0000439extern Int VG_(fstat) ( Int fd, struct vki_stat* buf );
fitzhardingee1c06d82003-10-30 07:21:44 +0000440extern Int VG_(dup2) ( Int oldfd, Int newfd );
njn25e49d8e72002-09-23 09:36:25 +0000441
njn13f02932003-04-30 20:23:58 +0000442extern Char* VG_(getcwd) ( Char* buf, Int size );
443
njn99ccf082003-09-30 13:51:23 +0000444/* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself.
445 String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d.
446 Returns False if it fails. Will fail if the pathname is > 65535 bytes. */
447extern Bool VG_(getcwd_alloc) ( Char** cwd );
njn25e49d8e72002-09-23 09:36:25 +0000448
449/* ------------------------------------------------------------------ */
450/* assert.h */
451/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
452#define VG__STRING(__str) #__str
453
njne427a662002-10-02 11:08:25 +0000454#define sk_assert(expr) \
njn25e49d8e72002-09-23 09:36:25 +0000455 ((void) ((expr) ? 0 : \
njne427a662002-10-02 11:08:25 +0000456 (VG_(skin_assert_fail) (VG__STRING(expr), \
457 __FILE__, __LINE__, \
458 __PRETTY_FUNCTION__), 0)))
njn25e49d8e72002-09-23 09:36:25 +0000459
njne427a662002-10-02 11:08:25 +0000460__attribute__ ((__noreturn__))
daywalker5d945de2003-09-26 00:32:53 +0000461extern void VG_(skin_assert_fail) ( const Char* expr, const Char* file,
daywalkerdf9ae422003-09-18 01:41:48 +0000462 Int line, const Char* fn );
njn25e49d8e72002-09-23 09:36:25 +0000463
464
465/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000466/* system/mman.h */
daywalker5d945de2003-09-26 00:32:53 +0000467extern void* VG_(mmap)( void* start, UInt length,
njn25e49d8e72002-09-23 09:36:25 +0000468 UInt prot, UInt flags, UInt fd, UInt offset );
469extern Int VG_(munmap)( void* start, Int length );
470
471/* Get memory by anonymous mmap. */
472extern void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who );
473
474
475/* ------------------------------------------------------------------ */
daywalker5d945de2003-09-26 00:32:53 +0000476/* signal.h.
477
njn25e49d8e72002-09-23 09:36:25 +0000478 Note that these use the vk_ (kernel) structure
479 definitions, which are different in places from those that glibc
480 defines -- hence the 'k' prefix. Since we're operating right at the
481 kernel interface, glibc's view of the world is entirely irrelevant. */
482
483/* --- Signal set ops --- */
njnd5bb0a52002-09-27 10:24:48 +0000484extern Int VG_(ksigfillset) ( vki_ksigset_t* set );
485extern Int VG_(ksigemptyset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000486
njnd5bb0a52002-09-27 10:24:48 +0000487extern Bool VG_(kisfullsigset) ( vki_ksigset_t* set );
488extern Bool VG_(kisemptysigset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000489
njnd5bb0a52002-09-27 10:24:48 +0000490extern Int VG_(ksigaddset) ( vki_ksigset_t* set, Int signum );
491extern Int VG_(ksigdelset) ( vki_ksigset_t* set, Int signum );
njn25e49d8e72002-09-23 09:36:25 +0000492extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
493
njnd5bb0a52002-09-27 10:24:48 +0000494extern void VG_(ksigaddset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
495extern void VG_(ksigdelset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
njn25e49d8e72002-09-23 09:36:25 +0000496
497/* --- Mess with the kernel's sig state --- */
daywalker5d945de2003-09-26 00:32:53 +0000498extern Int VG_(ksigprocmask) ( Int how, const vki_ksigset_t* set,
njn25e49d8e72002-09-23 09:36:25 +0000499 vki_ksigset_t* oldset );
daywalker5d945de2003-09-26 00:32:53 +0000500extern Int VG_(ksigaction) ( Int signum,
501 const vki_ksigaction* act,
njnd5bb0a52002-09-27 10:24:48 +0000502 vki_ksigaction* oldact );
njn25e49d8e72002-09-23 09:36:25 +0000503
jsgf855d93d2003-10-13 22:26:55 +0000504extern Int VG_(ksigtimedwait)( const vki_ksigset_t *, vki_ksiginfo_t *,
505 const struct vki_timespec * );
506
njnd5bb0a52002-09-27 10:24:48 +0000507extern Int VG_(ksignal) ( Int signum, void (*sighandler)(Int) );
508extern Int VG_(ksigaltstack) ( const vki_kstack_t* ss, vki_kstack_t* oss );
njn25e49d8e72002-09-23 09:36:25 +0000509
sewardjdcaf3122002-09-30 23:12:33 +0000510extern Int VG_(kkill) ( Int pid, Int signo );
jsgf855d93d2003-10-13 22:26:55 +0000511extern Int VG_(ktkill) ( Int pid, Int signo );
sewardjdcaf3122002-09-30 23:12:33 +0000512extern Int VG_(ksigpending) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000513
jsgf855d93d2003-10-13 22:26:55 +0000514extern Int VG_(waitpid) ( Int pid, Int *status, Int options );
njn25e49d8e72002-09-23 09:36:25 +0000515
njne7442cf2003-09-30 14:03:21 +0000516/* ------------------------------------------------------------------ */
517/* other, randomly useful functions */
518extern UInt VG_(read_millisecond_timer) ( void );
519
njn25e49d8e72002-09-23 09:36:25 +0000520/*====================================================================*/
521/*=== UCode definition ===*/
522/*====================================================================*/
523
sewardje1042472002-09-30 12:33:11 +0000524/* Tags which describe what operands are. Must fit into 4 bits, which
525 they clearly do. */
njn25e49d8e72002-09-23 09:36:25 +0000526typedef
sewardje1042472002-09-30 12:33:11 +0000527enum { TempReg =0, /* virtual temp-reg */
528 ArchReg =1, /* simulated integer reg */
529 ArchRegS =2, /* simulated segment reg */
530 RealReg =3, /* real machine's real reg */
531 SpillNo =4, /* spill slot location */
532 Literal =5, /* literal; .lit32 field has actual value */
533 Lit16 =6, /* literal; .val[123] field has actual value */
534 NoValue =7 /* operand not in use */
535 }
536 Tag;
njn25e49d8e72002-09-23 09:36:25 +0000537
njnd5bb0a52002-09-27 10:24:48 +0000538/* Invalid register numbers (can't be negative) */
njn25e49d8e72002-09-23 09:36:25 +0000539#define INVALID_TEMPREG 999999999
540#define INVALID_REALREG 999999999
541
542/* Microinstruction opcodes. */
543typedef
544 enum {
njnd5bb0a52002-09-27 10:24:48 +0000545 NOP, /* Null op */
njn25e49d8e72002-09-23 09:36:25 +0000546
daywalker7e73e5f2003-07-04 16:18:15 +0000547 LOCK, /* Indicate the existence of a LOCK prefix (functionally NOP) */
sewardj7a5ebcf2002-11-13 22:42:13 +0000548
njnd5bb0a52002-09-27 10:24:48 +0000549 /* Moving values around */
550 GET, PUT, /* simulated register <--> TempReg */
551 GETF, PUTF, /* simulated %eflags <--> TempReg */
552 LOAD, STORE, /* memory <--> TempReg */
553 MOV, /* TempReg <--> TempReg */
554 CMOV, /* Used for cmpxchg and cmov */
njn25e49d8e72002-09-23 09:36:25 +0000555
njnd5bb0a52002-09-27 10:24:48 +0000556 /* Arithmetic/logical ops */
jsgf5efa4fd2003-10-14 21:49:11 +0000557 MUL, UMUL, /* Multiply */
njnd5bb0a52002-09-27 10:24:48 +0000558 ADD, ADC, SUB, SBB, /* Add/subtract (w/wo carry) */
559 AND, OR, XOR, NOT, /* Boolean ops */
560 SHL, SHR, SAR, ROL, ROR, RCL, RCR, /* Shift/rotate (w/wo carry) */
561 NEG, /* Negate */
562 INC, DEC, /* Increment/decrement */
563 BSWAP, /* Big-endian <--> little-endian */
564 CC2VAL, /* Condition code --> 0 or 1 */
565 WIDEN, /* Signed or unsigned widening */
njn25e49d8e72002-09-23 09:36:25 +0000566
njnd5bb0a52002-09-27 10:24:48 +0000567 /* Conditional or unconditional jump */
daywalker5d945de2003-09-26 00:32:53 +0000568 JMP,
njnd5bb0a52002-09-27 10:24:48 +0000569
570 /* FPU ops */
571 FPU, /* Doesn't touch memory */
572 FPU_R, FPU_W, /* Reads/writes memory */
573
sewardj3d7c9c82003-03-26 21:08:13 +0000574 /* ------------ MMX ops ------------ */
sewardj8cec6ee2003-05-18 11:56:39 +0000575 /* In this and the SSE encoding, bytes at higher addresses are
576 held in bits [7:0] in these 16-bit words. I guess this means
577 it is a big-endian encoding. */
sewardj3d7c9c82003-03-26 21:08:13 +0000578
579 /* 1 byte, no memrefs, no iregdefs, copy exactly to the
580 output. Held in val1[7:0]. */
581 MMX1,
582
583 /* 2 bytes, no memrefs, no iregdefs, copy exactly to the
584 output. Held in val1[15:0]. */
585 MMX2,
586
587 /* 3 bytes, no memrefs, no iregdefs, copy exactly to the
588 output. Held in val1[15:0] and val2[7:0]. */
589 MMX3,
590
591 /* 2 bytes, reads/writes mem. Insns of the form
592 bbbbbbbb:mod mmxreg r/m.
593 Held in val1[15:0], and mod and rm are to be replaced
daywalker5d945de2003-09-26 00:32:53 +0000594 at codegen time by a reference to the Temp/RealReg holding
sewardj3d7c9c82003-03-26 21:08:13 +0000595 the address. Arg2 holds this Temp/Real Reg.
596 Transfer is always at size 8.
597 */
598 MMX2_MemRd,
599 MMX2_MemWr,
600
sewardj4fbe6e92003-06-15 21:54:34 +0000601 /* 2 bytes, reads/writes an integer ("E") register. Insns of the form
sewardj3d7c9c82003-03-26 21:08:13 +0000602 bbbbbbbb:11 mmxreg ireg.
603 Held in val1[15:0], and ireg is to be replaced
604 at codegen time by a reference to the relevant RealReg.
605 Transfer is always at size 4. Arg2 holds this Temp/Real Reg.
606 */
sewardj4fbe6e92003-06-15 21:54:34 +0000607 MMX2_ERegRd,
608 MMX2_ERegWr,
sewardj3d7c9c82003-03-26 21:08:13 +0000609
sewardj8cec6ee2003-05-18 11:56:39 +0000610 /* ------------ SSE/SSE2 ops ------------ */
611 /* In the following:
612
sewardjfebaa3b2003-05-25 01:07:34 +0000613 a digit N indicates the next N bytes are to be copied exactly
614 to the output.
sewardj8cec6ee2003-05-18 11:56:39 +0000615
616 'a' indicates a mod-xmmreg-rm byte, where the mod-rm part is
617 to be replaced at codegen time to a Temp/RealReg holding the
618 address.
619
sewardj4fbe6e92003-06-15 21:54:34 +0000620 'e' indicates a byte of the form '11 xmmreg ireg', where ireg
621 is read or written, and is to be replaced at codegen time by
622 a reference to the relevant RealReg. 'e' because it's the E
623 reg in Intel encoding parlance.
sewardj8cec6ee2003-05-18 11:56:39 +0000624
sewardj4fbe6e92003-06-15 21:54:34 +0000625 'g' indicates a byte of the form '11 ireg xmmreg', where ireg
626 is read or written, and is to be replaced at codegen time by
627 a reference to the relevant RealReg. 'g' because it's called
628 G in Intel parlance. */
sewardj8cec6ee2003-05-18 11:56:39 +0000629
630 /* 3 bytes, no memrefs, no iregdefs, copy exactly to the
631 output. Held in val1[15:0] and val2[7:0]. */
632 SSE3,
633
634 /* 3 bytes, reads/writes mem. Insns of the form
635 bbbbbbbb:bbbbbbbb:mod mmxreg r/m.
636 Held in val1[15:0] and val2[7:0], and mod and rm are to be
637 replaced at codegen time by a reference to the Temp/RealReg
638 holding the address. Arg3 holds this Temp/Real Reg.
sewardjfebaa3b2003-05-25 01:07:34 +0000639 Transfer is usually, but not always, at size 16. */
sewardj8cec6ee2003-05-18 11:56:39 +0000640 SSE2a_MemRd,
641 SSE2a_MemWr,
642
643 /* 4 bytes, no memrefs, no iregdefs, copy exactly to the
644 output. Held in val1[15:0] and val2[15:0]. */
645 SSE4,
646
647 /* 4 bytes, reads/writes mem. Insns of the form
648 bbbbbbbb:bbbbbbbb:bbbbbbbb:mod mmxreg r/m.
649 Held in val1[15:0] and val2[15:0], and mod and rm are to be
650 replaced at codegen time by a reference to the Temp/RealReg
651 holding the address. Arg3 holds this Temp/Real Reg.
sewardj9dd209f2003-06-18 23:30:52 +0000652 Transfer is at stated size. */
sewardj8cec6ee2003-05-18 11:56:39 +0000653 SSE3a_MemRd,
654 SSE3a_MemWr,
655
656 /* 4 bytes, reads/writes mem. Insns of the form
657 bbbbbbbb:bbbbbbbb:mod mmxreg r/m:bbbbbbbb
658 Held in val1[15:0] and val2[15:0], and mod and rm are to be
659 replaced at codegen time by a reference to the Temp/RealReg
660 holding the address. Arg3 holds this Temp/Real Reg.
sewardj9dd209f2003-06-18 23:30:52 +0000661 Transfer is at stated size. */
sewardj8cec6ee2003-05-18 11:56:39 +0000662 SSE2a1_MemRd,
sewardj77d30a22003-10-19 08:18:52 +0000663
sewardj8cec6ee2003-05-18 11:56:39 +0000664 /* 4 bytes, writes an integer register. Insns of the form
sewardj4fbe6e92003-06-15 21:54:34 +0000665 bbbbbbbb:bbbbbbbb:bbbbbbbb:11 ireg bbb.
sewardj8cec6ee2003-05-18 11:56:39 +0000666 Held in val1[15:0] and val2[15:0], and ireg is to be replaced
667 at codegen time by a reference to the relevant RealReg.
668 Transfer is always at size 4. Arg3 holds this Temp/Real Reg.
669 */
670 SSE3g_RegWr,
671
sewardjb31b06d2003-06-13 00:26:02 +0000672 /* 5 bytes, writes an integer register. Insns of the form
673 bbbbbbbb:bbbbbbbb:bbbbbbbb: 11 ireg bbb :bbbbbbbb. Held in
674 val1[15:0] and val2[15:0] and lit32[7:0], and ireg is to be
675 replaced at codegen time by a reference to the relevant
676 RealReg. Transfer is always at size 4. Arg3 holds this
677 Temp/Real Reg.
678 */
679 SSE3g1_RegWr,
680
sewardj4fbe6e92003-06-15 21:54:34 +0000681 /* 4 bytes, reads an integer register. Insns of the form
682 bbbbbbbb:bbbbbbbb:bbbbbbbb:11 bbb ireg.
683 Held in val1[15:0] and val2[15:0], and ireg is to be replaced
684 at codegen time by a reference to the relevant RealReg.
685 Transfer is always at size 4. Arg3 holds this Temp/Real Reg.
686 */
687 SSE3e_RegRd,
sewardjabf8bf82003-06-15 22:28:05 +0000688 SSE3e_RegWr, /* variant that writes Ereg, not reads it */
sewardj4fbe6e92003-06-15 21:54:34 +0000689
sewardjb31b06d2003-06-13 00:26:02 +0000690 /* 5 bytes, reads an integer register. Insns of the form
691 bbbbbbbb:bbbbbbbb:bbbbbbbb: 11 bbb ireg :bbbbbbbb. Held in
692 val1[15:0] and val2[15:0] and lit32[7:0], and ireg is to be
693 replaced at codegen time by a reference to the relevant
694 RealReg. Transfer is always at size 4. Arg3 holds this
695 Temp/Real Reg.
696 */
sewardj4fbe6e92003-06-15 21:54:34 +0000697 SSE3e1_RegRd,
sewardj8cec6ee2003-05-18 11:56:39 +0000698
sewardj02af6bc2003-06-12 00:56:06 +0000699 /* 4 bytes, reads memory, writes an integer register, but is
700 nevertheless an SSE insn. The insn is of the form
701 bbbbbbbb:bbbbbbbb:bbbbbbbb:mod ireg rm where mod indicates
702 memory (ie is not 11b) and ireg is the int reg written. The
sewardje3891fa2003-06-15 03:13:48 +0000703 first 4 bytes are held in lit32[31:0] since there is
sewardj02af6bc2003-06-12 00:56:06 +0000704 insufficient space elsewhere. mod and rm are to be replaced
705 at codegen time by a reference to the Temp/RealReg holding
706 the address. Arg1 holds this Temp/RealReg. ireg is to be
707 replaced at codegen time by a reference to the relevant
708 RealReg in which the answer is to be written. Arg2 holds
709 this Temp/RealReg. Transfer to the destination reg is always
710 at size 4. However the memory read can be at sizes 4 or 8
sewardje3891fa2003-06-15 03:13:48 +0000711 and so this is what the sz field holds. Note that the 4th
712 byte of the instruction (the modrm byte) is redundant, but we
713 store it anyway so as to be consistent with all other SSE
714 uinstrs.
sewardj02af6bc2003-06-12 00:56:06 +0000715 */
716 SSE3ag_MemRd_RegWr,
sewardje3891fa2003-06-15 03:13:48 +0000717
sewardj8cec6ee2003-05-18 11:56:39 +0000718 /* 5 bytes, no memrefs, no iregdefs, copy exactly to the
719 output. Held in val1[15:0], val2[15:0] and val3[7:0]. */
720 SSE5,
sewardj77d30a22003-10-19 08:18:52 +0000721
sewardj8cec6ee2003-05-18 11:56:39 +0000722 /* 5 bytes, reads/writes mem. Insns of the form
723 bbbbbbbb:bbbbbbbb:bbbbbbbb:mod mmxreg r/m:bbbbbbbb
daywalker5d945de2003-09-26 00:32:53 +0000724 Held in val1[15:0], val2[15:0], lit32[7:0].
725 mod and rm are to be replaced at codegen time by a reference
726 to the Temp/RealReg holding the address. Arg3 holds this
sewardj8cec6ee2003-05-18 11:56:39 +0000727 Temp/Real Reg. Transfer is always at size 16. */
728 SSE3a1_MemRd,
sewardj77d30a22003-10-19 08:18:52 +0000729
sewardj3d7c9c82003-03-26 21:08:13 +0000730 /* ------------------------ */
731
njnd5bb0a52002-09-27 10:24:48 +0000732 /* Not strictly needed, but improve address calculation translations. */
njn25e49d8e72002-09-23 09:36:25 +0000733 LEA1, /* reg2 := const + reg1 */
734 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
735
sewardj8cec6ee2003-05-18 11:56:39 +0000736 /* Hack for x86 REP insns. Jump to literal if TempReg/RealReg
737 is zero. */
njnd5bb0a52002-09-27 10:24:48 +0000738 JIFZ,
njn25e49d8e72002-09-23 09:36:25 +0000739
njnd5bb0a52002-09-27 10:24:48 +0000740 /* Advance the simulated %eip by some small (< 128) number. */
741 INCEIP,
njn25e49d8e72002-09-23 09:36:25 +0000742
sewardje1042472002-09-30 12:33:11 +0000743 /* Dealing with segment registers */
744 GETSEG, PUTSEG, /* simulated segment register <--> TempReg */
745 USESEG, /* (LDT/GDT index, virtual addr) --> linear addr */
746
njnd5bb0a52002-09-27 10:24:48 +0000747 /* Not for translating x86 calls -- only to call helpers */
748 CALLM_S, CALLM_E, /* Mark start/end of CALLM push/pop sequence */
749 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers */
750 CALLM, /* Call assembly-code helper */
751
752 /* Not for translating x86 calls -- only to call C helper functions of
753 up to three arguments (or two if the functions has a return value).
754 Arguments and return value must be word-sized. More arguments can
755 be faked with global variables (eg. use VG_(set_global_var)()).
756
757 Seven possibilities: 'arg[123]' show where args go, 'ret' shows
758 where return value goes (if present).
daywalker5d945de2003-09-26 00:32:53 +0000759
njn25e49d8e72002-09-23 09:36:25 +0000760 CCALL(-, -, - ) void f(void)
761 CCALL(arg1, -, - ) void f(UInt arg1)
762 CCALL(arg1, arg2, - ) void f(UInt arg1, UInt arg2)
763 CCALL(arg1, arg2, arg3) void f(UInt arg1, UInt arg2, UInt arg3)
764 CCALL(-, -, ret ) UInt f(UInt)
765 CCALL(arg1, -, ret ) UInt f(UInt arg1)
njnd5bb0a52002-09-27 10:24:48 +0000766 CCALL(arg1, arg2, ret ) UInt f(UInt arg1, UInt arg2) */
njn25e49d8e72002-09-23 09:36:25 +0000767 CCALL,
768
njnd5bb0a52002-09-27 10:24:48 +0000769 /* This opcode makes it easy for skins that extend UCode to do this to
770 avoid opcode overlap:
njn25e49d8e72002-09-23 09:36:25 +0000771
daywalker5d945de2003-09-26 00:32:53 +0000772 enum { EU_OP1 = DUMMY_FINAL_UOPCODE + 1, ... }
773
njn25e49d8e72002-09-23 09:36:25 +0000774 WARNING: Do not add new opcodes after this one! They can be added
775 before, though. */
776 DUMMY_FINAL_UOPCODE
777 }
778 Opcode;
779
780
njnd5bb0a52002-09-27 10:24:48 +0000781/* Condition codes, using the Intel encoding. CondAlways is an extra. */
njn25e49d8e72002-09-23 09:36:25 +0000782typedef
783 enum {
784 CondO = 0, /* overflow */
785 CondNO = 1, /* no overflow */
786 CondB = 2, /* below */
787 CondNB = 3, /* not below */
788 CondZ = 4, /* zero */
789 CondNZ = 5, /* not zero */
790 CondBE = 6, /* below or equal */
791 CondNBE = 7, /* not below or equal */
792 CondS = 8, /* negative */
sewardje1042472002-09-30 12:33:11 +0000793 CondNS = 9, /* not negative */
njn25e49d8e72002-09-23 09:36:25 +0000794 CondP = 10, /* parity even */
795 CondNP = 11, /* not parity even */
796 CondL = 12, /* jump less */
797 CondNL = 13, /* not less */
798 CondLE = 14, /* less or equal */
799 CondNLE = 15, /* not less or equal */
800 CondAlways = 16 /* Jump always */
daywalker5d945de2003-09-26 00:32:53 +0000801 }
njn25e49d8e72002-09-23 09:36:25 +0000802 Condcode;
803
804
805/* Descriptions of additional properties of *unconditional* jumps. */
806typedef
807 enum {
808 JmpBoring=0, /* boring unconditional jump */
809 JmpCall=1, /* jump due to an x86 call insn */
810 JmpRet=2, /* jump due to an x86 ret insn */
811 JmpSyscall=3, /* do a system call, then jump */
812 JmpClientReq=4 /* do a client request, then jump */
813 }
814 JmpKind;
815
816
817/* Flags. User-level code can only read/write O(verflow), S(ign),
818 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
819 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
daywalker5d945de2003-09-26 00:32:53 +0000820 thusly:
njn25e49d8e72002-09-23 09:36:25 +0000821 76543210
822 DOSZACP
823 and bit 7 must always be zero since it is unused.
sewardj2370f3b2002-11-30 15:01:01 +0000824
825 Note: these Flag? values are **not** the positions in the actual
826 %eflags register. */
827
njn25e49d8e72002-09-23 09:36:25 +0000828typedef UChar FlagSet;
829
830#define FlagD (1<<6)
831#define FlagO (1<<5)
832#define FlagS (1<<4)
833#define FlagZ (1<<3)
834#define FlagA (1<<2)
835#define FlagC (1<<1)
836#define FlagP (1<<0)
837
838#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
839#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
840#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
841#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
842#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
843#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
844#define FlagsZCP ( FlagZ | FlagC | FlagP)
845#define FlagsOC (FlagO | FlagC )
846#define FlagsAC ( FlagA | FlagC )
847
848#define FlagsALL (FlagsOSZACP | FlagD)
849#define FlagsEmpty (FlagSet)0
850
851
sewardj2370f3b2002-11-30 15:01:01 +0000852/* flag positions in eflags */
853#define EFlagC (1 << 0) /* carry */
854#define EFlagP (1 << 2) /* parity */
sewardjfa492d42002-12-08 18:20:01 +0000855#define EFlagA (1 << 4) /* aux carry */
sewardj2370f3b2002-11-30 15:01:01 +0000856#define EFlagZ (1 << 6) /* zero */
857#define EFlagS (1 << 7) /* sign */
sewardjfa492d42002-12-08 18:20:01 +0000858#define EFlagD (1 << 10) /* direction */
sewardj2370f3b2002-11-30 15:01:01 +0000859#define EFlagO (1 << 11) /* overflow */
860
njn25e49d8e72002-09-23 09:36:25 +0000861/* Liveness of general purpose registers, useful for code generation.
862 Reg rank order 0..N-1 corresponds to bits 0..N-1, ie. first
863 reg's liveness in bit 0, last reg's in bit N-1. Note that
864 these rankings don't match the Intel register ordering. */
865typedef UInt RRegSet;
866
867#define ALL_RREGS_DEAD 0 /* 0000...00b */
njne7c258c2002-10-03 08:57:01 +0000868#define ALL_RREGS_LIVE ((1 << VG_MAX_REALREGS)-1) /* 0011...11b */
njn25e49d8e72002-09-23 09:36:25 +0000869#define UNIT_RREGSET(rank) (1 << (rank))
870
871#define IS_RREG_LIVE(rank,rregs_live) (rregs_live & UNIT_RREGSET(rank))
872#define SET_RREG_LIVENESS(rank,rregs_live,b) \
873 do { RRegSet unit = UNIT_RREGSET(rank); \
874 if (b) rregs_live |= unit; \
875 else rregs_live &= ~unit; \
876 } while(0)
877
878
879/* A Micro (u)-instruction. */
880typedef
881 struct {
882 /* word 1 */
883 UInt lit32; /* 32-bit literal */
884
885 /* word 2 */
886 UShort val1; /* first operand */
887 UShort val2; /* second operand */
888
889 /* word 3 */
890 UShort val3; /* third operand */
891 UChar opcode; /* opcode */
892 UChar size; /* data transfer size */
893
894 /* word 4 */
895 FlagSet flags_r; /* :: FlagSet */
896 FlagSet flags_w; /* :: FlagSet */
897 UChar tag1:4; /* first operand tag */
898 UChar tag2:4; /* second operand tag */
899 UChar tag3:4; /* third operand tag */
900 UChar extra4b:4; /* Spare field, used by WIDEN for src
901 -size, and by LEA2 for scale (1,2,4 or 8),
902 and by JMPs for original x86 instr size */
903
904 /* word 5 */
905 UChar cond; /* condition, for jumps */
906 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
907 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
908
daywalker5d945de2003-09-26 00:32:53 +0000909 /* Additional properties for UInstrs that call C functions:
njn25e49d8e72002-09-23 09:36:25 +0000910 - CCALL
911 - PUT (when %ESP is the target)
912 - possibly skin-specific UInstrs
913 */
914 UChar argc:2; /* Number of args, max 3 */
915 UChar regparms_n:2; /* Number of args passed in registers */
916 Bool has_ret_val:1; /* Function has return value? */
917
918 /* RealReg liveness; only sensical after reg alloc and liveness
919 analysis done. This info is a little bit arch-specific --
920 VG_MAX_REALREGS can vary on different architectures. Note that
921 to use this information requires converting between register ranks
njn4ba5a792002-09-30 10:23:54 +0000922 and the Intel register numbers, using VG_(realreg_to_rank)()
923 and/or VG_(rank_to_realreg)() */
daywalker5d945de2003-09-26 00:32:53 +0000924 RRegSet regs_live_after:VG_MAX_REALREGS;
njn25e49d8e72002-09-23 09:36:25 +0000925 }
926 UInstr;
927
928
daywalker5d945de2003-09-26 00:32:53 +0000929typedef
njn810086f2002-11-14 12:42:47 +0000930 struct _UCodeBlock
njn25e49d8e72002-09-23 09:36:25 +0000931 UCodeBlock;
932
njn810086f2002-11-14 12:42:47 +0000933extern Int VG_(get_num_instrs) (UCodeBlock* cb);
934extern Int VG_(get_num_temps) (UCodeBlock* cb);
njn25e49d8e72002-09-23 09:36:25 +0000935
njn810086f2002-11-14 12:42:47 +0000936extern UInstr* VG_(get_instr) (UCodeBlock* cb, Int i);
937extern UInstr* VG_(get_last_instr) (UCodeBlock* cb);
daywalker5d945de2003-09-26 00:32:53 +0000938
njn211b6ad2003-02-03 12:33:31 +0000939
njn25e49d8e72002-09-23 09:36:25 +0000940/*====================================================================*/
941/*=== Instrumenting UCode ===*/
942/*====================================================================*/
943
njnf4ce3d32003-02-10 10:17:26 +0000944/* Maximum number of registers read or written by a single UInstruction. */
945#define VG_MAX_REGS_USED 3
njn25e49d8e72002-09-23 09:36:25 +0000946
njnf4ce3d32003-02-10 10:17:26 +0000947/* Find what this instruction does to its regs, useful for
948 analysis/optimisation passes. `tag' indicates whether we're considering
949 TempRegs (pre-reg-alloc) or RealRegs (post-reg-alloc). `regs' is filled
950 with the affected register numbers, `isWrites' parallels it and indicates
951 if the reg is read or written. If a reg is read and written, it will
952 appear twice in `regs'. `regs' and `isWrites' must be able to fit
953 VG_MAX_REGS_USED elements. */
njn810086f2002-11-14 12:42:47 +0000954extern Int VG_(get_reg_usage) ( UInstr* u, Tag tag, Int* regs, Bool* isWrites );
njn25e49d8e72002-09-23 09:36:25 +0000955
956
njnd5bb0a52002-09-27 10:24:48 +0000957/* Used to register helper functions to be called from generated code. A
958 limited number of compact helpers can be registered; the code generated
959 to call them is slightly shorter -- so register the mostly frequently
960 called helpers as compact. */
njn25e49d8e72002-09-23 09:36:25 +0000961extern void VG_(register_compact_helper) ( Addr a );
962extern void VG_(register_noncompact_helper) ( Addr a );
963
964
965/* ------------------------------------------------------------------ */
966/* Virtual register allocation */
967
968/* Get a new virtual register */
njn4ba5a792002-09-30 10:23:54 +0000969extern Int VG_(get_new_temp) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000970
971/* Get a new virtual shadow register */
njn4ba5a792002-09-30 10:23:54 +0000972extern Int VG_(get_new_shadow) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000973
974/* Get a virtual register's corresponding virtual shadow register */
975#define SHADOW(tempreg) ((tempreg)+1)
976
977
978/* ------------------------------------------------------------------ */
979/* Low-level UInstr builders */
njn4ba5a792002-09-30 10:23:54 +0000980extern void VG_(new_NOP) ( UInstr* u );
981extern void VG_(new_UInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
982extern void VG_(new_UInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000983 Tag tag1, UInt val1 );
njn4ba5a792002-09-30 10:23:54 +0000984extern void VG_(new_UInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000985 Tag tag1, UInt val1,
986 Tag tag2, UInt val2 );
njn4ba5a792002-09-30 10:23:54 +0000987extern void VG_(new_UInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +0000988 Tag tag1, UInt val1,
989 Tag tag2, UInt val2,
990 Tag tag3, UInt val3 );
njn25e49d8e72002-09-23 09:36:25 +0000991
daywalker5d945de2003-09-26 00:32:53 +0000992/* Set read/write/undefined flags. Undefined flags are treaten as written,
njn810086f2002-11-14 12:42:47 +0000993 but it's worth keeping them logically distinct. */
994extern void VG_(set_flag_fields) ( UCodeBlock* cb, FlagSet fr, FlagSet fw,
995 FlagSet fu);
njn4ba5a792002-09-30 10:23:54 +0000996extern void VG_(set_lit_field) ( UCodeBlock* cb, UInt lit32 );
997extern void VG_(set_ccall_fields) ( UCodeBlock* cb, Addr fn, UChar argc,
998 UChar regparms_n, Bool has_ret_val );
njn810086f2002-11-14 12:42:47 +0000999extern void VG_(set_cond_field) ( UCodeBlock* cb, Condcode code );
njn25e49d8e72002-09-23 09:36:25 +00001000
njn4ba5a792002-09-30 10:23:54 +00001001extern void VG_(copy_UInstr) ( UCodeBlock* cb, UInstr* instr );
1002
1003extern Bool VG_(any_flag_use)( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +00001004
njnac6c1762002-10-04 14:34:15 +00001005/* Macro versions of the above; just shorter to type. */
1006#define uInstr0 VG_(new_UInstr0)
1007#define uInstr1 VG_(new_UInstr1)
1008#define uInstr2 VG_(new_UInstr2)
1009#define uInstr3 VG_(new_UInstr3)
1010#define uLiteral VG_(set_lit_field)
1011#define uCCall VG_(set_ccall_fields)
njn810086f2002-11-14 12:42:47 +00001012#define uCond VG_(set_cond_field)
1013#define uFlagsRWU VG_(set_flag_fields)
njnac6c1762002-10-04 14:34:15 +00001014#define newTemp VG_(get_new_temp)
1015#define newShadow VG_(get_new_shadow)
1016
njn25e49d8e72002-09-23 09:36:25 +00001017/* Refer to `the last instruction stuffed in' (can be lvalue). */
1018#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
1019
1020
1021/* ------------------------------------------------------------------ */
1022/* Higher-level UInstr sequence builders */
njn4ba5a792002-09-30 10:23:54 +00001023extern void VG_(call_helper_0_0) ( UCodeBlock* cb, Addr f);
1024extern void VG_(call_helper_1_0) ( UCodeBlock* cb, Addr f, UInt arg1,
1025 UInt regparms_n);
1026extern void VG_(call_helper_2_0) ( UCodeBlock* cb, Addr f, UInt arg1, UInt arg2,
1027 UInt regparms_n);
njn25e49d8e72002-09-23 09:36:25 +00001028
1029/* One way around the 3-arg C function limit is to pass args via global
njn6fefa1b2003-02-24 10:32:51 +00001030 * variables... ugly, but it works. This one puts a literal in there. */
njn4ba5a792002-09-30 10:23:54 +00001031extern void VG_(set_global_var) ( UCodeBlock* cb, Addr globvar_ptr, UInt val);
njn25e49d8e72002-09-23 09:36:25 +00001032
njn6fefa1b2003-02-24 10:32:51 +00001033/* This one puts the contents of a TempReg in the global variable. */
1034extern void VG_(set_global_var_tempreg) ( UCodeBlock* cb, Addr globvar_ptr,
1035 UInt t_val);
1036
njn25e49d8e72002-09-23 09:36:25 +00001037/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +00001038/* Allocating/freeing basic blocks of UCode */
njn810086f2002-11-14 12:42:47 +00001039extern UCodeBlock* VG_(setup_UCodeBlock) ( UCodeBlock* cb );
njn4ba5a792002-09-30 10:23:54 +00001040extern void VG_(free_UCodeBlock) ( UCodeBlock* cb );
njnd5bb0a52002-09-27 10:24:48 +00001041
1042/* ------------------------------------------------------------------ */
daywalker5d945de2003-09-26 00:32:53 +00001043/* UCode pretty/ugly printing. Probably only useful to call from a skin
njn25e49d8e72002-09-23 09:36:25 +00001044 if VG_(needs).extended_UCode == True. */
1045
1046/* When True, all generated code is/should be printed. */
1047extern Bool VG_(print_codegen);
1048
njn4ba5a792002-09-30 10:23:54 +00001049/* Pretty/ugly printing functions */
1050extern void VG_(pp_UCodeBlock) ( UCodeBlock* cb, Char* title );
1051extern void VG_(pp_UInstr) ( Int instrNo, UInstr* u );
1052extern void VG_(pp_UInstr_regs) ( Int instrNo, UInstr* u );
1053extern void VG_(up_UInstr) ( Int instrNo, UInstr* u );
1054extern Char* VG_(name_UOpcode) ( Bool upper, Opcode opc );
njn563f96f2003-02-03 11:17:46 +00001055extern Char* VG_(name_UCondcode) ( Condcode cond );
daywalker5d945de2003-09-26 00:32:53 +00001056extern void VG_(pp_UOperand) ( UInstr* u, Int operandNo,
njn4ba5a792002-09-30 10:23:54 +00001057 Int sz, Bool parens );
njn25e49d8e72002-09-23 09:36:25 +00001058
njnb93d1782003-02-03 12:03:22 +00001059/* ------------------------------------------------------------------ */
njnf4ce3d32003-02-10 10:17:26 +00001060/* Accessing archregs and their shadows */
1061extern UInt VG_(get_archreg) ( UInt archreg );
1062extern UInt VG_(get_thread_archreg) ( ThreadId tid, UInt archreg );
1063
njnb93d1782003-02-03 12:03:22 +00001064extern UInt VG_(get_shadow_archreg) ( UInt archreg );
1065extern void VG_(set_shadow_archreg) ( UInt archreg, UInt val );
njnd3040452003-05-19 15:04:06 +00001066extern void VG_(set_shadow_eflags) ( UInt val );
njnb93d1782003-02-03 12:03:22 +00001067extern Addr VG_(shadow_archreg_address) ( UInt archreg );
njn25e49d8e72002-09-23 09:36:25 +00001068
njnf4ce3d32003-02-10 10:17:26 +00001069extern UInt VG_(get_thread_shadow_archreg) ( ThreadId tid, UInt archreg );
1070extern void VG_(set_thread_shadow_archreg) ( ThreadId tid, UInt archreg,
1071 UInt val );
njn211b6ad2003-02-03 12:33:31 +00001072
1073/* ------------------------------------------------------------------ */
1074/* Offsets of addresses of helper functions. A "helper" function is one
1075 which is called from generated code via CALLM. */
1076
1077extern Int VGOFF_(helper_idiv_64_32);
1078extern Int VGOFF_(helper_div_64_32);
1079extern Int VGOFF_(helper_idiv_32_16);
1080extern Int VGOFF_(helper_div_32_16);
1081extern Int VGOFF_(helper_idiv_16_8);
1082extern Int VGOFF_(helper_div_16_8);
1083
1084extern Int VGOFF_(helper_imul_32_64);
1085extern Int VGOFF_(helper_mul_32_64);
1086extern Int VGOFF_(helper_imul_16_32);
1087extern Int VGOFF_(helper_mul_16_32);
1088extern Int VGOFF_(helper_imul_8_16);
1089extern Int VGOFF_(helper_mul_8_16);
1090
1091extern Int VGOFF_(helper_CLD);
1092extern Int VGOFF_(helper_STD);
1093extern Int VGOFF_(helper_get_dirflag);
1094
1095extern Int VGOFF_(helper_CLC);
1096extern Int VGOFF_(helper_STC);
1097
1098extern Int VGOFF_(helper_shldl);
1099extern Int VGOFF_(helper_shldw);
1100extern Int VGOFF_(helper_shrdl);
1101extern Int VGOFF_(helper_shrdw);
1102
1103extern Int VGOFF_(helper_RDTSC);
1104extern Int VGOFF_(helper_CPUID);
1105
daywalkerb18d2532003-09-27 20:15:01 +00001106extern Int VGOFF_(helper_IN);
1107extern Int VGOFF_(helper_OUT);
1108
njn211b6ad2003-02-03 12:33:31 +00001109extern Int VGOFF_(helper_bsf);
1110extern Int VGOFF_(helper_bsr);
1111
1112extern Int VGOFF_(helper_fstsw_AX);
1113extern Int VGOFF_(helper_SAHF);
njnd6251f12003-06-03 13:38:51 +00001114extern Int VGOFF_(helper_LAHF);
njn211b6ad2003-02-03 12:33:31 +00001115extern Int VGOFF_(helper_DAS);
1116extern Int VGOFF_(helper_DAA);
1117
1118
njn25e49d8e72002-09-23 09:36:25 +00001119/*====================================================================*/
njnd5bb0a52002-09-27 10:24:48 +00001120/*=== Generating x86 code from UCode ===*/
njn25e49d8e72002-09-23 09:36:25 +00001121/*====================================================================*/
1122
njnd5bb0a52002-09-27 10:24:48 +00001123/* All this only necessary for skins with VG_(needs).extends_UCode == True. */
njn25e49d8e72002-09-23 09:36:25 +00001124
sewardje1042472002-09-30 12:33:11 +00001125/* This is the Intel register encoding -- integer regs. */
njn25e49d8e72002-09-23 09:36:25 +00001126#define R_EAX 0
1127#define R_ECX 1
1128#define R_EDX 2
1129#define R_EBX 3
1130#define R_ESP 4
1131#define R_EBP 5
1132#define R_ESI 6
1133#define R_EDI 7
1134
1135#define R_AL (0+R_EAX)
1136#define R_CL (0+R_ECX)
1137#define R_DL (0+R_EDX)
1138#define R_BL (0+R_EBX)
1139#define R_AH (4+R_EAX)
1140#define R_CH (4+R_ECX)
1141#define R_DH (4+R_EDX)
1142#define R_BH (4+R_EBX)
1143
sewardje1042472002-09-30 12:33:11 +00001144/* This is the Intel register encoding -- segment regs. */
1145#define R_ES 0
1146#define R_CS 1
1147#define R_SS 2
1148#define R_DS 3
1149#define R_FS 4
1150#define R_GS 5
1151
njn25e49d8e72002-09-23 09:36:25 +00001152/* For pretty printing x86 code */
daywalker5d945de2003-09-26 00:32:53 +00001153extern const Char* VG_(name_of_mmx_gran) ( UChar gran );
1154extern const Char* VG_(name_of_mmx_reg) ( Int mmxreg );
1155extern const Char* VG_(name_of_seg_reg) ( Int sreg );
1156extern const Char* VG_(name_of_int_reg) ( Int size, Int reg );
1157extern const Char VG_(name_of_int_size) ( Int size );
njn25e49d8e72002-09-23 09:36:25 +00001158
njnac6c1762002-10-04 14:34:15 +00001159/* Shorter macros for convenience */
sewardj3d7c9c82003-03-26 21:08:13 +00001160#define nameIReg VG_(name_of_int_reg)
1161#define nameISize VG_(name_of_int_size)
1162#define nameSReg VG_(name_of_seg_reg)
1163#define nameMMXReg VG_(name_of_mmx_reg)
1164#define nameMMXGran VG_(name_of_mmx_gran)
sewardjfebaa3b2003-05-25 01:07:34 +00001165#define nameXMMReg VG_(name_of_xmm_reg)
njnac6c1762002-10-04 14:34:15 +00001166
njn25e49d8e72002-09-23 09:36:25 +00001167/* Randomly useful things */
1168extern UInt VG_(extend_s_8to32) ( UInt x );
1169
1170/* Code emitters */
njn4ba5a792002-09-30 10:23:54 +00001171extern void VG_(emitB) ( UInt b );
1172extern void VG_(emitW) ( UInt w );
1173extern void VG_(emitL) ( UInt l );
sewardjfa492d42002-12-08 18:20:01 +00001174extern void VG_(new_emit) ( Bool upd_cc, FlagSet uses_flags, FlagSet sets_flags );
njn25e49d8e72002-09-23 09:36:25 +00001175
1176/* Finding offsets */
njn4ba5a792002-09-30 10:23:54 +00001177extern Int VG_(helper_offset) ( Addr a );
1178extern Int VG_(shadow_reg_offset) ( Int arch );
1179extern Int VG_(shadow_flags_offset) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001180
njnd5bb0a52002-09-27 10:24:48 +00001181/* Convert reg ranks <-> Intel register ordering, for using register
1182 liveness information. */
njn4ba5a792002-09-30 10:23:54 +00001183extern Int VG_(realreg_to_rank) ( Int realreg );
1184extern Int VG_(rank_to_realreg) ( Int rank );
njn25e49d8e72002-09-23 09:36:25 +00001185
njnd5bb0a52002-09-27 10:24:48 +00001186/* Call a subroutine. Does no argument passing, stack manipulations, etc. */
daywalker5d945de2003-09-26 00:32:53 +00001187extern void VG_(synth_call) ( Bool ensure_shortform, Int word_offset,
sewardjfa492d42002-12-08 18:20:01 +00001188 Bool upd_cc, FlagSet use_flags, FlagSet set_flags );
njn25e49d8e72002-09-23 09:36:25 +00001189
njnd5bb0a52002-09-27 10:24:48 +00001190/* For calling C functions -- saves caller save regs, pushes args, calls,
1191 clears the stack, restores caller save regs. `fn' must be registered in
1192 the baseBlock first. Acceptable tags are RealReg and Literal. Optimises
1193 things, eg. by not preserving non-live caller-save registers.
njn25e49d8e72002-09-23 09:36:25 +00001194
njnd5bb0a52002-09-27 10:24:48 +00001195 WARNING: a UInstr should *not* be translated with synth_ccall() followed
1196 by some other x86 assembly code; this will invalidate the results of
1197 vg_realreg_liveness_analysis() and everything will fall over. */
njn4ba5a792002-09-30 10:23:54 +00001198extern void VG_(synth_ccall) ( Addr fn, Int argc, Int regparms_n, UInt argv[],
daywalker5d945de2003-09-26 00:32:53 +00001199 Tag tagv[], Int ret_reg,
njn4ba5a792002-09-30 10:23:54 +00001200 RRegSet regs_live_before,
1201 RRegSet regs_live_after );
njn25e49d8e72002-09-23 09:36:25 +00001202
1203/* Addressing modes */
njn4ba5a792002-09-30 10:23:54 +00001204extern void VG_(emit_amode_offregmem_reg)( Int off, Int regmem, Int reg );
1205extern void VG_(emit_amode_ereg_greg) ( Int e_reg, Int g_reg );
njn25e49d8e72002-09-23 09:36:25 +00001206
1207/* v-size (4, or 2 with OSO) insn emitters */
njn4ba5a792002-09-30 10:23:54 +00001208extern void VG_(emit_movv_offregmem_reg) ( Int sz, Int off, Int areg, Int reg );
1209extern void VG_(emit_movv_reg_offregmem) ( Int sz, Int reg, Int off, Int areg );
1210extern void VG_(emit_movv_reg_reg) ( Int sz, Int reg1, Int reg2 );
sewardjfa492d42002-12-08 18:20:01 +00001211extern void VG_(emit_nonshiftopv_lit_reg)( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001212 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001213extern void VG_(emit_shiftopv_lit_reg) ( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001214 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001215extern void VG_(emit_nonshiftopv_reg_reg)( Bool upd_cc, Int sz, Opcode opc,
njn4ba5a792002-09-30 10:23:54 +00001216 Int reg1, Int reg2 );
1217extern void VG_(emit_movv_lit_reg) ( Int sz, UInt lit, Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001218extern void VG_(emit_unaryopv_reg) ( Bool upd_cc, Int sz, Opcode opc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001219extern void VG_(emit_pushv_reg) ( Int sz, Int reg );
1220extern void VG_(emit_popv_reg) ( Int sz, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001221
njn4ba5a792002-09-30 10:23:54 +00001222extern void VG_(emit_pushl_lit32) ( UInt int32 );
1223extern void VG_(emit_pushl_lit8) ( Int lit8 );
sewardjfa492d42002-12-08 18:20:01 +00001224extern void VG_(emit_cmpl_zero_reg) ( Bool upd_cc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001225extern void VG_(emit_swapl_reg_EAX) ( Int reg );
1226extern void VG_(emit_movv_lit_offregmem) ( Int sz, UInt lit, Int off,
1227 Int memreg );
njn25e49d8e72002-09-23 09:36:25 +00001228
1229/* b-size (1 byte) instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001230extern void VG_(emit_movb_lit_offregmem) ( UInt lit, Int off, Int memreg );
1231extern void VG_(emit_movb_reg_offregmem) ( Int reg, Int off, Int areg );
sewardjfa492d42002-12-08 18:20:01 +00001232extern void VG_(emit_unaryopb_reg) ( Bool upd_cc, Opcode opc, Int reg );
1233extern void VG_(emit_testb_lit_reg) ( Bool upd_cc, UInt lit, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001234
1235/* zero-extended load emitters */
njn4ba5a792002-09-30 10:23:54 +00001236extern void VG_(emit_movzbl_offregmem_reg) ( Int off, Int regmem, Int reg );
1237extern void VG_(emit_movzwl_offregmem_reg) ( Int off, Int areg, Int reg );
daywalkerf26b2162003-09-30 23:01:50 +00001238extern void VG_(emit_movzwl_regmem_reg) ( Int reg1, Int reg2 );
njn25e49d8e72002-09-23 09:36:25 +00001239
1240/* misc instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001241extern void VG_(emit_call_reg) ( Int reg );
1242extern void VG_(emit_add_lit_to_esp) ( Int lit );
njn4ba5a792002-09-30 10:23:54 +00001243extern void VG_(emit_pushal) ( void );
1244extern void VG_(emit_popal) ( void );
1245extern void VG_(emit_AMD_prefetch_reg) ( Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001246
sewardja2113f92002-12-12 23:42:48 +00001247/* jump emitters */
1248extern void VG_(init_target) ( Int *tgt );
1249
1250extern void VG_(target_back) ( Int *tgt );
1251extern void VG_(target_forward) ( Int *tgt );
1252extern void VG_(emit_target_delta) ( Int *tgt );
1253
1254extern void VG_(emit_jcondshort_delta) ( Bool simd_cc, Condcode cond, Int delta );
1255extern void VG_(emit_jcondshort_target)( Bool simd_cc, Condcode cond, Int *tgt );
1256
njn25e49d8e72002-09-23 09:36:25 +00001257
1258/*====================================================================*/
1259/*=== Execution contexts ===*/
1260/*====================================================================*/
1261
1262/* Generic resolution type used in a few different ways, such as deciding
1263 how closely to compare two errors for equality. */
daywalker5d945de2003-09-26 00:32:53 +00001264typedef
1265 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
njn25e49d8e72002-09-23 09:36:25 +00001266 VgRes;
1267
1268typedef
1269 struct _ExeContext
1270 ExeContext;
1271
daywalker5d945de2003-09-26 00:32:53 +00001272/* Compare two ExeContexts. Number of callers considered depends on `res':
1273 Vg_LowRes: 2
1274 Vg_MedRes: 4
njnd5bb0a52002-09-27 10:24:48 +00001275 Vg_HighRes: all */
njn25e49d8e72002-09-23 09:36:25 +00001276extern Bool VG_(eq_ExeContext) ( VgRes res,
1277 ExeContext* e1, ExeContext* e2 );
1278
1279/* Print an ExeContext. */
1280extern void VG_(pp_ExeContext) ( ExeContext* );
1281
1282/* Take a snapshot of the client's stack. Search our collection of
1283 ExeContexts to see if we already have it, and if not, allocate a
njn6c846552003-09-16 07:41:43 +00001284 new one. Either way, return a pointer to the context. Context size
1285 controlled by --num-callers option.
daywalker5d945de2003-09-26 00:32:53 +00001286
njn72718642003-07-24 08:45:32 +00001287 If called from generated code, use VG_(get_current_tid)() to get the
1288 current ThreadId. If called from non-generated code, the current
daywalker5d945de2003-09-26 00:32:53 +00001289 ThreadId should be passed in by the core.
njn7b456f52003-05-19 11:16:50 +00001290*/
njn72718642003-07-24 08:45:32 +00001291extern ExeContext* VG_(get_ExeContext) ( ThreadId tid );
njn25e49d8e72002-09-23 09:36:25 +00001292
njn6c846552003-09-16 07:41:43 +00001293/* Get the nth EIP from the ExeContext. 0 is the EIP of the top function, 1
1294 is its caller, etc. Returns 0 if there isn't one, or if n is greater
1295 than VG_(clo_backtrace_size), set by the --num-callers option. */
1296extern Addr VG_(get_EIP_from_ExeContext) ( ExeContext* e, UInt n );
1297
sewardj499e3de2002-11-13 22:22:25 +00001298/* Just grab the client's EIP, as a much smaller and cheaper
njn72718642003-07-24 08:45:32 +00001299 indication of where they are. Use is basically same as for
daywalker5d945de2003-09-26 00:32:53 +00001300 VG_(get_ExeContext)() above.
njn72718642003-07-24 08:45:32 +00001301*/
1302extern Addr VG_(get_EIP)( ThreadId tid );
njn25e49d8e72002-09-23 09:36:25 +00001303
njn6c846552003-09-16 07:41:43 +00001304/* For skins needing more control over stack traces: walks the stack to get
1305 %eips from the top stack frames for thread 'tid'. Maximum of 'n_eips'
1306 addresses put into 'eips'; 0 is the top of the stack, 1 is its caller,
1307 etc. */
1308extern UInt VG_(stack_snapshot) ( ThreadId tid, Addr* eips, UInt n_eips );
1309
1310/* Does the same thing as VG_(pp_ExeContext)(), just with slightly
1311 different input. */
1312extern void VG_(mini_stack_dump) ( Addr eips[], UInt n_eips );
1313
njn211b6ad2003-02-03 12:33:31 +00001314
njn25e49d8e72002-09-23 09:36:25 +00001315/*====================================================================*/
1316/*=== Error reporting ===*/
1317/*====================================================================*/
1318
1319/* ------------------------------------------------------------------ */
daywalker5d945de2003-09-26 00:32:53 +00001320/* Suppressions describe errors which we want to suppress, ie, not
njn25e49d8e72002-09-23 09:36:25 +00001321 show the user, usually because it is caused by a problem in a library
daywalker5d945de2003-09-26 00:32:53 +00001322 which we can't fix, replace or work around. Suppressions are read from
njnd5bb0a52002-09-27 10:24:48 +00001323 a file at startup time. This gives flexibility so that new
njn25e49d8e72002-09-23 09:36:25 +00001324 suppressions can be added to the file as and when needed.
1325*/
1326
1327typedef
1328 Int /* Do not make this unsigned! */
1329 SuppKind;
1330
njn810086f2002-11-14 12:42:47 +00001331/* The skin-relevant parts of a suppression are:
1332 kind: what kind of suppression; must be in the range (0..)
1333 string: use is optional. NULL by default.
1334 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001335*/
1336typedef
njn810086f2002-11-14 12:42:47 +00001337 struct _Supp
1338 Supp;
1339
1340/* Useful in SK_(error_matches_suppression)() */
1341SuppKind VG_(get_supp_kind) ( Supp* su );
1342Char* VG_(get_supp_string) ( Supp* su );
1343void* VG_(get_supp_extra) ( Supp* su );
1344
1345/* Must be used in VG_(recognised_suppression)() */
1346void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
1347/* May be used in VG_(read_extra_suppression_info)() */
1348void VG_(set_supp_string) ( Supp* su, Char* string );
1349void VG_(set_supp_extra) ( Supp* su, void* extra );
njn25e49d8e72002-09-23 09:36:25 +00001350
1351
1352/* ------------------------------------------------------------------ */
1353/* Error records contain enough info to generate an error report. The idea
1354 is that (typically) the same few points in the program generate thousands
njnd5bb0a52002-09-27 10:24:48 +00001355 of errors, and we don't want to spew out a fresh error message for each
1356 one. Instead, we use these structures to common up duplicates.
njn25e49d8e72002-09-23 09:36:25 +00001357*/
1358
1359typedef
1360 Int /* Do not make this unsigned! */
1361 ErrorKind;
1362
njn810086f2002-11-14 12:42:47 +00001363/* The skin-relevant parts of an Error are:
1364 kind: what kind of error; must be in the range (0..)
1365 addr: use is optional. 0 by default.
1366 string: use is optional. NULL by default.
1367 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001368*/
1369typedef
njn810086f2002-11-14 12:42:47 +00001370 struct _Error
1371 Error;
njn25e49d8e72002-09-23 09:36:25 +00001372
njn810086f2002-11-14 12:42:47 +00001373/* Useful in SK_(error_matches_suppression)(), SK_(pp_SkinError)(), etc */
njnb877d492003-01-28 20:40:57 +00001374ExeContext* VG_(get_error_where) ( Error* err );
1375SuppKind VG_(get_error_kind) ( Error* err );
1376Addr VG_(get_error_address) ( Error* err );
1377Char* VG_(get_error_string) ( Error* err );
1378void* VG_(get_error_extra) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001379
njnd5bb0a52002-09-27 10:24:48 +00001380/* Call this when an error occurs. It will be recorded if it hasn't been
njn25e49d8e72002-09-23 09:36:25 +00001381 seen before. If it has, the existing error record will have its count
daywalker5d945de2003-09-26 00:32:53 +00001382 incremented.
1383
njn72718642003-07-24 08:45:32 +00001384 'tid' can be found as for VG_(get_ExeContext)(). The `extra' field can
1385 be stack-allocated; it will be copied by the core if needed (but it
1386 won't be copied if it's NULL).
njnd5bb0a52002-09-27 10:24:48 +00001387
1388 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
njn3e884182003-04-15 13:03:23 +00001389 NULL for them. */
daywalker5d945de2003-09-26 00:32:53 +00001390extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind,
njn25e49d8e72002-09-23 09:36:25 +00001391 Addr a, Char* s, void* extra );
1392
njn43c799e2003-04-08 00:08:52 +00001393/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
1394 error -- useful for errors that can only happen once. The errors can be
1395 suppressed, though. Return value is True if it was suppressed.
daywalker5d945de2003-09-26 00:32:53 +00001396 `print_error' dictates whether to print the error, which is a bit of a
njn43c799e2003-04-08 00:08:52 +00001397 hack that's useful sometimes if you just want to know if the error would
daywalker5d945de2003-09-26 00:32:53 +00001398 be suppressed without possibly printing it. `count_error' dictates
njn47363ab2003-04-21 13:24:40 +00001399 whether to add the error in the error total count (another mild hack). */
njn72718642003-07-24 08:45:32 +00001400extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
njn43c799e2003-04-08 00:08:52 +00001401 Addr a, Char* s, void* extra,
njn3e884182003-04-15 13:03:23 +00001402 ExeContext* where, Bool print_error,
njn47363ab2003-04-21 13:24:40 +00001403 Bool allow_GDB_attach, Bool count_error );
njn43c799e2003-04-08 00:08:52 +00001404
njn25e49d8e72002-09-23 09:36:25 +00001405/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
daywalker5d945de2003-09-26 00:32:53 +00001406 Skips leading spaces on the line. Returns True if EOF was hit instead.
njn3e884182003-04-15 13:03:23 +00001407 Useful for reading in extra skin-specific suppression lines. */
njn4ba5a792002-09-30 10:23:54 +00001408extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
njn25e49d8e72002-09-23 09:36:25 +00001409
1410
1411/*====================================================================*/
1412/*=== Obtaining debug information ===*/
1413/*====================================================================*/
1414
sewardj6e008cb2002-12-15 13:11:39 +00001415/* Get the file/function/line number of the instruction at address
1416 'a'. For these four, if debug info for the address is found, it
1417 copies the info into the buffer/UInt and returns True. If not, it
1418 returns False and nothing is copied. VG_(get_fnname) always
1419 demangles C++ function names. VG_(get_fnname_w_offset) is the
njn3e884182003-04-15 13:03:23 +00001420 same, except it appends "+N" to symbol names to indicate offsets. */
njn25e49d8e72002-09-23 09:36:25 +00001421extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
1422extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
1423extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
daywalker5d945de2003-09-26 00:32:53 +00001424extern Bool VG_(get_fnname_w_offset)
sewardj6e008cb2002-12-15 13:11:39 +00001425 ( Addr a, Char* fnname, Int n_fnname );
njn25e49d8e72002-09-23 09:36:25 +00001426
1427/* This one is more efficient if getting both filename and line number,
1428 because the two lookups are done together. */
daywalker5d945de2003-09-26 00:32:53 +00001429extern Bool VG_(get_filename_linenum)
njn25e49d8e72002-09-23 09:36:25 +00001430 ( Addr a, Char* filename, Int n_filename,
1431 UInt* linenum );
1432
1433/* Succeeds only if we find from debug info that 'a' is the address of the
1434 first instruction in a function -- as opposed to VG_(get_fnname) which
1435 succeeds if we find from debug info that 'a' is the address of any
1436 instruction in a function. Use this to instrument the start of
njnd5bb0a52002-09-27 10:24:48 +00001437 a particular function. Nb: if an executable/shared object is stripped
njn25e49d8e72002-09-23 09:36:25 +00001438 of its symbols, this function will not be able to recognise function
1439 entry points within it. */
njn497ec3f2003-05-19 08:38:23 +00001440extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname );
njn25e49d8e72002-09-23 09:36:25 +00001441
1442/* Succeeds if the address is within a shared object or the main executable.
1443 It doesn't matter if debug info is present or not. */
1444extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
1445
njn6c846552003-09-16 07:41:43 +00001446/* Puts into 'buf' info about the code address %eip: the address, function
1447 name (if known) and filename/line number (if known), like this:
1448
1449 0x4001BF05: realloc (vg_replace_malloc.c:339)
1450
1451 'n_buf' gives length of 'buf'. Returns 'buf'.
1452*/
1453extern Char* VG_(describe_eip)(Addr eip, Char* buf, Int n_buf);
1454
jsgfcb1d1c02003-10-14 21:55:10 +00001455/* Returns a string containing an expression for the given
1456 address. String is malloced with VG_(malloc)() */
1457Char *VG_(describe_addr)(ThreadId, Addr);
1458
sewardj47104382002-10-20 18:35:48 +00001459/* A way to get information about what segments are mapped */
1460typedef struct _SegInfo SegInfo;
1461
njnb877d492003-01-28 20:40:57 +00001462/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
1463 is present or not. */
1464extern SegInfo* VG_(get_obj) ( Addr a );
1465
1466extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
1467extern Addr VG_(seg_start) ( const SegInfo *seg );
1468extern UInt VG_(seg_size) ( const SegInfo *seg );
1469extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
1470extern UInt VG_(seg_sym_offset)( const SegInfo *seg );
sewardj47104382002-10-20 18:35:48 +00001471
1472typedef
1473 enum {
1474 Vg_SectUnknown,
1475 Vg_SectText,
sewardj8fe15a32002-10-20 19:29:21 +00001476 Vg_SectData,
1477 Vg_SectBSS,
sewardj47104382002-10-20 18:35:48 +00001478 Vg_SectGOT,
sewardj8fe15a32002-10-20 19:29:21 +00001479 Vg_SectPLT,
sewardj47104382002-10-20 18:35:48 +00001480 }
1481 VgSectKind;
1482
1483extern VgSectKind VG_(seg_sect_kind)(Addr);
1484
njn25e49d8e72002-09-23 09:36:25 +00001485
1486/*====================================================================*/
njn3e884182003-04-15 13:03:23 +00001487/*=== Generic hash table ===*/
njn25e49d8e72002-09-23 09:36:25 +00001488/*====================================================================*/
1489
njn3e884182003-04-15 13:03:23 +00001490/* Generic type for a separately-chained hash table. Via a kind of dodgy
1491 C-as-C++ style inheritance, skins can extend the VgHashNode type, so long
1492 as the first two fields match the sizes of these two fields. Requires
1493 a bit of casting by the skin. */
njn25e49d8e72002-09-23 09:36:25 +00001494typedef
njn3e884182003-04-15 13:03:23 +00001495 struct _VgHashNode {
1496 struct _VgHashNode * next;
1497 UInt key;
1498 }
1499 VgHashNode;
njn25e49d8e72002-09-23 09:36:25 +00001500
njn3e884182003-04-15 13:03:23 +00001501typedef
1502 VgHashNode**
1503 VgHashTable;
njn810086f2002-11-14 12:42:47 +00001504
njn3e884182003-04-15 13:03:23 +00001505/* Make a new table. */
1506extern VgHashTable VG_(HT_construct) ( void );
1507
njn69c06872003-09-30 15:43:51 +00001508/* Count the number of nodes in a table. */
1509extern Int VG_(HT_count_nodes) ( VgHashTable table );
1510
njn3e884182003-04-15 13:03:23 +00001511/* Add a node to the table. */
1512extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
1513
daywalker5d945de2003-09-26 00:32:53 +00001514/* Looks up a node in the hash table. Also returns the address of the
njn3e884182003-04-15 13:03:23 +00001515 previous node's `next' pointer which allows it to be removed from the
1516 list later without having to look it up again. */
1517extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UInt key,
1518 /*OUT*/VgHashNode*** next_ptr );
1519
njn06072ec2003-09-30 15:35:13 +00001520/* Allocates an array of pointers to all the shadow chunks of malloc'd
1521 blocks. Must be freed with VG_(free)(). */
1522extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
njn3e884182003-04-15 13:03:23 +00001523
1524/* Returns first node that matches predicate `p', or NULL if none do.
1525 Extra arguments can be implicitly passed to `p' using nested functions;
1526 see memcheck/mc_errcontext.c for an example. */
1527extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
1528 Bool (*p)(VgHashNode*) );
1529
1530/* Applies a function f() once to each node. Again, nested functions
1531 can be very useful. */
1532extern void VG_(HT_apply_to_all_nodes)( VgHashTable t, void (*f)(VgHashNode*) );
1533
1534/* Destroy a table. */
1535extern void VG_(HT_destruct) ( VgHashTable t );
njn810086f2002-11-14 12:42:47 +00001536
1537
njn3e884182003-04-15 13:03:23 +00001538/*====================================================================*/
njnd3040452003-05-19 15:04:06 +00001539/*=== Functions for shadow registers ===*/
1540/*====================================================================*/
1541
1542/* Nb: make sure the shadow_regs 'need' is set before using these! */
1543
1544/* This one lets you override the shadow of the return value register for a
1545 syscall. Call it from SK_(post_syscall)() (not SK_(pre_syscall)()!) to
1546 override the default shadow register value. */
daywalker5d945de2003-09-26 00:32:53 +00001547extern void VG_(set_return_from_syscall_shadow) ( ThreadId tid,
njnd3040452003-05-19 15:04:06 +00001548 UInt ret_shadow );
1549
1550/* This can be called from SK_(fini)() to find the shadow of the argument
1551 to exit(), ie. the shadow of the program's return value. */
1552extern UInt VG_(get_exit_status_shadow) ( void );
1553
1554
1555/*====================================================================*/
njn3e884182003-04-15 13:03:23 +00001556/*=== General stuff for replacing functions ===*/
1557/*====================================================================*/
njn25e49d8e72002-09-23 09:36:25 +00001558
njn3e884182003-04-15 13:03:23 +00001559/* Some skins need to replace the standard definitions of some functions. */
njn25e49d8e72002-09-23 09:36:25 +00001560
njn3e884182003-04-15 13:03:23 +00001561/* ------------------------------------------------------------------ */
1562/* General stuff, for replacing any functions */
njn25e49d8e72002-09-23 09:36:25 +00001563
daywalker5d945de2003-09-26 00:32:53 +00001564/* Is the client running on the simulated CPU or the real one?
njn25e49d8e72002-09-23 09:36:25 +00001565
njn3e884182003-04-15 13:03:23 +00001566 Nb: If it is, and you want to call a function to be run on the real CPU,
njn057c65f2003-04-21 13:30:55 +00001567 use one of the VALGRIND_NON_SIMD_CALL[123] macros in valgrind.h to call it.
njn25e49d8e72002-09-23 09:36:25 +00001568
daywalker5d945de2003-09-26 00:32:53 +00001569 Nb: don't forget the function parentheses when using this in a
njn3e884182003-04-15 13:03:23 +00001570 condition... write this:
1571
1572 if (VG_(is_running_on_simd_CPU)()) { ... } // calls function
1573
1574 not this:
daywalker5d945de2003-09-26 00:32:53 +00001575
njn3e884182003-04-15 13:03:23 +00001576 if (VG_(is_running_on_simd_CPU)) { ... } // address of var!
1577*/
daywalker5d945de2003-09-26 00:32:53 +00001578extern Bool VG_(is_running_on_simd_CPU) ( void );
njn3e884182003-04-15 13:03:23 +00001579
1580
1581/*====================================================================*/
1582/*=== Specific stuff for replacing malloc() and friends ===*/
1583/*====================================================================*/
1584
njn3e884182003-04-15 13:03:23 +00001585/* If a skin replaces malloc() et al, the easiest way to do so is to link
1586 with coregrind/vg_replace_malloc.c, and follow the following instructions.
1587 You can do it from scratch, though, if you enjoy that sort of thing. */
1588
1589/* Arena size for valgrind's own malloc(); default value is 0, but can
1590 be overridden by skin -- but must be done so *statically*, eg:
daywalker5d945de2003-09-26 00:32:53 +00001591
njn3e884182003-04-15 13:03:23 +00001592 Int VG_(vg_malloc_redzone_szB) = 4;
daywalker5d945de2003-09-26 00:32:53 +00001593
njn3e884182003-04-15 13:03:23 +00001594 It can't be done from a function like SK_(pre_clo_init)(). So it can't,
1595 for example, be controlled with a command line option, unfortunately. */
1596extern UInt VG_(vg_malloc_redzone_szB);
1597
1598/* If a skin links with vg_replace_malloc.c, the following functions will be
1599 called appropriately when malloc() et al are called. */
njn72718642003-07-24 08:45:32 +00001600extern void* SK_(malloc) ( Int n );
1601extern void* SK_(__builtin_new) ( Int n );
1602extern void* SK_(__builtin_vec_new) ( Int n );
1603extern void* SK_(memalign) ( Int align, Int n );
1604extern void* SK_(calloc) ( Int nmemb, Int n );
1605extern void SK_(free) ( void* p );
1606extern void SK_(__builtin_delete) ( void* p );
1607extern void SK_(__builtin_vec_delete) ( void* p );
1608extern void* SK_(realloc) ( void* p, Int size );
njn3e884182003-04-15 13:03:23 +00001609
1610/* Can be called from SK_(malloc) et al to do the actual alloc/freeing. */
daywalker5d945de2003-09-26 00:32:53 +00001611extern void* VG_(cli_malloc) ( UInt align, Int nbytes );
njn3e884182003-04-15 13:03:23 +00001612extern void VG_(cli_free) ( void* p );
1613
1614/* Check if an address is within a range, allowing for redzones at edges */
1615extern Bool VG_(addr_is_in_block)( Addr a, Addr start, UInt size );
1616
1617/* ------------------------------------------------------------------ */
daywalker5d945de2003-09-26 00:32:53 +00001618/* Some options that can be used by a skin if malloc() et al are replaced.
njnd3040452003-05-19 15:04:06 +00001619 The skin should call the functions in the appropriate places to give
1620 control over these aspects of Valgrind's version of malloc(). */
njn3e884182003-04-15 13:03:23 +00001621
1622/* Round malloc sizes upwards to integral number of words? default: NO */
1623extern Bool VG_(clo_sloppy_malloc);
1624/* DEBUG: print malloc details? default: NO */
1625extern Bool VG_(clo_trace_malloc);
1626/* Minimum alignment in functions that don't specify alignment explicitly.
1627 default: 0, i.e. use default of the machine (== 4) */
1628extern Int VG_(clo_alignment);
1629
1630extern Bool VG_(replacement_malloc_process_cmd_line_option) ( Char* arg );
1631extern void VG_(replacement_malloc_print_usage) ( void );
1632extern void VG_(replacement_malloc_print_debug_usage) ( void );
sewardja4495682002-10-21 07:29:59 +00001633
1634
njn25e49d8e72002-09-23 09:36:25 +00001635/*====================================================================*/
1636/*=== Skin-specific stuff ===*/
1637/*====================================================================*/
1638
njnd04b7c62002-10-03 14:05:52 +00001639/* ------------------------------------------------------------------ */
1640/* Details */
njnd04b7c62002-10-03 14:05:52 +00001641
njn120281f2003-02-03 12:20:07 +00001642/* Default value for avg_translations_sizeB (in bytes), indicating typical
1643 code expansion of about 6:1. */
1644#define VG_DEFAULT_TRANS_SIZEB 100
1645
njn810086f2002-11-14 12:42:47 +00001646/* Information used in the startup message. `name' also determines the
1647 string used for identifying suppressions in a suppression file as
1648 belonging to this skin. `version' can be NULL, in which case (not
1649 surprisingly) no version info is printed; this mechanism is designed for
1650 skins distributed with Valgrind that share a version number with
1651 Valgrind. Other skins not distributed as part of Valgrind should
sewardjc0d8f682002-11-30 00:49:43 +00001652 probably have their own version number. */
1653extern void VG_(details_name) ( Char* name );
1654extern void VG_(details_version) ( Char* version );
1655extern void VG_(details_description) ( Char* description );
1656extern void VG_(details_copyright_author) ( Char* copyright_author );
1657
1658/* Average size of a translation, in bytes, so that the translation
njn120281f2003-02-03 12:20:07 +00001659 storage machinery can allocate memory appropriately. Not critical,
daywalker5d945de2003-09-26 00:32:53 +00001660 setting is optional. */
njn120281f2003-02-03 12:20:07 +00001661extern void VG_(details_avg_translation_sizeB) ( UInt size );
njnd04b7c62002-10-03 14:05:52 +00001662
njn810086f2002-11-14 12:42:47 +00001663/* String printed if an `sk_assert' assertion fails or VG_(skin_panic)
1664 is called. Should probably be an email address. */
1665extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
njnd04b7c62002-10-03 14:05:52 +00001666
1667/* ------------------------------------------------------------------ */
1668/* Needs */
1669
njn810086f2002-11-14 12:42:47 +00001670/* Booleans that decide core behaviour, but don't require extra
1671 operations to be defined if `True' */
njnd5bb0a52002-09-27 10:24:48 +00001672
njn810086f2002-11-14 12:42:47 +00001673/* Should __libc_freeres() be run? Bugs in it can crash the skin. */
1674extern void VG_(needs_libc_freeres) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001675
njn810086f2002-11-14 12:42:47 +00001676/* Want to have errors detected by Valgrind's core reported? Includes:
1677 - pthread API errors (many; eg. unlocking a non-locked mutex)
njn810086f2002-11-14 12:42:47 +00001678 - invalid file descriptors to blocking syscalls read() and write()
1679 - bad signal numbers passed to sigaction()
daywalker5d945de2003-09-26 00:32:53 +00001680 - attempt to install signal handler for SIGKILL or SIGSTOP */
njn810086f2002-11-14 12:42:47 +00001681extern void VG_(needs_core_errors) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001682
njn810086f2002-11-14 12:42:47 +00001683/* Booleans that indicate extra operations are defined; if these are True,
1684 the corresponding template functions (given below) must be defined. A
1685 lot like being a member of a type class. */
njn25e49d8e72002-09-23 09:36:25 +00001686
njn810086f2002-11-14 12:42:47 +00001687/* Want to report errors from skin? This implies use of suppressions, too. */
1688extern void VG_(needs_skin_errors) ( void );
njnd5bb0a52002-09-27 10:24:48 +00001689
njn810086f2002-11-14 12:42:47 +00001690/* Is information kept about specific individual basic blocks? (Eg. for
1691 cachegrind there are cost-centres for every instruction, stored at a
1692 basic block level.) If so, it sometimes has to be discarded, because
1693 .so mmap/munmap-ping or self-modifying code (informed by the
1694 DISCARD_TRANSLATIONS user request) can cause one instruction address
1695 to be used for more than one instruction in one program run... */
1696extern void VG_(needs_basic_block_discards) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001697
njn810086f2002-11-14 12:42:47 +00001698/* Skin maintains information about each register? */
1699extern void VG_(needs_shadow_regs) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001700
njn810086f2002-11-14 12:42:47 +00001701/* Skin defines its own command line options? */
1702extern void VG_(needs_command_line_options) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001703
njn810086f2002-11-14 12:42:47 +00001704/* Skin defines its own client requests? */
1705extern void VG_(needs_client_requests) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001706
njn810086f2002-11-14 12:42:47 +00001707/* Skin defines its own UInstrs? */
1708extern void VG_(needs_extended_UCode) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001709
njn810086f2002-11-14 12:42:47 +00001710/* Skin does stuff before and/or after system calls? */
1711extern void VG_(needs_syscall_wrapper) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001712
njn810086f2002-11-14 12:42:47 +00001713/* Are skin-state sanity checks performed? */
1714extern void VG_(needs_sanity_checks) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001715
njn810086f2002-11-14 12:42:47 +00001716/* Do we need to see data symbols? */
1717extern void VG_(needs_data_syms) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001718
1719/* ------------------------------------------------------------------ */
1720/* Core events to track */
1721
1722/* Part of the core from which this call was made. Useful for determining
njnd5bb0a52002-09-27 10:24:48 +00001723 what kind of error message should be emitted. */
daywalker5d945de2003-09-26 00:32:53 +00001724typedef
njn25e49d8e72002-09-23 09:36:25 +00001725 enum { Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall, Vg_CoreTranslate }
1726 CorePart;
1727
njn810086f2002-11-14 12:42:47 +00001728#define EV extern void
njn25e49d8e72002-09-23 09:36:25 +00001729
njn810086f2002-11-14 12:42:47 +00001730/* Events happening in core to track. To be notified, pass a callback
1731 function to the appropriate function. To ignore an event, don't do
daywalker5d945de2003-09-26 00:32:53 +00001732 anything (default is for events to be ignored).
1733
njn72718642003-07-24 08:45:32 +00001734 Note that most events aren't passed a ThreadId. To find out the ThreadId
1735 of the affected thread, use VG_(get_current_or_recent_tid)(). For the
1736 ones passed a ThreadId, use that instead, since
1737 VG_(get_current_or_recent_tid)() might not give the right ThreadId in
1738 that case.
1739*/
njn810086f2002-11-14 12:42:47 +00001740
njn810086f2002-11-14 12:42:47 +00001741
njn3e884182003-04-15 13:03:23 +00001742/* Memory events (Nb: to track heap allocation/freeing, a skin must replace
1743 malloc() et al. See above how to do this.) */
1744
1745/* These ones occur at startup, upon some signals, and upon some syscalls */
daywalker5d945de2003-09-26 00:32:53 +00001746EV VG_(track_new_mem_startup) ( void (*f)(Addr a, UInt len,
njn810086f2002-11-14 12:42:47 +00001747 Bool rr, Bool ww, Bool xx) );
njn810086f2002-11-14 12:42:47 +00001748EV VG_(track_new_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1749EV VG_(track_new_mem_brk) ( void (*f)(Addr a, UInt len) );
1750EV VG_(track_new_mem_mmap) ( void (*f)(Addr a, UInt len,
1751 Bool rr, Bool ww, Bool xx) );
1752
njn3e884182003-04-15 13:03:23 +00001753EV VG_(track_copy_mem_remap) ( void (*f)(Addr from, Addr to, UInt len) );
1754EV VG_(track_change_mem_mprotect) ( void (*f)(Addr a, UInt len,
1755 Bool rr, Bool ww, Bool xx) );
1756EV VG_(track_die_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1757EV VG_(track_die_mem_brk) ( void (*f)(Addr a, UInt len) );
1758EV VG_(track_die_mem_munmap) ( void (*f)(Addr a, UInt len) );
1759
1760
1761/* These ones are called when %esp changes. A skin could track these itself
1762 (except for ban_mem_stack) but it's much easier to use the core's help.
daywalker5d945de2003-09-26 00:32:53 +00001763
njn3e884182003-04-15 13:03:23 +00001764 The specialised ones are called in preference to the general one, if they
njn9b007f62003-04-07 14:40:25 +00001765 are defined. These functions are called a lot if they are used, so
1766 specialising can optimise things significantly. If any of the
daywalker5d945de2003-09-26 00:32:53 +00001767 specialised cases are defined, the general case must be defined too.
1768
njn9b007f62003-04-07 14:40:25 +00001769 Nb: they must all use the __attribute__((regparm(n))) attribute. */
1770EV VG_(track_new_mem_stack_4) ( void (*f)(Addr new_ESP) );
1771EV VG_(track_new_mem_stack_8) ( void (*f)(Addr new_ESP) );
1772EV VG_(track_new_mem_stack_12) ( void (*f)(Addr new_ESP) );
1773EV VG_(track_new_mem_stack_16) ( void (*f)(Addr new_ESP) );
1774EV VG_(track_new_mem_stack_32) ( void (*f)(Addr new_ESP) );
1775EV VG_(track_new_mem_stack) ( void (*f)(Addr a, UInt len) );
1776
njn9b007f62003-04-07 14:40:25 +00001777EV VG_(track_die_mem_stack_4) ( void (*f)(Addr die_ESP) );
1778EV VG_(track_die_mem_stack_8) ( void (*f)(Addr die_ESP) );
1779EV VG_(track_die_mem_stack_12) ( void (*f)(Addr die_ESP) );
1780EV VG_(track_die_mem_stack_16) ( void (*f)(Addr die_ESP) );
1781EV VG_(track_die_mem_stack_32) ( void (*f)(Addr die_ESP) );
1782EV VG_(track_die_mem_stack) ( void (*f)(Addr a, UInt len) );
1783
njn3e884182003-04-15 13:03:23 +00001784/* Used for redzone at end of thread stacks */
1785EV VG_(track_ban_mem_stack) ( void (*f)(Addr a, UInt len) );
njn25e49d8e72002-09-23 09:36:25 +00001786
njn3e884182003-04-15 13:03:23 +00001787/* These ones occur around syscalls, signal handling, etc */
njn72718642003-07-24 08:45:32 +00001788EV VG_(track_pre_mem_read) ( void (*f)(CorePart part, ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001789 Char* s, Addr a, UInt size) );
njn72718642003-07-24 08:45:32 +00001790EV VG_(track_pre_mem_read_asciiz) ( void (*f)(CorePart part, ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001791 Char* s, Addr a) );
njn72718642003-07-24 08:45:32 +00001792EV VG_(track_pre_mem_write) ( void (*f)(CorePart part, ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001793 Char* s, Addr a, UInt size) );
1794/* Not implemented yet -- have to add in lots of places, which is a
1795 pain. Won't bother unless/until there's a need. */
daywalker5d945de2003-09-26 00:32:53 +00001796/* EV VG_(track_post_mem_read) ( void (*f)(ThreadId tid, Char* s,
njn810086f2002-11-14 12:42:47 +00001797 Addr a, UInt size) ); */
1798EV VG_(track_post_mem_write) ( void (*f)(Addr a, UInt size) );
njn25e49d8e72002-09-23 09:36:25 +00001799
1800
njnd3040452003-05-19 15:04:06 +00001801/* Register events -- if `shadow_regs' need is set, all should probably be
1802 used. Use VG_(set_thread_shadow_archreg)() to set the shadow of the
1803 changed register. */
1804
1805/* Use VG_(set_shadow_archreg)() to set the eight general purpose regs,
1806 and use VG_(set_shadow_eflags)() to set eflags. */
daywalker5d945de2003-09-26 00:32:53 +00001807EV VG_(track_post_regs_write_init) ( void (*f)() );
njnd3040452003-05-19 15:04:06 +00001808
daywalker5d945de2003-09-26 00:32:53 +00001809/* Use VG_(set_thread_shadow_archreg)() to set the shadow regs for these
njnd3040452003-05-19 15:04:06 +00001810 events. */
daywalker5d945de2003-09-26 00:32:53 +00001811EV VG_(track_post_reg_write_syscall_return)
njnd3040452003-05-19 15:04:06 +00001812 ( void (*f)(ThreadId tid, UInt reg) );
1813EV VG_(track_post_reg_write_deliver_signal)
1814 ( void (*f)(ThreadId tid, UInt reg) );
1815EV VG_(track_post_reg_write_pthread_return)
1816 ( void (*f)(ThreadId tid, UInt reg) );
1817EV VG_(track_post_reg_write_clientreq_return)
1818 ( void (*f)(ThreadId tid, UInt reg) );
1819 /* This one is called for malloc() et al if they are replaced by a skin. */
1820EV VG_(track_post_reg_write_clientcall_return)
1821 ( void (*f)(ThreadId tid, UInt reg,
1822 Addr called_function) );
1823
1824
njn810086f2002-11-14 12:42:47 +00001825/* Scheduler events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001826
njn810086f2002-11-14 12:42:47 +00001827EV VG_(track_thread_run) ( void (*f)(ThreadId tid) );
njn25e49d8e72002-09-23 09:36:25 +00001828
njn810086f2002-11-14 12:42:47 +00001829/* Thread events (not exhaustive) */
sewardjdca84112002-11-13 22:29:34 +00001830
njn810086f2002-11-14 12:42:47 +00001831/* Called during thread create, before the new thread has run any
1832 instructions (or touched any memory). */
1833EV VG_(track_post_thread_create)( void (*f)(ThreadId tid, ThreadId child) );
1834/* Called once the joinee thread is terminated and the joining thread is
1835 about to resume. */
1836EV VG_(track_post_thread_join) ( void (*f)(ThreadId joiner, ThreadId joinee) );
njn25e49d8e72002-09-23 09:36:25 +00001837
daywalker5d945de2003-09-26 00:32:53 +00001838
njn810086f2002-11-14 12:42:47 +00001839/* Mutex events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001840
njn810086f2002-11-14 12:42:47 +00001841/* Called before a thread can block while waiting for a mutex (called
1842 regardless of whether the thread will block or not). */
daywalker5d945de2003-09-26 00:32:53 +00001843EV VG_(track_pre_mutex_lock) ( void (*f)(ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001844 void* /*pthread_mutex_t* */ mutex) );
1845/* Called once the thread actually holds the mutex (always paired with
1846 pre_mutex_lock). */
daywalker5d945de2003-09-26 00:32:53 +00001847EV VG_(track_post_mutex_lock) ( void (*f)(ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001848 void* /*pthread_mutex_t* */ mutex) );
1849/* Called after a thread has released a mutex (no need for a corresponding
1850 pre_mutex_unlock, because unlocking can't block). */
daywalker5d945de2003-09-26 00:32:53 +00001851EV VG_(track_post_mutex_unlock) ( void (*f)(ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001852 void* /*pthread_mutex_t* */ mutex) );
njn25e49d8e72002-09-23 09:36:25 +00001853
njn1045b0a2003-02-24 10:42:47 +00001854
1855/* Signal events (not exhaustive) */
1856
njn7b456f52003-05-19 11:16:50 +00001857/* ... pre_send_signal, post_send_signal ... */
1858
njn1045b0a2003-02-24 10:42:47 +00001859/* Called before a signal is delivered; `alt_stack' indicates if it is
1860 delivered on an alternative stack. */
1861EV VG_(track_pre_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum,
1862 Bool alt_stack) );
njn7b456f52003-05-19 11:16:50 +00001863/* Called after a signal is delivered. Nb: unfortunately, if the signal
1864 handler longjmps, this won't be called. */
njn1045b0a2003-02-24 10:42:47 +00001865EV VG_(track_post_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum ) );
1866
1867
1868/* Others... condition variables... */
njn810086f2002-11-14 12:42:47 +00001869/* ... */
1870
1871#undef EV
njn25e49d8e72002-09-23 09:36:25 +00001872
1873/* ------------------------------------------------------------------ */
1874/* Template functions */
1875
1876/* These are the parameterised functions in the core. The default definitions
njnd5bb0a52002-09-27 10:24:48 +00001877 are overridden by LD_PRELOADed skin version. At the very least, a skin
1878 must define the fundamental template functions. Depending on what needs
1879 are set, extra template functions will be used too. Functions are
1880 grouped under the needs that govern their use. */
njn25e49d8e72002-09-23 09:36:25 +00001881
1882
1883/* ------------------------------------------------------------------ */
1884/* Fundamental template functions */
1885
1886/* Initialise skin. Must do the following:
njn810086f2002-11-14 12:42:47 +00001887 - initialise the `details' struct, via the VG_(details_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001888 - register any helpers called by generated code
daywalker5d945de2003-09-26 00:32:53 +00001889
njn25e49d8e72002-09-23 09:36:25 +00001890 May do the following:
njn810086f2002-11-14 12:42:47 +00001891 - initialise the `needs' struct to indicate certain requirements, via
1892 the VG_(needs_*)() functions
1893 - initialise the `track' struct to indicate core events of interest, via
1894 the VG_(track_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001895 - register any skin-specific profiling events
1896 - any other skin-specific initialisation
1897*/
njn810086f2002-11-14 12:42:47 +00001898extern void SK_(pre_clo_init) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001899
njnd5bb0a52002-09-27 10:24:48 +00001900/* Do initialisation that can only be done after command line processing. */
njn25e49d8e72002-09-23 09:36:25 +00001901extern void SK_(post_clo_init)( void );
1902
1903/* Instrument a basic block. Must be a true function, ie. the same input
1904 always results in the same output, because basic blocks can be
1905 retranslated. Unless you're doing something really strange...
1906 'orig_addr' is the address of the first instruction in the block. */
1907extern UCodeBlock* SK_(instrument) ( UCodeBlock* cb, Addr orig_addr );
1908
njn7d9f94d2003-04-22 21:41:40 +00001909/* Finish up, print out any results, etc. `exitcode' is program's exit
1910 code. The shadow (if the `shadow_regs' need is set) can be found with
1911 VG_(get_shadow_archreg)(R_EBX), since %ebx holds the argument to the
1912 exit() syscall. */
1913extern void SK_(fini) ( Int exitcode );
njn25e49d8e72002-09-23 09:36:25 +00001914
1915
1916/* ------------------------------------------------------------------ */
njn6a230532003-07-21 10:38:23 +00001917/* VG_(needs).core_errors */
1918
1919/* (none needed) */
1920
1921/* ------------------------------------------------------------------ */
1922/* VG_(needs).skin_errors */
njn25e49d8e72002-09-23 09:36:25 +00001923
1924/* Identify if two errors are equal, or equal enough. `res' indicates how
1925 close is "close enough". `res' should be passed on as necessary, eg. if
njn810086f2002-11-14 12:42:47 +00001926 the Error's `extra' part contains an ExeContext, `res' should be
njn25e49d8e72002-09-23 09:36:25 +00001927 passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other
1928 than that, probably don't worry about it unless you have lots of very
1929 similar errors occurring.
1930 */
njn810086f2002-11-14 12:42:47 +00001931extern Bool SK_(eq_SkinError) ( VgRes res, Error* e1, Error* e2 );
njn25e49d8e72002-09-23 09:36:25 +00001932
njn43c799e2003-04-08 00:08:52 +00001933/* Print error context. */
1934extern void SK_(pp_SkinError) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001935
njn43c799e2003-04-08 00:08:52 +00001936/* Should fill in any details that could be postponed until after the
njn810086f2002-11-14 12:42:47 +00001937 decision whether to ignore the error (ie. details not affecting the
1938 result of SK_(eq_SkinError)()). This saves time when errors are ignored.
njn25e49d8e72002-09-23 09:36:25 +00001939 Yuk.
njn43c799e2003-04-08 00:08:52 +00001940
1941 Return value: must be the size of the `extra' part in bytes -- used by
1942 the core to make a copy.
njn25e49d8e72002-09-23 09:36:25 +00001943*/
njn43c799e2003-04-08 00:08:52 +00001944extern UInt SK_(update_extra) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001945
njn810086f2002-11-14 12:42:47 +00001946/* Return value indicates recognition. If recognised, must set skind using
1947 VG_(set_supp_kind)(). */
1948extern Bool SK_(recognised_suppression) ( Char* name, Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001949
njn810086f2002-11-14 12:42:47 +00001950/* Read any extra info for this suppression kind. Most likely for filling
1951 in the `extra' and `string' parts (with VG_(set_supp_{extra,string})())
daywalker5d945de2003-09-26 00:32:53 +00001952 of a suppression if necessary. Should return False if a syntax error
njn810086f2002-11-14 12:42:47 +00001953 occurred, True otherwise. */
1954extern Bool SK_(read_extra_suppression_info) ( Int fd, Char* buf, Int nBuf,
1955 Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001956
1957/* This should just check the kinds match and maybe some stuff in the
njn810086f2002-11-14 12:42:47 +00001958 `string' and `extra' field if appropriate (using VG_(get_supp_*)() to
1959 get the relevant suppression parts). */
njn43c799e2003-04-08 00:08:52 +00001960extern Bool SK_(error_matches_suppression) ( Error* err, Supp* su );
1961
1962/* This should return the suppression name, for --gen-suppressions, or NULL
1963 if that error type cannot be suppressed. This is the inverse of
1964 SK_(recognised_suppression)(). */
1965extern Char* SK_(get_error_name) ( Error* err );
1966
1967/* This should print any extra info for the error, for --gen-suppressions,
1968 including the newline. This is the inverse of
1969 SK_(read_extra_suppression_info)(). */
1970extern void SK_(print_extra_suppression_info) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001971
1972
1973/* ------------------------------------------------------------------ */
1974/* VG_(needs).basic_block_discards */
1975
njnd5bb0a52002-09-27 10:24:48 +00001976/* Should discard any information that pertains to specific basic blocks
1977 or instructions within the address range given. */
njn25e49d8e72002-09-23 09:36:25 +00001978extern void SK_(discard_basic_block_info) ( Addr a, UInt size );
1979
1980
1981/* ------------------------------------------------------------------ */
1982/* VG_(needs).shadow_regs */
1983
njnd3040452003-05-19 15:04:06 +00001984/* No functions must be defined, but the post_reg[s]_write_* events should
1985 be tracked. */
njn25e49d8e72002-09-23 09:36:25 +00001986
1987/* ------------------------------------------------------------------ */
1988/* VG_(needs).command_line_options */
1989
njnd5bb0a52002-09-27 10:24:48 +00001990/* Return True if option was recognised. Presumably sets some state to
1991 record the option as well. */
1992extern Bool SK_(process_cmd_line_option) ( Char* argv );
njn25e49d8e72002-09-23 09:36:25 +00001993
njn3e884182003-04-15 13:03:23 +00001994/* Print out command line usage for options for normal skin operation. */
1995extern void SK_(print_usage) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001996
njn3e884182003-04-15 13:03:23 +00001997/* Print out command line usage for options for debugging the skin. */
1998extern void SK_(print_debug_usage) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001999
2000/* ------------------------------------------------------------------ */
2001/* VG_(needs).client_requests */
2002
njnd3040452003-05-19 15:04:06 +00002003/* If using client requests, the number of the first request should be equal
2004 to VG_USERREQ_SKIN_BASE('X','Y'), where 'X' and 'Y' form a suitable two
2005 character identification for the string. The second and subsequent
2006 requests should follow. */
2007
2008/* This function should use the VG_IS_SKIN_USERREQ macro (in
2009 include/valgrind.h) to first check if it's a request for this skin. Then
2010 should handle it if it's recognised (and return True), or return False if
2011 not recognised. arg_block[0] holds the request number, any further args
2012 from the request are in arg_block[1..]. 'ret' is for the return value...
2013 it should probably be filled, if only with 0. */
njn72718642003-07-24 08:45:32 +00002014extern Bool SK_(handle_client_request) ( ThreadId tid, UInt* arg_block,
njnd3040452003-05-19 15:04:06 +00002015 UInt *ret );
njn25e49d8e72002-09-23 09:36:25 +00002016
2017
2018/* ------------------------------------------------------------------ */
2019/* VG_(needs).extends_UCode */
2020
njn4ba5a792002-09-30 10:23:54 +00002021/* Useful to use in VG_(get_Xreg_usage)() */
njn810086f2002-11-14 12:42:47 +00002022#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
njn25e49d8e72002-09-23 09:36:25 +00002023 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00002024 { regs[n] = mycat(u->val,ono); \
2025 isWrites[n] = False; \
njn25e49d8e72002-09-23 09:36:25 +00002026 n++; \
2027 } \
2028 }
njn810086f2002-11-14 12:42:47 +00002029#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
njnd5bb0a52002-09-27 10:24:48 +00002030 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00002031 { regs[n] = mycat(u->val,ono); \
2032 isWrites[n] = True; \
njnd5bb0a52002-09-27 10:24:48 +00002033 n++; \
2034 } \
njn25e49d8e72002-09-23 09:36:25 +00002035 }
2036
njn4ba5a792002-09-30 10:23:54 +00002037/* 'X' prefix indicates eXtended UCode. */
njn810086f2002-11-14 12:42:47 +00002038extern Int SK_(get_Xreg_usage) ( UInstr* u, Tag tag, Int* regs,
2039 Bool* isWrites );
njn4ba5a792002-09-30 10:23:54 +00002040extern void SK_(emit_XUInstr) ( UInstr* u, RRegSet regs_live_before );
2041extern Bool SK_(sane_XUInstr) ( Bool beforeRA, Bool beforeLiveness,
njn25e49d8e72002-09-23 09:36:25 +00002042 UInstr* u );
njn4ba5a792002-09-30 10:23:54 +00002043extern Char* SK_(name_XUOpcode) ( Opcode opc );
2044extern void SK_(pp_XUInstr) ( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +00002045
2046
2047/* ------------------------------------------------------------------ */
2048/* VG_(needs).syscall_wrapper */
2049
2050/* If either of the pre_ functions malloc() something to return, the
daywalker5d945de2003-09-26 00:32:53 +00002051 * corresponding post_ function had better free() it!
2052 */
njn25e49d8e72002-09-23 09:36:25 +00002053extern void* SK_( pre_syscall) ( ThreadId tid, UInt syscallno,
2054 Bool is_blocking );
2055extern void SK_(post_syscall) ( ThreadId tid, UInt syscallno,
2056 void* pre_result, Int res,
2057 Bool is_blocking );
2058
njnd5bb0a52002-09-27 10:24:48 +00002059
njn25e49d8e72002-09-23 09:36:25 +00002060/* ---------------------------------------------------------------------
2061 VG_(needs).sanity_checks */
2062
njnd5bb0a52002-09-27 10:24:48 +00002063/* Can be useful for ensuring a skin's correctness. SK_(cheap_sanity_check)
2064 is called very frequently; SK_(expensive_sanity_check) is called less
2065 frequently and can be more involved. */
njn25e49d8e72002-09-23 09:36:25 +00002066extern Bool SK_(cheap_sanity_check) ( void );
2067extern Bool SK_(expensive_sanity_check) ( void );
2068
2069
2070#endif /* NDEF __VG_SKIN_H */
2071
2072/*--------------------------------------------------------------------*/
2073/*--- end vg_skin.h ---*/
2074/*--------------------------------------------------------------------*/
2075