sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 3 | /*--- begin main_util.h ---*/ |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 4 | /*---------------------------------------------------------------*/ |
| 5 | |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 6 | /* |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 9 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 10 | Copyright (C) 2004-2010 OpenWorks LLP |
| 11 | info@open-works.net |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 12 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 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. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 17 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 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., 51 Franklin Street, Fifth Floor, Boston, MA |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 26 | 02110-1301, USA. |
| 27 | |
sewardj | 752f906 | 2010-05-03 21:38:49 +0000 | [diff] [blame] | 28 | The GNU General Public License is contained in the file COPYING. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 29 | |
| 30 | Neither the names of the U.S. Department of Energy nor the |
| 31 | University of California nor the names of its contributors may be |
| 32 | used to endorse or promote products derived from this software |
| 33 | without prior written permission. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 34 | */ |
| 35 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 36 | #ifndef __VEX_MAIN_UTIL_H |
| 37 | #define __VEX_MAIN_UTIL_H |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 38 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 39 | #include "libvex_basictypes.h" |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 40 | |
| 41 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 42 | /* Misc. */ |
| 43 | |
| 44 | #define NULL ((void*)0) |
| 45 | |
sewardj | 7ee9752 | 2011-05-09 21:45:04 +0000 | [diff] [blame^] | 46 | #define LIKELY(x) __builtin_expect(!!(x), 1) |
| 47 | #define UNLIKELY(x) __builtin_expect(!!(x), 0) |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 48 | |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 49 | /* Stuff for panicking and assertion. */ |
| 50 | |
| 51 | #define VG__STRING(__str) #__str |
| 52 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 53 | #define vassert(expr) \ |
sewardj | 7ee9752 | 2011-05-09 21:45:04 +0000 | [diff] [blame^] | 54 | ((void) (LIKELY(expr) ? 0 : \ |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 55 | (vex_assert_fail (VG__STRING(expr), \ |
| 56 | __FILE__, __LINE__, \ |
| 57 | __PRETTY_FUNCTION__), 0))) |
| 58 | |
| 59 | __attribute__ ((__noreturn__)) |
sewardj | 5827784 | 2005-02-07 03:11:17 +0000 | [diff] [blame] | 60 | extern void vex_assert_fail ( const HChar* expr, const HChar* file, |
| 61 | Int line, const HChar* fn ); |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 62 | __attribute__ ((__noreturn__)) |
sewardj | 8c332e2 | 2005-01-28 01:36:56 +0000 | [diff] [blame] | 63 | extern void vpanic ( HChar* str ); |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 64 | |
| 65 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 66 | /* Printing */ |
| 67 | |
| 68 | __attribute__ ((format (printf, 1, 2))) |
sewardj | da46fdd | 2005-08-25 21:20:18 +0000 | [diff] [blame] | 69 | extern UInt vex_printf ( HChar *format, ... ); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 70 | |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 71 | __attribute__ ((format (printf, 2, 3))) |
sewardj | da46fdd | 2005-08-25 21:20:18 +0000 | [diff] [blame] | 72 | extern UInt vex_sprintf ( HChar* buf, HChar *format, ... ); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 73 | |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 74 | |
| 75 | /* String ops */ |
| 76 | |
sewardj | 5827784 | 2005-02-07 03:11:17 +0000 | [diff] [blame] | 77 | extern Bool vex_streq ( const HChar* s1, const HChar* s2 ); |
sewardj | d7bde72 | 2011-04-05 13:19:33 +0000 | [diff] [blame] | 78 | extern Int vex_strlen ( const HChar* str ); |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 79 | |
| 80 | |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 81 | /* Storage management: clear the area, and allocate from it. */ |
| 82 | |
| 83 | /* By default allocation occurs in the temporary area. However, it is |
| 84 | possible to switch to permanent area allocation if that's what you |
| 85 | want. Permanent area allocation is very limited, tho. */ |
| 86 | |
| 87 | typedef |
| 88 | enum { |
| 89 | VexAllocModeTEMP, |
| 90 | VexAllocModePERM |
| 91 | } |
| 92 | VexAllocMode; |
| 93 | |
| 94 | extern void vexSetAllocMode ( VexAllocMode ); |
| 95 | extern VexAllocMode vexGetAllocMode ( void ); |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 96 | extern void vexAllocSanityCheck ( void ); |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 97 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 98 | extern void vexSetAllocModeTEMP_and_clear ( void ); |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 99 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 100 | #endif /* ndef __VEX_MAIN_UTIL_H */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 101 | |
| 102 | /*---------------------------------------------------------------*/ |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame] | 103 | /*--- main_util.h ---*/ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 104 | /*---------------------------------------------------------------*/ |