blob: 6ec1e7a9cf02e61d648ca89745c2bd659d4a0476 [file] [log] [blame]
sewardj5cf515f2004-06-26 20:10:35 +00001
2/*---------------------------------------------------------------*/
3/*--- ---*/
sewardj35421a32004-07-05 13:12:34 +00004/*--- This file (vex_util.h) is ---*/
sewardjdbcfae72005-08-02 11:14:04 +00005/*--- Copyright (C) OpenWorks LLP. All rights reserved. ---*/
sewardj5cf515f2004-06-26 20:10:35 +00006/*--- ---*/
7/*---------------------------------------------------------------*/
8
sewardjf8ed9d82004-11-12 17:40:23 +00009/*
10 This file is part of LibVEX, a library for dynamic binary
11 instrumentation and translation.
12
sewardj7bd6ffe2005-08-03 16:07:36 +000013 Copyright (C) 2004-2005 OpenWorks LLP. All rights reserved.
sewardjf8ed9d82004-11-12 17:40:23 +000014
sewardj7bd6ffe2005-08-03 16:07:36 +000015 This library is made available under a dual licensing scheme.
sewardjf8ed9d82004-11-12 17:40:23 +000016
sewardj7bd6ffe2005-08-03 16:07:36 +000017 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.
sewardjf8ed9d82004-11-12 17:40:23 +000040
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.
sewardjf8ed9d82004-11-12 17:40:23 +000045*/
46
sewardj35421a32004-07-05 13:12:34 +000047#ifndef __VEX_UTIL_H
48#define __VEX_UTIL_H
sewardj5cf515f2004-06-26 20:10:35 +000049
sewardj887a11a2004-07-05 17:26:47 +000050#include "libvex_basictypes.h"
sewardj5cf515f2004-06-26 20:10:35 +000051
52
sewardj35421a32004-07-05 13:12:34 +000053/* Misc. */
54
55#define NULL ((void*)0)
56
57
sewardj5cf515f2004-06-26 20:10:35 +000058/* Stuff for panicking and assertion. */
59
60#define VG__STRING(__str) #__str
61
sewardj35421a32004-07-05 13:12:34 +000062#define vassert(expr) \
sewardj5cf515f2004-06-26 20:10:35 +000063 ((void) ((expr) ? 0 : \
64 (vex_assert_fail (VG__STRING(expr), \
65 __FILE__, __LINE__, \
66 __PRETTY_FUNCTION__), 0)))
67
68__attribute__ ((__noreturn__))
sewardj58277842005-02-07 03:11:17 +000069extern void vex_assert_fail ( const HChar* expr, const HChar* file,
70 Int line, const HChar* fn );
sewardj5cf515f2004-06-26 20:10:35 +000071__attribute__ ((__noreturn__))
sewardj8c332e22005-01-28 01:36:56 +000072extern void vpanic ( HChar* str );
sewardj5cf515f2004-06-26 20:10:35 +000073
74
sewardj35421a32004-07-05 13:12:34 +000075/* Printing */
76
77__attribute__ ((format (printf, 1, 2)))
sewardjda46fdd2005-08-25 21:20:18 +000078extern UInt vex_printf ( HChar *format, ... );
sewardj35421a32004-07-05 13:12:34 +000079
sewardj41f43bc2004-07-08 14:23:22 +000080__attribute__ ((format (printf, 2, 3)))
sewardjda46fdd2005-08-25 21:20:18 +000081extern UInt vex_sprintf ( HChar* buf, HChar *format, ... );
sewardj35421a32004-07-05 13:12:34 +000082
sewardj36ca5132004-07-24 13:12:23 +000083
84/* String ops */
85
sewardj58277842005-02-07 03:11:17 +000086extern Bool vex_streq ( const HChar* s1, const HChar* s2 );
sewardj36ca5132004-07-24 13:12:23 +000087
88
sewardjd887b862005-01-17 18:34:34 +000089/* 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
95typedef
96 enum {
97 VexAllocModeTEMP,
98 VexAllocModePERM
99 }
100 VexAllocMode;
101
102extern void vexSetAllocMode ( VexAllocMode );
103extern VexAllocMode vexGetAllocMode ( void );
sewardj2d6b14a2005-11-23 04:25:07 +0000104extern void vexAllocSanityCheck ( void );
sewardjd887b862005-01-17 18:34:34 +0000105
sewardj2d6b14a2005-11-23 04:25:07 +0000106extern void vexSetAllocModeTEMP_and_clear ( void );
sewardjd887b862005-01-17 18:34:34 +0000107
sewardj35421a32004-07-05 13:12:34 +0000108#endif /* ndef __VEX_UTIL_H */
sewardjac9af022004-07-05 01:15:34 +0000109
110/*---------------------------------------------------------------*/
sewardj35421a32004-07-05 13:12:34 +0000111/*--- vex_util.h ---*/
sewardjac9af022004-07-05 01:15:34 +0000112/*---------------------------------------------------------------*/