main_util.h revision 436e89c602e787e7a27dd6624b09beed41a0da8a
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-2013 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 ( const HChar* str );
64
65
66/* Printing */
67
68__attribute__ ((format (printf, 1, 2)))
69extern UInt vex_printf ( const HChar *format, ... );
70
71__attribute__ ((format (printf, 2, 3)))
72extern UInt vex_sprintf ( HChar* buf, const 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 );
79extern void vex_bzero ( void* s, UInt n );
80
81
82/* Storage management: clear the area, and allocate from it. */
83
84/* By default allocation occurs in the temporary area.  However, it is
85   possible to switch to permanent area allocation if that's what you
86   want.  Permanent area allocation is very limited, tho. */
87
88typedef
89   enum {
90      VexAllocModeTEMP,
91      VexAllocModePERM
92   }
93   VexAllocMode;
94
95extern void         vexSetAllocMode ( VexAllocMode );
96extern VexAllocMode vexGetAllocMode ( void );
97extern void         vexAllocSanityCheck ( void );
98
99extern void vexSetAllocModeTEMP_and_clear ( void );
100
101#endif /* ndef __VEX_MAIN_UTIL_H */
102
103/*---------------------------------------------------------------*/
104/*---                                             main_util.h ---*/
105/*---------------------------------------------------------------*/
106