sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 4 | /*--- This file (vex_util.h) is ---*/ |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 5 | /*--- Copyright (c) 2004 OpenWorks LLP. All rights reserved. ---*/ |
| 6 | /*--- ---*/ |
| 7 | /*---------------------------------------------------------------*/ |
| 8 | |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 9 | /* |
| 10 | This file is part of LibVEX, a library for dynamic binary |
| 11 | instrumentation and translation. |
| 12 | |
| 13 | Copyright (C) 2004 OpenWorks, LLP. |
| 14 | |
| 15 | This program is free software; you can redistribute it and/or modify |
| 16 | it under the terms of the GNU General Public License as published by |
| 17 | the Free Software Foundation; Version 2 dated June 1991 of the |
| 18 | license. |
| 19 | |
| 20 | This program is distributed in the hope that it will be useful, |
| 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or liability |
| 23 | for damages. See the GNU General Public License for more details. |
| 24 | |
| 25 | Neither the names of the U.S. Department of Energy nor the |
| 26 | University of California nor the names of its contributors may be |
| 27 | used to endorse or promote products derived from this software |
| 28 | without prior written permission. |
| 29 | |
| 30 | You should have received a copy of the GNU General Public License |
| 31 | along with this program; if not, write to the Free Software |
| 32 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 33 | USA. |
| 34 | */ |
| 35 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 36 | #ifndef __VEX_UTIL_H |
| 37 | #define __VEX_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 | |
| 46 | |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 47 | /* Stuff for panicking and assertion. */ |
| 48 | |
| 49 | #define VG__STRING(__str) #__str |
| 50 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 51 | #define vassert(expr) \ |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 52 | ((void) ((expr) ? 0 : \ |
| 53 | (vex_assert_fail (VG__STRING(expr), \ |
| 54 | __FILE__, __LINE__, \ |
| 55 | __PRETTY_FUNCTION__), 0))) |
| 56 | |
| 57 | __attribute__ ((__noreturn__)) |
sewardj | 5827784 | 2005-02-07 03:11:17 +0000 | [diff] [blame^] | 58 | extern void vex_assert_fail ( const HChar* expr, const HChar* file, |
| 59 | Int line, const HChar* fn ); |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 60 | __attribute__ ((__noreturn__)) |
sewardj | 8c332e2 | 2005-01-28 01:36:56 +0000 | [diff] [blame] | 61 | extern void vpanic ( HChar* str ); |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 62 | |
| 63 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 64 | /* Printing */ |
| 65 | |
| 66 | __attribute__ ((format (printf, 1, 2))) |
sewardj | 810dcf0 | 2004-11-22 12:55:45 +0000 | [diff] [blame] | 67 | extern UInt vex_printf ( const HChar *format, ... ); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 68 | |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 69 | __attribute__ ((format (printf, 2, 3))) |
sewardj | 8c332e2 | 2005-01-28 01:36:56 +0000 | [diff] [blame] | 70 | extern UInt vex_sprintf ( HChar* buf, const HChar *format, ... ); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 71 | |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 72 | |
| 73 | /* String ops */ |
| 74 | |
sewardj | 5827784 | 2005-02-07 03:11:17 +0000 | [diff] [blame^] | 75 | extern Bool vex_streq ( const HChar* s1, const HChar* s2 ); |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 76 | |
| 77 | |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 78 | /* Storage management: clear the area, and allocate from it. */ |
| 79 | |
| 80 | /* By default allocation occurs in the temporary area. However, it is |
| 81 | possible to switch to permanent area allocation if that's what you |
| 82 | want. Permanent area allocation is very limited, tho. */ |
| 83 | |
| 84 | typedef |
| 85 | enum { |
| 86 | VexAllocModeTEMP, |
| 87 | VexAllocModePERM |
| 88 | } |
| 89 | VexAllocMode; |
| 90 | |
| 91 | extern void vexSetAllocMode ( VexAllocMode ); |
| 92 | extern VexAllocMode vexGetAllocMode ( void ); |
| 93 | |
| 94 | extern void vexClearTEMP ( void ); |
| 95 | |
| 96 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 97 | #endif /* ndef __VEX_UTIL_H */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 98 | |
| 99 | /*---------------------------------------------------------------*/ |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 100 | /*--- vex_util.h ---*/ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 101 | /*---------------------------------------------------------------*/ |