1
2/*---------------------------------------------------------------*/
3/*--- begin                                       main_util.h ---*/
4/*---------------------------------------------------------------*/
5
6/*
7   This file is part of Valgrind, a dynamic binary instrumentation
8   framework.
9
10   Copyright (C) 2004-2011 OpenWorks LLP
11      info@open-works.net
12
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.
17
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
26   02110-1301, USA.
27
28   The GNU General Public License is contained in the file COPYING.
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.
34*/
35
36#ifndef __VEX_MAIN_UTIL_H
37#define __VEX_MAIN_UTIL_H
38
39#include "libvex_basictypes.h"
40
41
42/* Misc. */
43
44#define NULL ((void*)0)
45
46#define LIKELY(x)       __builtin_expect(!!(x), 1)
47#define UNLIKELY(x)     __builtin_expect(!!(x), 0)
48
49/* Stuff for panicking and assertion. */
50
51#define VG__STRING(__str)  #__str
52
53#define vassert(expr)                                           \
54  ((void) (LIKELY(expr) ? 0 :                                   \
55           (vex_assert_fail (VG__STRING(expr),                  \
56                             __FILE__, __LINE__,                \
57                             __PRETTY_FUNCTION__), 0)))
58
59__attribute__ ((__noreturn__))
60extern void vex_assert_fail ( const HChar* expr, const HChar* file,
61                              Int line, const HChar* fn );
62__attribute__ ((__noreturn__))
63extern void vpanic ( HChar* str );
64
65
66/* Printing */
67
68__attribute__ ((format (printf, 1, 2)))
69extern UInt vex_printf ( HChar *format, ... );
70
71__attribute__ ((format (printf, 2, 3)))
72extern UInt vex_sprintf ( HChar* buf, HChar *format, ... );
73
74
75/* String ops */
76
77extern Bool vex_streq ( const HChar* s1, const HChar* s2 );
78extern Int vex_strlen ( const HChar* str );
79
80
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
87typedef
88   enum {
89      VexAllocModeTEMP,
90      VexAllocModePERM
91   }
92   VexAllocMode;
93
94extern void         vexSetAllocMode ( VexAllocMode );
95extern VexAllocMode vexGetAllocMode ( void );
96extern void         vexAllocSanityCheck ( void );
97
98extern void vexSetAllocModeTEMP_and_clear ( void );
99
100#endif /* ndef __VEX_MAIN_UTIL_H */
101
102/*---------------------------------------------------------------*/
103/*---                                             main_util.h ---*/
104/*---------------------------------------------------------------*/
105