blob: 5e74d98791f07e0e3f97792818eb140f03c10b88 [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
nethercote421281e2003-11-20 16:20:55 +000041/* ---------------------------------------------------------------------
42 Where to send bug reports to.
43 ------------------------------------------------------------------ */
44
45#define VG_BUGS_TO "valgrind.kde.org"
46
47
njn25e49d8e72002-09-23 09:36:25 +000048/*====================================================================*/
49/*=== Build options and table sizes. ===*/
50/*====================================================================*/
51
daywalker5d945de2003-09-26 00:32:53 +000052/* You should be able to change these options or sizes, recompile, and
njn25e49d8e72002-09-23 09:36:25 +000053 still have a working system. */
54
55/* The maximum number of pthreads that we support. This is
56 deliberately not very high since our implementation of some of the
57 scheduler algorithms is surely O(N) in the number of threads, since
58 that's simple, at least. And (in practice) we hope that most
59 programs do not need many threads. */
sewardj989dad92003-07-06 01:52:32 +000060#define VG_N_THREADS 100
njn25e49d8e72002-09-23 09:36:25 +000061
62/* Maximum number of pthread keys available. Again, we start low until
63 the need for a higher number presents itself. */
64#define VG_N_THREAD_KEYS 50
65
66/* Total number of integer registers available for allocation -- all of
67 them except %esp, %ebp. %ebp permanently points at VG_(baseBlock).
daywalker5d945de2003-09-26 00:32:53 +000068
njn211b6ad2003-02-03 12:33:31 +000069 If you increase this you'll have to also change at least these:
njn4ba5a792002-09-30 10:23:54 +000070 - VG_(rank_to_realreg)()
71 - VG_(realreg_to_rank)()
njn25e49d8e72002-09-23 09:36:25 +000072 - ppRegsLiveness()
73 - the RegsLive type (maybe -- RegsLive type must have more than
74 VG_MAX_REALREGS bits)
njn211b6ad2003-02-03 12:33:31 +000075
76 You can decrease it, and performance will drop because more spills will
77 occur. If you decrease it too much, everything will fall over.
daywalker5d945de2003-09-26 00:32:53 +000078
njn25e49d8e72002-09-23 09:36:25 +000079 Do not change this unless you really know what you are doing! */
80#define VG_MAX_REALREGS 6
81
82
83/*====================================================================*/
njn1a1dd8b2002-09-27 10:42:20 +000084/*=== Basic types, useful macros ===*/
njn25e49d8e72002-09-23 09:36:25 +000085/*====================================================================*/
86
njn25e49d8e72002-09-23 09:36:25 +000087typedef unsigned char UChar;
88typedef unsigned short UShort;
89typedef unsigned int UInt;
90typedef unsigned long long int ULong;
91
92typedef signed char Char;
93typedef signed short Short;
94typedef signed int Int;
95typedef signed long long int Long;
96
97typedef unsigned int Addr;
98
99typedef unsigned char Bool;
100#define False ((Bool)0)
101#define True ((Bool)1)
102
103
njn1a1dd8b2002-09-27 10:42:20 +0000104#define mycat_wrk(aaa,bbb) aaa##bbb
105#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
106
107/* No, really. I _am_ that strange. */
108#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
109
njn25e49d8e72002-09-23 09:36:25 +0000110/* ---------------------------------------------------------------------
111 Now the basic types are set up, we can haul in the kernel-interface
112 definitions.
113 ------------------------------------------------------------------ */
114
njn78adbf42003-07-24 19:35:00 +0000115#include "vg_kerneliface.h"
njn25e49d8e72002-09-23 09:36:25 +0000116
117
118/*====================================================================*/
njn27f1a382002-11-08 15:48:16 +0000119/*=== Core/skin interface version ===*/
120/*====================================================================*/
121
122/* The major version number indicates binary-incompatible changes to the
123 interface; if the core and skin major versions don't match, Valgrind
124 will abort. The minor version indicates binary-compatible changes.
njn27f1a382002-11-08 15:48:16 +0000125*/
jseward157689b2003-11-05 23:59:21 +0000126#define VG_CORE_INTERFACE_MAJOR_VERSION 5
njn9b007f62003-04-07 14:40:25 +0000127#define VG_CORE_INTERFACE_MINOR_VERSION 0
njn27f1a382002-11-08 15:48:16 +0000128
129extern const Int VG_(skin_interface_major_version);
130extern const Int VG_(skin_interface_minor_version);
131
njn563f96f2003-02-03 11:17:46 +0000132/* Every skin must include this macro somewhere, exactly once. */
njn27f1a382002-11-08 15:48:16 +0000133#define VG_DETERMINE_INTERFACE_VERSION \
134const Int VG_(skin_interface_major_version) = VG_CORE_INTERFACE_MAJOR_VERSION; \
135const Int VG_(skin_interface_minor_version) = VG_CORE_INTERFACE_MINOR_VERSION;
136
njn211b6ad2003-02-03 12:33:31 +0000137
njn27f1a382002-11-08 15:48:16 +0000138/*====================================================================*/
njn25e49d8e72002-09-23 09:36:25 +0000139/*=== Command-line options ===*/
140/*====================================================================*/
141
njn43c799e2003-04-08 00:08:52 +0000142/* Use this for normal null-termination-style string comparison */
143#define VG_STREQ(s1,s2) (s1 != NULL && s2 != NULL \
144 && VG_(strcmp)((s1),(s2))==0)
145
146/* Use these for recognising skin command line options -- stops comparing
147 once whitespace is reached. */
148# define VG_CLO_STREQ(s1,s2) (0==VG_(strcmp_ws)((s1),(s2)))
149# define VG_CLO_STREQN(nn,s1,s2) (0==VG_(strncmp_ws)((s1),(s2),(nn)))
150
njn25e49d8e72002-09-23 09:36:25 +0000151/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
152extern Int VG_(clo_verbosity);
153
154/* Profile? */
155extern Bool VG_(clo_profile);
156
njn25e49d8e72002-09-23 09:36:25 +0000157/* Call this if a recognised option was bad for some reason.
158 Note: don't use it just because an option was unrecognised -- return 'False'
159 from SKN_(process_cmd_line_option) to indicate that. */
160extern void VG_(bad_option) ( Char* opt );
161
162/* Client args */
163extern Int VG_(client_argc);
164extern Char** VG_(client_argv);
165
njnd5bb0a52002-09-27 10:24:48 +0000166/* Client environment. Can be inspected with VG_(getenv)() */
njn25e49d8e72002-09-23 09:36:25 +0000167extern Char** VG_(client_envp);
168
169
170/*====================================================================*/
171/*=== Printing messages for the user ===*/
172/*====================================================================*/
173
174/* Print a message prefixed by "??<pid>?? "; '?' depends on the VgMsgKind.
175 Should be used for all user output. */
176
177typedef
178 enum { Vg_UserMsg, /* '?' == '=' */
179 Vg_DebugMsg, /* '?' == '-' */
fitzhardinge39de4b42003-10-31 07:12:21 +0000180 Vg_DebugExtraMsg, /* '?' == '+' */
181 Vg_ClientMsg, /* '?' == '*' */
njn25e49d8e72002-09-23 09:36:25 +0000182 }
183 VgMsgKind;
184
185/* Functions for building a message from multiple parts. */
fitzhardinge39de4b42003-10-31 07:12:21 +0000186extern int VG_(start_msg) ( VgMsgKind kind );
187extern int VG_(add_to_msg) ( Char* format, ... );
njn25e49d8e72002-09-23 09:36:25 +0000188/* Ends and prints the message. Appends a newline. */
fitzhardinge39de4b42003-10-31 07:12:21 +0000189extern int VG_(end_msg) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000190
njnd5bb0a52002-09-27 10:24:48 +0000191/* Send a single-part message. Appends a newline. */
fitzhardinge39de4b42003-10-31 07:12:21 +0000192extern int VG_(message) ( VgMsgKind kind, Char* format, ... );
193extern int VG_(vmessage) ( VgMsgKind kind, Char* format, va_list vargs );
njn25e49d8e72002-09-23 09:36:25 +0000194
195
196/*====================================================================*/
197/*=== Profiling ===*/
198/*====================================================================*/
199
200/* Nb: VGP_(register_profile_event)() relies on VgpUnc being the first one */
201#define VGP_CORE_LIST \
202 /* These ones depend on the core */ \
203 VGP_PAIR(VgpUnc, "unclassified"), \
204 VGP_PAIR(VgpRun, "running"), \
205 VGP_PAIR(VgpSched, "scheduler"), \
206 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
207 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
njn25e49d8e72002-09-23 09:36:25 +0000208 VGP_PAIR(VgpTranslate, "translate-main"), \
209 VGP_PAIR(VgpToUCode, "to-ucode"), \
210 VGP_PAIR(VgpFromUcode, "from-ucode"), \
211 VGP_PAIR(VgpImprove, "improve"), \
njn9b007f62003-04-07 14:40:25 +0000212 VGP_PAIR(VgpESPUpdate, "ESP-update"), \
njn25e49d8e72002-09-23 09:36:25 +0000213 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
214 VGP_PAIR(VgpLiveness, "liveness-analysis"), \
215 VGP_PAIR(VgpDoLRU, "do-lru"), \
216 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
217 VGP_PAIR(VgpInitMem, "init-memory"), \
218 VGP_PAIR(VgpExeContext, "exe-context"), \
219 VGP_PAIR(VgpReadSyms, "read-syms"), \
220 VGP_PAIR(VgpSearchSyms, "search-syms"), \
221 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
222 VGP_PAIR(VgpCoreSysWrap, "core-syscall-wrapper"), \
223 VGP_PAIR(VgpDemangle, "demangle"), \
njn37cea302002-09-30 11:24:00 +0000224 VGP_PAIR(VgpCoreCheapSanity, "core-cheap-sanity"), \
225 VGP_PAIR(VgpCoreExpensiveSanity, "core-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000226 /* These ones depend on the skin */ \
227 VGP_PAIR(VgpPreCloInit, "pre-clo-init"), \
228 VGP_PAIR(VgpPostCloInit, "post-clo-init"), \
229 VGP_PAIR(VgpInstrument, "instrument"), \
230 VGP_PAIR(VgpSkinSysWrap, "skin-syscall-wrapper"), \
njn37cea302002-09-30 11:24:00 +0000231 VGP_PAIR(VgpSkinCheapSanity, "skin-cheap-sanity"), \
232 VGP_PAIR(VgpSkinExpensiveSanity, "skin-expensive-sanity"), \
njn25e49d8e72002-09-23 09:36:25 +0000233 VGP_PAIR(VgpFini, "fini")
234
235#define VGP_PAIR(n,name) n
236typedef enum { VGP_CORE_LIST } VgpCoreCC;
237#undef VGP_PAIR
238
239/* When registering skin profiling events, ensure that the 'n' value is in
240 * the range (VgpFini+1..) */
241extern void VGP_(register_profile_event) ( Int n, Char* name );
242
243extern void VGP_(pushcc) ( UInt cc );
244extern void VGP_(popcc) ( UInt cc );
245
246/* Define them only if they haven't already been defined by vg_profile.c */
247#ifndef VGP_PUSHCC
248# define VGP_PUSHCC(x)
249#endif
250#ifndef VGP_POPCC
251# define VGP_POPCC(x)
252#endif
253
254
255/*====================================================================*/
256/*=== Useful stuff to call from generated code ===*/
257/*====================================================================*/
258
259/* ------------------------------------------------------------------ */
260/* General stuff */
261
njn41557122002-10-14 09:25:37 +0000262/* 64-bit counter for the number of basic blocks done. */
263extern ULong VG_(bbs_done);
264
njn25e49d8e72002-09-23 09:36:25 +0000265/* Get the simulated %esp */
266extern Addr VG_(get_stack_pointer) ( void );
267
sewardjecf8e102003-07-12 12:11:39 +0000268/* Detect if an address is within Valgrind's stack, Valgrind's
269 m_state_static, or the VG_(threads) array. This is useful for
270 memory leak detectors to rule out spurious pointers to a block. */
njn25e49d8e72002-09-23 09:36:25 +0000271extern Bool VG_(within_stack)(Addr a);
sewardjecf8e102003-07-12 12:11:39 +0000272extern Bool VG_(within_m_state_static_OR_threads)(Addr a);
njn25e49d8e72002-09-23 09:36:25 +0000273
274/* Check if an address is 4-byte aligned */
275#define IS_ALIGNED4_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 3))
njn9b007f62003-04-07 14:40:25 +0000276#define IS_ALIGNED8_ADDR(aaa_p) (0 == (((UInt)(aaa_p)) & 7))
njn25e49d8e72002-09-23 09:36:25 +0000277
278
279/* ------------------------------------------------------------------ */
280/* Thread-related stuff */
281
282/* Special magic value for an invalid ThreadId. It corresponds to
283 LinuxThreads using zero as the initial value for
284 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
285#define VG_INVALID_THREADID ((ThreadId)(0))
286
njn72718642003-07-24 08:45:32 +0000287/* ThreadIds are simply indices into the VG_(threads)[] array. */
daywalker5d945de2003-09-26 00:32:53 +0000288typedef
289 UInt
njn25e49d8e72002-09-23 09:36:25 +0000290 ThreadId;
291
njn72718642003-07-24 08:45:32 +0000292/* When looking for the current ThreadId, this is the safe option and
293 probably the one you want.
daywalker5d945de2003-09-26 00:32:53 +0000294
njn72718642003-07-24 08:45:32 +0000295 Details: Use this one from non-generated code, eg. from functions called
296 on events like 'new_mem_heap'. In such a case, the "current" thread is
297 temporarily suspended as Valgrind's dispatcher is running. This function
298 is also suitable to be called from generated code (ie. from UCode, or a C
299 function called directly from UCode).
daywalker5d945de2003-09-26 00:32:53 +0000300
njn72718642003-07-24 08:45:32 +0000301 If you use VG_(get_current_tid)() from non-generated code, it will return
302 0 signifying the invalid thread, which is probably not what you want. */
303extern ThreadId VG_(get_current_or_recent_tid) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000304
njn72718642003-07-24 08:45:32 +0000305/* When looking for the current ThreadId, only use this one if you know what
306 you are doing.
daywalker5d945de2003-09-26 00:32:53 +0000307
njn72718642003-07-24 08:45:32 +0000308 Details: Use this one from generated code, eg. from C functions called
309 from UCode. (VG_(get_current_or_recent_tid)() is also suitable in that
310 case.) If you use this function from non-generated code, it will return
311 0 signifying the invalid thread, which is probably not what you want. */
312extern ThreadId VG_(get_current_tid) ( void );
njn25e49d8e72002-09-23 09:36:25 +0000313
njn3e884182003-04-15 13:03:23 +0000314/* Searches through all thread's stacks to see if any match. Returns
njn72718642003-07-24 08:45:32 +0000315 VG_INVALID_THREADID if none match. */
njn3e884182003-04-15 13:03:23 +0000316extern ThreadId VG_(first_matching_thread_stack)
317 ( Bool (*p) ( Addr stack_min, Addr stack_max ));
318
njn25e49d8e72002-09-23 09:36:25 +0000319
320/*====================================================================*/
321/*=== Valgrind's version of libc ===*/
322/*====================================================================*/
323
324/* Valgrind doesn't use libc at all, for good reasons (trust us). So here
325 are its own versions of C library functions, but with VG_ prefixes. Note
326 that the types of some are slightly different to the real ones. Some
njnf4ce3d32003-02-10 10:17:26 +0000327 additional useful functions are provided too; descriptions of how they
328 work are given below. */
njn25e49d8e72002-09-23 09:36:25 +0000329
330#if !defined(NULL)
331# define NULL ((void*)0)
332#endif
333
334
335/* ------------------------------------------------------------------ */
336/* stdio.h
337 *
338 * Note that they all output to the file descriptor given by the
339 * --logfile-fd=N argument, which defaults to 2 (stderr). Hence no
daywalker5d945de2003-09-26 00:32:53 +0000340 * need for VG_(fprintf)().
njn25e49d8e72002-09-23 09:36:25 +0000341 */
sewardj78e3cd92002-10-22 04:45:48 +0000342extern UInt VG_(printf) ( const char *format, ... );
njn25e49d8e72002-09-23 09:36:25 +0000343/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
sewardj78e3cd92002-10-22 04:45:48 +0000344extern UInt VG_(sprintf) ( Char* buf, Char *format, ... );
daywalker5d945de2003-09-26 00:32:53 +0000345extern UInt VG_(vprintf) ( void(*send)(Char),
njn25e49d8e72002-09-23 09:36:25 +0000346 const Char *format, va_list vargs );
347
njn41557122002-10-14 09:25:37 +0000348extern Int VG_(rename) ( Char* old_name, Char* new_name );
349
njn25e49d8e72002-09-23 09:36:25 +0000350/* ------------------------------------------------------------------ */
351/* stdlib.h */
352
353extern void* VG_(malloc) ( Int nbytes );
njnd5bb0a52002-09-27 10:24:48 +0000354extern void VG_(free) ( void* p );
355extern void* VG_(calloc) ( Int n, Int nbytes );
356extern void* VG_(realloc) ( void* p, Int size );
357extern void* VG_(malloc_aligned) ( Int align_bytes, Int nbytes );
njn25e49d8e72002-09-23 09:36:25 +0000358
359extern void VG_(print_malloc_stats) ( void );
360
361
362extern void VG_(exit)( Int status )
363 __attribute__ ((__noreturn__));
njne427a662002-10-02 11:08:25 +0000364/* Prints a panic message (a constant string), appends newline and bug
365 reporting info, aborts. */
366__attribute__ ((__noreturn__))
367extern void VG_(skin_panic) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000368
njnd5bb0a52002-09-27 10:24:48 +0000369/* Looks up VG_(client_envp) */
njn25e49d8e72002-09-23 09:36:25 +0000370extern Char* VG_(getenv) ( Char* name );
371
rjwalshf5f536f2003-11-17 17:45:00 +0000372/* Get client resource limit*/
373extern Int VG_(getrlimit) ( Int resource, struct vki_rlimit *rlim );
374
njn25e49d8e72002-09-23 09:36:25 +0000375/* Crude stand-in for the glibc system() call. */
376extern Int VG_(system) ( Char* cmd );
377
njnd5bb0a52002-09-27 10:24:48 +0000378extern Long VG_(atoll) ( Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000379
380/* Like atoll(), but converts a number of base 2..36 */
381extern Long VG_(atoll36) ( UInt base, Char* str );
382
njne36543a2003-09-30 15:37:24 +0000383/* Like qsort(), but does shell-sort. The size==1/2/4 cases are specialised. */
njnd3b0c5f2003-09-30 14:43:54 +0000384extern void VG_(ssort)( void* base, UInt nmemb, UInt size,
385 Int (*compar)(void*, void*) );
386
njn25e49d8e72002-09-23 09:36:25 +0000387
388/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000389/* ctype.h */
njn25e49d8e72002-09-23 09:36:25 +0000390extern Bool VG_(isspace) ( Char c );
391extern Bool VG_(isdigit) ( Char c );
392extern Char VG_(toupper) ( Char c );
393
394
395/* ------------------------------------------------------------------ */
396/* string.h */
397extern Int VG_(strlen) ( const Char* str );
398extern Char* VG_(strcat) ( Char* dest, const Char* src );
399extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
400extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
401extern Char* VG_(strcpy) ( Char* dest, const Char* src );
402extern Char* VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
403extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
404extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
405extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
406extern Char* VG_(strchr) ( const Char* s, Char c );
407extern Char* VG_(strdup) ( const Char* s);
sewardj7ab2aca2002-10-20 19:40:32 +0000408extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
409extern void* VG_(memset) ( void *s, Int c, Int sz );
njn6d68e792003-02-24 10:49:08 +0000410extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
njn25e49d8e72002-09-23 09:36:25 +0000411
njnd5bb0a52002-09-27 10:24:48 +0000412/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
njn25e49d8e72002-09-23 09:36:25 +0000413extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
njn25e49d8e72002-09-23 09:36:25 +0000414extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
415
daywalker5d945de2003-09-26 00:32:53 +0000416/* Like strncpy(), but if 'src' is longer than 'ndest' inserts a '\0' as the
njnd5bb0a52002-09-27 10:24:48 +0000417 last character. */
njn25e49d8e72002-09-23 09:36:25 +0000418extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
419
420/* Mini-regexp function. Searches for 'pat' in 'str'. Supports
421 * meta-symbols '*' and '?'. '\' escapes meta-symbols. */
njn4ba5a792002-09-30 10:23:54 +0000422extern Bool VG_(string_match) ( Char* pat, Char* str );
njn25e49d8e72002-09-23 09:36:25 +0000423
424
425/* ------------------------------------------------------------------ */
426/* math.h */
njnd5bb0a52002-09-27 10:24:48 +0000427/* Returns the base-2 logarithm of x. */
njn25e49d8e72002-09-23 09:36:25 +0000428extern Int VG_(log2) ( Int x );
429
430
431/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000432/* unistd.h, fcntl.h, sys/stat.h */
rjwalshf5f536f2003-11-17 17:45:00 +0000433extern Int VG_(getdents)( UInt fd, struct vki_dirent *dirp, UInt count );
434extern Int VG_(readlink)( Char* path, Char* buf, UInt bufsize );
sewardj4cf05692002-10-27 20:28:29 +0000435extern Int VG_(getpid) ( void );
436extern Int VG_(getppid) ( void );
jsgf855d93d2003-10-13 22:26:55 +0000437extern Int VG_(getpgrp) ( void );
438extern Int VG_(gettid) ( void );
439extern Int VG_(setpgid) ( Int pid, Int pgrp );
njnd5bb0a52002-09-27 10:24:48 +0000440
njn4aca2d22002-10-04 10:29:38 +0000441extern Int VG_(open) ( const Char* pathname, Int flags, Int mode );
442extern Int VG_(read) ( Int fd, void* buf, Int count);
jsgf855d93d2003-10-13 22:26:55 +0000443extern Int VG_(write) ( Int fd, const void* buf, Int count);
rjwalshf5f536f2003-11-17 17:45:00 +0000444extern Int VG_(lseek) ( Int fd, Long offset, Int whence);
njn4aca2d22002-10-04 10:29:38 +0000445extern void VG_(close) ( Int fd );
njnd5bb0a52002-09-27 10:24:48 +0000446
jsgf855d93d2003-10-13 22:26:55 +0000447extern Int VG_(pipe) ( Int fd[2] );
448
njn41557122002-10-14 09:25:37 +0000449/* Nb: VG_(rename)() declared in stdio.h section above */
njn4aca2d22002-10-04 10:29:38 +0000450extern Int VG_(unlink) ( Char* file_name );
451extern Int VG_(stat) ( Char* file_name, struct vki_stat* buf );
njnc9d4ba72003-10-15 10:34:03 +0000452extern Int VG_(fstat) ( Int fd, struct vki_stat* buf );
fitzhardingee1c06d82003-10-30 07:21:44 +0000453extern Int VG_(dup2) ( Int oldfd, Int newfd );
njn25e49d8e72002-09-23 09:36:25 +0000454
njn13f02932003-04-30 20:23:58 +0000455extern Char* VG_(getcwd) ( Char* buf, Int size );
456
njn99ccf082003-09-30 13:51:23 +0000457/* Easier to use than VG_(getcwd)() -- does the buffer fiddling itself.
458 String put into 'cwd' is VG_(malloc)'d, and should be VG_(free)'d.
459 Returns False if it fails. Will fail if the pathname is > 65535 bytes. */
460extern Bool VG_(getcwd_alloc) ( Char** cwd );
njn25e49d8e72002-09-23 09:36:25 +0000461
462/* ------------------------------------------------------------------ */
463/* assert.h */
464/* Asserts permanently enabled -- no turning off with NDEBUG. Hurrah! */
465#define VG__STRING(__str) #__str
466
njne427a662002-10-02 11:08:25 +0000467#define sk_assert(expr) \
njn25e49d8e72002-09-23 09:36:25 +0000468 ((void) ((expr) ? 0 : \
njne427a662002-10-02 11:08:25 +0000469 (VG_(skin_assert_fail) (VG__STRING(expr), \
470 __FILE__, __LINE__, \
471 __PRETTY_FUNCTION__), 0)))
njn25e49d8e72002-09-23 09:36:25 +0000472
njne427a662002-10-02 11:08:25 +0000473__attribute__ ((__noreturn__))
daywalker5d945de2003-09-26 00:32:53 +0000474extern void VG_(skin_assert_fail) ( const Char* expr, const Char* file,
daywalkerdf9ae422003-09-18 01:41:48 +0000475 Int line, const Char* fn );
njn25e49d8e72002-09-23 09:36:25 +0000476
477
478/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +0000479/* system/mman.h */
daywalker5d945de2003-09-26 00:32:53 +0000480extern void* VG_(mmap)( void* start, UInt length,
njn25e49d8e72002-09-23 09:36:25 +0000481 UInt prot, UInt flags, UInt fd, UInt offset );
482extern Int VG_(munmap)( void* start, Int length );
483
484/* Get memory by anonymous mmap. */
485extern void* VG_(get_memory_from_mmap) ( Int nBytes, Char* who );
486
487
488/* ------------------------------------------------------------------ */
daywalker5d945de2003-09-26 00:32:53 +0000489/* signal.h.
490
njn25e49d8e72002-09-23 09:36:25 +0000491 Note that these use the vk_ (kernel) structure
492 definitions, which are different in places from those that glibc
493 defines -- hence the 'k' prefix. Since we're operating right at the
494 kernel interface, glibc's view of the world is entirely irrelevant. */
495
496/* --- Signal set ops --- */
njnd5bb0a52002-09-27 10:24:48 +0000497extern Int VG_(ksigfillset) ( vki_ksigset_t* set );
498extern Int VG_(ksigemptyset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000499
njnd5bb0a52002-09-27 10:24:48 +0000500extern Bool VG_(kisfullsigset) ( vki_ksigset_t* set );
501extern Bool VG_(kisemptysigset) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000502
njnd5bb0a52002-09-27 10:24:48 +0000503extern Int VG_(ksigaddset) ( vki_ksigset_t* set, Int signum );
504extern Int VG_(ksigdelset) ( vki_ksigset_t* set, Int signum );
njn25e49d8e72002-09-23 09:36:25 +0000505extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
506
njnd5bb0a52002-09-27 10:24:48 +0000507extern void VG_(ksigaddset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
508extern void VG_(ksigdelset_from_set) ( vki_ksigset_t* dst, vki_ksigset_t* src );
njn25e49d8e72002-09-23 09:36:25 +0000509
510/* --- Mess with the kernel's sig state --- */
daywalker5d945de2003-09-26 00:32:53 +0000511extern Int VG_(ksigprocmask) ( Int how, const vki_ksigset_t* set,
njn25e49d8e72002-09-23 09:36:25 +0000512 vki_ksigset_t* oldset );
daywalker5d945de2003-09-26 00:32:53 +0000513extern Int VG_(ksigaction) ( Int signum,
514 const vki_ksigaction* act,
njnd5bb0a52002-09-27 10:24:48 +0000515 vki_ksigaction* oldact );
njn25e49d8e72002-09-23 09:36:25 +0000516
jsgf855d93d2003-10-13 22:26:55 +0000517extern Int VG_(ksigtimedwait)( const vki_ksigset_t *, vki_ksiginfo_t *,
518 const struct vki_timespec * );
519
njnd5bb0a52002-09-27 10:24:48 +0000520extern Int VG_(ksignal) ( Int signum, void (*sighandler)(Int) );
521extern Int VG_(ksigaltstack) ( const vki_kstack_t* ss, vki_kstack_t* oss );
njn25e49d8e72002-09-23 09:36:25 +0000522
sewardjdcaf3122002-09-30 23:12:33 +0000523extern Int VG_(kkill) ( Int pid, Int signo );
jsgf855d93d2003-10-13 22:26:55 +0000524extern Int VG_(ktkill) ( Int pid, Int signo );
sewardjdcaf3122002-09-30 23:12:33 +0000525extern Int VG_(ksigpending) ( vki_ksigset_t* set );
njn25e49d8e72002-09-23 09:36:25 +0000526
jsgf855d93d2003-10-13 22:26:55 +0000527extern Int VG_(waitpid) ( Int pid, Int *status, Int options );
njn25e49d8e72002-09-23 09:36:25 +0000528
njne7442cf2003-09-30 14:03:21 +0000529/* ------------------------------------------------------------------ */
rjwalshf5f536f2003-11-17 17:45:00 +0000530/* socket.h. */
531
532extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen);
533extern Int VG_(getpeername) ( Int sd, struct vki_sockaddr *name, Int *namelen);
534extern Int VG_(getsockopt) ( Int sd, Int level, Int optname, void *optval,
535 Int *optlen);
536
537/* ------------------------------------------------------------------ */
njne7442cf2003-09-30 14:03:21 +0000538/* other, randomly useful functions */
539extern UInt VG_(read_millisecond_timer) ( void );
540
njn25e49d8e72002-09-23 09:36:25 +0000541/*====================================================================*/
542/*=== UCode definition ===*/
543/*====================================================================*/
544
sewardje1042472002-09-30 12:33:11 +0000545/* Tags which describe what operands are. Must fit into 4 bits, which
546 they clearly do. */
njn25e49d8e72002-09-23 09:36:25 +0000547typedef
sewardje1042472002-09-30 12:33:11 +0000548enum { TempReg =0, /* virtual temp-reg */
549 ArchReg =1, /* simulated integer reg */
550 ArchRegS =2, /* simulated segment reg */
551 RealReg =3, /* real machine's real reg */
552 SpillNo =4, /* spill slot location */
553 Literal =5, /* literal; .lit32 field has actual value */
554 Lit16 =6, /* literal; .val[123] field has actual value */
555 NoValue =7 /* operand not in use */
556 }
557 Tag;
njn25e49d8e72002-09-23 09:36:25 +0000558
njnd5bb0a52002-09-27 10:24:48 +0000559/* Invalid register numbers (can't be negative) */
njn25e49d8e72002-09-23 09:36:25 +0000560#define INVALID_TEMPREG 999999999
561#define INVALID_REALREG 999999999
562
563/* Microinstruction opcodes. */
564typedef
565 enum {
njnd5bb0a52002-09-27 10:24:48 +0000566 NOP, /* Null op */
njn25e49d8e72002-09-23 09:36:25 +0000567
daywalker7e73e5f2003-07-04 16:18:15 +0000568 LOCK, /* Indicate the existence of a LOCK prefix (functionally NOP) */
sewardj7a5ebcf2002-11-13 22:42:13 +0000569
njnd5bb0a52002-09-27 10:24:48 +0000570 /* Moving values around */
571 GET, PUT, /* simulated register <--> TempReg */
572 GETF, PUTF, /* simulated %eflags <--> TempReg */
573 LOAD, STORE, /* memory <--> TempReg */
574 MOV, /* TempReg <--> TempReg */
575 CMOV, /* Used for cmpxchg and cmov */
njn25e49d8e72002-09-23 09:36:25 +0000576
njnd5bb0a52002-09-27 10:24:48 +0000577 /* Arithmetic/logical ops */
jsgf5efa4fd2003-10-14 21:49:11 +0000578 MUL, UMUL, /* Multiply */
njnd5bb0a52002-09-27 10:24:48 +0000579 ADD, ADC, SUB, SBB, /* Add/subtract (w/wo carry) */
580 AND, OR, XOR, NOT, /* Boolean ops */
581 SHL, SHR, SAR, ROL, ROR, RCL, RCR, /* Shift/rotate (w/wo carry) */
582 NEG, /* Negate */
583 INC, DEC, /* Increment/decrement */
584 BSWAP, /* Big-endian <--> little-endian */
585 CC2VAL, /* Condition code --> 0 or 1 */
586 WIDEN, /* Signed or unsigned widening */
njn25e49d8e72002-09-23 09:36:25 +0000587
njnd5bb0a52002-09-27 10:24:48 +0000588 /* Conditional or unconditional jump */
daywalker5d945de2003-09-26 00:32:53 +0000589 JMP,
njnd5bb0a52002-09-27 10:24:48 +0000590
591 /* FPU ops */
592 FPU, /* Doesn't touch memory */
593 FPU_R, FPU_W, /* Reads/writes memory */
594
sewardj3d7c9c82003-03-26 21:08:13 +0000595 /* ------------ MMX ops ------------ */
sewardj8cec6ee2003-05-18 11:56:39 +0000596 /* In this and the SSE encoding, bytes at higher addresses are
597 held in bits [7:0] in these 16-bit words. I guess this means
598 it is a big-endian encoding. */
sewardj3d7c9c82003-03-26 21:08:13 +0000599
600 /* 1 byte, no memrefs, no iregdefs, copy exactly to the
601 output. Held in val1[7:0]. */
602 MMX1,
603
604 /* 2 bytes, no memrefs, no iregdefs, copy exactly to the
605 output. Held in val1[15:0]. */
606 MMX2,
607
608 /* 3 bytes, no memrefs, no iregdefs, copy exactly to the
609 output. Held in val1[15:0] and val2[7:0]. */
610 MMX3,
611
612 /* 2 bytes, reads/writes mem. Insns of the form
613 bbbbbbbb:mod mmxreg r/m.
614 Held in val1[15:0], and mod and rm are to be replaced
daywalker5d945de2003-09-26 00:32:53 +0000615 at codegen time by a reference to the Temp/RealReg holding
sewardj3d7c9c82003-03-26 21:08:13 +0000616 the address. Arg2 holds this Temp/Real Reg.
617 Transfer is always at size 8.
618 */
619 MMX2_MemRd,
620 MMX2_MemWr,
621
sewardj4fbe6e92003-06-15 21:54:34 +0000622 /* 2 bytes, reads/writes an integer ("E") register. Insns of the form
sewardj3d7c9c82003-03-26 21:08:13 +0000623 bbbbbbbb:11 mmxreg ireg.
624 Held in val1[15:0], and ireg is to be replaced
625 at codegen time by a reference to the relevant RealReg.
626 Transfer is always at size 4. Arg2 holds this Temp/Real Reg.
627 */
sewardj4fbe6e92003-06-15 21:54:34 +0000628 MMX2_ERegRd,
629 MMX2_ERegWr,
sewardj3d7c9c82003-03-26 21:08:13 +0000630
sewardj8cec6ee2003-05-18 11:56:39 +0000631 /* ------------ SSE/SSE2 ops ------------ */
632 /* In the following:
633
sewardjfebaa3b2003-05-25 01:07:34 +0000634 a digit N indicates the next N bytes are to be copied exactly
635 to the output.
sewardj8cec6ee2003-05-18 11:56:39 +0000636
637 'a' indicates a mod-xmmreg-rm byte, where the mod-rm part is
638 to be replaced at codegen time to a Temp/RealReg holding the
639 address.
640
sewardj4fbe6e92003-06-15 21:54:34 +0000641 'e' indicates a byte of the form '11 xmmreg ireg', where ireg
642 is read or written, and is to be replaced at codegen time by
643 a reference to the relevant RealReg. 'e' because it's the E
644 reg in Intel encoding parlance.
sewardj8cec6ee2003-05-18 11:56:39 +0000645
sewardj4fbe6e92003-06-15 21:54:34 +0000646 'g' indicates a byte of the form '11 ireg xmmreg', where ireg
647 is read or written, and is to be replaced at codegen time by
648 a reference to the relevant RealReg. 'g' because it's called
649 G in Intel parlance. */
sewardj8cec6ee2003-05-18 11:56:39 +0000650
651 /* 3 bytes, no memrefs, no iregdefs, copy exactly to the
652 output. Held in val1[15:0] and val2[7:0]. */
653 SSE3,
654
655 /* 3 bytes, reads/writes mem. Insns of the form
656 bbbbbbbb:bbbbbbbb:mod mmxreg r/m.
657 Held in val1[15:0] and val2[7:0], and mod and rm are to be
658 replaced at codegen time by a reference to the Temp/RealReg
659 holding the address. Arg3 holds this Temp/Real Reg.
sewardjfebaa3b2003-05-25 01:07:34 +0000660 Transfer is usually, but not always, at size 16. */
sewardj8cec6ee2003-05-18 11:56:39 +0000661 SSE2a_MemRd,
662 SSE2a_MemWr,
663
664 /* 4 bytes, no memrefs, no iregdefs, copy exactly to the
665 output. Held in val1[15:0] and val2[15:0]. */
666 SSE4,
667
668 /* 4 bytes, reads/writes mem. Insns of the form
669 bbbbbbbb:bbbbbbbb:bbbbbbbb:mod mmxreg r/m.
670 Held in val1[15:0] and val2[15:0], and mod and rm are to be
671 replaced at codegen time by a reference to the Temp/RealReg
672 holding the address. Arg3 holds this Temp/Real Reg.
sewardj9dd209f2003-06-18 23:30:52 +0000673 Transfer is at stated size. */
sewardj8cec6ee2003-05-18 11:56:39 +0000674 SSE3a_MemRd,
675 SSE3a_MemWr,
676
677 /* 4 bytes, reads/writes mem. Insns of the form
678 bbbbbbbb:bbbbbbbb:mod mmxreg r/m:bbbbbbbb
679 Held in val1[15:0] and val2[15:0], and mod and rm are to be
680 replaced at codegen time by a reference to the Temp/RealReg
681 holding the address. Arg3 holds this Temp/Real Reg.
sewardj9dd209f2003-06-18 23:30:52 +0000682 Transfer is at stated size. */
sewardj8cec6ee2003-05-18 11:56:39 +0000683 SSE2a1_MemRd,
sewardj77d30a22003-10-19 08:18:52 +0000684
sewardj8cec6ee2003-05-18 11:56:39 +0000685 /* 4 bytes, writes an integer register. Insns of the form
sewardj4fbe6e92003-06-15 21:54:34 +0000686 bbbbbbbb:bbbbbbbb:bbbbbbbb:11 ireg bbb.
sewardj8cec6ee2003-05-18 11:56:39 +0000687 Held in val1[15:0] and val2[15:0], and ireg is to be replaced
688 at codegen time by a reference to the relevant RealReg.
689 Transfer is always at size 4. Arg3 holds this Temp/Real Reg.
690 */
691 SSE3g_RegWr,
692
sewardjb31b06d2003-06-13 00:26:02 +0000693 /* 5 bytes, writes an integer register. Insns of the form
694 bbbbbbbb:bbbbbbbb:bbbbbbbb: 11 ireg bbb :bbbbbbbb. Held in
695 val1[15:0] and val2[15:0] and lit32[7:0], and ireg is to be
696 replaced at codegen time by a reference to the relevant
697 RealReg. Transfer is always at size 4. Arg3 holds this
698 Temp/Real Reg.
699 */
700 SSE3g1_RegWr,
701
sewardj4fbe6e92003-06-15 21:54:34 +0000702 /* 4 bytes, reads an integer register. Insns of the form
703 bbbbbbbb:bbbbbbbb:bbbbbbbb:11 bbb ireg.
704 Held in val1[15:0] and val2[15:0], and ireg is to be replaced
705 at codegen time by a reference to the relevant RealReg.
706 Transfer is always at size 4. Arg3 holds this Temp/Real Reg.
707 */
708 SSE3e_RegRd,
sewardjabf8bf82003-06-15 22:28:05 +0000709 SSE3e_RegWr, /* variant that writes Ereg, not reads it */
sewardj4fbe6e92003-06-15 21:54:34 +0000710
sewardjb31b06d2003-06-13 00:26:02 +0000711 /* 5 bytes, reads an integer register. Insns of the form
712 bbbbbbbb:bbbbbbbb:bbbbbbbb: 11 bbb ireg :bbbbbbbb. Held in
713 val1[15:0] and val2[15:0] and lit32[7:0], and ireg is to be
714 replaced at codegen time by a reference to the relevant
715 RealReg. Transfer is always at size 4. Arg3 holds this
716 Temp/Real Reg.
717 */
sewardj4fbe6e92003-06-15 21:54:34 +0000718 SSE3e1_RegRd,
sewardj8cec6ee2003-05-18 11:56:39 +0000719
sewardj02af6bc2003-06-12 00:56:06 +0000720 /* 4 bytes, reads memory, writes an integer register, but is
721 nevertheless an SSE insn. The insn is of the form
722 bbbbbbbb:bbbbbbbb:bbbbbbbb:mod ireg rm where mod indicates
723 memory (ie is not 11b) and ireg is the int reg written. The
sewardje3891fa2003-06-15 03:13:48 +0000724 first 4 bytes are held in lit32[31:0] since there is
sewardj02af6bc2003-06-12 00:56:06 +0000725 insufficient space elsewhere. mod and rm are to be replaced
726 at codegen time by a reference to the Temp/RealReg holding
727 the address. Arg1 holds this Temp/RealReg. ireg is to be
728 replaced at codegen time by a reference to the relevant
729 RealReg in which the answer is to be written. Arg2 holds
730 this Temp/RealReg. Transfer to the destination reg is always
731 at size 4. However the memory read can be at sizes 4 or 8
sewardje3891fa2003-06-15 03:13:48 +0000732 and so this is what the sz field holds. Note that the 4th
733 byte of the instruction (the modrm byte) is redundant, but we
734 store it anyway so as to be consistent with all other SSE
735 uinstrs.
sewardj02af6bc2003-06-12 00:56:06 +0000736 */
737 SSE3ag_MemRd_RegWr,
sewardje3891fa2003-06-15 03:13:48 +0000738
sewardj8cec6ee2003-05-18 11:56:39 +0000739 /* 5 bytes, no memrefs, no iregdefs, copy exactly to the
740 output. Held in val1[15:0], val2[15:0] and val3[7:0]. */
741 SSE5,
sewardj77d30a22003-10-19 08:18:52 +0000742
sewardj8cec6ee2003-05-18 11:56:39 +0000743 /* 5 bytes, reads/writes mem. Insns of the form
744 bbbbbbbb:bbbbbbbb:bbbbbbbb:mod mmxreg r/m:bbbbbbbb
daywalker5d945de2003-09-26 00:32:53 +0000745 Held in val1[15:0], val2[15:0], lit32[7:0].
746 mod and rm are to be replaced at codegen time by a reference
747 to the Temp/RealReg holding the address. Arg3 holds this
sewardj8cec6ee2003-05-18 11:56:39 +0000748 Temp/Real Reg. Transfer is always at size 16. */
749 SSE3a1_MemRd,
sewardj77d30a22003-10-19 08:18:52 +0000750
sewardj3d7c9c82003-03-26 21:08:13 +0000751 /* ------------------------ */
752
njnd5bb0a52002-09-27 10:24:48 +0000753 /* Not strictly needed, but improve address calculation translations. */
njn25e49d8e72002-09-23 09:36:25 +0000754 LEA1, /* reg2 := const + reg1 */
755 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
756
sewardj8cec6ee2003-05-18 11:56:39 +0000757 /* Hack for x86 REP insns. Jump to literal if TempReg/RealReg
758 is zero. */
njnd5bb0a52002-09-27 10:24:48 +0000759 JIFZ,
njn25e49d8e72002-09-23 09:36:25 +0000760
njnd5bb0a52002-09-27 10:24:48 +0000761 /* Advance the simulated %eip by some small (< 128) number. */
762 INCEIP,
njn25e49d8e72002-09-23 09:36:25 +0000763
sewardje1042472002-09-30 12:33:11 +0000764 /* Dealing with segment registers */
765 GETSEG, PUTSEG, /* simulated segment register <--> TempReg */
766 USESEG, /* (LDT/GDT index, virtual addr) --> linear addr */
767
njnd5bb0a52002-09-27 10:24:48 +0000768 /* Not for translating x86 calls -- only to call helpers */
769 CALLM_S, CALLM_E, /* Mark start/end of CALLM push/pop sequence */
770 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers */
771 CALLM, /* Call assembly-code helper */
772
773 /* Not for translating x86 calls -- only to call C helper functions of
774 up to three arguments (or two if the functions has a return value).
775 Arguments and return value must be word-sized. More arguments can
776 be faked with global variables (eg. use VG_(set_global_var)()).
777
778 Seven possibilities: 'arg[123]' show where args go, 'ret' shows
779 where return value goes (if present).
daywalker5d945de2003-09-26 00:32:53 +0000780
njn25e49d8e72002-09-23 09:36:25 +0000781 CCALL(-, -, - ) void f(void)
782 CCALL(arg1, -, - ) void f(UInt arg1)
783 CCALL(arg1, arg2, - ) void f(UInt arg1, UInt arg2)
784 CCALL(arg1, arg2, arg3) void f(UInt arg1, UInt arg2, UInt arg3)
785 CCALL(-, -, ret ) UInt f(UInt)
786 CCALL(arg1, -, ret ) UInt f(UInt arg1)
njnd5bb0a52002-09-27 10:24:48 +0000787 CCALL(arg1, arg2, ret ) UInt f(UInt arg1, UInt arg2) */
njn25e49d8e72002-09-23 09:36:25 +0000788 CCALL,
789
njnd5bb0a52002-09-27 10:24:48 +0000790 /* This opcode makes it easy for skins that extend UCode to do this to
791 avoid opcode overlap:
njn25e49d8e72002-09-23 09:36:25 +0000792
daywalker5d945de2003-09-26 00:32:53 +0000793 enum { EU_OP1 = DUMMY_FINAL_UOPCODE + 1, ... }
794
njn25e49d8e72002-09-23 09:36:25 +0000795 WARNING: Do not add new opcodes after this one! They can be added
796 before, though. */
797 DUMMY_FINAL_UOPCODE
798 }
799 Opcode;
800
801
njnd5bb0a52002-09-27 10:24:48 +0000802/* Condition codes, using the Intel encoding. CondAlways is an extra. */
njn25e49d8e72002-09-23 09:36:25 +0000803typedef
804 enum {
805 CondO = 0, /* overflow */
806 CondNO = 1, /* no overflow */
807 CondB = 2, /* below */
808 CondNB = 3, /* not below */
809 CondZ = 4, /* zero */
810 CondNZ = 5, /* not zero */
811 CondBE = 6, /* below or equal */
812 CondNBE = 7, /* not below or equal */
813 CondS = 8, /* negative */
sewardje1042472002-09-30 12:33:11 +0000814 CondNS = 9, /* not negative */
njn25e49d8e72002-09-23 09:36:25 +0000815 CondP = 10, /* parity even */
816 CondNP = 11, /* not parity even */
817 CondL = 12, /* jump less */
818 CondNL = 13, /* not less */
819 CondLE = 14, /* less or equal */
820 CondNLE = 15, /* not less or equal */
821 CondAlways = 16 /* Jump always */
daywalker5d945de2003-09-26 00:32:53 +0000822 }
njn25e49d8e72002-09-23 09:36:25 +0000823 Condcode;
824
825
826/* Descriptions of additional properties of *unconditional* jumps. */
827typedef
828 enum {
829 JmpBoring=0, /* boring unconditional jump */
830 JmpCall=1, /* jump due to an x86 call insn */
831 JmpRet=2, /* jump due to an x86 ret insn */
832 JmpSyscall=3, /* do a system call, then jump */
833 JmpClientReq=4 /* do a client request, then jump */
834 }
835 JmpKind;
836
837
838/* Flags. User-level code can only read/write O(verflow), S(ign),
839 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
840 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
daywalker5d945de2003-09-26 00:32:53 +0000841 thusly:
njn25e49d8e72002-09-23 09:36:25 +0000842 76543210
843 DOSZACP
844 and bit 7 must always be zero since it is unused.
sewardj2370f3b2002-11-30 15:01:01 +0000845
846 Note: these Flag? values are **not** the positions in the actual
847 %eflags register. */
848
njn25e49d8e72002-09-23 09:36:25 +0000849typedef UChar FlagSet;
850
851#define FlagD (1<<6)
852#define FlagO (1<<5)
853#define FlagS (1<<4)
854#define FlagZ (1<<3)
855#define FlagA (1<<2)
856#define FlagC (1<<1)
857#define FlagP (1<<0)
858
859#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
860#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
861#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
862#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
863#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
864#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
865#define FlagsZCP ( FlagZ | FlagC | FlagP)
866#define FlagsOC (FlagO | FlagC )
867#define FlagsAC ( FlagA | FlagC )
868
869#define FlagsALL (FlagsOSZACP | FlagD)
870#define FlagsEmpty (FlagSet)0
871
872
sewardj2370f3b2002-11-30 15:01:01 +0000873/* flag positions in eflags */
874#define EFlagC (1 << 0) /* carry */
875#define EFlagP (1 << 2) /* parity */
sewardjfa492d42002-12-08 18:20:01 +0000876#define EFlagA (1 << 4) /* aux carry */
sewardj2370f3b2002-11-30 15:01:01 +0000877#define EFlagZ (1 << 6) /* zero */
878#define EFlagS (1 << 7) /* sign */
sewardjfa492d42002-12-08 18:20:01 +0000879#define EFlagD (1 << 10) /* direction */
sewardj2370f3b2002-11-30 15:01:01 +0000880#define EFlagO (1 << 11) /* overflow */
881
njn25e49d8e72002-09-23 09:36:25 +0000882/* Liveness of general purpose registers, useful for code generation.
883 Reg rank order 0..N-1 corresponds to bits 0..N-1, ie. first
884 reg's liveness in bit 0, last reg's in bit N-1. Note that
885 these rankings don't match the Intel register ordering. */
886typedef UInt RRegSet;
887
888#define ALL_RREGS_DEAD 0 /* 0000...00b */
njne7c258c2002-10-03 08:57:01 +0000889#define ALL_RREGS_LIVE ((1 << VG_MAX_REALREGS)-1) /* 0011...11b */
njn25e49d8e72002-09-23 09:36:25 +0000890#define UNIT_RREGSET(rank) (1 << (rank))
891
892#define IS_RREG_LIVE(rank,rregs_live) (rregs_live & UNIT_RREGSET(rank))
893#define SET_RREG_LIVENESS(rank,rregs_live,b) \
894 do { RRegSet unit = UNIT_RREGSET(rank); \
895 if (b) rregs_live |= unit; \
896 else rregs_live &= ~unit; \
897 } while(0)
898
899
900/* A Micro (u)-instruction. */
901typedef
902 struct {
903 /* word 1 */
904 UInt lit32; /* 32-bit literal */
905
906 /* word 2 */
907 UShort val1; /* first operand */
908 UShort val2; /* second operand */
909
910 /* word 3 */
911 UShort val3; /* third operand */
912 UChar opcode; /* opcode */
913 UChar size; /* data transfer size */
914
915 /* word 4 */
916 FlagSet flags_r; /* :: FlagSet */
917 FlagSet flags_w; /* :: FlagSet */
918 UChar tag1:4; /* first operand tag */
919 UChar tag2:4; /* second operand tag */
920 UChar tag3:4; /* third operand tag */
921 UChar extra4b:4; /* Spare field, used by WIDEN for src
922 -size, and by LEA2 for scale (1,2,4 or 8),
923 and by JMPs for original x86 instr size */
924
925 /* word 5 */
926 UChar cond; /* condition, for jumps */
927 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
928 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
929
daywalker5d945de2003-09-26 00:32:53 +0000930 /* Additional properties for UInstrs that call C functions:
njn25e49d8e72002-09-23 09:36:25 +0000931 - CCALL
932 - PUT (when %ESP is the target)
933 - possibly skin-specific UInstrs
934 */
935 UChar argc:2; /* Number of args, max 3 */
936 UChar regparms_n:2; /* Number of args passed in registers */
937 Bool has_ret_val:1; /* Function has return value? */
938
939 /* RealReg liveness; only sensical after reg alloc and liveness
940 analysis done. This info is a little bit arch-specific --
941 VG_MAX_REALREGS can vary on different architectures. Note that
942 to use this information requires converting between register ranks
njn4ba5a792002-09-30 10:23:54 +0000943 and the Intel register numbers, using VG_(realreg_to_rank)()
944 and/or VG_(rank_to_realreg)() */
daywalker5d945de2003-09-26 00:32:53 +0000945 RRegSet regs_live_after:VG_MAX_REALREGS;
njn25e49d8e72002-09-23 09:36:25 +0000946 }
947 UInstr;
948
949
daywalker5d945de2003-09-26 00:32:53 +0000950typedef
njn810086f2002-11-14 12:42:47 +0000951 struct _UCodeBlock
njn25e49d8e72002-09-23 09:36:25 +0000952 UCodeBlock;
953
njn810086f2002-11-14 12:42:47 +0000954extern Int VG_(get_num_instrs) (UCodeBlock* cb);
955extern Int VG_(get_num_temps) (UCodeBlock* cb);
njn25e49d8e72002-09-23 09:36:25 +0000956
njn810086f2002-11-14 12:42:47 +0000957extern UInstr* VG_(get_instr) (UCodeBlock* cb, Int i);
958extern UInstr* VG_(get_last_instr) (UCodeBlock* cb);
daywalker5d945de2003-09-26 00:32:53 +0000959
njn211b6ad2003-02-03 12:33:31 +0000960
njn25e49d8e72002-09-23 09:36:25 +0000961/*====================================================================*/
962/*=== Instrumenting UCode ===*/
963/*====================================================================*/
964
njnf4ce3d32003-02-10 10:17:26 +0000965/* Maximum number of registers read or written by a single UInstruction. */
966#define VG_MAX_REGS_USED 3
njn25e49d8e72002-09-23 09:36:25 +0000967
njnf4ce3d32003-02-10 10:17:26 +0000968/* Find what this instruction does to its regs, useful for
969 analysis/optimisation passes. `tag' indicates whether we're considering
970 TempRegs (pre-reg-alloc) or RealRegs (post-reg-alloc). `regs' is filled
971 with the affected register numbers, `isWrites' parallels it and indicates
972 if the reg is read or written. If a reg is read and written, it will
973 appear twice in `regs'. `regs' and `isWrites' must be able to fit
974 VG_MAX_REGS_USED elements. */
njn810086f2002-11-14 12:42:47 +0000975extern Int VG_(get_reg_usage) ( UInstr* u, Tag tag, Int* regs, Bool* isWrites );
njn25e49d8e72002-09-23 09:36:25 +0000976
977
njnd5bb0a52002-09-27 10:24:48 +0000978/* Used to register helper functions to be called from generated code. A
979 limited number of compact helpers can be registered; the code generated
980 to call them is slightly shorter -- so register the mostly frequently
981 called helpers as compact. */
njn25e49d8e72002-09-23 09:36:25 +0000982extern void VG_(register_compact_helper) ( Addr a );
983extern void VG_(register_noncompact_helper) ( Addr a );
984
985
986/* ------------------------------------------------------------------ */
987/* Virtual register allocation */
988
989/* Get a new virtual register */
njn4ba5a792002-09-30 10:23:54 +0000990extern Int VG_(get_new_temp) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000991
992/* Get a new virtual shadow register */
njn4ba5a792002-09-30 10:23:54 +0000993extern Int VG_(get_new_shadow) ( UCodeBlock* cb );
njn25e49d8e72002-09-23 09:36:25 +0000994
995/* Get a virtual register's corresponding virtual shadow register */
996#define SHADOW(tempreg) ((tempreg)+1)
997
998
999/* ------------------------------------------------------------------ */
1000/* Low-level UInstr builders */
njn4ba5a792002-09-30 10:23:54 +00001001extern void VG_(new_NOP) ( UInstr* u );
1002extern void VG_(new_UInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
1003extern void VG_(new_UInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +00001004 Tag tag1, UInt val1 );
njn4ba5a792002-09-30 10:23:54 +00001005extern void VG_(new_UInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +00001006 Tag tag1, UInt val1,
1007 Tag tag2, UInt val2 );
njn4ba5a792002-09-30 10:23:54 +00001008extern void VG_(new_UInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
njn25e49d8e72002-09-23 09:36:25 +00001009 Tag tag1, UInt val1,
1010 Tag tag2, UInt val2,
1011 Tag tag3, UInt val3 );
njn25e49d8e72002-09-23 09:36:25 +00001012
daywalker5d945de2003-09-26 00:32:53 +00001013/* Set read/write/undefined flags. Undefined flags are treaten as written,
njn810086f2002-11-14 12:42:47 +00001014 but it's worth keeping them logically distinct. */
1015extern void VG_(set_flag_fields) ( UCodeBlock* cb, FlagSet fr, FlagSet fw,
1016 FlagSet fu);
njn4ba5a792002-09-30 10:23:54 +00001017extern void VG_(set_lit_field) ( UCodeBlock* cb, UInt lit32 );
1018extern void VG_(set_ccall_fields) ( UCodeBlock* cb, Addr fn, UChar argc,
1019 UChar regparms_n, Bool has_ret_val );
njn810086f2002-11-14 12:42:47 +00001020extern void VG_(set_cond_field) ( UCodeBlock* cb, Condcode code );
njn25e49d8e72002-09-23 09:36:25 +00001021
njn4ba5a792002-09-30 10:23:54 +00001022extern void VG_(copy_UInstr) ( UCodeBlock* cb, UInstr* instr );
1023
1024extern Bool VG_(any_flag_use)( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +00001025
njnac6c1762002-10-04 14:34:15 +00001026/* Macro versions of the above; just shorter to type. */
1027#define uInstr0 VG_(new_UInstr0)
1028#define uInstr1 VG_(new_UInstr1)
1029#define uInstr2 VG_(new_UInstr2)
1030#define uInstr3 VG_(new_UInstr3)
1031#define uLiteral VG_(set_lit_field)
1032#define uCCall VG_(set_ccall_fields)
njn810086f2002-11-14 12:42:47 +00001033#define uCond VG_(set_cond_field)
1034#define uFlagsRWU VG_(set_flag_fields)
njnac6c1762002-10-04 14:34:15 +00001035#define newTemp VG_(get_new_temp)
1036#define newShadow VG_(get_new_shadow)
1037
njn25e49d8e72002-09-23 09:36:25 +00001038/* Refer to `the last instruction stuffed in' (can be lvalue). */
1039#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
1040
1041
1042/* ------------------------------------------------------------------ */
1043/* Higher-level UInstr sequence builders */
njn4ba5a792002-09-30 10:23:54 +00001044extern void VG_(call_helper_0_0) ( UCodeBlock* cb, Addr f);
1045extern void VG_(call_helper_1_0) ( UCodeBlock* cb, Addr f, UInt arg1,
1046 UInt regparms_n);
1047extern void VG_(call_helper_2_0) ( UCodeBlock* cb, Addr f, UInt arg1, UInt arg2,
1048 UInt regparms_n);
njn25e49d8e72002-09-23 09:36:25 +00001049
1050/* One way around the 3-arg C function limit is to pass args via global
njn6fefa1b2003-02-24 10:32:51 +00001051 * variables... ugly, but it works. This one puts a literal in there. */
njn4ba5a792002-09-30 10:23:54 +00001052extern void VG_(set_global_var) ( UCodeBlock* cb, Addr globvar_ptr, UInt val);
njn25e49d8e72002-09-23 09:36:25 +00001053
njn6fefa1b2003-02-24 10:32:51 +00001054/* This one puts the contents of a TempReg in the global variable. */
1055extern void VG_(set_global_var_tempreg) ( UCodeBlock* cb, Addr globvar_ptr,
1056 UInt t_val);
1057
njn25e49d8e72002-09-23 09:36:25 +00001058/* ------------------------------------------------------------------ */
njnd5bb0a52002-09-27 10:24:48 +00001059/* Allocating/freeing basic blocks of UCode */
njn810086f2002-11-14 12:42:47 +00001060extern UCodeBlock* VG_(setup_UCodeBlock) ( UCodeBlock* cb );
njn4ba5a792002-09-30 10:23:54 +00001061extern void VG_(free_UCodeBlock) ( UCodeBlock* cb );
njnd5bb0a52002-09-27 10:24:48 +00001062
1063/* ------------------------------------------------------------------ */
daywalker5d945de2003-09-26 00:32:53 +00001064/* UCode pretty/ugly printing. Probably only useful to call from a skin
njn25e49d8e72002-09-23 09:36:25 +00001065 if VG_(needs).extended_UCode == True. */
1066
1067/* When True, all generated code is/should be printed. */
1068extern Bool VG_(print_codegen);
1069
njn4ba5a792002-09-30 10:23:54 +00001070/* Pretty/ugly printing functions */
1071extern void VG_(pp_UCodeBlock) ( UCodeBlock* cb, Char* title );
1072extern void VG_(pp_UInstr) ( Int instrNo, UInstr* u );
1073extern void VG_(pp_UInstr_regs) ( Int instrNo, UInstr* u );
1074extern void VG_(up_UInstr) ( Int instrNo, UInstr* u );
1075extern Char* VG_(name_UOpcode) ( Bool upper, Opcode opc );
njn563f96f2003-02-03 11:17:46 +00001076extern Char* VG_(name_UCondcode) ( Condcode cond );
daywalker5d945de2003-09-26 00:32:53 +00001077extern void VG_(pp_UOperand) ( UInstr* u, Int operandNo,
njn4ba5a792002-09-30 10:23:54 +00001078 Int sz, Bool parens );
njn25e49d8e72002-09-23 09:36:25 +00001079
njnb93d1782003-02-03 12:03:22 +00001080/* ------------------------------------------------------------------ */
njnf4ce3d32003-02-10 10:17:26 +00001081/* Accessing archregs and their shadows */
1082extern UInt VG_(get_archreg) ( UInt archreg );
1083extern UInt VG_(get_thread_archreg) ( ThreadId tid, UInt archreg );
1084
njnb93d1782003-02-03 12:03:22 +00001085extern UInt VG_(get_shadow_archreg) ( UInt archreg );
1086extern void VG_(set_shadow_archreg) ( UInt archreg, UInt val );
njnd3040452003-05-19 15:04:06 +00001087extern void VG_(set_shadow_eflags) ( UInt val );
njnb93d1782003-02-03 12:03:22 +00001088extern Addr VG_(shadow_archreg_address) ( UInt archreg );
njn25e49d8e72002-09-23 09:36:25 +00001089
njnf4ce3d32003-02-10 10:17:26 +00001090extern UInt VG_(get_thread_shadow_archreg) ( ThreadId tid, UInt archreg );
1091extern void VG_(set_thread_shadow_archreg) ( ThreadId tid, UInt archreg,
1092 UInt val );
njn211b6ad2003-02-03 12:33:31 +00001093
1094/* ------------------------------------------------------------------ */
1095/* Offsets of addresses of helper functions. A "helper" function is one
1096 which is called from generated code via CALLM. */
1097
1098extern Int VGOFF_(helper_idiv_64_32);
1099extern Int VGOFF_(helper_div_64_32);
1100extern Int VGOFF_(helper_idiv_32_16);
1101extern Int VGOFF_(helper_div_32_16);
1102extern Int VGOFF_(helper_idiv_16_8);
1103extern Int VGOFF_(helper_div_16_8);
1104
1105extern Int VGOFF_(helper_imul_32_64);
1106extern Int VGOFF_(helper_mul_32_64);
1107extern Int VGOFF_(helper_imul_16_32);
1108extern Int VGOFF_(helper_mul_16_32);
1109extern Int VGOFF_(helper_imul_8_16);
1110extern Int VGOFF_(helper_mul_8_16);
1111
1112extern Int VGOFF_(helper_CLD);
1113extern Int VGOFF_(helper_STD);
1114extern Int VGOFF_(helper_get_dirflag);
1115
1116extern Int VGOFF_(helper_CLC);
1117extern Int VGOFF_(helper_STC);
1118
1119extern Int VGOFF_(helper_shldl);
1120extern Int VGOFF_(helper_shldw);
1121extern Int VGOFF_(helper_shrdl);
1122extern Int VGOFF_(helper_shrdw);
1123
1124extern Int VGOFF_(helper_RDTSC);
1125extern Int VGOFF_(helper_CPUID);
1126
daywalkerb18d2532003-09-27 20:15:01 +00001127extern Int VGOFF_(helper_IN);
1128extern Int VGOFF_(helper_OUT);
1129
njn211b6ad2003-02-03 12:33:31 +00001130extern Int VGOFF_(helper_bsf);
1131extern Int VGOFF_(helper_bsr);
1132
1133extern Int VGOFF_(helper_fstsw_AX);
1134extern Int VGOFF_(helper_SAHF);
njnd6251f12003-06-03 13:38:51 +00001135extern Int VGOFF_(helper_LAHF);
njn211b6ad2003-02-03 12:33:31 +00001136extern Int VGOFF_(helper_DAS);
1137extern Int VGOFF_(helper_DAA);
1138
1139
njn25e49d8e72002-09-23 09:36:25 +00001140/*====================================================================*/
njnd5bb0a52002-09-27 10:24:48 +00001141/*=== Generating x86 code from UCode ===*/
njn25e49d8e72002-09-23 09:36:25 +00001142/*====================================================================*/
1143
njnd5bb0a52002-09-27 10:24:48 +00001144/* All this only necessary for skins with VG_(needs).extends_UCode == True. */
njn25e49d8e72002-09-23 09:36:25 +00001145
sewardje1042472002-09-30 12:33:11 +00001146/* This is the Intel register encoding -- integer regs. */
njn25e49d8e72002-09-23 09:36:25 +00001147#define R_EAX 0
1148#define R_ECX 1
1149#define R_EDX 2
1150#define R_EBX 3
1151#define R_ESP 4
1152#define R_EBP 5
1153#define R_ESI 6
1154#define R_EDI 7
1155
1156#define R_AL (0+R_EAX)
1157#define R_CL (0+R_ECX)
1158#define R_DL (0+R_EDX)
1159#define R_BL (0+R_EBX)
1160#define R_AH (4+R_EAX)
1161#define R_CH (4+R_ECX)
1162#define R_DH (4+R_EDX)
1163#define R_BH (4+R_EBX)
1164
sewardje1042472002-09-30 12:33:11 +00001165/* This is the Intel register encoding -- segment regs. */
1166#define R_ES 0
1167#define R_CS 1
1168#define R_SS 2
1169#define R_DS 3
1170#define R_FS 4
1171#define R_GS 5
1172
njn25e49d8e72002-09-23 09:36:25 +00001173/* For pretty printing x86 code */
daywalker5d945de2003-09-26 00:32:53 +00001174extern const Char* VG_(name_of_mmx_gran) ( UChar gran );
1175extern const Char* VG_(name_of_mmx_reg) ( Int mmxreg );
1176extern const Char* VG_(name_of_seg_reg) ( Int sreg );
1177extern const Char* VG_(name_of_int_reg) ( Int size, Int reg );
1178extern const Char VG_(name_of_int_size) ( Int size );
njn25e49d8e72002-09-23 09:36:25 +00001179
njnac6c1762002-10-04 14:34:15 +00001180/* Shorter macros for convenience */
sewardj3d7c9c82003-03-26 21:08:13 +00001181#define nameIReg VG_(name_of_int_reg)
1182#define nameISize VG_(name_of_int_size)
1183#define nameSReg VG_(name_of_seg_reg)
1184#define nameMMXReg VG_(name_of_mmx_reg)
1185#define nameMMXGran VG_(name_of_mmx_gran)
sewardjfebaa3b2003-05-25 01:07:34 +00001186#define nameXMMReg VG_(name_of_xmm_reg)
njnac6c1762002-10-04 14:34:15 +00001187
njn25e49d8e72002-09-23 09:36:25 +00001188/* Randomly useful things */
1189extern UInt VG_(extend_s_8to32) ( UInt x );
1190
1191/* Code emitters */
njn4ba5a792002-09-30 10:23:54 +00001192extern void VG_(emitB) ( UInt b );
1193extern void VG_(emitW) ( UInt w );
1194extern void VG_(emitL) ( UInt l );
sewardjfa492d42002-12-08 18:20:01 +00001195extern void VG_(new_emit) ( Bool upd_cc, FlagSet uses_flags, FlagSet sets_flags );
njn25e49d8e72002-09-23 09:36:25 +00001196
1197/* Finding offsets */
njn4ba5a792002-09-30 10:23:54 +00001198extern Int VG_(helper_offset) ( Addr a );
1199extern Int VG_(shadow_reg_offset) ( Int arch );
1200extern Int VG_(shadow_flags_offset) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001201
njnd5bb0a52002-09-27 10:24:48 +00001202/* Convert reg ranks <-> Intel register ordering, for using register
1203 liveness information. */
njn4ba5a792002-09-30 10:23:54 +00001204extern Int VG_(realreg_to_rank) ( Int realreg );
1205extern Int VG_(rank_to_realreg) ( Int rank );
njn25e49d8e72002-09-23 09:36:25 +00001206
njnd5bb0a52002-09-27 10:24:48 +00001207/* Call a subroutine. Does no argument passing, stack manipulations, etc. */
daywalker5d945de2003-09-26 00:32:53 +00001208extern void VG_(synth_call) ( Bool ensure_shortform, Int word_offset,
sewardjfa492d42002-12-08 18:20:01 +00001209 Bool upd_cc, FlagSet use_flags, FlagSet set_flags );
njn25e49d8e72002-09-23 09:36:25 +00001210
njnd5bb0a52002-09-27 10:24:48 +00001211/* For calling C functions -- saves caller save regs, pushes args, calls,
1212 clears the stack, restores caller save regs. `fn' must be registered in
1213 the baseBlock first. Acceptable tags are RealReg and Literal. Optimises
1214 things, eg. by not preserving non-live caller-save registers.
njn25e49d8e72002-09-23 09:36:25 +00001215
njnd5bb0a52002-09-27 10:24:48 +00001216 WARNING: a UInstr should *not* be translated with synth_ccall() followed
1217 by some other x86 assembly code; this will invalidate the results of
1218 vg_realreg_liveness_analysis() and everything will fall over. */
njn4ba5a792002-09-30 10:23:54 +00001219extern void VG_(synth_ccall) ( Addr fn, Int argc, Int regparms_n, UInt argv[],
daywalker5d945de2003-09-26 00:32:53 +00001220 Tag tagv[], Int ret_reg,
njn4ba5a792002-09-30 10:23:54 +00001221 RRegSet regs_live_before,
1222 RRegSet regs_live_after );
njn25e49d8e72002-09-23 09:36:25 +00001223
1224/* Addressing modes */
njn4ba5a792002-09-30 10:23:54 +00001225extern void VG_(emit_amode_offregmem_reg)( Int off, Int regmem, Int reg );
1226extern void VG_(emit_amode_ereg_greg) ( Int e_reg, Int g_reg );
njn25e49d8e72002-09-23 09:36:25 +00001227
1228/* v-size (4, or 2 with OSO) insn emitters */
njn4ba5a792002-09-30 10:23:54 +00001229extern void VG_(emit_movv_offregmem_reg) ( Int sz, Int off, Int areg, Int reg );
1230extern void VG_(emit_movv_reg_offregmem) ( Int sz, Int reg, Int off, Int areg );
1231extern void VG_(emit_movv_reg_reg) ( Int sz, Int reg1, Int reg2 );
sewardjfa492d42002-12-08 18:20:01 +00001232extern void VG_(emit_nonshiftopv_lit_reg)( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001233 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001234extern void VG_(emit_shiftopv_lit_reg) ( Bool upd_cc, Int sz, Opcode opc, UInt lit,
njn4ba5a792002-09-30 10:23:54 +00001235 Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001236extern void VG_(emit_nonshiftopv_reg_reg)( Bool upd_cc, Int sz, Opcode opc,
njn4ba5a792002-09-30 10:23:54 +00001237 Int reg1, Int reg2 );
1238extern void VG_(emit_movv_lit_reg) ( Int sz, UInt lit, Int reg );
sewardjfa492d42002-12-08 18:20:01 +00001239extern void VG_(emit_unaryopv_reg) ( Bool upd_cc, Int sz, Opcode opc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001240extern void VG_(emit_pushv_reg) ( Int sz, Int reg );
1241extern void VG_(emit_popv_reg) ( Int sz, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001242
njn4ba5a792002-09-30 10:23:54 +00001243extern void VG_(emit_pushl_lit32) ( UInt int32 );
1244extern void VG_(emit_pushl_lit8) ( Int lit8 );
sewardjfa492d42002-12-08 18:20:01 +00001245extern void VG_(emit_cmpl_zero_reg) ( Bool upd_cc, Int reg );
njn4ba5a792002-09-30 10:23:54 +00001246extern void VG_(emit_swapl_reg_EAX) ( Int reg );
1247extern void VG_(emit_movv_lit_offregmem) ( Int sz, UInt lit, Int off,
1248 Int memreg );
njn25e49d8e72002-09-23 09:36:25 +00001249
1250/* b-size (1 byte) instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001251extern void VG_(emit_movb_lit_offregmem) ( UInt lit, Int off, Int memreg );
1252extern void VG_(emit_movb_reg_offregmem) ( Int reg, Int off, Int areg );
sewardjfa492d42002-12-08 18:20:01 +00001253extern void VG_(emit_unaryopb_reg) ( Bool upd_cc, Opcode opc, Int reg );
1254extern void VG_(emit_testb_lit_reg) ( Bool upd_cc, UInt lit, Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001255
1256/* zero-extended load emitters */
njn4ba5a792002-09-30 10:23:54 +00001257extern void VG_(emit_movzbl_offregmem_reg) ( Int off, Int regmem, Int reg );
1258extern void VG_(emit_movzwl_offregmem_reg) ( Int off, Int areg, Int reg );
daywalkerf26b2162003-09-30 23:01:50 +00001259extern void VG_(emit_movzwl_regmem_reg) ( Int reg1, Int reg2 );
njn25e49d8e72002-09-23 09:36:25 +00001260
1261/* misc instruction emitters */
njn4ba5a792002-09-30 10:23:54 +00001262extern void VG_(emit_call_reg) ( Int reg );
1263extern void VG_(emit_add_lit_to_esp) ( Int lit );
njn4ba5a792002-09-30 10:23:54 +00001264extern void VG_(emit_pushal) ( void );
1265extern void VG_(emit_popal) ( void );
1266extern void VG_(emit_AMD_prefetch_reg) ( Int reg );
njn25e49d8e72002-09-23 09:36:25 +00001267
sewardja2113f92002-12-12 23:42:48 +00001268/* jump emitters */
1269extern void VG_(init_target) ( Int *tgt );
1270
1271extern void VG_(target_back) ( Int *tgt );
1272extern void VG_(target_forward) ( Int *tgt );
1273extern void VG_(emit_target_delta) ( Int *tgt );
1274
1275extern void VG_(emit_jcondshort_delta) ( Bool simd_cc, Condcode cond, Int delta );
1276extern void VG_(emit_jcondshort_target)( Bool simd_cc, Condcode cond, Int *tgt );
1277
njn25e49d8e72002-09-23 09:36:25 +00001278
1279/*====================================================================*/
1280/*=== Execution contexts ===*/
1281/*====================================================================*/
1282
1283/* Generic resolution type used in a few different ways, such as deciding
1284 how closely to compare two errors for equality. */
daywalker5d945de2003-09-26 00:32:53 +00001285typedef
1286 enum { Vg_LowRes, Vg_MedRes, Vg_HighRes }
njn25e49d8e72002-09-23 09:36:25 +00001287 VgRes;
1288
1289typedef
1290 struct _ExeContext
1291 ExeContext;
1292
daywalker5d945de2003-09-26 00:32:53 +00001293/* Compare two ExeContexts. Number of callers considered depends on `res':
1294 Vg_LowRes: 2
1295 Vg_MedRes: 4
njnd5bb0a52002-09-27 10:24:48 +00001296 Vg_HighRes: all */
njn25e49d8e72002-09-23 09:36:25 +00001297extern Bool VG_(eq_ExeContext) ( VgRes res,
1298 ExeContext* e1, ExeContext* e2 );
1299
1300/* Print an ExeContext. */
1301extern void VG_(pp_ExeContext) ( ExeContext* );
1302
1303/* Take a snapshot of the client's stack. Search our collection of
1304 ExeContexts to see if we already have it, and if not, allocate a
njn6c846552003-09-16 07:41:43 +00001305 new one. Either way, return a pointer to the context. Context size
1306 controlled by --num-callers option.
daywalker5d945de2003-09-26 00:32:53 +00001307
njn72718642003-07-24 08:45:32 +00001308 If called from generated code, use VG_(get_current_tid)() to get the
1309 current ThreadId. If called from non-generated code, the current
daywalker5d945de2003-09-26 00:32:53 +00001310 ThreadId should be passed in by the core.
njn7b456f52003-05-19 11:16:50 +00001311*/
njn72718642003-07-24 08:45:32 +00001312extern ExeContext* VG_(get_ExeContext) ( ThreadId tid );
njn25e49d8e72002-09-23 09:36:25 +00001313
njn6c846552003-09-16 07:41:43 +00001314/* Get the nth EIP from the ExeContext. 0 is the EIP of the top function, 1
1315 is its caller, etc. Returns 0 if there isn't one, or if n is greater
1316 than VG_(clo_backtrace_size), set by the --num-callers option. */
1317extern Addr VG_(get_EIP_from_ExeContext) ( ExeContext* e, UInt n );
1318
sewardj499e3de2002-11-13 22:22:25 +00001319/* Just grab the client's EIP, as a much smaller and cheaper
njn72718642003-07-24 08:45:32 +00001320 indication of where they are. Use is basically same as for
daywalker5d945de2003-09-26 00:32:53 +00001321 VG_(get_ExeContext)() above.
njn72718642003-07-24 08:45:32 +00001322*/
1323extern Addr VG_(get_EIP)( ThreadId tid );
njn25e49d8e72002-09-23 09:36:25 +00001324
njn6c846552003-09-16 07:41:43 +00001325/* For skins needing more control over stack traces: walks the stack to get
1326 %eips from the top stack frames for thread 'tid'. Maximum of 'n_eips'
1327 addresses put into 'eips'; 0 is the top of the stack, 1 is its caller,
1328 etc. */
1329extern UInt VG_(stack_snapshot) ( ThreadId tid, Addr* eips, UInt n_eips );
1330
1331/* Does the same thing as VG_(pp_ExeContext)(), just with slightly
1332 different input. */
1333extern void VG_(mini_stack_dump) ( Addr eips[], UInt n_eips );
1334
njn211b6ad2003-02-03 12:33:31 +00001335
njn25e49d8e72002-09-23 09:36:25 +00001336/*====================================================================*/
1337/*=== Error reporting ===*/
1338/*====================================================================*/
1339
1340/* ------------------------------------------------------------------ */
daywalker5d945de2003-09-26 00:32:53 +00001341/* Suppressions describe errors which we want to suppress, ie, not
njn25e49d8e72002-09-23 09:36:25 +00001342 show the user, usually because it is caused by a problem in a library
daywalker5d945de2003-09-26 00:32:53 +00001343 which we can't fix, replace or work around. Suppressions are read from
njnd5bb0a52002-09-27 10:24:48 +00001344 a file at startup time. This gives flexibility so that new
njn25e49d8e72002-09-23 09:36:25 +00001345 suppressions can be added to the file as and when needed.
1346*/
1347
1348typedef
1349 Int /* Do not make this unsigned! */
1350 SuppKind;
1351
njn810086f2002-11-14 12:42:47 +00001352/* The skin-relevant parts of a suppression are:
1353 kind: what kind of suppression; must be in the range (0..)
1354 string: use is optional. NULL by default.
1355 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001356*/
1357typedef
njn810086f2002-11-14 12:42:47 +00001358 struct _Supp
1359 Supp;
1360
1361/* Useful in SK_(error_matches_suppression)() */
1362SuppKind VG_(get_supp_kind) ( Supp* su );
1363Char* VG_(get_supp_string) ( Supp* su );
1364void* VG_(get_supp_extra) ( Supp* su );
1365
1366/* Must be used in VG_(recognised_suppression)() */
1367void VG_(set_supp_kind) ( Supp* su, SuppKind suppkind );
1368/* May be used in VG_(read_extra_suppression_info)() */
1369void VG_(set_supp_string) ( Supp* su, Char* string );
1370void VG_(set_supp_extra) ( Supp* su, void* extra );
njn25e49d8e72002-09-23 09:36:25 +00001371
1372
1373/* ------------------------------------------------------------------ */
1374/* Error records contain enough info to generate an error report. The idea
1375 is that (typically) the same few points in the program generate thousands
njnd5bb0a52002-09-27 10:24:48 +00001376 of errors, and we don't want to spew out a fresh error message for each
1377 one. Instead, we use these structures to common up duplicates.
njn25e49d8e72002-09-23 09:36:25 +00001378*/
1379
1380typedef
1381 Int /* Do not make this unsigned! */
1382 ErrorKind;
1383
njn810086f2002-11-14 12:42:47 +00001384/* The skin-relevant parts of an Error are:
1385 kind: what kind of error; must be in the range (0..)
1386 addr: use is optional. 0 by default.
1387 string: use is optional. NULL by default.
1388 extra: use is optional. NULL by default. void* so it's extensible.
njn25e49d8e72002-09-23 09:36:25 +00001389*/
1390typedef
njn810086f2002-11-14 12:42:47 +00001391 struct _Error
1392 Error;
njn25e49d8e72002-09-23 09:36:25 +00001393
njn810086f2002-11-14 12:42:47 +00001394/* Useful in SK_(error_matches_suppression)(), SK_(pp_SkinError)(), etc */
njnb877d492003-01-28 20:40:57 +00001395ExeContext* VG_(get_error_where) ( Error* err );
1396SuppKind VG_(get_error_kind) ( Error* err );
1397Addr VG_(get_error_address) ( Error* err );
1398Char* VG_(get_error_string) ( Error* err );
1399void* VG_(get_error_extra) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001400
njnd5bb0a52002-09-27 10:24:48 +00001401/* Call this when an error occurs. It will be recorded if it hasn't been
njn25e49d8e72002-09-23 09:36:25 +00001402 seen before. If it has, the existing error record will have its count
daywalker5d945de2003-09-26 00:32:53 +00001403 incremented.
1404
njn72718642003-07-24 08:45:32 +00001405 'tid' can be found as for VG_(get_ExeContext)(). The `extra' field can
1406 be stack-allocated; it will be copied by the core if needed (but it
1407 won't be copied if it's NULL).
njnd5bb0a52002-09-27 10:24:48 +00001408
1409 If no 'a', 's' or 'extra' of interest needs to be recorded, just use
njn3e884182003-04-15 13:03:23 +00001410 NULL for them. */
daywalker5d945de2003-09-26 00:32:53 +00001411extern void VG_(maybe_record_error) ( ThreadId tid, ErrorKind ekind,
njn25e49d8e72002-09-23 09:36:25 +00001412 Addr a, Char* s, void* extra );
1413
njn43c799e2003-04-08 00:08:52 +00001414/* Similar to VG_(maybe_record_error)(), except this one doesn't record the
1415 error -- useful for errors that can only happen once. The errors can be
1416 suppressed, though. Return value is True if it was suppressed.
daywalker5d945de2003-09-26 00:32:53 +00001417 `print_error' dictates whether to print the error, which is a bit of a
njn43c799e2003-04-08 00:08:52 +00001418 hack that's useful sometimes if you just want to know if the error would
daywalker5d945de2003-09-26 00:32:53 +00001419 be suppressed without possibly printing it. `count_error' dictates
njn47363ab2003-04-21 13:24:40 +00001420 whether to add the error in the error total count (another mild hack). */
njn72718642003-07-24 08:45:32 +00001421extern Bool VG_(unique_error) ( ThreadId tid, ErrorKind ekind,
njn43c799e2003-04-08 00:08:52 +00001422 Addr a, Char* s, void* extra,
njn3e884182003-04-15 13:03:23 +00001423 ExeContext* where, Bool print_error,
njn47363ab2003-04-21 13:24:40 +00001424 Bool allow_GDB_attach, Bool count_error );
njn43c799e2003-04-08 00:08:52 +00001425
njn25e49d8e72002-09-23 09:36:25 +00001426/* Gets a non-blank, non-comment line of at most nBuf chars from fd.
daywalker5d945de2003-09-26 00:32:53 +00001427 Skips leading spaces on the line. Returns True if EOF was hit instead.
njn3e884182003-04-15 13:03:23 +00001428 Useful for reading in extra skin-specific suppression lines. */
njn4ba5a792002-09-30 10:23:54 +00001429extern Bool VG_(get_line) ( Int fd, Char* buf, Int nBuf );
njn25e49d8e72002-09-23 09:36:25 +00001430
1431
1432/*====================================================================*/
1433/*=== Obtaining debug information ===*/
1434/*====================================================================*/
1435
sewardj6e008cb2002-12-15 13:11:39 +00001436/* Get the file/function/line number of the instruction at address
1437 'a'. For these four, if debug info for the address is found, it
1438 copies the info into the buffer/UInt and returns True. If not, it
1439 returns False and nothing is copied. VG_(get_fnname) always
1440 demangles C++ function names. VG_(get_fnname_w_offset) is the
njn3e884182003-04-15 13:03:23 +00001441 same, except it appends "+N" to symbol names to indicate offsets. */
njn25e49d8e72002-09-23 09:36:25 +00001442extern Bool VG_(get_filename) ( Addr a, Char* filename, Int n_filename );
1443extern Bool VG_(get_fnname) ( Addr a, Char* fnname, Int n_fnname );
1444extern Bool VG_(get_linenum) ( Addr a, UInt* linenum );
daywalker5d945de2003-09-26 00:32:53 +00001445extern Bool VG_(get_fnname_w_offset)
sewardj6e008cb2002-12-15 13:11:39 +00001446 ( Addr a, Char* fnname, Int n_fnname );
njn25e49d8e72002-09-23 09:36:25 +00001447
1448/* This one is more efficient if getting both filename and line number,
1449 because the two lookups are done together. */
daywalker5d945de2003-09-26 00:32:53 +00001450extern Bool VG_(get_filename_linenum)
njn25e49d8e72002-09-23 09:36:25 +00001451 ( Addr a, Char* filename, Int n_filename,
1452 UInt* linenum );
1453
1454/* Succeeds only if we find from debug info that 'a' is the address of the
1455 first instruction in a function -- as opposed to VG_(get_fnname) which
1456 succeeds if we find from debug info that 'a' is the address of any
1457 instruction in a function. Use this to instrument the start of
njnd5bb0a52002-09-27 10:24:48 +00001458 a particular function. Nb: if an executable/shared object is stripped
njn25e49d8e72002-09-23 09:36:25 +00001459 of its symbols, this function will not be able to recognise function
1460 entry points within it. */
njn497ec3f2003-05-19 08:38:23 +00001461extern Bool VG_(get_fnname_if_entry) ( Addr a, Char* fnname, Int n_fnname );
njn25e49d8e72002-09-23 09:36:25 +00001462
1463/* Succeeds if the address is within a shared object or the main executable.
1464 It doesn't matter if debug info is present or not. */
1465extern Bool VG_(get_objname) ( Addr a, Char* objname, Int n_objname );
1466
njn6c846552003-09-16 07:41:43 +00001467/* Puts into 'buf' info about the code address %eip: the address, function
1468 name (if known) and filename/line number (if known), like this:
1469
1470 0x4001BF05: realloc (vg_replace_malloc.c:339)
1471
1472 'n_buf' gives length of 'buf'. Returns 'buf'.
1473*/
1474extern Char* VG_(describe_eip)(Addr eip, Char* buf, Int n_buf);
1475
jsgfcb1d1c02003-10-14 21:55:10 +00001476/* Returns a string containing an expression for the given
1477 address. String is malloced with VG_(malloc)() */
1478Char *VG_(describe_addr)(ThreadId, Addr);
1479
sewardj47104382002-10-20 18:35:48 +00001480/* A way to get information about what segments are mapped */
1481typedef struct _SegInfo SegInfo;
1482
njnb877d492003-01-28 20:40:57 +00001483/* Returns NULL if the SegInfo isn't found. It doesn't matter if debug info
1484 is present or not. */
1485extern SegInfo* VG_(get_obj) ( Addr a );
1486
1487extern const SegInfo* VG_(next_seginfo) ( const SegInfo *seg );
1488extern Addr VG_(seg_start) ( const SegInfo *seg );
1489extern UInt VG_(seg_size) ( const SegInfo *seg );
1490extern const UChar* VG_(seg_filename) ( const SegInfo *seg );
1491extern UInt VG_(seg_sym_offset)( const SegInfo *seg );
sewardj47104382002-10-20 18:35:48 +00001492
1493typedef
1494 enum {
1495 Vg_SectUnknown,
1496 Vg_SectText,
sewardj8fe15a32002-10-20 19:29:21 +00001497 Vg_SectData,
1498 Vg_SectBSS,
sewardj47104382002-10-20 18:35:48 +00001499 Vg_SectGOT,
sewardj8fe15a32002-10-20 19:29:21 +00001500 Vg_SectPLT,
sewardj47104382002-10-20 18:35:48 +00001501 }
1502 VgSectKind;
1503
1504extern VgSectKind VG_(seg_sect_kind)(Addr);
1505
njn25e49d8e72002-09-23 09:36:25 +00001506
1507/*====================================================================*/
njn3e884182003-04-15 13:03:23 +00001508/*=== Generic hash table ===*/
njn25e49d8e72002-09-23 09:36:25 +00001509/*====================================================================*/
1510
njn3e884182003-04-15 13:03:23 +00001511/* Generic type for a separately-chained hash table. Via a kind of dodgy
1512 C-as-C++ style inheritance, skins can extend the VgHashNode type, so long
1513 as the first two fields match the sizes of these two fields. Requires
1514 a bit of casting by the skin. */
njn25e49d8e72002-09-23 09:36:25 +00001515typedef
njn3e884182003-04-15 13:03:23 +00001516 struct _VgHashNode {
1517 struct _VgHashNode * next;
1518 UInt key;
1519 }
1520 VgHashNode;
njn25e49d8e72002-09-23 09:36:25 +00001521
njn3e884182003-04-15 13:03:23 +00001522typedef
1523 VgHashNode**
1524 VgHashTable;
njn810086f2002-11-14 12:42:47 +00001525
njn3e884182003-04-15 13:03:23 +00001526/* Make a new table. */
1527extern VgHashTable VG_(HT_construct) ( void );
1528
njn69c06872003-09-30 15:43:51 +00001529/* Count the number of nodes in a table. */
1530extern Int VG_(HT_count_nodes) ( VgHashTable table );
1531
njn3e884182003-04-15 13:03:23 +00001532/* Add a node to the table. */
1533extern void VG_(HT_add_node) ( VgHashTable t, VgHashNode* node );
1534
daywalker5d945de2003-09-26 00:32:53 +00001535/* Looks up a node in the hash table. Also returns the address of the
njn3e884182003-04-15 13:03:23 +00001536 previous node's `next' pointer which allows it to be removed from the
1537 list later without having to look it up again. */
1538extern VgHashNode* VG_(HT_get_node) ( VgHashTable t, UInt key,
1539 /*OUT*/VgHashNode*** next_ptr );
1540
njn06072ec2003-09-30 15:35:13 +00001541/* Allocates an array of pointers to all the shadow chunks of malloc'd
1542 blocks. Must be freed with VG_(free)(). */
1543extern VgHashNode** VG_(HT_to_array) ( VgHashTable t, /*OUT*/ UInt* n_shadows );
njn3e884182003-04-15 13:03:23 +00001544
1545/* Returns first node that matches predicate `p', or NULL if none do.
1546 Extra arguments can be implicitly passed to `p' using nested functions;
1547 see memcheck/mc_errcontext.c for an example. */
1548extern VgHashNode* VG_(HT_first_match) ( VgHashTable t,
1549 Bool (*p)(VgHashNode*) );
1550
1551/* Applies a function f() once to each node. Again, nested functions
1552 can be very useful. */
1553extern void VG_(HT_apply_to_all_nodes)( VgHashTable t, void (*f)(VgHashNode*) );
1554
1555/* Destroy a table. */
1556extern void VG_(HT_destruct) ( VgHashTable t );
njn810086f2002-11-14 12:42:47 +00001557
1558
njn3e884182003-04-15 13:03:23 +00001559/*====================================================================*/
njnd3040452003-05-19 15:04:06 +00001560/*=== Functions for shadow registers ===*/
1561/*====================================================================*/
1562
1563/* Nb: make sure the shadow_regs 'need' is set before using these! */
1564
1565/* This one lets you override the shadow of the return value register for a
1566 syscall. Call it from SK_(post_syscall)() (not SK_(pre_syscall)()!) to
1567 override the default shadow register value. */
daywalker5d945de2003-09-26 00:32:53 +00001568extern void VG_(set_return_from_syscall_shadow) ( ThreadId tid,
njnd3040452003-05-19 15:04:06 +00001569 UInt ret_shadow );
1570
1571/* This can be called from SK_(fini)() to find the shadow of the argument
1572 to exit(), ie. the shadow of the program's return value. */
1573extern UInt VG_(get_exit_status_shadow) ( void );
1574
1575
1576/*====================================================================*/
njn3e884182003-04-15 13:03:23 +00001577/*=== General stuff for replacing functions ===*/
1578/*====================================================================*/
njn25e49d8e72002-09-23 09:36:25 +00001579
njn3e884182003-04-15 13:03:23 +00001580/* Some skins need to replace the standard definitions of some functions. */
njn25e49d8e72002-09-23 09:36:25 +00001581
njn3e884182003-04-15 13:03:23 +00001582/* ------------------------------------------------------------------ */
1583/* General stuff, for replacing any functions */
njn25e49d8e72002-09-23 09:36:25 +00001584
daywalker5d945de2003-09-26 00:32:53 +00001585/* Is the client running on the simulated CPU or the real one?
njn25e49d8e72002-09-23 09:36:25 +00001586
njn3e884182003-04-15 13:03:23 +00001587 Nb: If it is, and you want to call a function to be run on the real CPU,
njn057c65f2003-04-21 13:30:55 +00001588 use one of the VALGRIND_NON_SIMD_CALL[123] macros in valgrind.h to call it.
njn25e49d8e72002-09-23 09:36:25 +00001589
daywalker5d945de2003-09-26 00:32:53 +00001590 Nb: don't forget the function parentheses when using this in a
njn3e884182003-04-15 13:03:23 +00001591 condition... write this:
1592
1593 if (VG_(is_running_on_simd_CPU)()) { ... } // calls function
1594
1595 not this:
daywalker5d945de2003-09-26 00:32:53 +00001596
njn3e884182003-04-15 13:03:23 +00001597 if (VG_(is_running_on_simd_CPU)) { ... } // address of var!
1598*/
daywalker5d945de2003-09-26 00:32:53 +00001599extern Bool VG_(is_running_on_simd_CPU) ( void );
njn3e884182003-04-15 13:03:23 +00001600
1601
1602/*====================================================================*/
1603/*=== Specific stuff for replacing malloc() and friends ===*/
1604/*====================================================================*/
1605
njn3e884182003-04-15 13:03:23 +00001606/* If a skin replaces malloc() et al, the easiest way to do so is to link
1607 with coregrind/vg_replace_malloc.c, and follow the following instructions.
1608 You can do it from scratch, though, if you enjoy that sort of thing. */
1609
1610/* Arena size for valgrind's own malloc(); default value is 0, but can
1611 be overridden by skin -- but must be done so *statically*, eg:
daywalker5d945de2003-09-26 00:32:53 +00001612
njn3e884182003-04-15 13:03:23 +00001613 Int VG_(vg_malloc_redzone_szB) = 4;
daywalker5d945de2003-09-26 00:32:53 +00001614
njn3e884182003-04-15 13:03:23 +00001615 It can't be done from a function like SK_(pre_clo_init)(). So it can't,
1616 for example, be controlled with a command line option, unfortunately. */
1617extern UInt VG_(vg_malloc_redzone_szB);
1618
1619/* If a skin links with vg_replace_malloc.c, the following functions will be
1620 called appropriately when malloc() et al are called. */
njn72718642003-07-24 08:45:32 +00001621extern void* SK_(malloc) ( Int n );
1622extern void* SK_(__builtin_new) ( Int n );
1623extern void* SK_(__builtin_vec_new) ( Int n );
1624extern void* SK_(memalign) ( Int align, Int n );
1625extern void* SK_(calloc) ( Int nmemb, Int n );
1626extern void SK_(free) ( void* p );
1627extern void SK_(__builtin_delete) ( void* p );
1628extern void SK_(__builtin_vec_delete) ( void* p );
1629extern void* SK_(realloc) ( void* p, Int size );
njn3e884182003-04-15 13:03:23 +00001630
1631/* Can be called from SK_(malloc) et al to do the actual alloc/freeing. */
daywalker5d945de2003-09-26 00:32:53 +00001632extern void* VG_(cli_malloc) ( UInt align, Int nbytes );
njn3e884182003-04-15 13:03:23 +00001633extern void VG_(cli_free) ( void* p );
1634
1635/* Check if an address is within a range, allowing for redzones at edges */
1636extern Bool VG_(addr_is_in_block)( Addr a, Addr start, UInt size );
1637
1638/* ------------------------------------------------------------------ */
daywalker5d945de2003-09-26 00:32:53 +00001639/* Some options that can be used by a skin if malloc() et al are replaced.
njnd3040452003-05-19 15:04:06 +00001640 The skin should call the functions in the appropriate places to give
1641 control over these aspects of Valgrind's version of malloc(). */
njn3e884182003-04-15 13:03:23 +00001642
1643/* Round malloc sizes upwards to integral number of words? default: NO */
1644extern Bool VG_(clo_sloppy_malloc);
1645/* DEBUG: print malloc details? default: NO */
1646extern Bool VG_(clo_trace_malloc);
1647/* Minimum alignment in functions that don't specify alignment explicitly.
1648 default: 0, i.e. use default of the machine (== 4) */
1649extern Int VG_(clo_alignment);
1650
1651extern Bool VG_(replacement_malloc_process_cmd_line_option) ( Char* arg );
1652extern void VG_(replacement_malloc_print_usage) ( void );
1653extern void VG_(replacement_malloc_print_debug_usage) ( void );
sewardja4495682002-10-21 07:29:59 +00001654
1655
njn25e49d8e72002-09-23 09:36:25 +00001656/*====================================================================*/
1657/*=== Skin-specific stuff ===*/
1658/*====================================================================*/
1659
njnd04b7c62002-10-03 14:05:52 +00001660/* ------------------------------------------------------------------ */
1661/* Details */
njnd04b7c62002-10-03 14:05:52 +00001662
njn120281f2003-02-03 12:20:07 +00001663/* Default value for avg_translations_sizeB (in bytes), indicating typical
1664 code expansion of about 6:1. */
1665#define VG_DEFAULT_TRANS_SIZEB 100
1666
njn810086f2002-11-14 12:42:47 +00001667/* Information used in the startup message. `name' also determines the
1668 string used for identifying suppressions in a suppression file as
1669 belonging to this skin. `version' can be NULL, in which case (not
1670 surprisingly) no version info is printed; this mechanism is designed for
1671 skins distributed with Valgrind that share a version number with
1672 Valgrind. Other skins not distributed as part of Valgrind should
sewardjc0d8f682002-11-30 00:49:43 +00001673 probably have their own version number. */
1674extern void VG_(details_name) ( Char* name );
1675extern void VG_(details_version) ( Char* version );
1676extern void VG_(details_description) ( Char* description );
1677extern void VG_(details_copyright_author) ( Char* copyright_author );
1678
1679/* Average size of a translation, in bytes, so that the translation
njn120281f2003-02-03 12:20:07 +00001680 storage machinery can allocate memory appropriately. Not critical,
daywalker5d945de2003-09-26 00:32:53 +00001681 setting is optional. */
njn120281f2003-02-03 12:20:07 +00001682extern void VG_(details_avg_translation_sizeB) ( UInt size );
njnd04b7c62002-10-03 14:05:52 +00001683
njn810086f2002-11-14 12:42:47 +00001684/* String printed if an `sk_assert' assertion fails or VG_(skin_panic)
1685 is called. Should probably be an email address. */
1686extern void VG_(details_bug_reports_to) ( Char* bug_reports_to );
njnd04b7c62002-10-03 14:05:52 +00001687
1688/* ------------------------------------------------------------------ */
1689/* Needs */
1690
njn810086f2002-11-14 12:42:47 +00001691/* Booleans that decide core behaviour, but don't require extra
1692 operations to be defined if `True' */
njnd5bb0a52002-09-27 10:24:48 +00001693
njn810086f2002-11-14 12:42:47 +00001694/* Should __libc_freeres() be run? Bugs in it can crash the skin. */
1695extern void VG_(needs_libc_freeres) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001696
njn810086f2002-11-14 12:42:47 +00001697/* Want to have errors detected by Valgrind's core reported? Includes:
1698 - pthread API errors (many; eg. unlocking a non-locked mutex)
njn810086f2002-11-14 12:42:47 +00001699 - invalid file descriptors to blocking syscalls read() and write()
1700 - bad signal numbers passed to sigaction()
daywalker5d945de2003-09-26 00:32:53 +00001701 - attempt to install signal handler for SIGKILL or SIGSTOP */
njn810086f2002-11-14 12:42:47 +00001702extern void VG_(needs_core_errors) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001703
njn810086f2002-11-14 12:42:47 +00001704/* Booleans that indicate extra operations are defined; if these are True,
1705 the corresponding template functions (given below) must be defined. A
1706 lot like being a member of a type class. */
njn25e49d8e72002-09-23 09:36:25 +00001707
njn810086f2002-11-14 12:42:47 +00001708/* Want to report errors from skin? This implies use of suppressions, too. */
1709extern void VG_(needs_skin_errors) ( void );
njnd5bb0a52002-09-27 10:24:48 +00001710
njn810086f2002-11-14 12:42:47 +00001711/* Is information kept about specific individual basic blocks? (Eg. for
1712 cachegrind there are cost-centres for every instruction, stored at a
1713 basic block level.) If so, it sometimes has to be discarded, because
1714 .so mmap/munmap-ping or self-modifying code (informed by the
1715 DISCARD_TRANSLATIONS user request) can cause one instruction address
1716 to be used for more than one instruction in one program run... */
1717extern void VG_(needs_basic_block_discards) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001718
njn810086f2002-11-14 12:42:47 +00001719/* Skin maintains information about each register? */
1720extern void VG_(needs_shadow_regs) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001721
njn810086f2002-11-14 12:42:47 +00001722/* Skin defines its own command line options? */
1723extern void VG_(needs_command_line_options) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001724
njn810086f2002-11-14 12:42:47 +00001725/* Skin defines its own client requests? */
1726extern void VG_(needs_client_requests) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001727
njn810086f2002-11-14 12:42:47 +00001728/* Skin defines its own UInstrs? */
1729extern void VG_(needs_extended_UCode) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001730
njn810086f2002-11-14 12:42:47 +00001731/* Skin does stuff before and/or after system calls? */
1732extern void VG_(needs_syscall_wrapper) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001733
njn810086f2002-11-14 12:42:47 +00001734/* Are skin-state sanity checks performed? */
1735extern void VG_(needs_sanity_checks) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001736
njn810086f2002-11-14 12:42:47 +00001737/* Do we need to see data symbols? */
1738extern void VG_(needs_data_syms) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001739
1740/* ------------------------------------------------------------------ */
1741/* Core events to track */
1742
1743/* Part of the core from which this call was made. Useful for determining
njnd5bb0a52002-09-27 10:24:48 +00001744 what kind of error message should be emitted. */
daywalker5d945de2003-09-26 00:32:53 +00001745typedef
njn25e49d8e72002-09-23 09:36:25 +00001746 enum { Vg_CorePThread, Vg_CoreSignal, Vg_CoreSysCall, Vg_CoreTranslate }
1747 CorePart;
1748
njn810086f2002-11-14 12:42:47 +00001749#define EV extern void
njn25e49d8e72002-09-23 09:36:25 +00001750
njn810086f2002-11-14 12:42:47 +00001751/* Events happening in core to track. To be notified, pass a callback
1752 function to the appropriate function. To ignore an event, don't do
daywalker5d945de2003-09-26 00:32:53 +00001753 anything (default is for events to be ignored).
1754
njn72718642003-07-24 08:45:32 +00001755 Note that most events aren't passed a ThreadId. To find out the ThreadId
1756 of the affected thread, use VG_(get_current_or_recent_tid)(). For the
1757 ones passed a ThreadId, use that instead, since
1758 VG_(get_current_or_recent_tid)() might not give the right ThreadId in
1759 that case.
1760*/
njn810086f2002-11-14 12:42:47 +00001761
njn810086f2002-11-14 12:42:47 +00001762
njn3e884182003-04-15 13:03:23 +00001763/* Memory events (Nb: to track heap allocation/freeing, a skin must replace
1764 malloc() et al. See above how to do this.) */
1765
1766/* These ones occur at startup, upon some signals, and upon some syscalls */
daywalker5d945de2003-09-26 00:32:53 +00001767EV VG_(track_new_mem_startup) ( void (*f)(Addr a, UInt len,
njn810086f2002-11-14 12:42:47 +00001768 Bool rr, Bool ww, Bool xx) );
njn810086f2002-11-14 12:42:47 +00001769EV VG_(track_new_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1770EV VG_(track_new_mem_brk) ( void (*f)(Addr a, UInt len) );
1771EV VG_(track_new_mem_mmap) ( void (*f)(Addr a, UInt len,
1772 Bool rr, Bool ww, Bool xx) );
1773
njn3e884182003-04-15 13:03:23 +00001774EV VG_(track_copy_mem_remap) ( void (*f)(Addr from, Addr to, UInt len) );
1775EV VG_(track_change_mem_mprotect) ( void (*f)(Addr a, UInt len,
1776 Bool rr, Bool ww, Bool xx) );
1777EV VG_(track_die_mem_stack_signal) ( void (*f)(Addr a, UInt len) );
1778EV VG_(track_die_mem_brk) ( void (*f)(Addr a, UInt len) );
1779EV VG_(track_die_mem_munmap) ( void (*f)(Addr a, UInt len) );
1780
1781
1782/* These ones are called when %esp changes. A skin could track these itself
1783 (except for ban_mem_stack) but it's much easier to use the core's help.
daywalker5d945de2003-09-26 00:32:53 +00001784
njn3e884182003-04-15 13:03:23 +00001785 The specialised ones are called in preference to the general one, if they
njn9b007f62003-04-07 14:40:25 +00001786 are defined. These functions are called a lot if they are used, so
1787 specialising can optimise things significantly. If any of the
daywalker5d945de2003-09-26 00:32:53 +00001788 specialised cases are defined, the general case must be defined too.
1789
njn9b007f62003-04-07 14:40:25 +00001790 Nb: they must all use the __attribute__((regparm(n))) attribute. */
1791EV VG_(track_new_mem_stack_4) ( void (*f)(Addr new_ESP) );
1792EV VG_(track_new_mem_stack_8) ( void (*f)(Addr new_ESP) );
1793EV VG_(track_new_mem_stack_12) ( void (*f)(Addr new_ESP) );
1794EV VG_(track_new_mem_stack_16) ( void (*f)(Addr new_ESP) );
1795EV VG_(track_new_mem_stack_32) ( void (*f)(Addr new_ESP) );
1796EV VG_(track_new_mem_stack) ( void (*f)(Addr a, UInt len) );
1797
njn9b007f62003-04-07 14:40:25 +00001798EV VG_(track_die_mem_stack_4) ( void (*f)(Addr die_ESP) );
1799EV VG_(track_die_mem_stack_8) ( void (*f)(Addr die_ESP) );
1800EV VG_(track_die_mem_stack_12) ( void (*f)(Addr die_ESP) );
1801EV VG_(track_die_mem_stack_16) ( void (*f)(Addr die_ESP) );
1802EV VG_(track_die_mem_stack_32) ( void (*f)(Addr die_ESP) );
1803EV VG_(track_die_mem_stack) ( void (*f)(Addr a, UInt len) );
1804
njn3e884182003-04-15 13:03:23 +00001805/* Used for redzone at end of thread stacks */
1806EV VG_(track_ban_mem_stack) ( void (*f)(Addr a, UInt len) );
njn25e49d8e72002-09-23 09:36:25 +00001807
njn3e884182003-04-15 13:03:23 +00001808/* These ones occur around syscalls, signal handling, etc */
njn72718642003-07-24 08:45:32 +00001809EV VG_(track_pre_mem_read) ( void (*f)(CorePart part, ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001810 Char* s, Addr a, UInt size) );
njn72718642003-07-24 08:45:32 +00001811EV VG_(track_pre_mem_read_asciiz) ( void (*f)(CorePart part, ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001812 Char* s, Addr a) );
njn72718642003-07-24 08:45:32 +00001813EV VG_(track_pre_mem_write) ( void (*f)(CorePart part, ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001814 Char* s, Addr a, UInt size) );
1815/* Not implemented yet -- have to add in lots of places, which is a
1816 pain. Won't bother unless/until there's a need. */
daywalker5d945de2003-09-26 00:32:53 +00001817/* EV VG_(track_post_mem_read) ( void (*f)(ThreadId tid, Char* s,
njn810086f2002-11-14 12:42:47 +00001818 Addr a, UInt size) ); */
1819EV VG_(track_post_mem_write) ( void (*f)(Addr a, UInt size) );
njn25e49d8e72002-09-23 09:36:25 +00001820
1821
njnd3040452003-05-19 15:04:06 +00001822/* Register events -- if `shadow_regs' need is set, all should probably be
1823 used. Use VG_(set_thread_shadow_archreg)() to set the shadow of the
1824 changed register. */
1825
1826/* Use VG_(set_shadow_archreg)() to set the eight general purpose regs,
1827 and use VG_(set_shadow_eflags)() to set eflags. */
daywalker5d945de2003-09-26 00:32:53 +00001828EV VG_(track_post_regs_write_init) ( void (*f)() );
njnd3040452003-05-19 15:04:06 +00001829
daywalker5d945de2003-09-26 00:32:53 +00001830/* Use VG_(set_thread_shadow_archreg)() to set the shadow regs for these
njnd3040452003-05-19 15:04:06 +00001831 events. */
daywalker5d945de2003-09-26 00:32:53 +00001832EV VG_(track_post_reg_write_syscall_return)
njnd3040452003-05-19 15:04:06 +00001833 ( void (*f)(ThreadId tid, UInt reg) );
1834EV VG_(track_post_reg_write_deliver_signal)
1835 ( void (*f)(ThreadId tid, UInt reg) );
1836EV VG_(track_post_reg_write_pthread_return)
1837 ( void (*f)(ThreadId tid, UInt reg) );
1838EV VG_(track_post_reg_write_clientreq_return)
1839 ( void (*f)(ThreadId tid, UInt reg) );
1840 /* This one is called for malloc() et al if they are replaced by a skin. */
1841EV VG_(track_post_reg_write_clientcall_return)
1842 ( void (*f)(ThreadId tid, UInt reg,
1843 Addr called_function) );
1844
1845
njn810086f2002-11-14 12:42:47 +00001846/* Scheduler events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001847
njn810086f2002-11-14 12:42:47 +00001848EV VG_(track_thread_run) ( void (*f)(ThreadId tid) );
njn25e49d8e72002-09-23 09:36:25 +00001849
njn810086f2002-11-14 12:42:47 +00001850/* Thread events (not exhaustive) */
sewardjdca84112002-11-13 22:29:34 +00001851
njn810086f2002-11-14 12:42:47 +00001852/* Called during thread create, before the new thread has run any
1853 instructions (or touched any memory). */
1854EV VG_(track_post_thread_create)( void (*f)(ThreadId tid, ThreadId child) );
1855/* Called once the joinee thread is terminated and the joining thread is
1856 about to resume. */
1857EV VG_(track_post_thread_join) ( void (*f)(ThreadId joiner, ThreadId joinee) );
njn25e49d8e72002-09-23 09:36:25 +00001858
daywalker5d945de2003-09-26 00:32:53 +00001859
njn810086f2002-11-14 12:42:47 +00001860/* Mutex events (not exhaustive) */
njn25e49d8e72002-09-23 09:36:25 +00001861
njn810086f2002-11-14 12:42:47 +00001862/* Called before a thread can block while waiting for a mutex (called
1863 regardless of whether the thread will block or not). */
daywalker5d945de2003-09-26 00:32:53 +00001864EV VG_(track_pre_mutex_lock) ( void (*f)(ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001865 void* /*pthread_mutex_t* */ mutex) );
1866/* Called once the thread actually holds the mutex (always paired with
1867 pre_mutex_lock). */
daywalker5d945de2003-09-26 00:32:53 +00001868EV VG_(track_post_mutex_lock) ( void (*f)(ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001869 void* /*pthread_mutex_t* */ mutex) );
1870/* Called after a thread has released a mutex (no need for a corresponding
1871 pre_mutex_unlock, because unlocking can't block). */
daywalker5d945de2003-09-26 00:32:53 +00001872EV VG_(track_post_mutex_unlock) ( void (*f)(ThreadId tid,
njn810086f2002-11-14 12:42:47 +00001873 void* /*pthread_mutex_t* */ mutex) );
njn25e49d8e72002-09-23 09:36:25 +00001874
njn1045b0a2003-02-24 10:42:47 +00001875
1876/* Signal events (not exhaustive) */
1877
njn7b456f52003-05-19 11:16:50 +00001878/* ... pre_send_signal, post_send_signal ... */
1879
njn1045b0a2003-02-24 10:42:47 +00001880/* Called before a signal is delivered; `alt_stack' indicates if it is
1881 delivered on an alternative stack. */
1882EV VG_(track_pre_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum,
1883 Bool alt_stack) );
njn7b456f52003-05-19 11:16:50 +00001884/* Called after a signal is delivered. Nb: unfortunately, if the signal
1885 handler longjmps, this won't be called. */
njn1045b0a2003-02-24 10:42:47 +00001886EV VG_(track_post_deliver_signal) ( void (*f)(ThreadId tid, Int sigNum ) );
1887
1888
1889/* Others... condition variables... */
njn810086f2002-11-14 12:42:47 +00001890/* ... */
1891
1892#undef EV
njn25e49d8e72002-09-23 09:36:25 +00001893
1894/* ------------------------------------------------------------------ */
1895/* Template functions */
1896
1897/* These are the parameterised functions in the core. The default definitions
njnd5bb0a52002-09-27 10:24:48 +00001898 are overridden by LD_PRELOADed skin version. At the very least, a skin
1899 must define the fundamental template functions. Depending on what needs
1900 are set, extra template functions will be used too. Functions are
1901 grouped under the needs that govern their use. */
njn25e49d8e72002-09-23 09:36:25 +00001902
1903
1904/* ------------------------------------------------------------------ */
1905/* Fundamental template functions */
1906
1907/* Initialise skin. Must do the following:
njn810086f2002-11-14 12:42:47 +00001908 - initialise the `details' struct, via the VG_(details_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001909 - register any helpers called by generated code
daywalker5d945de2003-09-26 00:32:53 +00001910
njn25e49d8e72002-09-23 09:36:25 +00001911 May do the following:
njn810086f2002-11-14 12:42:47 +00001912 - initialise the `needs' struct to indicate certain requirements, via
1913 the VG_(needs_*)() functions
1914 - initialise the `track' struct to indicate core events of interest, via
1915 the VG_(track_*)() functions
njn25e49d8e72002-09-23 09:36:25 +00001916 - register any skin-specific profiling events
1917 - any other skin-specific initialisation
1918*/
njn810086f2002-11-14 12:42:47 +00001919extern void SK_(pre_clo_init) ( void );
njn25e49d8e72002-09-23 09:36:25 +00001920
njnd5bb0a52002-09-27 10:24:48 +00001921/* Do initialisation that can only be done after command line processing. */
njn25e49d8e72002-09-23 09:36:25 +00001922extern void SK_(post_clo_init)( void );
1923
1924/* Instrument a basic block. Must be a true function, ie. the same input
1925 always results in the same output, because basic blocks can be
1926 retranslated. Unless you're doing something really strange...
1927 'orig_addr' is the address of the first instruction in the block. */
1928extern UCodeBlock* SK_(instrument) ( UCodeBlock* cb, Addr orig_addr );
1929
njn7d9f94d2003-04-22 21:41:40 +00001930/* Finish up, print out any results, etc. `exitcode' is program's exit
1931 code. The shadow (if the `shadow_regs' need is set) can be found with
1932 VG_(get_shadow_archreg)(R_EBX), since %ebx holds the argument to the
1933 exit() syscall. */
1934extern void SK_(fini) ( Int exitcode );
njn25e49d8e72002-09-23 09:36:25 +00001935
1936
1937/* ------------------------------------------------------------------ */
njn6a230532003-07-21 10:38:23 +00001938/* VG_(needs).core_errors */
1939
1940/* (none needed) */
1941
1942/* ------------------------------------------------------------------ */
1943/* VG_(needs).skin_errors */
njn25e49d8e72002-09-23 09:36:25 +00001944
1945/* Identify if two errors are equal, or equal enough. `res' indicates how
1946 close is "close enough". `res' should be passed on as necessary, eg. if
njn810086f2002-11-14 12:42:47 +00001947 the Error's `extra' part contains an ExeContext, `res' should be
njn25e49d8e72002-09-23 09:36:25 +00001948 passed to VG_(eq_ExeContext)() if the ExeContexts are considered. Other
1949 than that, probably don't worry about it unless you have lots of very
1950 similar errors occurring.
1951 */
njn810086f2002-11-14 12:42:47 +00001952extern Bool SK_(eq_SkinError) ( VgRes res, Error* e1, Error* e2 );
njn25e49d8e72002-09-23 09:36:25 +00001953
njn43c799e2003-04-08 00:08:52 +00001954/* Print error context. */
1955extern void SK_(pp_SkinError) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001956
njn43c799e2003-04-08 00:08:52 +00001957/* Should fill in any details that could be postponed until after the
njn810086f2002-11-14 12:42:47 +00001958 decision whether to ignore the error (ie. details not affecting the
1959 result of SK_(eq_SkinError)()). This saves time when errors are ignored.
njn25e49d8e72002-09-23 09:36:25 +00001960 Yuk.
njn43c799e2003-04-08 00:08:52 +00001961
1962 Return value: must be the size of the `extra' part in bytes -- used by
1963 the core to make a copy.
njn25e49d8e72002-09-23 09:36:25 +00001964*/
njn43c799e2003-04-08 00:08:52 +00001965extern UInt SK_(update_extra) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001966
njn810086f2002-11-14 12:42:47 +00001967/* Return value indicates recognition. If recognised, must set skind using
1968 VG_(set_supp_kind)(). */
1969extern Bool SK_(recognised_suppression) ( Char* name, Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001970
njn810086f2002-11-14 12:42:47 +00001971/* Read any extra info for this suppression kind. Most likely for filling
1972 in the `extra' and `string' parts (with VG_(set_supp_{extra,string})())
daywalker5d945de2003-09-26 00:32:53 +00001973 of a suppression if necessary. Should return False if a syntax error
njn810086f2002-11-14 12:42:47 +00001974 occurred, True otherwise. */
1975extern Bool SK_(read_extra_suppression_info) ( Int fd, Char* buf, Int nBuf,
1976 Supp* su );
njn25e49d8e72002-09-23 09:36:25 +00001977
1978/* This should just check the kinds match and maybe some stuff in the
njn810086f2002-11-14 12:42:47 +00001979 `string' and `extra' field if appropriate (using VG_(get_supp_*)() to
1980 get the relevant suppression parts). */
njn43c799e2003-04-08 00:08:52 +00001981extern Bool SK_(error_matches_suppression) ( Error* err, Supp* su );
1982
1983/* This should return the suppression name, for --gen-suppressions, or NULL
1984 if that error type cannot be suppressed. This is the inverse of
1985 SK_(recognised_suppression)(). */
1986extern Char* SK_(get_error_name) ( Error* err );
1987
1988/* This should print any extra info for the error, for --gen-suppressions,
1989 including the newline. This is the inverse of
1990 SK_(read_extra_suppression_info)(). */
1991extern void SK_(print_extra_suppression_info) ( Error* err );
njn25e49d8e72002-09-23 09:36:25 +00001992
1993
1994/* ------------------------------------------------------------------ */
1995/* VG_(needs).basic_block_discards */
1996
njnd5bb0a52002-09-27 10:24:48 +00001997/* Should discard any information that pertains to specific basic blocks
1998 or instructions within the address range given. */
njn25e49d8e72002-09-23 09:36:25 +00001999extern void SK_(discard_basic_block_info) ( Addr a, UInt size );
2000
2001
2002/* ------------------------------------------------------------------ */
2003/* VG_(needs).shadow_regs */
2004
njnd3040452003-05-19 15:04:06 +00002005/* No functions must be defined, but the post_reg[s]_write_* events should
2006 be tracked. */
njn25e49d8e72002-09-23 09:36:25 +00002007
2008/* ------------------------------------------------------------------ */
2009/* VG_(needs).command_line_options */
2010
njnd5bb0a52002-09-27 10:24:48 +00002011/* Return True if option was recognised. Presumably sets some state to
2012 record the option as well. */
2013extern Bool SK_(process_cmd_line_option) ( Char* argv );
njn25e49d8e72002-09-23 09:36:25 +00002014
njn3e884182003-04-15 13:03:23 +00002015/* Print out command line usage for options for normal skin operation. */
2016extern void SK_(print_usage) ( void );
njn25e49d8e72002-09-23 09:36:25 +00002017
njn3e884182003-04-15 13:03:23 +00002018/* Print out command line usage for options for debugging the skin. */
2019extern void SK_(print_debug_usage) ( void );
njn25e49d8e72002-09-23 09:36:25 +00002020
2021/* ------------------------------------------------------------------ */
2022/* VG_(needs).client_requests */
2023
njnd3040452003-05-19 15:04:06 +00002024/* If using client requests, the number of the first request should be equal
2025 to VG_USERREQ_SKIN_BASE('X','Y'), where 'X' and 'Y' form a suitable two
2026 character identification for the string. The second and subsequent
2027 requests should follow. */
2028
2029/* This function should use the VG_IS_SKIN_USERREQ macro (in
2030 include/valgrind.h) to first check if it's a request for this skin. Then
2031 should handle it if it's recognised (and return True), or return False if
2032 not recognised. arg_block[0] holds the request number, any further args
2033 from the request are in arg_block[1..]. 'ret' is for the return value...
2034 it should probably be filled, if only with 0. */
njn72718642003-07-24 08:45:32 +00002035extern Bool SK_(handle_client_request) ( ThreadId tid, UInt* arg_block,
njnd3040452003-05-19 15:04:06 +00002036 UInt *ret );
njn25e49d8e72002-09-23 09:36:25 +00002037
2038
2039/* ------------------------------------------------------------------ */
2040/* VG_(needs).extends_UCode */
2041
njn4ba5a792002-09-30 10:23:54 +00002042/* Useful to use in VG_(get_Xreg_usage)() */
njn810086f2002-11-14 12:42:47 +00002043#define VG_UINSTR_READS_REG(ono,regs,isWrites) \
njn25e49d8e72002-09-23 09:36:25 +00002044 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00002045 { regs[n] = mycat(u->val,ono); \
2046 isWrites[n] = False; \
njn25e49d8e72002-09-23 09:36:25 +00002047 n++; \
2048 } \
2049 }
njn810086f2002-11-14 12:42:47 +00002050#define VG_UINSTR_WRITES_REG(ono,regs,isWrites) \
njnd5bb0a52002-09-27 10:24:48 +00002051 { if (mycat(u->tag,ono) == tag) \
njn810086f2002-11-14 12:42:47 +00002052 { regs[n] = mycat(u->val,ono); \
2053 isWrites[n] = True; \
njnd5bb0a52002-09-27 10:24:48 +00002054 n++; \
2055 } \
njn25e49d8e72002-09-23 09:36:25 +00002056 }
2057
njn4ba5a792002-09-30 10:23:54 +00002058/* 'X' prefix indicates eXtended UCode. */
njn810086f2002-11-14 12:42:47 +00002059extern Int SK_(get_Xreg_usage) ( UInstr* u, Tag tag, Int* regs,
2060 Bool* isWrites );
njn4ba5a792002-09-30 10:23:54 +00002061extern void SK_(emit_XUInstr) ( UInstr* u, RRegSet regs_live_before );
2062extern Bool SK_(sane_XUInstr) ( Bool beforeRA, Bool beforeLiveness,
njn25e49d8e72002-09-23 09:36:25 +00002063 UInstr* u );
njn4ba5a792002-09-30 10:23:54 +00002064extern Char* SK_(name_XUOpcode) ( Opcode opc );
2065extern void SK_(pp_XUInstr) ( UInstr* u );
njn25e49d8e72002-09-23 09:36:25 +00002066
2067
2068/* ------------------------------------------------------------------ */
2069/* VG_(needs).syscall_wrapper */
2070
2071/* If either of the pre_ functions malloc() something to return, the
daywalker5d945de2003-09-26 00:32:53 +00002072 * corresponding post_ function had better free() it!
2073 */
njn25e49d8e72002-09-23 09:36:25 +00002074extern void* SK_( pre_syscall) ( ThreadId tid, UInt syscallno,
2075 Bool is_blocking );
2076extern void SK_(post_syscall) ( ThreadId tid, UInt syscallno,
2077 void* pre_result, Int res,
2078 Bool is_blocking );
2079
njnd5bb0a52002-09-27 10:24:48 +00002080
njn25e49d8e72002-09-23 09:36:25 +00002081/* ---------------------------------------------------------------------
2082 VG_(needs).sanity_checks */
2083
njnd5bb0a52002-09-27 10:24:48 +00002084/* Can be useful for ensuring a skin's correctness. SK_(cheap_sanity_check)
2085 is called very frequently; SK_(expensive_sanity_check) is called less
2086 frequently and can be more involved. */
njn25e49d8e72002-09-23 09:36:25 +00002087extern Bool SK_(cheap_sanity_check) ( void );
2088extern Bool SK_(expensive_sanity_check) ( void );
2089
2090
2091#endif /* NDEF __VG_SKIN_H */
2092
2093/*--------------------------------------------------------------------*/
2094/*--- end vg_skin.h ---*/
2095/*--------------------------------------------------------------------*/
2096