blob: 0c00e1ab8330cd7b7977d04cab45218a50c7b97c [file] [log] [blame]
sewardjde4a1d02002-03-22 01:27:54 +00001
2/*--------------------------------------------------------------------*/
3/*--- A header file for all parts of Valgrind. ---*/
4/*--- Include no other! ---*/
5/*--- vg_include.h ---*/
6/*--------------------------------------------------------------------*/
7
8/*
9 This file is part of Valgrind, an x86 protected-mode emulator
10 designed for debugging and profiling binaries on x86-Unixes.
11
12 Copyright (C) 2000-2002 Julian Seward
13 jseward@acm.org
sewardjde4a1d02002-03-22 01:27:54 +000014
15 This program is free software; you can redistribute it and/or
16 modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation; either version 2 of the
18 License, or (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
28 02111-1307, USA.
29
30 The GNU General Public License is contained in the file LICENSE.
31*/
32
33#ifndef __VG_INCLUDE_H
34#define __VG_INCLUDE_H
35
36
37#include <stdarg.h> /* ANSI varargs stuff */
38#include <setjmp.h> /* for jmp_buf */
39
40
41/* ---------------------------------------------------------------------
42 Build options and table sizes. You should be able to change these
43 options or sizes, recompile, and still have a working system.
44 ------------------------------------------------------------------ */
45
46#include "vg_constants.h"
47
48
49/* Set to 1 to enable time profiling. Since this uses SIGPROF, we
50 don't want this permanently enabled -- only for profiling
51 builds. */
52#if 0
53# define VG_PROFILE
54#endif
55
56
57/* Total number of integer registers available for allocation. That's
58 all of them except %esp, %edi and %ebp. %edi is a general spare
59 temporary. %ebp permanently points at VG_(baseBlock). Note that
60 it's important that this tie in with what rankToRealRegNo() says.
61 DO NOT CHANGE THIS VALUE FROM 5. ! */
62#define VG_MAX_REALREGS 5
63
64/* Total number of spill slots available for allocation, if a TempReg
65 doesn't make it into a RealReg. Just bomb the entire system if
66 this value is too small; we don't expect it will ever get
67 particularly high. */
68#define VG_MAX_SPILLSLOTS 24
69
70
71/* Constants for the slow translation lookup cache. */
72#define VG_TRANSTAB_SLOW_BITS 11
73#define VG_TRANSTAB_SLOW_SIZE (1 << VG_TRANSTAB_SLOW_BITS)
74#define VG_TRANSTAB_SLOW_MASK ((VG_TRANSTAB_SLOW_SIZE) - 1)
75
76/* Size of a buffer used for creating messages. */
77#define M_VG_MSGBUF 10000
78
79/* Size of a smallish table used to read /proc/self/map entries. */
sewardjebc82332002-04-24 14:44:23 +000080#define M_PROCMAP_BUF 50000
sewardjde4a1d02002-03-22 01:27:54 +000081
82/* Max length of pathname to a .so/executable file. */
83#define M_VG_LIBNAMESTR 100
84
85/* Max length of a text fragment used to construct error messages. */
86#define M_VG_ERRTXT 512
87
88/* Max length of the string copied from env var VG_ARGS at startup. */
89#define M_VG_CMDLINE_STRLEN 1000
90
91/* Max number of options for Valgrind which we can handle. */
92#define M_VG_CMDLINE_OPTS 100
93
94/* After this many different unsuppressed errors have been observed,
95 be more conservative about collecting new ones. */
96#define M_VG_COLLECT_ERRORS_SLOWLY_AFTER 50
97
98/* After this many different unsuppressed errors have been observed,
99 stop collecting errors at all, and tell the user their program is
100 evidently a steaming pile of camel dung. */
101#define M_VG_COLLECT_NO_ERRORS_AFTER 500
102
103/* These many bytes below %ESP are considered addressible if we're
104 doing the --workaround-gcc296-bugs hack. */
sewardjd8091eb2002-04-24 02:19:36 +0000105#define VG_GCC296_BUG_STACK_SLOP 256
sewardjde4a1d02002-03-22 01:27:54 +0000106
107/* The maximum number of calls we're prepared to save in a
108 backtrace. */
109#define VG_DEEPEST_BACKTRACE 50
110
111/* Number of lists in which we keep track of malloc'd but not free'd
112 blocks. Should be prime. */
113#define VG_N_MALLOCLISTS 997
114
115/* Number of lists in which we keep track of ExeContexts. Should be
116 prime. */
117#define VG_N_EC_LISTS /*997*/ 4999
118
sewardj2e93c502002-04-12 11:12:52 +0000119/* Defines the thread-scheduling timeslice, in terms of the number of
120 basic blocks we attempt to run each thread for. Smaller values
121 give finer interleaving but much increased scheduling overheads. */
sewardjd8091eb2002-04-24 02:19:36 +0000122#define VG_SCHEDULING_QUANTUM 20000
sewardj2e93c502002-04-12 11:12:52 +0000123
124/* The maximum number of pthreads that we support. This is
125 deliberately not very high since our implementation of some of the
sewardj5f07b662002-04-23 16:52:51 +0000126 scheduler algorithms is surely O(N) in the number of threads, since
127 that's simple, at least. And (in practice) we hope that most
sewardj2e93c502002-04-12 11:12:52 +0000128 programs do not need many threads. */
sewardjebc82332002-04-24 14:44:23 +0000129#define VG_N_THREADS 50
sewardj5f07b662002-04-23 16:52:51 +0000130
131/* Maximum number of pthread keys available. Again, we start low until
132 the need for a higher number presents itself. */
133#define VG_N_THREAD_KEYS 10
sewardj2e93c502002-04-12 11:12:52 +0000134
135/* Number of file descriptors that can simultaneously be waited on for
136 I/O to complete. Perhaps this should be the same as VG_N_THREADS
137 (surely a thread can't wait on more than one fd at once?. Who
138 knows.) */
139#define VG_N_WAITING_FDS 10
140
sewardjde4a1d02002-03-22 01:27:54 +0000141
142/* ---------------------------------------------------------------------
143 Basic types
144 ------------------------------------------------------------------ */
145
146typedef unsigned char UChar;
147typedef unsigned short UShort;
148typedef unsigned int UInt;
149typedef unsigned long long int ULong;
150
151typedef signed char Char;
152typedef signed short Short;
153typedef signed int Int;
154typedef signed long long int Long;
155
156typedef unsigned int Addr;
157
158typedef unsigned char Bool;
159#define False ((Bool)0)
160#define True ((Bool)1)
161
162#define mycat_wrk(aaa,bbb) aaa##bbb
163#define mycat(aaa,bbb) mycat_wrk(aaa,bbb)
164
165/* Just pray that gcc's constant folding works properly ... */
166#define BITS(bit7,bit6,bit5,bit4,bit3,bit2,bit1,bit0) \
167 ( ((bit7) << 7) | ((bit6) << 6) | ((bit5) << 5) | ((bit4) << 4) \
168 | ((bit3) << 3) | ((bit2) << 2) | ((bit1) << 1) | (bit0))
169
170
171/* ---------------------------------------------------------------------
172 Now the basic types are set up, we can haul in the kernel-interface
173 definitions.
174 ------------------------------------------------------------------ */
175
176#include "./vg_kerneliface.h"
177
178
179/* ---------------------------------------------------------------------
180 Command-line-settable options
181 ------------------------------------------------------------------ */
182
183#define VG_CLO_SMC_NONE 0
184#define VG_CLO_SMC_SOME 1
185#define VG_CLO_SMC_ALL 2
186
187#define VG_CLO_MAX_SFILES 10
188
sewardj97ced732002-03-25 00:07:36 +0000189/* Shall we V-check addrs (they are always A checked too): default: YES */
190extern Bool VG_(clo_check_addrVs);
sewardjde4a1d02002-03-22 01:27:54 +0000191/* Enquire about whether to attach to GDB at errors? default: NO */
192extern Bool VG_(clo_GDB_attach);
193/* Sanity-check level: 0 = none, 1 (default), > 1 = expensive. */
194extern Int VG_(sanity_level);
195/* Verbosity level: 0 = silent, 1 (default), > 1 = more verbose. */
196extern Int VG_(clo_verbosity);
197/* Automatically attempt to demangle C++ names? default: YES */
198extern Bool VG_(clo_demangle);
199/* Do leak check at exit? default: NO */
200extern Bool VG_(clo_leak_check);
201/* In leak check, show reachable-but-not-freed blocks? default: NO */
202extern Bool VG_(clo_show_reachable);
203/* How closely should we compare ExeContexts in leak records? default: 2 */
204extern Int VG_(clo_leak_resolution);
205/* Round malloc sizes upwards to integral number of words? default:
206 NO */
207extern Bool VG_(clo_sloppy_malloc);
208/* Allow loads from partially-valid addresses? default: YES */
209extern Bool VG_(clo_partial_loads_ok);
210/* Simulate child processes? default: NO */
211extern Bool VG_(clo_trace_children);
212/* The file id on which we send all messages. default: 2 (stderr). */
213extern Int VG_(clo_logfile_fd);
214/* Max volume of the freed blocks queue. */
215extern Int VG_(clo_freelist_vol);
216/* Assume accesses immediately below %esp are due to gcc-2.96 bugs.
217 default: NO */
218extern Bool VG_(clo_workaround_gcc296_bugs);
219
220/* The number of suppression files specified. */
221extern Int VG_(clo_n_suppressions);
222/* The names of the suppression files. */
223extern Char* VG_(clo_suppressions)[VG_CLO_MAX_SFILES];
224
225/* Single stepping? default: NO */
226extern Bool VG_(clo_single_step);
227/* Code improvement? default: YES */
228extern Bool VG_(clo_optimise);
229/* Memory-check instrumentation? default: YES */
230extern Bool VG_(clo_instrument);
231/* DEBUG: clean up instrumented code? default: YES */
232extern Bool VG_(clo_cleanup);
sewardjde4a1d02002-03-22 01:27:54 +0000233/* SMC write checks? default: SOME (1,2,4 byte movs to mem) */
234extern Int VG_(clo_smc_check);
235/* DEBUG: print system calls? default: NO */
236extern Bool VG_(clo_trace_syscalls);
237/* DEBUG: print signal details? default: NO */
238extern Bool VG_(clo_trace_signals);
239/* DEBUG: print symtab details? default: NO */
240extern Bool VG_(clo_trace_symtab);
241/* DEBUG: print malloc details? default: NO */
242extern Bool VG_(clo_trace_malloc);
sewardj8937c812002-04-12 20:12:20 +0000243/* DEBUG: print thread scheduling events? default: NO */
244extern Bool VG_(clo_trace_sched);
sewardj45b4b372002-04-16 22:50:32 +0000245/* DEBUG: print pthread (mutex etc) events? default: 0 (none), 1
246 (some), 2 (all) */
247extern Int VG_(clo_trace_pthread_level);
sewardjde4a1d02002-03-22 01:27:54 +0000248/* Stop after this many basic blocks. default: Infinity. */
249extern ULong VG_(clo_stop_after);
250/* Display gory details for the k'th most popular error. default:
251 Infinity. */
252extern Int VG_(clo_dump_error);
253/* Number of parents of a backtrace. Default: 8. */
254extern Int VG_(clo_backtrace_size);
255
256
257/* ---------------------------------------------------------------------
258 Debugging and profiling stuff
259 ------------------------------------------------------------------ */
260
261/* No, really. I _am_ that strange. */
262#define OINK(nnn) VG_(message)(Vg_DebugMsg, "OINK %d",nnn)
263
264/* Tools for building messages from multiple parts. */
265typedef
266 enum { Vg_UserMsg, Vg_DebugMsg, Vg_DebugExtraMsg }
267 VgMsgKind;
268
269extern void VG_(start_msg) ( VgMsgKind kind );
270extern void VG_(add_to_msg) ( Char* format, ... );
271extern void VG_(end_msg) ( void );
272
273/* Send a simple, single-part message. */
274extern void VG_(message) ( VgMsgKind kind, Char* format, ... );
275
276/* Create a logfile into which messages can be dumped. */
277extern void VG_(startup_logging) ( void );
278extern void VG_(shutdown_logging) ( void );
279
280
281/* Profiling stuff */
282#ifdef VG_PROFILE
283
284#define VGP_M_STACK 10
285
286#define VGP_M_CCS 20 /* == the # of elems in VGP_LIST */
287#define VGP_LIST \
288 VGP_PAIR(VgpRun=0, "running"), \
289 VGP_PAIR(VgpMalloc, "low-lev malloc/free"), \
290 VGP_PAIR(VgpCliMalloc, "client malloc/free"), \
291 VGP_PAIR(VgpTranslate, "translate-main"), \
292 VGP_PAIR(VgpToUCode, "to-ucode"), \
293 VGP_PAIR(VgpFromUcode, "from-ucode"), \
294 VGP_PAIR(VgpImprove, "improve"), \
295 VGP_PAIR(VgpInstrument, "instrument"), \
296 VGP_PAIR(VgpCleanup, "cleanup"), \
297 VGP_PAIR(VgpRegAlloc, "reg-alloc"), \
298 VGP_PAIR(VgpDoLRU, "do-lru"), \
299 VGP_PAIR(VgpSlowFindT, "slow-search-transtab"), \
300 VGP_PAIR(VgpInitAudit, "init-mem-audit"), \
301 VGP_PAIR(VgpExeContext, "exe-context"), \
302 VGP_PAIR(VgpReadSyms, "read-syms"), \
303 VGP_PAIR(VgpAddToT, "add-to-transtab"), \
304 VGP_PAIR(VgpSARP, "set-addr-range-perms"), \
305 VGP_PAIR(VgpSyscall, "syscall wrapper"), \
306 VGP_PAIR(VgpSpare1, "spare 1"), \
307 VGP_PAIR(VgpSpare2, "spare 2")
308
309#define VGP_PAIR(enumname,str) enumname
310typedef enum { VGP_LIST } VgpCC;
311#undef VGP_PAIR
312
313extern void VGP_(init_profiling) ( void );
314extern void VGP_(done_profiling) ( void );
315extern void VGP_(pushcc) ( VgpCC );
316extern void VGP_(popcc) ( void );
317
318#define VGP_PUSHCC(cc) VGP_(pushcc)(cc)
319#define VGP_POPCC VGP_(popcc)()
320
321#else
322
323#define VGP_PUSHCC(cc) /* */
324#define VGP_POPCC /* */
325
326#endif /* VG_PROFILE */
327
328
329/* ---------------------------------------------------------------------
330 Exports of vg_malloc2.c
331 ------------------------------------------------------------------ */
332
333/* Allocation arenas.
334 SYMTAB is for Valgrind's symbol table storage.
335 CLIENT is for the client's mallocs/frees.
336 DEMANGLE is for the C++ demangler.
337 EXECTXT is for storing ExeContexts.
338 ERRCTXT is for storing ErrContexts.
339 PRIVATE is for Valgrind general stuff.
340 TRANSIENT is for very short-term use. It should be empty
341 in between uses.
342 When adding a new arena, remember also to add it
343 to ensure_mm_init().
344*/
345typedef Int ArenaId;
346
347#define VG_N_ARENAS 7
348
349#define VG_AR_PRIVATE 0 /* :: ArenaId */
350#define VG_AR_SYMTAB 1 /* :: ArenaId */
351#define VG_AR_CLIENT 2 /* :: ArenaId */
352#define VG_AR_DEMANGLE 3 /* :: ArenaId */
353#define VG_AR_EXECTXT 4 /* :: ArenaId */
354#define VG_AR_ERRCTXT 5 /* :: ArenaId */
355#define VG_AR_TRANSIENT 6 /* :: ArenaId */
356
357extern void* VG_(malloc) ( ArenaId arena, Int nbytes );
358extern void VG_(free) ( ArenaId arena, void* ptr );
359extern void* VG_(calloc) ( ArenaId arena, Int nmemb, Int nbytes );
360extern void* VG_(realloc) ( ArenaId arena, void* ptr, Int size );
361extern void* VG_(malloc_aligned) ( ArenaId aid, Int req_alignB,
362 Int req_pszB );
363
364extern void VG_(mallocSanityCheckArena) ( ArenaId arena );
365extern void VG_(mallocSanityCheckAll) ( void );
366
367extern void VG_(show_all_arena_stats) ( void );
368extern Bool VG_(is_empty_arena) ( ArenaId aid );
369
370
371/* The red-zone size for the client. This can be arbitrary, but
372 unfortunately must be set at compile time. */
373#define VG_AR_CLIENT_REDZONE_SZW 4
374
375#define VG_AR_CLIENT_REDZONE_SZB \
376 (VG_AR_CLIENT_REDZONE_SZW * VKI_BYTES_PER_WORD)
377
378
379/* ---------------------------------------------------------------------
sewardj2e93c502002-04-12 11:12:52 +0000380 Exports of vg_clientfuns.c
381 ------------------------------------------------------------------ */
382
383/* This doesn't export code or data that valgrind.so needs to link
384 against. However, the scheduler does need to know the following
385 request codes. A few, publically-visible, request codes are also
386 defined in valgrind.h. */
387
388#define VG_USERREQ__MALLOC 0x2001
389#define VG_USERREQ__BUILTIN_NEW 0x2002
390#define VG_USERREQ__BUILTIN_VEC_NEW 0x2003
391
392#define VG_USERREQ__FREE 0x2004
393#define VG_USERREQ__BUILTIN_DELETE 0x2005
394#define VG_USERREQ__BUILTIN_VEC_DELETE 0x2006
395
396#define VG_USERREQ__CALLOC 0x2007
397#define VG_USERREQ__REALLOC 0x2008
398#define VG_USERREQ__MEMALIGN 0x2009
399
400
401#define VG_USERREQ__PTHREAD_CREATE 0x3001
sewardjbc5b99f2002-04-13 00:08:51 +0000402#define VG_USERREQ__PTHREAD_JOIN 0x3002
403#define VG_USERREQ__PTHREAD_GET_THREADID 0x3003
sewardj3b5d8862002-04-20 13:53:23 +0000404#define VG_USERREQ__PTHREAD_MUTEX_LOCK 0x3004
sewardj30671ff2002-04-21 00:13:57 +0000405#define VG_USERREQ__PTHREAD_MUTEX_TRYLOCK 0x3005
406#define VG_USERREQ__PTHREAD_MUTEX_UNLOCK 0x3006
407#define VG_USERREQ__PTHREAD_CANCEL 0x3007
408#define VG_USERREQ__PTHREAD_EXIT 0x3008
409#define VG_USERREQ__PTHREAD_COND_WAIT 0x3009
sewardj5f07b662002-04-23 16:52:51 +0000410#define VG_USERREQ__PTHREAD_COND_TIMEDWAIT 0x300A
411#define VG_USERREQ__PTHREAD_COND_SIGNAL 0x300B
412#define VG_USERREQ__PTHREAD_COND_BROADCAST 0x300C
413#define VG_USERREQ__PTHREAD_KEY_CREATE 0x300D
414#define VG_USERREQ__PTHREAD_KEY_DELETE 0x300E
415#define VG_USERREQ__PTHREAD_SETSPECIFIC 0x300F
416#define VG_USERREQ__PTHREAD_GETSPECIFIC 0x3010
sewardj56fc53d2002-04-24 01:17:42 +0000417#define VG_USERREQ__READ_MILLISECOND_TIMER 0x3011
sewardj2e93c502002-04-12 11:12:52 +0000418
sewardj45b4b372002-04-16 22:50:32 +0000419/* Cosmetic ... */
420#define VG_USERREQ__GET_PTHREAD_TRACE_LEVEL 0x3101
421
sewardj54cacf02002-04-12 23:24:59 +0000422/*
423In vg_constants.h:
424#define VG_USERREQ__SIGNAL_RETURNS 0x4001
sewardjbc5b99f2002-04-13 00:08:51 +0000425#define VG_USERREQ__PTHREAD_RETURNS 0x4002
426#define VG_USERREQ__SHUTDOWN_VALGRIND 0x4003
sewardj54cacf02002-04-12 23:24:59 +0000427*/
428
429
sewardj2e93c502002-04-12 11:12:52 +0000430/* ---------------------------------------------------------------------
431 Constants pertaining to the simulated CPU state, VG_(baseBlock),
432 which need to go here to avoid ugly circularities.
433 ------------------------------------------------------------------ */
434
435/* How big is the saved FPU state? */
436#define VG_SIZE_OF_FPUSTATE 108
437/* ... and in words ... */
438#define VG_SIZE_OF_FPUSTATE_W ((VG_SIZE_OF_FPUSTATE+3)/4)
439
440
441/* ---------------------------------------------------------------------
442 Exports of vg_scheduler.c
443 ------------------------------------------------------------------ */
444
445/* ThreadIds are simply indices into the vg_threads[] array. */
446typedef
447 UInt
448 ThreadId;
449
sewardj6072c362002-04-19 14:40:57 +0000450/* Special magic value for an invalid ThreadId. It corresponds to
451 LinuxThreads using zero as the initial value for
452 pthread_mutex_t.__m_owner and pthread_cond_t.__c_waiting. */
453#define VG_INVALID_THREADID ((ThreadId)(0))
sewardj2e93c502002-04-12 11:12:52 +0000454
455typedef
456 enum {
457 VgTs_Empty, /* this slot is not in use */
458 VgTs_Runnable, /* waiting to be scheduled */
459 VgTs_WaitJoiner, /* waiting for someone to do join on me */
460 VgTs_WaitJoinee, /* waiting for the thread I did join on */
461 VgTs_WaitFD, /* waiting for I/O completion on a fd */
462 VgTs_WaitMX, /* waiting on a mutex */
sewardj3b5d8862002-04-20 13:53:23 +0000463 VgTs_WaitCV, /* waiting on a condition variable */
sewardj2e93c502002-04-12 11:12:52 +0000464 VgTs_Sleeping /* sleeping for a while */
465 }
466 ThreadStatus;
467
468typedef
469 struct {
sewardj6072c362002-04-19 14:40:57 +0000470 /* ThreadId == 0 (and hence vg_threads[0]) is NEVER USED.
471 The thread identity is simply the index in vg_threads[].
472 ThreadId == 1 is the root thread and has the special property
sewardj1e8cdc92002-04-18 11:37:52 +0000473 that we don't try and allocate or deallocate its stack. For
474 convenience of generating error message, we also put the
475 ThreadId in this tid field, but be aware that it should
sewardj604ec3c2002-04-18 22:38:41 +0000476 ALWAYS == the index in vg_threads[]. */
sewardj1e8cdc92002-04-18 11:37:52 +0000477 ThreadId tid;
sewardj2e93c502002-04-12 11:12:52 +0000478
sewardj5f07b662002-04-23 16:52:51 +0000479 /* Current scheduling status.
480
481 Complications: whenever this is set to VgTs_WaitMX, you
482 should also set .m_edx to whatever the required return value
483 is for pthread_mutex_lock / pthread_cond_timedwait for when
484 the mutex finally gets unblocked. */
sewardj2e93c502002-04-12 11:12:52 +0000485 ThreadStatus status;
486
487 /* Identity of joiner (thread who called join on me), or
488 VG_INVALID_THREADID if no one asked to join yet. */
489 ThreadId joiner;
490
sewardj3b5d8862002-04-20 13:53:23 +0000491 /* When .status == WaitMX, points to the mutex I am waiting for.
492 When .status == WaitCV, points to the mutex associated with
493 the condition variable indicated by the .associated_cv field.
494 In all other cases, should be NULL. */
495 void* /* pthread_mutex_t* */ associated_mx;
496
497 /* When .status == WaitCV, points to the condition variable I am
498 waiting for. In all other cases, should be NULL. */
499 void* /* pthread_cond_t* */ associated_cv;
sewardj2e93c502002-04-12 11:12:52 +0000500
sewardj5f07b662002-04-23 16:52:51 +0000501 /* If VgTs_Sleeping, this is when we should wake up, measured in
502 milliseconds as supplied by VG_(read_millisecond_counter).
503
504 If VgTs_WaitCV, this indicates the time at which
505 pthread_cond_timedwait should wake up. If == 0xFFFFFFFF,
506 this means infinitely far in the future, viz,
507 pthread_cond_wait. */
508 UInt awaken_at;
sewardj2e93c502002-04-12 11:12:52 +0000509
510 /* return value */
511 void* retval;
512
sewardj5f07b662002-04-23 16:52:51 +0000513 /* thread-specific data */
514 void* specifics[VG_N_THREAD_KEYS];
515
sewardj2e93c502002-04-12 11:12:52 +0000516 /* Stacks. When a thread slot is freed, we don't deallocate its
517 stack; we just leave it lying around for the next use of the
518 slot. If the next use of the slot requires a larger stack,
519 only then is the old one deallocated and a new one
520 allocated.
521
522 For the main thread (threadid == 0), this mechanism doesn't
523 apply. We don't know the size of the stack since we didn't
524 allocate it, and furthermore we never reallocate it. */
525
526 /* The allocated size of this thread's stack (permanently zero
527 if this is ThreadId == 0, since we didn't allocate its stack) */
528 UInt stack_size;
529
530 /* Address of the lowest word in this thread's stack. NULL means
531 not allocated yet.
532 */
533 Addr stack_base;
534
sewardj1e8cdc92002-04-18 11:37:52 +0000535 /* Address of the highest legitimate word in this stack. This is
536 used for error messages only -- not critical for execution
537 correctness. Is is set for all stacks, specifically including
538 ThreadId == 0 (the main thread). */
539 Addr stack_highest_word;
540
sewardj2e93c502002-04-12 11:12:52 +0000541 /* Saved machine context. */
542 UInt m_eax;
543 UInt m_ebx;
544 UInt m_ecx;
545 UInt m_edx;
546 UInt m_esi;
547 UInt m_edi;
548 UInt m_ebp;
549 UInt m_esp;
550 UInt m_eflags;
551 UInt m_eip;
552 UInt m_fpu[VG_SIZE_OF_FPUSTATE_W];
553
554 UInt sh_eax;
555 UInt sh_ebx;
556 UInt sh_ecx;
557 UInt sh_edx;
558 UInt sh_esi;
559 UInt sh_edi;
560 UInt sh_ebp;
561 UInt sh_esp;
562 UInt sh_eflags;
563 }
564 ThreadState;
565
566
567/* Copy the specified thread's state into VG_(baseBlock) in
568 preparation for running it. */
569extern void VG_(load_thread_state)( ThreadId );
570
571/* Save the specified thread's state back in VG_(baseBlock), and fill
572 VG_(baseBlock) with junk, for sanity-check reasons. */
573extern void VG_(save_thread_state)( ThreadId );
574
575/* Get the thread state block for the specified thread. */
576extern ThreadState* VG_(get_thread_state)( ThreadId );
577
sewardj1e8cdc92002-04-18 11:37:52 +0000578/* And for the currently running one, if valid. */
579extern ThreadState* VG_(get_current_thread_state) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000580
sewardj1e8cdc92002-04-18 11:37:52 +0000581/* Similarly ... */
582extern ThreadId VG_(get_current_tid) ( void );
583
584/* Which thread is this address in the stack of, if any? Used for
585 error message generation. */
586extern ThreadId VG_(identify_stack_addr)( Addr a );
587
sewardj2e93c502002-04-12 11:12:52 +0000588
589/* Return codes from the scheduler. */
590typedef
591 enum { VgSrc_Deadlock, VgSrc_Shutdown, VgSrc_BbsDone }
592 VgSchedReturnCode;
593
594/* The scheduler. */
595extern VgSchedReturnCode VG_(scheduler) ( void );
596
597extern void VG_(scheduler_init) ( void );
598
sewardj15a43e12002-04-17 19:35:12 +0000599extern void VG_(pp_sched_status) ( void );
sewardj2e93c502002-04-12 11:12:52 +0000600
601/* vg_oursignalhandler() might longjmp(). Here's the jmp_buf. */
602extern jmp_buf VG_(scheduler_jmpbuf);
603/* ... and if so, here's the signal which caused it to do so. */
604extern Int VG_(longjmpd_on_signal);
605
606
607/* We check that the initial stack, which we can't move, is allocated
608 here. VG_(scheduler_init) checks this.
609*/
sewardjebc82332002-04-24 14:44:23 +0000610#define VG_STARTUP_STACK_MASK (Addr)0xBFF80000
sewardj2e93c502002-04-12 11:12:52 +0000611
612
613/* The red-zone size which we put at the bottom (highest address) of
614 thread stacks, for paranoia reasons. This can be arbitrary, and
615 doesn't really need to be set at compile time. */
616#define VG_AR_CLIENT_STACKBASE_REDZONE_SZW 4
617
618#define VG_AR_CLIENT_STACKBASE_REDZONE_SZB \
619 (VG_AR_CLIENT_STACKBASE_REDZONE_SZW * VKI_BYTES_PER_WORD)
620
621
622
623/* ---------------------------------------------------------------------
sewardjde4a1d02002-03-22 01:27:54 +0000624 Exports of vg_signals.c
625 ------------------------------------------------------------------ */
626
sewardjde4a1d02002-03-22 01:27:54 +0000627extern void VG_(sigstartup_actions) ( void );
628
sewardj2e93c502002-04-12 11:12:52 +0000629extern void VG_(deliver_signals) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000630extern void VG_(unblock_host_signal) ( Int sigNo );
631
632
633/* Fake system calls for signal handling. */
sewardj2e93c502002-04-12 11:12:52 +0000634extern void VG_(do__NR_sigaction) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +0000635extern void VG_(do__NR_sigprocmask) ( Int how, vki_ksigset_t* set );
636
sewardj2e93c502002-04-12 11:12:52 +0000637/* Modify the current thread's state once we have detected it is
638 returning from a signal handler. */
sewardj77e466c2002-04-14 02:29:29 +0000639extern Bool VG_(signal_returns) ( ThreadId );
sewardjde4a1d02002-03-22 01:27:54 +0000640
sewardj2e93c502002-04-12 11:12:52 +0000641/* Handy utilities to block/restore all host signals. */
642extern void VG_(block_all_host_signals)
643 ( /* OUT */ vki_ksigset_t* saved_mask );
644extern void VG_(restore_host_signals)
645 ( /* IN */ vki_ksigset_t* saved_mask );
sewardjde4a1d02002-03-22 01:27:54 +0000646
647/* ---------------------------------------------------------------------
648 Exports of vg_mylibc.c
649 ------------------------------------------------------------------ */
650
651
652#define NULL ((void*)0)
653
654extern void VG_(exit)( Int status )
655 __attribute__ ((__noreturn__));
656
657extern void VG_(printf) ( const char *format, ... );
658/* too noisy ... __attribute__ ((format (printf, 1, 2))) ; */
659
660extern void VG_(sprintf) ( Char* buf, Char *format, ... );
661
662extern void VG_(vprintf) ( void(*send)(Char),
663 const Char *format, va_list vargs );
664
665extern Bool VG_(isspace) ( Char c );
666
667extern Int VG_(strlen) ( const Char* str );
668
669extern Long VG_(atoll) ( Char* str );
670
671extern Char* VG_(strcat) ( Char* dest, const Char* src );
672extern Char* VG_(strncat) ( Char* dest, const Char* src, Int n );
673extern Char* VG_(strpbrk) ( const Char* s, const Char* accept );
674
675extern Char* VG_(strcpy) ( Char* dest, const Char* src );
676
677extern Int VG_(strcmp) ( const Char* s1, const Char* s2 );
678extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );
679
680extern Int VG_(strncmp) ( const Char* s1, const Char* s2, Int nmax );
681extern Int VG_(strncmp_ws) ( const Char* s1, const Char* s2, Int nmax );
682
683extern Char* VG_(strstr) ( const Char* haystack, Char* needle );
684extern Char* VG_(strchr) ( const Char* s, Char c );
685extern Char* VG_(strdup) ( ArenaId aid, const Char* s);
686
687extern Char* VG_(getenv) ( Char* name );
688extern Int VG_(getpid) ( void );
sewardj5f07b662002-04-23 16:52:51 +0000689
690extern void VG_(start_rdtsc_calibration) ( void );
691extern void VG_(end_rdtsc_calibration) ( void );
692extern UInt VG_(read_millisecond_timer) ( void );
sewardjde4a1d02002-03-22 01:27:54 +0000693
694
695extern Char VG_(toupper) ( Char c );
696
697extern void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest );
698
699extern void VG_(strncpy) ( Char* dest, const Char* src, Int ndest );
700
701extern Bool VG_(stringMatch) ( Char* pat, Char* str );
702
703
704#define __STRING(x) #x
705
706/* Asserts are permanently enabled. Hurrah! */
707#define vg_assert(expr) \
708 ((void) ((expr) ? 0 : \
709 (VG_(assert_fail) (__STRING(expr), \
710 __FILE__, __LINE__, \
711 __PRETTY_FUNCTION__), 0)))
712
713extern void VG_(assert_fail) ( Char* expr, Char* file,
714 Int line, Char* fn )
715 __attribute__ ((__noreturn__));
716
sewardjde4a1d02002-03-22 01:27:54 +0000717/* Reading files. */
718extern Int VG_(open_read) ( Char* pathname );
719extern void VG_(close) ( Int fd );
720extern Int VG_(read) ( Int fd, void* buf, Int count);
721extern Int VG_(write) ( Int fd, void* buf, Int count);
722
sewardj2e93c502002-04-12 11:12:52 +0000723extern Int VG_(fcntl) ( Int fd, Int cmd, Int arg );
724
725extern Int VG_(select)( Int n,
726 vki_fd_set* readfds,
727 vki_fd_set* writefds,
728 vki_fd_set* exceptfds,
729 struct vki_timeval * timeout );
730extern Int VG_(nanosleep)( const struct vki_timespec *req,
731 struct vki_timespec *rem );
732
733
sewardjde4a1d02002-03-22 01:27:54 +0000734/* mmap-ery ... */
735extern void* VG_(mmap)( void* start, UInt length,
736 UInt prot, UInt flags, UInt fd, UInt offset );
737
sewardj2e93c502002-04-12 11:12:52 +0000738extern Int VG_(munmap)( void* start, Int length );
sewardjde4a1d02002-03-22 01:27:54 +0000739
740
741/* Print a (panic) message, and abort. */
742extern void VG_(panic) ( Char* str )
743 __attribute__ ((__noreturn__));
744
745/* Get memory by anonymous mmap. */
sewardje6a25242002-04-21 22:03:07 +0000746extern void* VG_(get_memory_from_mmap) ( Int nBytes );
747
748/* Crude stand-in for the glibc system() call. */
749extern Int VG_(system) ( Char* cmd );
750
sewardjde4a1d02002-03-22 01:27:54 +0000751
752/* Signal stuff. Note that these use the vk_ (kernel) structure
753 definitions, which are different in places from those that glibc
754 defines. Since we're operating right at the kernel interface,
755 glibc's view of the world is entirely irrelevant. */
756extern Int VG_(ksigfillset)( vki_ksigset_t* set );
757extern Int VG_(ksigemptyset)( vki_ksigset_t* set );
758extern Int VG_(ksigaddset)( vki_ksigset_t* set, Int signum );
759
760extern Int VG_(ksigprocmask)( Int how, const vki_ksigset_t* set,
761 vki_ksigset_t* oldset );
762extern Int VG_(ksigaction) ( Int signum,
763 const vki_ksigaction* act,
764 vki_ksigaction* oldact );
765extern Int VG_(ksigismember) ( vki_ksigset_t* set, Int signum );
766
767extern Int VG_(ksignal)(Int signum, void (*sighandler)(Int));
768
769extern Int VG_(ksigaltstack)( const vki_kstack_t* ss, vki_kstack_t* oss );
770
771
772
773/* ---------------------------------------------------------------------
774 Definitions for the JITter (vg_translate.c, vg_to_ucode.c,
775 vg_from_ucode.c).
776 ------------------------------------------------------------------ */
777
778/* Tags which describe what operands are. */
779typedef
780 enum { TempReg=0, ArchReg=1, RealReg=2,
781 SpillNo=3, Literal=4, Lit16=5,
782 NoValue=6 }
783 Tag;
784
785
786/* Microinstruction opcodes. */
787typedef
788 enum {
789 NOP,
790 GET,
791 PUT,
792 LOAD,
793 STORE,
794 MOV,
795 CMOV, /* Used for cmpxchg and cmov */
796 WIDEN,
797 JMP,
798
799 /* Read/write the %EFLAGS register into a TempReg. */
800 GETF, PUTF,
801
802 ADD, ADC, AND, OR, XOR, SUB, SBB,
803 SHL, SHR, SAR, ROL, ROR, RCL, RCR,
804 NOT, NEG, INC, DEC, BSWAP,
805 CC2VAL,
806
807 /* Not strictly needed, but useful for making better
808 translations of address calculations. */
809 LEA1, /* reg2 := const + reg1 */
810 LEA2, /* reg3 := const + reg1 + reg2 * 1,2,4 or 8 */
811
812 /* not for translating x86 calls -- only to call helpers */
813 CALLM_S, CALLM_E, /* Mark start and end of push/pop sequences
814 for CALLM. */
815 PUSH, POP, CLEAR, /* Add/remove/zap args for helpers. */
816 CALLM, /* call to a machine-code helper */
817
818 /* Hack for translating string (REP-) insns. Jump to literal if
819 TempReg/RealReg is zero. */
820 JIFZ,
821
822 /* FPU ops which read/write mem or don't touch mem at all. */
823 FPU_R,
824 FPU_W,
825 FPU,
826
827 /* Advance the simulated %eip by some small (< 128) number. */
828 INCEIP,
829
830 /* uinstrs which are not needed for mere translation of x86 code,
831 only for instrumentation of it. */
832 LOADV,
833 STOREV,
834 GETV,
835 PUTV,
836 TESTV,
837 SETV,
838 /* Get/set the v-bit (and it is only one bit) for the simulated
839 %eflags register. */
840 GETVF,
841 PUTVF,
842
843 /* Do a unary or binary tag op. Only for post-instrumented
844 code. For TAG1, first and only arg is a TempReg, and is both
845 arg and result reg. For TAG2, first arg is src, second is
846 dst, in the normal way; both are TempRegs. In both cases,
847 3rd arg is a RiCHelper with a Lit16 tag. This indicates
848 which tag op to do. */
849 TAG1,
850 TAG2
851 }
852 Opcode;
853
854
855/* Condition codes, observing the Intel encoding. CondAlways is an
856 extra. */
857typedef
858 enum {
859 CondO = 0, /* overflow */
860 CondNO = 1, /* no overflow */
861 CondB = 2, /* below */
862 CondNB = 3, /* not below */
863 CondZ = 4, /* zero */
864 CondNZ = 5, /* not zero */
865 CondBE = 6, /* below or equal */
866 CondNBE = 7, /* not below or equal */
867 CondS = 8, /* negative */
868 ConsNS = 9, /* not negative */
869 CondP = 10, /* parity even */
870 CondNP = 11, /* not parity even */
871 CondL = 12, /* jump less */
872 CondNL = 13, /* not less */
873 CondLE = 14, /* less or equal */
874 CondNLE = 15, /* not less or equal */
875 CondAlways = 16 /* Jump always */
876 }
877 Condcode;
878
879
sewardj2e93c502002-04-12 11:12:52 +0000880/* Descriptions of additional properties of *unconditional* jumps. */
881typedef
882 enum {
883 JmpBoring=0, /* boring unconditional jump */
884 JmpCall=1, /* jump due to an x86 call insn */
885 JmpRet=2, /* jump due to an x86 ret insn */
886 JmpSyscall=3, /* do a system call, then jump */
887 JmpClientReq=4 /* do a client request, then jump */
888 }
889 JmpKind;
890
891
sewardjde4a1d02002-03-22 01:27:54 +0000892/* Flags. User-level code can only read/write O(verflow), S(ign),
893 Z(ero), A(ux-carry), C(arry), P(arity), and may also write
894 D(irection). That's a total of 7 flags. A FlagSet is a bitset,
895 thusly:
896 76543210
897 DOSZACP
898 and bit 7 must always be zero since it is unused.
899*/
900typedef UChar FlagSet;
901
902#define FlagD (1<<6)
903#define FlagO (1<<5)
904#define FlagS (1<<4)
905#define FlagZ (1<<3)
906#define FlagA (1<<2)
907#define FlagC (1<<1)
908#define FlagP (1<<0)
909
910#define FlagsOSZACP (FlagO | FlagS | FlagZ | FlagA | FlagC | FlagP)
911#define FlagsOSZAP (FlagO | FlagS | FlagZ | FlagA | FlagP)
912#define FlagsOSZCP (FlagO | FlagS | FlagZ | FlagC | FlagP)
913#define FlagsOSACP (FlagO | FlagS | FlagA | FlagC | FlagP)
914#define FlagsSZACP ( FlagS | FlagZ | FlagA | FlagC | FlagP)
915#define FlagsSZAP ( FlagS | FlagZ | FlagA | FlagP)
sewardj4a7456e2002-03-24 13:52:19 +0000916#define FlagsZCP ( FlagZ | FlagC | FlagP)
sewardjde4a1d02002-03-22 01:27:54 +0000917#define FlagsOC (FlagO | FlagC )
sewardj4d0ab1f2002-03-24 10:00:09 +0000918#define FlagsAC ( FlagA | FlagC )
sewardjde4a1d02002-03-22 01:27:54 +0000919
920#define FlagsALL (FlagsOSZACP | FlagD)
921#define FlagsEmpty (FlagSet)0
922
923#define VG_IS_FLAG_SUBSET(set1,set2) \
924 (( ((FlagSet)set1) & ((FlagSet)set2) ) == ((FlagSet)set1) )
925
926#define VG_UNION_FLAG_SETS(set1,set2) \
927 ( ((FlagSet)set1) | ((FlagSet)set2) )
928
929
930
931/* A Micro (u)-instruction. */
932typedef
933 struct {
934 /* word 1 */
935 UInt lit32; /* 32-bit literal */
936
937 /* word 2 */
938 UShort val1; /* first operand */
939 UShort val2; /* second operand */
940
941 /* word 3 */
942 UShort val3; /* third operand */
943 UChar opcode; /* opcode */
944 UChar size; /* data transfer size */
945
946 /* word 4 */
947 FlagSet flags_r; /* :: FlagSet */
948 FlagSet flags_w; /* :: FlagSet */
949 UChar tag1:4; /* first operand tag */
950 UChar tag2:4; /* second operand tag */
951 UChar tag3:4; /* third operand tag */
952 UChar extra4b:4; /* Spare field, used by WIDEN for src
953 -size, and by LEA2 for scale
954 (1,2,4 or 8) */
955
956 /* word 5 */
957 UChar cond; /* condition, for jumps */
958 Bool smc_check:1; /* do a smc test, if writes memory. */
959 Bool signed_widen:1; /* signed or unsigned WIDEN ? */
sewardj2e93c502002-04-12 11:12:52 +0000960 JmpKind jmpkind:3; /* additional properties of unconditional JMP */
sewardjde4a1d02002-03-22 01:27:54 +0000961 }
962 UInstr;
963
964
965/* Expandable arrays of uinstrs. */
966typedef
967 struct {
968 Int used;
969 Int size;
970 UInstr* instrs;
971 Int nextTemp;
972 }
973 UCodeBlock;
974
975/* Refer to `the last instruction stuffed in', including as an
976 lvalue. */
977#define LAST_UINSTR(cb) (cb)->instrs[(cb)->used-1]
978
979/* An invalid temporary number :-) */
980#define INVALID_TEMPREG 999999999
981
982
983/* ---------------------------------------------------------------------
984 Exports of vg_demangle.c
985 ------------------------------------------------------------------ */
986
987extern void VG_(demangle) ( Char* orig, Char* result, Int result_size );
988
989
990/* ---------------------------------------------------------------------
991 Exports of vg_from_ucode.c
992 ------------------------------------------------------------------ */
993
994extern UChar* VG_(emit_code) ( UCodeBlock* cb, Int* nbytes );
995
996
997/* ---------------------------------------------------------------------
998 Exports of vg_to_ucode.c
999 ------------------------------------------------------------------ */
1000
1001extern Int VG_(disBB) ( UCodeBlock* cb, Addr eip0 );
1002extern Char* VG_(nameOfIntReg) ( Int size, Int reg );
1003extern Char VG_(nameOfIntSize) ( Int size );
1004extern UInt VG_(extend_s_8to32) ( UInt x );
1005extern Int VG_(getNewTemp) ( UCodeBlock* cb );
1006extern Int VG_(getNewShadow) ( UCodeBlock* cb );
1007
1008#define SHADOW(tempreg) ((tempreg)+1)
1009
1010
1011/* ---------------------------------------------------------------------
1012 Exports of vg_translate.c
1013 ------------------------------------------------------------------ */
1014
sewardj1e8cdc92002-04-18 11:37:52 +00001015extern void VG_(translate) ( ThreadState* tst,
1016 Addr orig_addr,
sewardjde4a1d02002-03-22 01:27:54 +00001017 UInt* orig_size,
1018 Addr* trans_addr,
1019 UInt* trans_size );
1020
1021extern void VG_(emptyUInstr) ( UInstr* u );
1022extern void VG_(newUInstr0) ( UCodeBlock* cb, Opcode opcode, Int sz );
1023extern void VG_(newUInstr1) ( UCodeBlock* cb, Opcode opcode, Int sz,
1024 Tag tag1, UInt val1 );
1025extern void VG_(newUInstr2) ( UCodeBlock* cb, Opcode opcode, Int sz,
1026 Tag tag1, UInt val1,
1027 Tag tag2, UInt val2 );
1028extern void VG_(newUInstr3) ( UCodeBlock* cb, Opcode opcode, Int sz,
1029 Tag tag1, UInt val1,
1030 Tag tag2, UInt val2,
1031 Tag tag3, UInt val3 );
1032extern void VG_(setFlagRW) ( UInstr* u,
1033 FlagSet fr, FlagSet fw );
1034
1035extern void VG_(setLiteralField) ( UCodeBlock* cb, UInt lit32 );
1036extern Bool VG_(anyFlagUse) ( UInstr* u );
1037
1038
1039
1040extern void VG_(ppUInstr) ( Int instrNo, UInstr* u );
1041extern void VG_(ppUCodeBlock) ( UCodeBlock* cb, Char* title );
1042
1043extern Char* VG_(nameCondcode) ( Condcode cond );
1044extern Bool VG_(saneUInstr) ( Bool beforeRA, UInstr* u );
1045extern Bool VG_(saneUCodeBlock) ( UCodeBlock* cb );
1046extern Char* VG_(nameUOpcode) ( Bool upper, Opcode opc );
1047extern Int VG_(rankToRealRegNo) ( Int rank );
1048
1049extern void* VG_(jitmalloc) ( Int nbytes );
1050extern void VG_(jitfree) ( void* ptr );
1051
1052
1053/* ---------------------------------------------------------------------
1054 Exports of vg_execontext.c.
1055 ------------------------------------------------------------------ */
1056
1057/* Records the PC and a bit of the call chain. The first 4 %eip
1058 values are used in comparisons do remove duplicate errors, and for
1059 comparing against suppression specifications. The rest are purely
1060 informational (but often important). */
1061
1062typedef
1063 struct _ExeContextRec {
1064 struct _ExeContextRec * next;
1065 /* The size of this array is VG_(clo_backtrace_size); at least
1066 2, at most VG_DEEPEST_BACKTRACE. [0] is the current %eip,
1067 [1] is its caller, [2] is the caller of [1], etc. */
1068 Addr eips[0];
1069 }
1070 ExeContext;
1071
1072
1073/* Initialise the ExeContext storage mechanism. */
1074extern void VG_(init_ExeContext_storage) ( void );
1075
1076/* Print stats (informational only). */
1077extern void VG_(show_ExeContext_stats) ( void );
1078
1079
1080/* Take a snapshot of the client's stack. Search our collection of
1081 ExeContexts to see if we already have it, and if not, allocate a
1082 new one. Either way, return a pointer to the context. */
sewardj8c824512002-04-14 04:16:48 +00001083extern ExeContext* VG_(get_ExeContext) ( Bool skip_top_frame,
1084 Addr eip, Addr ebp );
sewardjde4a1d02002-03-22 01:27:54 +00001085
1086/* Print an ExeContext. */
1087extern void VG_(pp_ExeContext) ( ExeContext* );
1088
1089/* Compare two ExeContexts, just comparing the top two callers. */
1090extern Bool VG_(eq_ExeContext_top2) ( ExeContext* e1, ExeContext* e2 );
1091
1092/* Compare two ExeContexts, just comparing the top four callers. */
1093extern Bool VG_(eq_ExeContext_top4) ( ExeContext* e1, ExeContext* e2 );
1094
1095/* Compare two ExeContexts, comparing all callers. */
1096extern Bool VG_(eq_ExeContext_all) ( ExeContext* e1, ExeContext* e2 );
1097
1098
1099
1100/* ---------------------------------------------------------------------
1101 Exports of vg_errcontext.c.
1102 ------------------------------------------------------------------ */
1103
1104extern void VG_(load_suppressions) ( void );
1105extern void VG_(show_all_errors) ( void );
1106extern void VG_(record_value_error) ( Int size );
sewardjaabd5ad2002-04-19 15:43:37 +00001107extern void VG_(record_free_error) ( ThreadState* tst, Addr a );
1108extern void VG_(record_freemismatch_error) ( ThreadState* tst, Addr a );
sewardjde4a1d02002-03-22 01:27:54 +00001109extern void VG_(record_address_error) ( Addr a, Int size,
1110 Bool isWrite );
sewardj1e8cdc92002-04-18 11:37:52 +00001111
1112extern void VG_(record_jump_error) ( ThreadState* tst, Addr a );
sewardj8c824512002-04-14 04:16:48 +00001113
1114extern void VG_(record_param_err) ( ThreadState* tst,
1115 Addr a,
sewardjde4a1d02002-03-22 01:27:54 +00001116 Bool isWriteLack,
1117 Char* msg );
sewardj8c824512002-04-14 04:16:48 +00001118extern void VG_(record_user_err) ( ThreadState* tst,
1119 Addr a, Bool isWriteLack );
sewardjde4a1d02002-03-22 01:27:54 +00001120
1121
1122/* The classification of a faulting address. */
1123typedef
1124 enum { Stack, Unknown, Freed, Mallocd, UserG, UserS }
1125 AddrKind;
1126
1127/* Records info about a faulting address. */
1128typedef
1129 struct {
1130 /* ALL */
1131 AddrKind akind;
1132 /* Freed, Mallocd */
1133 Int blksize;
1134 /* Freed, Mallocd */
1135 Int rwoffset;
1136 /* Freed, Mallocd */
1137 ExeContext* lastchange;
sewardj1e8cdc92002-04-18 11:37:52 +00001138 /* Stack */
1139 ThreadId stack_tid;
sewardjde4a1d02002-03-22 01:27:54 +00001140 }
1141 AddrInfo;
1142
1143
1144/* ---------------------------------------------------------------------
1145 Exports of vg_clientperms.c
1146 ------------------------------------------------------------------ */
1147
1148extern Bool VG_(client_perm_maybe_describe)( Addr a, AddrInfo* ai );
1149
sewardj8c824512002-04-14 04:16:48 +00001150extern UInt VG_(handle_client_request) ( ThreadState* tst, UInt* arg_block );
sewardjde4a1d02002-03-22 01:27:54 +00001151
1152extern void VG_(delete_client_stack_blocks_following_ESP_change) ( void );
1153
1154extern void VG_(show_client_block_stats) ( void );
1155
1156
1157/* ---------------------------------------------------------------------
1158 Exports of vg_procselfmaps.c
1159 ------------------------------------------------------------------ */
1160
1161extern
1162void VG_(read_procselfmaps) (
1163 void (*record_mapping)( Addr, UInt, Char, Char, Char, UInt, UChar* )
1164);
1165
1166
1167/* ---------------------------------------------------------------------
1168 Exports of vg_symtab2.c
1169 ------------------------------------------------------------------ */
1170
1171/* We assume the executable is loaded here ... can't really find
1172 out. There is a hacky sanity check in vg_init_memory_audit()
1173 which should trip up most stupidities.
1174*/
1175#define VG_ASSUMED_EXE_BASE (Addr)0x8048000
1176
1177extern void VG_(read_symbols) ( void );
1178extern void VG_(mini_stack_dump) ( ExeContext* ec );
1179extern void VG_(what_obj_and_fun_is_this)
1180 ( Addr a,
1181 Char* obj_buf, Int n_obj_buf,
1182 Char* fun_buf, Int n_fun_buf );
1183
1184extern void VG_(symtab_notify_munmap) ( Addr start, UInt length );
1185
1186
1187/* ---------------------------------------------------------------------
1188 Exports of vg_clientmalloc.c
1189 ------------------------------------------------------------------ */
1190
sewardjde4a1d02002-03-22 01:27:54 +00001191typedef
1192 enum {
1193 Vg_AllocMalloc = 0,
sewardj2e93c502002-04-12 11:12:52 +00001194 Vg_AllocNew = 1,
sewardjde4a1d02002-03-22 01:27:54 +00001195 Vg_AllocNewVec = 2
1196 }
1197 VgAllocKind;
1198
1199/* Description of a malloc'd chunk. */
1200typedef
1201 struct _ShadowChunk {
1202 struct _ShadowChunk* next;
1203 ExeContext* where; /* where malloc'd/free'd */
1204 UInt size : 30; /* size requested. */
1205 VgAllocKind allockind : 2; /* which wrapper did the allocation */
1206 Addr data; /* ptr to actual block. */
1207 }
1208 ShadowChunk;
1209
1210extern void VG_(clientmalloc_done) ( void );
1211extern void VG_(describe_addr) ( Addr a, AddrInfo* ai );
1212extern ShadowChunk** VG_(get_malloc_shadows) ( /*OUT*/ UInt* n_shadows );
1213
sewardj2e93c502002-04-12 11:12:52 +00001214/* These are called from the scheduler, when it intercepts a user
1215 request. */
sewardj8c824512002-04-14 04:16:48 +00001216extern void* VG_(client_malloc) ( ThreadState* tst,
1217 UInt size, VgAllocKind kind );
1218extern void* VG_(client_memalign) ( ThreadState* tst,
1219 UInt align, UInt size );
1220extern void VG_(client_free) ( ThreadState* tst,
1221 void* ptrV, VgAllocKind kind );
1222extern void* VG_(client_calloc) ( ThreadState* tst,
1223 UInt nmemb, UInt size1 );
1224extern void* VG_(client_realloc) ( ThreadState* tst,
1225 void* ptrV, UInt size_new );
sewardjde4a1d02002-03-22 01:27:54 +00001226
1227
1228/* ---------------------------------------------------------------------
1229 Exports of vg_main.c
1230 ------------------------------------------------------------------ */
1231
sewardjde4a1d02002-03-22 01:27:54 +00001232/* A structure used as an intermediary when passing the simulated
1233 CPU's state to some assembly fragments, particularly system calls.
1234 Stuff is copied from baseBlock to here, the assembly magic runs,
1235 and then the inverse copy is done. */
1236
1237extern UInt VG_(m_state_static) [8 /* int regs, in Intel order */
1238 + 1 /* %eflags */
1239 + 1 /* %eip */
1240 + VG_SIZE_OF_FPUSTATE_W /* FPU state */
1241 ];
1242
1243/* Handy fns for doing the copy back and forth. */
1244extern void VG_(copy_baseBlock_to_m_state_static) ( void );
1245extern void VG_(copy_m_state_static_to_baseBlock) ( void );
1246
sewardjde4a1d02002-03-22 01:27:54 +00001247/* Called when some unhandleable client behaviour is detected.
1248 Prints a msg and aborts. */
1249extern void VG_(unimplemented) ( Char* msg );
1250
1251/* The stack on which Valgrind runs. We can't use the same stack as the
1252 simulatee -- that's an important design decision. */
1253extern UInt VG_(stack)[10000];
1254
1255/* Similarly, we have to ask for signals to be delivered on an
1256 alternative stack, since it is possible, although unlikely, that
1257 we'll have to run client code from inside the Valgrind-installed
1258 signal handler. If this happens it will be done by
1259 vg_deliver_signal_immediately(). */
1260extern UInt VG_(sigstack)[10000];
1261
sewardjde4a1d02002-03-22 01:27:54 +00001262/* Holds client's %esp at the point we gained control. From this the
1263 client's argc, argv and envp are deduced. */
1264extern Addr VG_(esp_at_startup);
1265extern Int VG_(client_argc);
1266extern Char** VG_(client_argv);
1267extern Char** VG_(client_envp);
1268
1269/* Remove valgrind.so from a LD_PRELOAD=... string so child processes
1270 don't get traced into. */
1271extern void VG_(mash_LD_PRELOAD_string)( Char* ld_preload_str );
1272
1273/* Something of a function looking for a home ... start up GDB. This
1274 is called from VG_(swizzle_esp_then_start_GDB) and so runs on the
1275 *client's* stack. This is necessary to give GDB the illusion that
1276 the client program really was running on the real cpu. */
1277extern void VG_(start_GDB_whilst_on_client_stack) ( void );
1278
1279/* Spew out vast amounts of junk during JITting? */
1280extern Bool VG_(disassemble);
1281
1282/* 64-bit counter for the number of basic blocks done. */
1283extern ULong VG_(bbs_done);
1284/* 64-bit counter for the number of bbs to go before a debug exit. */
1285extern ULong VG_(bbs_to_go);
1286
1287/* Counts downwards in vg_run_innerloop. */
1288extern UInt VG_(dispatch_ctr);
1289
sewardjde4a1d02002-03-22 01:27:54 +00001290/* Is the client running on the simulated CPU or the real one? */
1291extern Bool VG_(running_on_simd_CPU); /* Initially False */
1292
1293/* The current LRU epoch. */
1294extern UInt VG_(current_epoch);
1295
1296
1297/* --- Counters, for informational purposes only. --- */
1298
1299/* Number of lookups which miss the fast tt helper. */
1300extern UInt VG_(tt_fast_misses);
1301
1302/* Counts for LRU informational messages. */
1303
1304/* Number and total o/t size of new translations this epoch. */
1305extern UInt VG_(this_epoch_in_count);
1306extern UInt VG_(this_epoch_in_osize);
1307extern UInt VG_(this_epoch_in_tsize);
1308/* Number and total o/t size of discarded translations this epoch. */
1309extern UInt VG_(this_epoch_out_count);
1310extern UInt VG_(this_epoch_out_osize);
1311extern UInt VG_(this_epoch_out_tsize);
1312/* Number and total o/t size of translations overall. */
1313extern UInt VG_(overall_in_count);
1314extern UInt VG_(overall_in_osize);
1315extern UInt VG_(overall_in_tsize);
1316/* Number and total o/t size of discards overall. */
1317extern UInt VG_(overall_out_count);
1318extern UInt VG_(overall_out_osize);
1319extern UInt VG_(overall_out_tsize);
1320
1321/* The number of LRU-clearings of TT/TC. */
1322extern UInt VG_(number_of_lrus);
1323
1324/* Counts pertaining to the register allocator. */
1325
1326/* total number of uinstrs input to reg-alloc */
1327extern UInt VG_(uinstrs_prealloc);
1328
1329/* total number of uinstrs added due to spill code */
1330extern UInt VG_(uinstrs_spill);
1331
1332/* number of bbs requiring spill code */
1333extern UInt VG_(translations_needing_spill);
1334
1335/* total of register ranks over all translations */
1336extern UInt VG_(total_reg_rank);
1337
1338/* Counts pertaining to the self-modifying-code detection machinery. */
1339
1340/* Total number of writes checked. */
1341//extern UInt VG_(smc_total_check4s);
1342
1343/* Number of writes which the fast smc check couldn't show were
1344 harmless. */
1345extern UInt VG_(smc_cache_passed);
1346
1347/* Numnber of writes which really did write on original code. */
1348extern UInt VG_(smc_fancy_passed);
1349
1350/* Number of translations discarded as a result. */
1351//extern UInt VG_(smc_discard_count);
1352
1353/* Counts pertaining to internal sanity checking. */
1354extern UInt VG_(sanity_fast_count);
1355extern UInt VG_(sanity_slow_count);
1356
sewardj2e93c502002-04-12 11:12:52 +00001357/* Counts pertaining to the scheduler. */
1358extern UInt VG_(num_scheduling_events_MINOR);
1359extern UInt VG_(num_scheduling_events_MAJOR);
1360
sewardjde4a1d02002-03-22 01:27:54 +00001361
1362/* ---------------------------------------------------------------------
1363 Exports of vg_memory.c
1364 ------------------------------------------------------------------ */
1365
1366extern void VGM_(init_memory_audit) ( void );
1367extern Addr VGM_(curr_dataseg_end);
1368extern void VG_(show_reg_tags) ( void );
1369extern void VG_(detect_memory_leaks) ( void );
1370extern void VG_(done_prof_mem) ( void );
1371
1372/* Set permissions for an address range. Not speed-critical. */
1373extern void VGM_(make_noaccess) ( Addr a, UInt len );
1374extern void VGM_(make_writable) ( Addr a, UInt len );
1375extern void VGM_(make_readable) ( Addr a, UInt len );
1376/* Use with care! (read: use for shmat only) */
1377extern void VGM_(make_readwritable) ( Addr a, UInt len );
1378extern void VGM_(copy_address_range_perms) ( Addr src, Addr dst,
1379 UInt len );
1380
1381/* Check permissions for an address range. Not speed-critical. */
1382extern Bool VGM_(check_writable) ( Addr a, UInt len, Addr* bad_addr );
1383extern Bool VGM_(check_readable) ( Addr a, UInt len, Addr* bad_addr );
1384extern Bool VGM_(check_readable_asciiz) ( Addr a, Addr* bad_addr );
1385
1386/* Sanity checks which may be done at any time. Doing them at
1387 signal-delivery time turns out to be convenient. */
sewardj2e93c502002-04-12 11:12:52 +00001388extern void VG_(do_sanity_checks) ( ThreadId tid, Bool force_expensive );
sewardjde4a1d02002-03-22 01:27:54 +00001389/* Very cheap ... */
1390extern Bool VG_(first_and_last_secondaries_look_plausible) ( void );
1391
1392/* These functions are called from generated code. */
1393extern void VG_(helperc_STOREV4) ( UInt, Addr );
1394extern void VG_(helperc_STOREV2) ( UInt, Addr );
1395extern void VG_(helperc_STOREV1) ( UInt, Addr );
1396
1397extern UInt VG_(helperc_LOADV1) ( Addr );
1398extern UInt VG_(helperc_LOADV2) ( Addr );
1399extern UInt VG_(helperc_LOADV4) ( Addr );
1400
1401extern void VGM_(handle_esp_assignment) ( Addr new_espA );
1402extern void VGM_(fpu_write_check) ( Addr addr, Int size );
1403extern void VGM_(fpu_read_check) ( Addr addr, Int size );
1404
1405/* Safely (avoiding SIGSEGV / SIGBUS) scan the entire valid address
1406 space and pass the addresses and values of all addressible,
1407 defined, aligned words to notify_word. This is the basis for the
1408 leak detector. Returns the number of calls made to notify_word. */
1409UInt VG_(scan_all_valid_memory) ( void (*notify_word)( Addr, UInt ) );
1410
1411/* Is this address within some small distance below %ESP? Used only
1412 for the --workaround-gcc296-bugs kludge. */
sewardj8c824512002-04-14 04:16:48 +00001413extern Bool VG_(is_just_below_ESP)( Addr esp, Addr aa );
sewardjde4a1d02002-03-22 01:27:54 +00001414
1415/* Nasty kludgery to deal with applications which switch stacks,
1416 like netscape. */
sewardjde4a1d02002-03-22 01:27:54 +00001417#define VG_PLAUSIBLE_STACK_SIZE 8000000
1418
sewardjde4a1d02002-03-22 01:27:54 +00001419
1420/* ---------------------------------------------------------------------
1421 Exports of vg_syscall_mem.c
1422 ------------------------------------------------------------------ */
1423
sewardj2e93c502002-04-12 11:12:52 +00001424extern void VG_(perform_assumed_nonblocking_syscall) ( ThreadId tid );
sewardjde4a1d02002-03-22 01:27:54 +00001425
sewardj2e93c502002-04-12 11:12:52 +00001426extern void VG_(check_known_blocking_syscall) ( ThreadId tid,
1427 Int syscallno,
1428 Int* /*IN*/ res );
sewardjde4a1d02002-03-22 01:27:54 +00001429
1430extern Bool VG_(is_kerror) ( Int res );
1431
sewardj2e93c502002-04-12 11:12:52 +00001432#define KERNEL_DO_SYSCALL(thread_id, result_lvalue) \
1433 VG_(load_thread_state)(thread_id); \
sewardjde4a1d02002-03-22 01:27:54 +00001434 VG_(copy_baseBlock_to_m_state_static)(); \
1435 VG_(do_syscall)(); \
1436 VG_(copy_m_state_static_to_baseBlock)(); \
sewardj2e93c502002-04-12 11:12:52 +00001437 VG_(save_thread_state)(thread_id); \
1438 result_lvalue = VG_(get_thread_state)(thread_id)->m_eax;
sewardjde4a1d02002-03-22 01:27:54 +00001439
1440
1441/* ---------------------------------------------------------------------
1442 Exports of vg_transtab.c
1443 ------------------------------------------------------------------ */
1444
1445/* An entry in the translation table (TT). */
1446typedef
1447 struct {
1448 /* +0 */ Addr orig_addr;
1449 /* +4 */ Addr trans_addr;
1450 /* +8 */ UInt mru_epoch;
1451 /* +12 */ UShort orig_size;
1452 /* +14 */ UShort trans_size;
1453 }
1454 TTEntry;
1455
1456/* The number of basic blocks in an epoch (one age-step). */
1457#define VG_BBS_PER_EPOCH 20000
1458
1459extern void VG_(get_tt_tc_used) ( UInt* tt_used, UInt* tc_used );
1460extern void VG_(maybe_do_lru_pass) ( void );
1461extern void VG_(flush_transtab) ( void );
1462extern Addr VG_(copy_to_transcache) ( Addr trans_addr, Int trans_size );
1463extern void VG_(add_to_trans_tab) ( TTEntry* tte );
1464
1465extern void VG_(smc_mark_original) ( Addr original_addr,
1466 Int original_len );
1467
1468extern void VG_(init_transtab_and_SMC) ( void );
1469
1470extern void VG_(sanity_check_tc_tt) ( void );
1471extern Addr VG_(search_transtab) ( Addr original_addr );
1472
1473extern void VG_(invalidate_tt_fast)( void );
1474
1475
1476/* ---------------------------------------------------------------------
1477 Exports of vg_vtagops.c
1478 ------------------------------------------------------------------ */
1479
1480/* Lists the names of value-tag operations used in instrumented
1481 code. These are the third argument to TAG1 and TAG2 uinsns. */
1482
1483typedef
1484 enum {
1485 /* Unary. */
1486 VgT_PCast40, VgT_PCast20, VgT_PCast10,
1487 VgT_PCast01, VgT_PCast02, VgT_PCast04,
1488
1489 VgT_PCast14, VgT_PCast12, VgT_PCast11,
1490
1491 VgT_Left4, VgT_Left2, VgT_Left1,
1492
1493 VgT_SWiden14, VgT_SWiden24, VgT_SWiden12,
1494 VgT_ZWiden14, VgT_ZWiden24, VgT_ZWiden12,
1495
1496 /* Binary; 1st is rd; 2nd is rd+wr */
1497 VgT_UifU4, VgT_UifU2, VgT_UifU1, VgT_UifU0,
1498 VgT_DifD4, VgT_DifD2, VgT_DifD1,
1499
1500 VgT_ImproveAND4_TQ, VgT_ImproveAND2_TQ, VgT_ImproveAND1_TQ,
1501 VgT_ImproveOR4_TQ, VgT_ImproveOR2_TQ, VgT_ImproveOR1_TQ,
1502 VgT_DebugFn
1503 }
1504 VgTagOp;
1505
1506extern Char* VG_(nameOfTagOp) ( VgTagOp );
1507extern UInt VG_(DebugFn) ( UInt a1, UInt a2 );
1508
1509
1510/* ---------------------------------------------------------------------
1511 Exports of vg_syscall.S
1512 ------------------------------------------------------------------ */
1513
1514extern void VG_(do_syscall) ( void );
1515
1516
1517/* ---------------------------------------------------------------------
1518 Exports of vg_startup.S
1519 ------------------------------------------------------------------ */
1520
1521extern void VG_(shutdown);
1522extern void VG_(switch_to_real_CPU) ( void );
1523
sewardj35805422002-04-21 13:05:34 +00001524extern void VG_(swizzle_esp_then_start_GDB) ( Addr m_eip_at_error,
1525 Addr m_esp_at_error,
1526 Addr m_ebp_at_error );
sewardjde4a1d02002-03-22 01:27:54 +00001527
1528
1529/* ---------------------------------------------------------------------
1530 Exports of vg_dispatch.S
1531 ------------------------------------------------------------------ */
1532
sewardj2e93c502002-04-12 11:12:52 +00001533/* Run a thread for a (very short) while, until some event happens
1534 which means we need to defer to the scheduler. */
1535extern UInt VG_(run_innerloop) ( void );
sewardjde4a1d02002-03-22 01:27:54 +00001536
1537
1538/* ---------------------------------------------------------------------
1539 Exports of vg_helpers.S
1540 ------------------------------------------------------------------ */
1541
sewardjde4a1d02002-03-22 01:27:54 +00001542/* SMC fast checks. */
1543extern void VG_(helper_smc_check4);
1544
1545/* Mul, div, etc, -- we don't codegen these directly. */
1546extern void VG_(helper_idiv_64_32);
1547extern void VG_(helper_div_64_32);
1548extern void VG_(helper_idiv_32_16);
1549extern void VG_(helper_div_32_16);
1550extern void VG_(helper_idiv_16_8);
1551extern void VG_(helper_div_16_8);
1552
1553extern void VG_(helper_imul_32_64);
1554extern void VG_(helper_mul_32_64);
1555extern void VG_(helper_imul_16_32);
1556extern void VG_(helper_mul_16_32);
1557extern void VG_(helper_imul_8_16);
1558extern void VG_(helper_mul_8_16);
1559
1560extern void VG_(helper_CLD);
1561extern void VG_(helper_STD);
1562extern void VG_(helper_get_dirflag);
1563
1564extern void VG_(helper_shldl);
1565extern void VG_(helper_shldw);
1566extern void VG_(helper_shrdl);
1567extern void VG_(helper_shrdw);
1568
1569extern void VG_(helper_RDTSC);
1570extern void VG_(helper_CPUID);
1571
sewardjde4a1d02002-03-22 01:27:54 +00001572extern void VG_(helper_bsf);
1573extern void VG_(helper_bsr);
1574
1575extern void VG_(helper_fstsw_AX);
1576extern void VG_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001577extern void VG_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001578extern void VG_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001579
1580extern void VG_(helper_value_check4_fail);
1581extern void VG_(helper_value_check2_fail);
1582extern void VG_(helper_value_check1_fail);
1583extern void VG_(helper_value_check0_fail);
1584
sewardjbc5b99f2002-04-13 00:08:51 +00001585/* NOT FUNCTIONS; these are bogus RETURN ADDRESS. */
sewardj54cacf02002-04-12 23:24:59 +00001586extern void VG_(signalreturn_bogusRA)( void );
sewardjbc5b99f2002-04-13 00:08:51 +00001587extern void VG_(pthreadreturn_bogusRA)( void );
sewardj54cacf02002-04-12 23:24:59 +00001588
sewardjde4a1d02002-03-22 01:27:54 +00001589
1590/* ---------------------------------------------------------------------
1591 The state of the simulated CPU.
1592 ------------------------------------------------------------------ */
1593
1594/* This is the Intel register encoding. */
1595#define R_EAX 0
1596#define R_ECX 1
1597#define R_EDX 2
1598#define R_EBX 3
1599#define R_ESP 4
1600#define R_EBP 5
1601#define R_ESI 6
1602#define R_EDI 7
1603
1604#define R_AL (0+R_EAX)
1605#define R_CL (0+R_ECX)
1606#define R_DL (0+R_EDX)
1607#define R_BL (0+R_EBX)
1608#define R_AH (4+R_EAX)
1609#define R_CH (4+R_ECX)
1610#define R_DH (4+R_EDX)
1611#define R_BH (4+R_EBX)
1612
1613
1614/* ---------------------------------------------------------------------
1615 Offsets into baseBlock for everything which needs to referred to
1616 from generated code. The order of these decls does not imply
1617 what the order of the actual offsets is. The latter is important
1618 and is set up in vg_main.c.
1619 ------------------------------------------------------------------ */
1620
1621/* An array of words. In generated code, %ebp always points to the
1622 start of this array. Useful stuff, like the simulated CPU state,
1623 and the addresses of helper functions, can then be found by
1624 indexing off %ebp. The following declares variables which, at
1625 startup time, are given values denoting offsets into baseBlock.
1626 These offsets are in *words* from the start of baseBlock. */
1627
1628#define VG_BASEBLOCK_WORDS 200
1629
1630extern UInt VG_(baseBlock)[VG_BASEBLOCK_WORDS];
1631
1632
1633/* -----------------------------------------------------
1634 Read-write parts of baseBlock.
1635 -------------------------------------------------- */
1636
1637/* State of the simulated CPU. */
1638extern Int VGOFF_(m_eax);
1639extern Int VGOFF_(m_ecx);
1640extern Int VGOFF_(m_edx);
1641extern Int VGOFF_(m_ebx);
1642extern Int VGOFF_(m_esp);
1643extern Int VGOFF_(m_ebp);
1644extern Int VGOFF_(m_esi);
1645extern Int VGOFF_(m_edi);
1646extern Int VGOFF_(m_eflags);
1647extern Int VGOFF_(m_fpustate);
1648extern Int VGOFF_(m_eip);
1649
1650/* Reg-alloc spill area (VG_MAX_SPILLSLOTS words long). */
1651extern Int VGOFF_(spillslots);
1652
1653/* Records the valid bits for the 8 integer regs & flags reg. */
1654extern Int VGOFF_(sh_eax);
1655extern Int VGOFF_(sh_ecx);
1656extern Int VGOFF_(sh_edx);
1657extern Int VGOFF_(sh_ebx);
1658extern Int VGOFF_(sh_esp);
1659extern Int VGOFF_(sh_ebp);
1660extern Int VGOFF_(sh_esi);
1661extern Int VGOFF_(sh_edi);
1662extern Int VGOFF_(sh_eflags);
1663
1664
1665/* -----------------------------------------------------
1666 Read-only parts of baseBlock.
1667 -------------------------------------------------- */
1668
1669/* Offsets of addresses of helper functions. A "helper" function is
1670 one which is called from generated code. */
1671
1672extern Int VGOFF_(helper_idiv_64_32);
1673extern Int VGOFF_(helper_div_64_32);
1674extern Int VGOFF_(helper_idiv_32_16);
1675extern Int VGOFF_(helper_div_32_16);
1676extern Int VGOFF_(helper_idiv_16_8);
1677extern Int VGOFF_(helper_div_16_8);
1678
1679extern Int VGOFF_(helper_imul_32_64);
1680extern Int VGOFF_(helper_mul_32_64);
1681extern Int VGOFF_(helper_imul_16_32);
1682extern Int VGOFF_(helper_mul_16_32);
1683extern Int VGOFF_(helper_imul_8_16);
1684extern Int VGOFF_(helper_mul_8_16);
1685
1686extern Int VGOFF_(helper_CLD);
1687extern Int VGOFF_(helper_STD);
1688extern Int VGOFF_(helper_get_dirflag);
1689
1690extern Int VGOFF_(helper_shldl);
1691extern Int VGOFF_(helper_shldw);
1692extern Int VGOFF_(helper_shrdl);
1693extern Int VGOFF_(helper_shrdw);
1694
1695extern Int VGOFF_(helper_RDTSC);
1696extern Int VGOFF_(helper_CPUID);
1697
sewardjde4a1d02002-03-22 01:27:54 +00001698extern Int VGOFF_(helper_bsf);
1699extern Int VGOFF_(helper_bsr);
1700
1701extern Int VGOFF_(helper_fstsw_AX);
1702extern Int VGOFF_(helper_SAHF);
sewardj4d0ab1f2002-03-24 10:00:09 +00001703extern Int VGOFF_(helper_DAS);
sewardjfe8a1662002-03-24 11:54:07 +00001704extern Int VGOFF_(helper_DAA);
sewardjde4a1d02002-03-22 01:27:54 +00001705
1706extern Int VGOFF_(helper_value_check4_fail);
1707extern Int VGOFF_(helper_value_check2_fail);
1708extern Int VGOFF_(helper_value_check1_fail);
1709extern Int VGOFF_(helper_value_check0_fail);
1710
sewardjde4a1d02002-03-22 01:27:54 +00001711extern Int VGOFF_(helperc_STOREV4); /* :: UInt -> Addr -> void */
1712extern Int VGOFF_(helperc_STOREV2); /* :: UInt -> Addr -> void */
1713extern Int VGOFF_(helperc_STOREV1); /* :: UInt -> Addr -> void */
1714
1715extern Int VGOFF_(helperc_LOADV4); /* :: Addr -> UInt -> void */
1716extern Int VGOFF_(helperc_LOADV2); /* :: Addr -> UInt -> void */
1717extern Int VGOFF_(helperc_LOADV1); /* :: Addr -> UInt -> void */
1718
1719extern Int VGOFF_(handle_esp_assignment); /* :: Addr -> void */
1720extern Int VGOFF_(fpu_write_check); /* :: Addr -> Int -> void */
1721extern Int VGOFF_(fpu_read_check); /* :: Addr -> Int -> void */
1722
sewardjde4a1d02002-03-22 01:27:54 +00001723
1724
1725#endif /* ndef __VG_INCLUDE_H */
1726
sewardj3b2736a2002-03-24 12:18:35 +00001727
1728/* ---------------------------------------------------------------------
1729 Finally - autoconf-generated settings
1730 ------------------------------------------------------------------ */
1731
1732#include "config.h"
1733
sewardjde4a1d02002-03-22 01:27:54 +00001734/*--------------------------------------------------------------------*/
1735/*--- end vg_include.h ---*/
1736/*--------------------------------------------------------------------*/