blob: 3292f00b9382ccbc43cf12a0cf66dad4cb61b95c [file] [log] [blame]
nethercoteebf1d862004-11-01 18:22:05 +00001
2/*--------------------------------------------------------------------*/
njnc7561b92005-06-19 01:24:32 +00003/*--- Header included by every tool C file. pub_tool_basics.h ---*/
nethercoteebf1d862004-11-01 18:22:05 +00004/*--------------------------------------------------------------------*/
5
6/*
njnb9c427c2004-12-01 14:14:42 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
nethercoteebf1d862004-11-01 18:22:05 +00009
sewardj4d474d02008-02-11 11:34:59 +000010 Copyright (C) 2000-2008 Julian Seward
nethercoteebf1d862004-11-01 18:22:05 +000011 jseward@acm.org
12
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
26 02111-1307, USA.
27
28 The GNU General Public License is contained in the file COPYING.
29*/
30
njnc7561b92005-06-19 01:24:32 +000031#ifndef __PUB_TOOL_BASICS_H
32#define __PUB_TOOL_BASICS_H
33
34//--------------------------------------------------------------------
35// PURPOSE: This header should be imported by every single C file in
36// tools. It contains the basic types and other things needed everywhere.
37// There is no corresponding C file because this isn't a module
38// containing executable code, it's all just declarations.
39//--------------------------------------------------------------------
40
41/* ---------------------------------------------------------------------
42 Other headers to include
43 ------------------------------------------------------------------ */
44
45// VEX defines Char, UChar, Short, UShort, Int, UInt, Long, ULong,
46// Addr32, Addr64, HWord, HChar, Bool, False and True.
47#include "libvex_basictypes.h"
48
49// For the VG_() macro
50#include "pub_tool_basics_asm.h"
51
52// For varargs types
53#include <stdarg.h>
54
bart5dd8e6a2008-03-22 08:04:29 +000055/* For HAVE_BUILTIN_EXPECT */
56#include "config.h"
57
nethercoteebf1d862004-11-01 18:22:05 +000058
59/* ---------------------------------------------------------------------
njnd01fef72005-03-25 23:35:48 +000060 builtin types
nethercoteebf1d862004-11-01 18:22:05 +000061 ------------------------------------------------------------------ */
62
63// By choosing the right types, we can get these right for 32-bit and 64-bit
64// platforms without having to do any conditional compilation or anything.
nethercote8b5f40c2004-11-02 13:29:50 +000065//
nethercoteebf1d862004-11-01 18:22:05 +000066// Size in bits on: 32-bit archs 64-bit archs
67// ------------ ------------
nethercoteebf1d862004-11-01 18:22:05 +000068typedef unsigned long UWord; // 32 64
nethercoteebf1d862004-11-01 18:22:05 +000069
nethercoteebf1d862004-11-01 18:22:05 +000070typedef signed long Word; // 32 64
nethercoteebf1d862004-11-01 18:22:05 +000071
72typedef UWord Addr; // 32 64
sewardjfa8ec112005-01-19 11:55:34 +000073typedef UWord AddrH; // 32 64
nethercoteebf1d862004-11-01 18:22:05 +000074
nethercote7ac7f7b2004-11-02 12:36:02 +000075typedef UWord SizeT; // 32 64
76typedef Word SSizeT; // 32 64
77
nethercoteada0d2b2004-11-04 19:10:43 +000078typedef Word OffT; // 32 64
nethercote5b9fafd2004-11-04 18:39:22 +000079
sewardj274461d2005-10-02 17:01:41 +000080typedef ULong Off64T; // 64 64
81
njn21edee32005-06-11 04:44:38 +000082#if !defined(NULL)
83# define NULL ((void*)0)
84#endif
sewardjbc7df202005-05-02 10:25:34 +000085
sewardj9c606bd2008-09-18 18:12:50 +000086/* This is just too useful to not have around the place somewhere. */
87typedef struct { UWord uw1; UWord uw2; } UWordPair;
88
sewardje1f33a42006-10-17 01:38:48 +000089
njnc7561b92005-06-19 01:24:32 +000090/* ---------------------------------------------------------------------
91 non-builtin types
92 ------------------------------------------------------------------ */
93
94// These probably shouldn't be here, but moving them to their logical
95// modules results in a lot more #includes...
96
97/* ThreadIds are simply indices into the VG_(threads)[] array. */
98typedef UInt ThreadId;
99
100/* An abstraction of syscall return values.
sewardje1f33a42006-10-17 01:38:48 +0000101 Linux:
102 When .isError == False,
103 res holds the return value, and err is zero.
104 When .isError == True,
105 err holds the error code, and res is zero.
106
107 AIX:
108 res is the POSIX result of the syscall.
109 err is the corresponding errno value.
110 isError === err==0
111
112 Unlike on Linux, it is possible for 'err' to be nonzero (thus an
113 error has occurred), nevertheless 'res' is also nonzero. AIX
114 userspace does not appear to consistently inspect 'err' to
115 determine whether or not an error has occurred. For example,
116 sys_open() will return -1 for 'val' if a file cannot be opened,
117 as well as the relevant errno value in 'err', but AIX userspace
118 then consults 'val' to figure out if the syscall failed, rather
119 than looking at 'err'. Hence we need to represent them both.
njnc7561b92005-06-19 01:24:32 +0000120*/
sewardje1f33a42006-10-17 01:38:48 +0000121typedef
122 struct {
123 UWord res;
124 UWord err;
125 Bool isError;
126 }
127 SysRes;
128
njnc7561b92005-06-19 01:24:32 +0000129
130/* ---------------------------------------------------------------------
sewardj45f4e7c2005-09-27 19:20:21 +0000131 Miscellaneous (word size, endianness, regparmness, stringification)
njnc7561b92005-06-19 01:24:32 +0000132 ------------------------------------------------------------------ */
133
sewardj6e340c72005-07-10 00:53:42 +0000134/* Word size: this is going to be either 4 or 8. */
njnc7561b92005-06-19 01:24:32 +0000135// It should probably be in m_machine.
136#define VG_WORDSIZE VEX_HOST_WORDSIZE
137
sewardj6e340c72005-07-10 00:53:42 +0000138/* Endianness */
139#undef VG_BIGENDIAN
140#undef VG_LITTLEENDIAN
141
142#if defined(VGA_x86) || defined(VGA_amd64)
143# define VG_LITTLEENDIAN 1
sewardj2c48c7b2005-11-29 13:05:56 +0000144#elif defined(VGA_ppc32) || defined(VGA_ppc64)
sewardj6e340c72005-07-10 00:53:42 +0000145# define VG_BIGENDIAN 1
146#endif
147
148/* Regparmness */
njnf536bbb2005-06-13 04:21:38 +0000149#if defined(VGA_x86)
njnaf839f52005-06-23 03:27:57 +0000150# define VG_REGPARM(n) __attribute__((regparm(n)))
sewardj2c48c7b2005-11-29 13:05:56 +0000151#elif defined(VGA_amd64) || defined(VGA_ppc32) || defined(VGA_ppc64)
njnaf839f52005-06-23 03:27:57 +0000152# define VG_REGPARM(n) /* */
njnf536bbb2005-06-13 04:21:38 +0000153#else
154# error Unknown arch
155#endif
156
sewardj45f4e7c2005-09-27 19:20:21 +0000157/* Macro games */
158#define VG_STRINGIFZ(__str) #__str
159#define VG_STRINGIFY(__str) VG_STRINGIFZ(__str)
160
njn64ea7f82006-10-14 23:26:21 +0000161// Where to send bug reports to.
162#define VG_BUGS_TO "www.valgrind.org"
163
bart5dd8e6a2008-03-22 08:04:29 +0000164/* Branch prediction hints. */
165#if HAVE_BUILTIN_EXPECT
166# define LIKELY(x) __builtin_expect(!!(x), 1)
167# define UNLIKELY(x) __builtin_expect((x), 0)
168#else
169# define LIKELY(x) (x)
170# define UNLIKELY(x) (x)
171#endif
172
173
njnc7561b92005-06-19 01:24:32 +0000174#endif /* __PUB_TOOL_BASICS_H */
nethercoteebf1d862004-11-01 18:22:05 +0000175
176/*--------------------------------------------------------------------*/
177/*--- end ---*/
178/*--------------------------------------------------------------------*/