sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 1 | |
| 2 | /*---------------------------------------------------------------*/ |
| 3 | /*--- ---*/ |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame^] | 4 | /*--- This file (main_util.h) is ---*/ |
sewardj | dbcfae7 | 2005-08-02 11:14:04 +0000 | [diff] [blame] | 5 | /*--- Copyright (C) OpenWorks LLP. All rights reserved. ---*/ |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 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 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame^] | 13 | Copyright (C) 2004-2009 OpenWorks LLP. All rights reserved. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 14 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 15 | This library is made available under a dual licensing scheme. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 16 | |
sewardj | 7bd6ffe | 2005-08-03 16:07:36 +0000 | [diff] [blame] | 17 | If you link LibVEX against other code all of which is itself |
| 18 | licensed under the GNU General Public License, version 2 dated June |
| 19 | 1991 ("GPL v2"), then you may use LibVEX under the terms of the GPL |
| 20 | v2, as appearing in the file LICENSE.GPL. If the file LICENSE.GPL |
| 21 | is missing, you can obtain a copy of the GPL v2 from the Free |
| 22 | Software Foundation Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 23 | 02110-1301, USA. |
| 24 | |
| 25 | For any other uses of LibVEX, you must first obtain a commercial |
| 26 | license from OpenWorks LLP. Please contact info@open-works.co.uk |
| 27 | for information about commercial licensing. |
| 28 | |
| 29 | This software is provided by OpenWorks LLP "as is" and any express |
| 30 | or implied warranties, including, but not limited to, the implied |
| 31 | warranties of merchantability and fitness for a particular purpose |
| 32 | are disclaimed. In no event shall OpenWorks LLP be liable for any |
| 33 | direct, indirect, incidental, special, exemplary, or consequential |
| 34 | damages (including, but not limited to, procurement of substitute |
| 35 | goods or services; loss of use, data, or profits; or business |
| 36 | interruption) however caused and on any theory of liability, |
| 37 | whether in contract, strict liability, or tort (including |
| 38 | negligence or otherwise) arising in any way out of the use of this |
| 39 | software, even if advised of the possibility of such damage. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 40 | |
| 41 | Neither the names of the U.S. Department of Energy nor the |
| 42 | University of California nor the names of its contributors may be |
| 43 | used to endorse or promote products derived from this software |
| 44 | without prior written permission. |
sewardj | f8ed9d8 | 2004-11-12 17:40:23 +0000 | [diff] [blame] | 45 | */ |
| 46 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame^] | 47 | #ifndef __VEX_MAIN_UTIL_H |
| 48 | #define __VEX_MAIN_UTIL_H |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 49 | |
sewardj | 887a11a | 2004-07-05 17:26:47 +0000 | [diff] [blame] | 50 | #include "libvex_basictypes.h" |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 51 | |
| 52 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 53 | /* Misc. */ |
| 54 | |
| 55 | #define NULL ((void*)0) |
| 56 | |
| 57 | |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 58 | /* Stuff for panicking and assertion. */ |
| 59 | |
| 60 | #define VG__STRING(__str) #__str |
| 61 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 62 | #define vassert(expr) \ |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 63 | ((void) ((expr) ? 0 : \ |
| 64 | (vex_assert_fail (VG__STRING(expr), \ |
| 65 | __FILE__, __LINE__, \ |
| 66 | __PRETTY_FUNCTION__), 0))) |
| 67 | |
| 68 | __attribute__ ((__noreturn__)) |
sewardj | 5827784 | 2005-02-07 03:11:17 +0000 | [diff] [blame] | 69 | extern void vex_assert_fail ( const HChar* expr, const HChar* file, |
| 70 | Int line, const HChar* fn ); |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 71 | __attribute__ ((__noreturn__)) |
sewardj | 8c332e2 | 2005-01-28 01:36:56 +0000 | [diff] [blame] | 72 | extern void vpanic ( HChar* str ); |
sewardj | 5cf515f | 2004-06-26 20:10:35 +0000 | [diff] [blame] | 73 | |
| 74 | |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 75 | /* Printing */ |
| 76 | |
| 77 | __attribute__ ((format (printf, 1, 2))) |
sewardj | da46fdd | 2005-08-25 21:20:18 +0000 | [diff] [blame] | 78 | extern UInt vex_printf ( HChar *format, ... ); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 79 | |
sewardj | 41f43bc | 2004-07-08 14:23:22 +0000 | [diff] [blame] | 80 | __attribute__ ((format (printf, 2, 3))) |
sewardj | da46fdd | 2005-08-25 21:20:18 +0000 | [diff] [blame] | 81 | extern UInt vex_sprintf ( HChar* buf, HChar *format, ... ); |
sewardj | 35421a3 | 2004-07-05 13:12:34 +0000 | [diff] [blame] | 82 | |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 83 | |
| 84 | /* String ops */ |
| 85 | |
sewardj | 5827784 | 2005-02-07 03:11:17 +0000 | [diff] [blame] | 86 | extern Bool vex_streq ( const HChar* s1, const HChar* s2 ); |
sewardj | 36ca513 | 2004-07-24 13:12:23 +0000 | [diff] [blame] | 87 | |
| 88 | |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 89 | /* Storage management: clear the area, and allocate from it. */ |
| 90 | |
| 91 | /* By default allocation occurs in the temporary area. However, it is |
| 92 | possible to switch to permanent area allocation if that's what you |
| 93 | want. Permanent area allocation is very limited, tho. */ |
| 94 | |
| 95 | typedef |
| 96 | enum { |
| 97 | VexAllocModeTEMP, |
| 98 | VexAllocModePERM |
| 99 | } |
| 100 | VexAllocMode; |
| 101 | |
| 102 | extern void vexSetAllocMode ( VexAllocMode ); |
| 103 | extern VexAllocMode vexGetAllocMode ( void ); |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 104 | extern void vexAllocSanityCheck ( void ); |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 105 | |
sewardj | 2d6b14a | 2005-11-23 04:25:07 +0000 | [diff] [blame] | 106 | extern void vexSetAllocModeTEMP_and_clear ( void ); |
sewardj | d887b86 | 2005-01-17 18:34:34 +0000 | [diff] [blame] | 107 | |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame^] | 108 | #endif /* ndef __VEX_MAIN_UTIL_H */ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 109 | |
| 110 | /*---------------------------------------------------------------*/ |
sewardj | cef7d3e | 2009-07-02 12:21:59 +0000 | [diff] [blame^] | 111 | /*--- main_util.h ---*/ |
sewardj | ac9af02 | 2004-07-05 01:15:34 +0000 | [diff] [blame] | 112 | /*---------------------------------------------------------------*/ |