blob: 85f13a420db2dc312808f3dfb4131d7368c64cb3 [file] [log] [blame]
sewardj5cf515f2004-06-26 20:10:35 +00001
2/*---------------------------------------------------------------*/
sewardj752f9062010-05-03 21:38:49 +00003/*--- begin main_util.h ---*/
sewardj5cf515f2004-06-26 20:10:35 +00004/*---------------------------------------------------------------*/
5
sewardjf8ed9d82004-11-12 17:40:23 +00006/*
sewardj752f9062010-05-03 21:38:49 +00007 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
sewardjf8ed9d82004-11-12 17:40:23 +00009
sewardj89ae8472013-10-18 14:12:58 +000010 Copyright (C) 2004-2013 OpenWorks LLP
sewardj752f9062010-05-03 21:38:49 +000011 info@open-works.net
sewardjf8ed9d82004-11-12 17:40:23 +000012
sewardj752f9062010-05-03 21:38:49 +000013 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.
sewardjf8ed9d82004-11-12 17:40:23 +000017
sewardj752f9062010-05-03 21:38:49 +000018 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
sewardj7bd6ffe2005-08-03 16:07:36 +000026 02110-1301, USA.
27
sewardj752f9062010-05-03 21:38:49 +000028 The GNU General Public License is contained in the file COPYING.
sewardjf8ed9d82004-11-12 17:40:23 +000029
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.
sewardjf8ed9d82004-11-12 17:40:23 +000034*/
35
sewardjcef7d3e2009-07-02 12:21:59 +000036#ifndef __VEX_MAIN_UTIL_H
37#define __VEX_MAIN_UTIL_H
sewardj5cf515f2004-06-26 20:10:35 +000038
sewardj887a11a2004-07-05 17:26:47 +000039#include "libvex_basictypes.h"
sewardj5cf515f2004-06-26 20:10:35 +000040
41
sewardj35421a32004-07-05 13:12:34 +000042/* Misc. */
43
44#define NULL ((void*)0)
45
sewardj7ee97522011-05-09 21:45:04 +000046#define LIKELY(x) __builtin_expect(!!(x), 1)
47#define UNLIKELY(x) __builtin_expect(!!(x), 0)
sewardj35421a32004-07-05 13:12:34 +000048
sewardj5cf515f2004-06-26 20:10:35 +000049/* Stuff for panicking and assertion. */
50
51#define VG__STRING(__str) #__str
52
sewardj35421a32004-07-05 13:12:34 +000053#define vassert(expr) \
sewardj7ee97522011-05-09 21:45:04 +000054 ((void) (LIKELY(expr) ? 0 : \
sewardj5cf515f2004-06-26 20:10:35 +000055 (vex_assert_fail (VG__STRING(expr), \
56 __FILE__, __LINE__, \
57 __PRETTY_FUNCTION__), 0)))
58
59__attribute__ ((__noreturn__))
sewardj58277842005-02-07 03:11:17 +000060extern void vex_assert_fail ( const HChar* expr, const HChar* file,
61 Int line, const HChar* fn );
sewardj5cf515f2004-06-26 20:10:35 +000062__attribute__ ((__noreturn__))
florian76714fd2012-09-13 20:21:42 +000063extern void vpanic ( const HChar* str );
sewardj5cf515f2004-06-26 20:10:35 +000064
florianeebdb2b2014-12-10 16:08:09 +000065__attribute__ ((__noreturn__)) __attribute__ ((format (printf, 1, 2)))
66extern void vfatal ( const HChar* format, ... );
67
sewardj5cf515f2004-06-26 20:10:35 +000068
sewardj35421a32004-07-05 13:12:34 +000069/* Printing */
70
71__attribute__ ((format (printf, 1, 2)))
florian76714fd2012-09-13 20:21:42 +000072extern UInt vex_printf ( const HChar *format, ... );
sewardj35421a32004-07-05 13:12:34 +000073
sewardj41f43bc2004-07-08 14:23:22 +000074__attribute__ ((format (printf, 2, 3)))
florian76714fd2012-09-13 20:21:42 +000075extern UInt vex_sprintf ( HChar* buf, const HChar *format, ... );
sewardj35421a32004-07-05 13:12:34 +000076
sewardj36ca5132004-07-24 13:12:23 +000077
78/* String ops */
79
sewardj58277842005-02-07 03:11:17 +000080extern Bool vex_streq ( const HChar* s1, const HChar* s2 );
sewardjc9069f22012-06-01 16:09:50 +000081extern Int vex_strlen ( const HChar* str );
82extern void vex_bzero ( void* s, UInt n );
sewardj36ca5132004-07-24 13:12:23 +000083
84
sewardjd887b862005-01-17 18:34:34 +000085/* Storage management: clear the area, and allocate from it. */
86
87/* By default allocation occurs in the temporary area. However, it is
88 possible to switch to permanent area allocation if that's what you
89 want. Permanent area allocation is very limited, tho. */
90
91typedef
92 enum {
93 VexAllocModeTEMP,
94 VexAllocModePERM
95 }
96 VexAllocMode;
97
98extern void vexSetAllocMode ( VexAllocMode );
99extern VexAllocMode vexGetAllocMode ( void );
sewardj2d6b14a2005-11-23 04:25:07 +0000100extern void vexAllocSanityCheck ( void );
sewardjd887b862005-01-17 18:34:34 +0000101
sewardj2d6b14a2005-11-23 04:25:07 +0000102extern void vexSetAllocModeTEMP_and_clear ( void );
sewardjd887b862005-01-17 18:34:34 +0000103
sewardjcef7d3e2009-07-02 12:21:59 +0000104#endif /* ndef __VEX_MAIN_UTIL_H */
sewardjac9af022004-07-05 01:15:34 +0000105
106/*---------------------------------------------------------------*/
sewardjcef7d3e2009-07-02 12:21:59 +0000107/*--- main_util.h ---*/
sewardjac9af022004-07-05 01:15:34 +0000108/*---------------------------------------------------------------*/