nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 3 | /*--- Header included by every tool C file. pub_tool_basics.h ---*/ |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
njn | b9c427c | 2004-12-01 14:14:42 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 9 | |
njn | 5361242 | 2005-03-12 16:22:54 +0000 | [diff] [blame] | 10 | Copyright (C) 2000-2005 Julian Seward |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 11 | 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 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 31 | #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 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 55 | // Kernel types. Might as well have them here, they're used so broadly |
| 56 | // (eg. in pub_core_threadstate.h). |
| 57 | #if defined(VGO_linux) |
| 58 | # include "vki-linux.h" |
| 59 | #else |
| 60 | # error Unknown OS |
| 61 | #endif |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 62 | |
| 63 | /* --------------------------------------------------------------------- |
njn | d01fef7 | 2005-03-25 23:35:48 +0000 | [diff] [blame] | 64 | builtin types |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 65 | ------------------------------------------------------------------ */ |
| 66 | |
| 67 | // By choosing the right types, we can get these right for 32-bit and 64-bit |
| 68 | // platforms without having to do any conditional compilation or anything. |
nethercote | 8b5f40c | 2004-11-02 13:29:50 +0000 | [diff] [blame] | 69 | // |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 70 | // Size in bits on: 32-bit archs 64-bit archs |
| 71 | // ------------ ------------ |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 72 | typedef unsigned long UWord; // 32 64 |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 73 | |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 74 | typedef signed long Word; // 32 64 |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 75 | |
| 76 | typedef UWord Addr; // 32 64 |
sewardj | fa8ec11 | 2005-01-19 11:55:34 +0000 | [diff] [blame] | 77 | typedef UWord AddrH; // 32 64 |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 78 | |
nethercote | 7ac7f7b | 2004-11-02 12:36:02 +0000 | [diff] [blame] | 79 | typedef UWord SizeT; // 32 64 |
| 80 | typedef Word SSizeT; // 32 64 |
| 81 | |
nethercote | ada0d2b | 2004-11-04 19:10:43 +0000 | [diff] [blame] | 82 | typedef Word OffT; // 32 64 |
nethercote | 5b9fafd | 2004-11-04 18:39:22 +0000 | [diff] [blame] | 83 | |
sewardj | 274461d | 2005-10-02 17:01:41 +0000 | [diff] [blame] | 84 | typedef ULong Off64T; // 64 64 |
| 85 | |
njn | 21edee3 | 2005-06-11 04:44:38 +0000 | [diff] [blame] | 86 | #if !defined(NULL) |
| 87 | # define NULL ((void*)0) |
| 88 | #endif |
sewardj | bc7df20 | 2005-05-02 10:25:34 +0000 | [diff] [blame] | 89 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 90 | /* --------------------------------------------------------------------- |
| 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. */ |
| 98 | typedef UInt ThreadId; |
| 99 | |
| 100 | /* An abstraction of syscall return values. |
| 101 | When .isError == False, val holds the return value. |
| 102 | When .isError == True, val holds the error code. |
| 103 | */ |
| 104 | typedef struct { |
| 105 | UWord val; |
| 106 | Bool isError; |
| 107 | } |
| 108 | SysRes; |
| 109 | |
| 110 | /* --------------------------------------------------------------------- |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 111 | Miscellaneous (word size, endianness, regparmness, stringification) |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 112 | ------------------------------------------------------------------ */ |
| 113 | |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 114 | /* Word size: this is going to be either 4 or 8. */ |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 115 | // It should probably be in m_machine. |
| 116 | #define VG_WORDSIZE VEX_HOST_WORDSIZE |
| 117 | |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 118 | /* Endianness */ |
| 119 | #undef VG_BIGENDIAN |
| 120 | #undef VG_LITTLEENDIAN |
| 121 | |
| 122 | #if defined(VGA_x86) || defined(VGA_amd64) |
| 123 | # define VG_LITTLEENDIAN 1 |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 124 | #elif defined(VGA_ppc32) || defined(VGA_ppc64) |
sewardj | 6e340c7 | 2005-07-10 00:53:42 +0000 | [diff] [blame] | 125 | # define VG_BIGENDIAN 1 |
| 126 | #endif |
| 127 | |
| 128 | /* Regparmness */ |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 129 | #if defined(VGA_x86) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 130 | # define VG_REGPARM(n) __attribute__((regparm(n))) |
sewardj | 2c48c7b | 2005-11-29 13:05:56 +0000 | [diff] [blame] | 131 | #elif defined(VGA_amd64) || defined(VGA_ppc32) || defined(VGA_ppc64) |
njn | af839f5 | 2005-06-23 03:27:57 +0000 | [diff] [blame] | 132 | # define VG_REGPARM(n) /* */ |
njn | f536bbb | 2005-06-13 04:21:38 +0000 | [diff] [blame] | 133 | #else |
| 134 | # error Unknown arch |
| 135 | #endif |
| 136 | |
sewardj | 45f4e7c | 2005-09-27 19:20:21 +0000 | [diff] [blame] | 137 | /* Macro games */ |
| 138 | #define VG_STRINGIFZ(__str) #__str |
| 139 | #define VG_STRINGIFY(__str) VG_STRINGIFZ(__str) |
| 140 | |
njn | c7561b9 | 2005-06-19 01:24:32 +0000 | [diff] [blame] | 141 | #endif /* __PUB_TOOL_BASICS_H */ |
nethercote | ebf1d86 | 2004-11-01 18:22:05 +0000 | [diff] [blame] | 142 | |
| 143 | /*--------------------------------------------------------------------*/ |
| 144 | /*--- end ---*/ |
| 145 | /*--------------------------------------------------------------------*/ |