From: Julian Seward Date: Mon, 7 Feb 2005 00:00:50 +0000 (+0000) Subject: Define ULong_to_Ptr / Ptr_to_ULong to help clean up 64/32 bit issues. X-Git-Tag: svn/VALGRIND_3_0_1^2~481 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=04149a3b0bc3040463b0da0ab16f3a9a9db34fa2;p=thirdparty%2Fvalgrind.git Define ULong_to_Ptr / Ptr_to_ULong to help clean up 64/32 bit issues. git-svn-id: svn://svn.valgrind.org/vex/trunk@853 --- diff --git a/VEX/priv/main/vex_main.c b/VEX/priv/main/vex_main.c index 36d93a6933..78b4fd1090 100644 --- a/VEX/priv/main/vex_main.c +++ b/VEX/priv/main/vex_main.c @@ -150,6 +150,9 @@ void LibVEX_Init ( vassert(sizeof(void*) == sizeof(int*)); vassert(sizeof(void*) == sizeof(HWord)); + vassert(VEX_HOST_WORDSIZE == sizeof(void*)); + vassert(VEX_HOST_WORDSIZE == sizeof(HWord)); + /* Really start up .. */ vex_debuglevel = debuglevel; vex_valgrind_support = valgrind_support; diff --git a/VEX/pub/libvex_basictypes.h b/VEX/pub/libvex_basictypes.h index 858c0c3199..54587399d0 100644 --- a/VEX/pub/libvex_basictypes.h +++ b/VEX/pub/libvex_basictypes.h @@ -94,8 +94,48 @@ typedef unsigned long HWord; #define offsetof(type,memb) ((Int)&((type*)0)->memb) -#endif /* ndef __LIBVEX_BASICTYPES_H */ +/* We need to know the host word size in order to write Ptr_to_ULong + and ULong_to_Ptr in a way that doesn't cause compilers to complain. + These functions allow us to case pointers to and from 64-bit + integers without complaints from compilers, regardless of the host + word size. */ + +#undef VEX_HOST_WORDSIZE + +#if defined(__amd64__) +# define VEX_HOST_WORDSIZE 8 +#elif defined(__i386__) +# define VEX_HOST_WORDSIZE 4 +#elif defined (__powerpc__) + /* need to distinguish ppc32 from ppc64 */ +# define VEX_HOST_WORDSIZE 4 +#else +# error "Vex: Fatal: Can't establish the host architecture" +#endif + + +#if VEX_HOST_WORDSIZE == 8 + static inline ULong Ptr_to_ULong ( void* p ) { + return (ULong)p; + } + static inline void* ULong_to_Ptr ( ULong n ) { + return (void*)n; + } +#elif VEX_HOST_WORDSIZE == 4 + static inline ULong Ptr_to_ULong ( void* p ) { + UInt w = (UInt)p; + return (ULong)w; + } + static inline void* ULong_to_Ptr ( ULong n ) { + UInt w = (UInt)n; + return (void*)w; + } +#else +# error "Vex: Fatal: Can't define Ptr_to_ULong / ULong_to_Ptr" +#endif + +#endif /* ndef __LIBVEX_BASICTYPES_H */ /*---------------------------------------------------------------*/ /*--- libvex_basictypes.h ---*/