1b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 2b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--------------------------------------------------------------------*/ 3b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- Misc simple stuff lacking a better home. priv_misc.h ---*/ 4b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--------------------------------------------------------------------*/ 5b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 6b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/* 7b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj This file is part of Valgrind, a dynamic binary instrumentation 8b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj framework. 9b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 100f157ddb404bcde7815a1c5bf2d7e41c114f3d73sewardj Copyright (C) 2008-2013 OpenWorks LLP 11b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj info@open-works.co.uk 12b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 13b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj This program is free software; you can redistribute it and/or 14b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj modify it under the terms of the GNU General Public License as 15b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj published by the Free Software Foundation; either version 2 of the 16b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj License, or (at your option) any later version. 17b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 18b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj This program is distributed in the hope that it will be useful, but 19b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj WITHOUT ANY WARRANTY; without even the implied warranty of 20b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 21b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj General Public License for more details. 22b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 23b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj You should have received a copy of the GNU General Public License 24b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj along with this program; if not, write to the Free Software 25b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 26b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 02111-1307, USA. 27b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 28b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj The GNU General Public License is contained in the file COPYING. 29b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 30b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj Neither the names of the U.S. Department of Energy nor the 31b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj University of California nor the names of its contributors may be 32b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj used to endorse or promote products derived from this software 33b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj without prior written permission. 34b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj*/ 35b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 36b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#ifndef __PRIV_MISC_H 37b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#define __PRIV_MISC_H 38b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 39535fb1b49a80f2e880f755ee618381de3e222ddfflorian#include "pub_core_basics.h" // SizeT 40b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 41bf0ea23aef2a2a1c5aac02ada367ca6f983cbcb7florian/* Allocate(zeroed), free, strdup, memdup, shrink, all in VG_AR_DINFO. 42bf0ea23aef2a2a1c5aac02ada367ca6f983cbcb7florian The allocation functions never return NULL. */ 4354fe2021b87b9e5edb8ec8070f47b86d5cafb8aaflorianvoid* ML_(dinfo_zalloc)( const HChar* cc, SizeT szB ); 44b8b79addf04dd5d0b558916e26df0b1927cbd758sewardjvoid ML_(dinfo_free)( void* v ); 451636d33c13958b9c0e7d3059cdd5005746418eb2florianHChar* ML_(dinfo_strdup)( const HChar* cc, const HChar* str ); 46518850bf0da07ed3e2244e307268ae0fd80e93a8florianvoid* ML_(dinfo_memdup)( const HChar* cc, const void* str, SizeT nStr ); 4746cc04521acf2827eb33310fadc119bf2dc039e4florianvoid* ML_(dinfo_realloc) ( const HChar* cc, void* ptr, SizeT new_size ); 480b9d0646949bd382758763664d3bf2d6115993aephilippevoid ML_(dinfo_shrink_block)( void* ptr, SizeT szB ); 499c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj 50c474069560175a011af75868e0cbe66a6646f8a1philippe/* Define functions to read/write types of various sizes from/to a 51c474069560175a011af75868e0cbe66a6646f8a1philippe (potentially unaligned) UChar *data buffer. 52c474069560175a011af75868e0cbe66a6646f8a1philippe Some archs can do efficient unaligned access. For these archs, 53c474069560175a011af75868e0cbe66a6646f8a1philippe do the load/store directly. For others, call the UAS (Un Aligned Safe) 54c474069560175a011af75868e0cbe66a6646f8a1philippe functions. */ 55c474069560175a011af75868e0cbe66a6646f8a1philippe#if defined(VGA_x86) || defined(VGA_amd64) 56c474069560175a011af75868e0cbe66a6646f8a1philippe 57c474069560175a011af75868e0cbe66a6646f8a1philippe#define DEF_READ(type) \ 58c474069560175a011af75868e0cbe66a6646f8a1philippestatic inline type VGAPPEND(vgModuleLocal_read_,type) ( const UChar* data ) \ 59c474069560175a011af75868e0cbe66a6646f8a1philippe{ \ 60c474069560175a011af75868e0cbe66a6646f8a1philippe return (*(const type*)(data)); \ 61c474069560175a011af75868e0cbe66a6646f8a1philippe} \ 62c474069560175a011af75868e0cbe66a6646f8a1philippetype VGAPPEND(vgModuleLocal_readUAS_,type) ( const UChar* data ) 63c474069560175a011af75868e0cbe66a6646f8a1philippe 64c474069560175a011af75868e0cbe66a6646f8a1philippe#define DEF_WRITE(type) \ 65c474069560175a011af75868e0cbe66a6646f8a1philippestatic inline UChar* VGAPPEND(vgModuleLocal_write_,type) ( UChar* ptr, type val ) \ 66c474069560175a011af75868e0cbe66a6646f8a1philippe{ \ 67c474069560175a011af75868e0cbe66a6646f8a1philippe (*(type*)(ptr)) = val; \ 68c474069560175a011af75868e0cbe66a6646f8a1philippe return ptr + sizeof(type); \ 69c474069560175a011af75868e0cbe66a6646f8a1philippe} \ 70c474069560175a011af75868e0cbe66a6646f8a1philippeUChar* VGAPPEND(vgModuleLocal_writeUAS_,type) ( UChar* ptr, type val ) 71c474069560175a011af75868e0cbe66a6646f8a1philippe 72c474069560175a011af75868e0cbe66a6646f8a1philippe#else 73c474069560175a011af75868e0cbe66a6646f8a1philippe 74c474069560175a011af75868e0cbe66a6646f8a1philippe#define DEF_READ(type) \ 75c474069560175a011af75868e0cbe66a6646f8a1philippetype VGAPPEND(vgModuleLocal_readUAS_,type) ( const UChar* data ); \ 76c474069560175a011af75868e0cbe66a6646f8a1philippestatic inline type VGAPPEND(vgModuleLocal_read_,type) ( const UChar* data ) \ 77c474069560175a011af75868e0cbe66a6646f8a1philippe{ \ 78c474069560175a011af75868e0cbe66a6646f8a1philippe return VGAPPEND(vgModuleLocal_readUAS_,type)(data); \ 79c474069560175a011af75868e0cbe66a6646f8a1philippe} 80c474069560175a011af75868e0cbe66a6646f8a1philippe 81c474069560175a011af75868e0cbe66a6646f8a1philippe#define DEF_WRITE(type) \ 82c474069560175a011af75868e0cbe66a6646f8a1philippeUChar* VGAPPEND(vgModuleLocal_writeUAS_,type) ( UChar* ptr, type val ); \ 83c474069560175a011af75868e0cbe66a6646f8a1philippestatic inline UChar* VGAPPEND(vgModuleLocal_write_,type) ( UChar* ptr, type val ) \ 84c474069560175a011af75868e0cbe66a6646f8a1philippe{ \ 85c474069560175a011af75868e0cbe66a6646f8a1philippe return VGAPPEND(vgModuleLocal_writeUAS_,type)(ptr,val); \ 86c474069560175a011af75868e0cbe66a6646f8a1philippe} 87c474069560175a011af75868e0cbe66a6646f8a1philippe 88c474069560175a011af75868e0cbe66a6646f8a1philippe#endif 89c474069560175a011af75868e0cbe66a6646f8a1philippe 90c474069560175a011af75868e0cbe66a6646f8a1philippe/* Defines a bunch of functions such as 91c474069560175a011af75868e0cbe66a6646f8a1philippe Short ML_(read_Short)( const UChar* data ); 92c474069560175a011af75868e0cbe66a6646f8a1philippe Int ML_(read_Int)( const UChar* data ); 93c474069560175a011af75868e0cbe66a6646f8a1philippe ... */ 94c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_READ(Short); 95c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_READ(Int); 96c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_READ(Long); 97c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_READ(UShort); 98c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_READ(UWord); 99c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_READ(UInt); 100c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_READ(ULong); 101c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_READ(Addr); 102c474069560175a011af75868e0cbe66a6646f8a1philippe 103c474069560175a011af75868e0cbe66a6646f8a1philippe/* Defines a bunch of functions such as 104c474069560175a011af75868e0cbe66a6646f8a1philippe UChar* ML_(write_UShort)( UChar* ptr, UShort val ); 105c474069560175a011af75868e0cbe66a6646f8a1philippe UChar* ML_(write_UInt)( UChar* ptr, UInt val ); 106c474069560175a011af75868e0cbe66a6646f8a1philippe ... */ 107c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_WRITE(UShort); 108c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_WRITE(UInt); 109c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_WRITE(ULong); 110c474069560175a011af75868e0cbe66a6646f8a1philippeDEF_WRITE(Addr); 111c474069560175a011af75868e0cbe66a6646f8a1philippe 112c474069560175a011af75868e0cbe66a6646f8a1philippestatic inline UChar ML_(read_UChar)( const UChar* data ) 113c474069560175a011af75868e0cbe66a6646f8a1philippe{ 114c474069560175a011af75868e0cbe66a6646f8a1philippe return data[0]; 115c474069560175a011af75868e0cbe66a6646f8a1philippe} 116c474069560175a011af75868e0cbe66a6646f8a1philippestatic inline UChar* ML_(write_UChar)( UChar* ptr, UChar val ) 117c474069560175a011af75868e0cbe66a6646f8a1philippe{ 118c474069560175a011af75868e0cbe66a6646f8a1philippe ptr[0] = val; 119c474069560175a011af75868e0cbe66a6646f8a1philippe return ptr + sizeof(UChar); 120c474069560175a011af75868e0cbe66a6646f8a1philippe} 12186781fabbfc019b752f9605e487cfce77b2a592atom 1229c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj/* A handy type, a la Haskell's Maybe type. Yes, I know, C sucks. 1239c606bd8634cd6b67bb41fa645b5c639668cfa2dsewardj Been there. Done that. Seen the movie. Got the T-shirt. Etc. */ 12450fde23467d92281b32dd537d0d9a590263628c3sewardjtypedef struct { ULong ul; Bool b; } MaybeULong; 125b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 126b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 127b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj#endif /* ndef __PRIV_MISC_H */ 128b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj 129b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--------------------------------------------------------------------*/ 130b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--- end priv_misc.h ---*/ 131b8b79addf04dd5d0b558916e26df0b1927cbd758sewardj/*--------------------------------------------------------------------*/ 132