Bug 439685 compiler warning in callgrind/main.c
[valgrind.git] / coregrind / m_debuginfo / priv_misc.h
blobca430d3d07954938a052547fc20b585022c4bb5c
2 /*--------------------------------------------------------------------*/
3 /*--- Misc simple stuff lacking a better home. priv_misc.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2008-2017 OpenWorks LLP
11 info@open-works.co.uk
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
28 Neither the names of the U.S. Department of Energy nor the
29 University of California nor the names of its contributors may be
30 used to endorse or promote products derived from this software
31 without prior written permission.
34 #ifndef __PRIV_MISC_H
35 #define __PRIV_MISC_H
37 #include "pub_core_basics.h" // SizeT
39 /* Allocate(zeroed), free, strdup, memdup, shrink, all in VG_AR_DINFO.
40 The allocation functions never return NULL. */
41 void* ML_(dinfo_zalloc)( const HChar* cc, SizeT szB );
42 void ML_(dinfo_free)( void* v );
43 HChar* ML_(dinfo_strdup)( const HChar* cc, const HChar* str );
44 void* ML_(dinfo_memdup)( const HChar* cc, const void* str, SizeT nStr );
45 void* ML_(dinfo_realloc) ( const HChar* cc, void* ptr, SizeT new_size );
46 void ML_(dinfo_shrink_block)( void* ptr, SizeT szB );
48 /* Define functions to read/write types of various sizes from/to a
49 (potentially unaligned) UChar *data buffer.
50 Some archs can do efficient unaligned access. For these archs,
51 do the load/store directly. For others, call the UAS (Un Aligned Safe)
52 functions. */
53 #if defined(VGA_x86) || defined(VGA_amd64)
55 #define DEF_READ(type) \
56 static inline type VGAPPEND(vgModuleLocal_read_,type) ( const UChar* data ) \
57 { \
58 return (*(const type*)(data)); \
59 } \
60 type VGAPPEND(vgModuleLocal_readUAS_,type) ( const UChar* data )
62 #define DEF_WRITE(type) \
63 static inline UChar* VGAPPEND(vgModuleLocal_write_,type) ( UChar* ptr, type val ) \
64 { \
65 (*(type*)(ptr)) = val; \
66 return ptr + sizeof(type); \
67 } \
68 UChar* VGAPPEND(vgModuleLocal_writeUAS_,type) ( UChar* ptr, type val )
70 #else
72 #define DEF_READ(type) \
73 type VGAPPEND(vgModuleLocal_readUAS_,type) ( const UChar* data ); \
74 static inline type VGAPPEND(vgModuleLocal_read_,type) ( const UChar* data ) \
75 { \
76 return VGAPPEND(vgModuleLocal_readUAS_,type)(data); \
79 #define DEF_WRITE(type) \
80 UChar* VGAPPEND(vgModuleLocal_writeUAS_,type) ( UChar* ptr, type val ); \
81 static inline UChar* VGAPPEND(vgModuleLocal_write_,type) ( UChar* ptr, type val ) \
82 { \
83 return VGAPPEND(vgModuleLocal_writeUAS_,type)(ptr,val); \
86 #endif
88 /* Defines a bunch of functions such as
89 Short ML_(read_Short)( const UChar* data );
90 Int ML_(read_Int)( const UChar* data );
91 ... */
92 DEF_READ(Short);
93 DEF_READ(Int);
94 DEF_READ(Long);
95 DEF_READ(UShort);
96 DEF_READ(UWord);
97 DEF_READ(UInt);
98 DEF_READ(ULong);
99 DEF_READ(Addr);
101 /* Defines a bunch of functions such as
102 UChar* ML_(write_UShort)( UChar* ptr, UShort val );
103 UChar* ML_(write_UInt)( UChar* ptr, UInt val );
104 ... */
105 DEF_WRITE(UShort);
106 DEF_WRITE(UInt);
107 DEF_WRITE(ULong);
108 DEF_WRITE(Addr);
110 static inline UChar ML_(read_UChar)( const UChar* data )
112 return data[0];
114 static inline UChar* ML_(write_UChar)( UChar* ptr, UChar val )
116 ptr[0] = val;
117 return ptr + sizeof(UChar);
120 /* A handy type, a la Haskell's Maybe type. Yes, I know, C sucks.
121 Been there. Done that. Seen the movie. Got the T-shirt. Etc. */
122 typedef struct { ULong ul; Bool b; } MaybeULong;
125 #endif /* ndef __PRIV_MISC_H */
127 /*--------------------------------------------------------------------*/
128 /*--- end priv_misc.h ---*/
129 /*--------------------------------------------------------------------*/