From cc195924a66b5c79f7b8521b4dc26d41cbe33349 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Wed, 27 Dec 2000 04:18:26 +0000 Subject: [PATCH] Added check whether unaligned memory access is allowed. Added macros to access unaligned WORDs / DWORDs. --- configure | 181 +++++++++++++++++++++++++--------------- configure.in | 15 ++++ dlls/dplayx/dplay.c | 1 + dlls/user/exticon.c | 1 + dlls/version/resource.c | 2 + include/acconfig.h | 3 + include/config.h.in | 3 + include/windef.h | 27 ------ include/wine/port.h | 51 +++++++++++ loader/pe_resource.c | 2 + loader/task.c | 5 +- memory/environ.c | 3 +- memory/heap.c | 33 ++++++++ windows/class.c | 1 + windows/dialog.c | 1 + 15 files changed, 230 insertions(+), 99 deletions(-) diff --git a/configure b/configure index ecfda11be3b..711c27c4198 100755 --- a/configure +++ b/configure @@ -5343,24 +5343,67 @@ EOF fi +echo $ac_n "checking "whether unaligned memory access is allowed"""... $ac_c" 1>&6 +echo "configure:5348: checking "whether unaligned memory access is allowed"" >&5 +if eval "test \"`echo '$''{'wine_cv_allow_unaligned_access'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test "$cross_compiling" = yes; then + wine_cv_allow_unaligned_access=no +else + cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + wine_cv_allow_unaligned_access=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + wine_cv_allow_unaligned_access=no +fi +rm -fr conftest* +fi + +fi + +echo "$ac_t""$wine_cv_allow_unaligned_access" 1>&6 +if test "$wine_allow_unaligned_access" = "yes" +then + cat >> confdefs.h <<\EOF +#define ALLOW_UNALIGNED_ACCESS 1 +EOF + +fi + # The Ultrix 4.2 mips builtin alloca declared by alloca.h only works # for constant arguments. Useless! echo $ac_n "checking for working alloca.h""... $ac_c" 1>&6 -echo "configure:5352: checking for working alloca.h" >&5 +echo "configure:5395: checking for working alloca.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_alloca_h'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < int main() { void *p = alloca(2 * sizeof(int)); ; return 0; } EOF -if { (eval echo configure:5364: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:5407: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ac_cv_header_alloca_h=yes else @@ -5381,12 +5424,12 @@ EOF fi echo $ac_n "checking for alloca""... $ac_c" 1>&6 -echo "configure:5385: checking for alloca" >&5 +echo "configure:5428: checking for alloca" >&5 if eval "test \"`echo '$''{'ac_cv_func_alloca_works'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:5461: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ac_cv_func_alloca_works=yes else @@ -5446,12 +5489,12 @@ EOF echo $ac_n "checking whether alloca needs Cray hooks""... $ac_c" 1>&6 -echo "configure:5450: checking whether alloca needs Cray hooks" >&5 +echo "configure:5493: checking whether alloca needs Cray hooks" >&5 if eval "test \"`echo '$''{'ac_cv_os_cray'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&6 if test $ac_cv_os_cray = yes; then for ac_func in _getb67 GETB67 getb67; do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:5480: checking for $ac_func" >&5 +echo "configure:5523: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:5551: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -5531,7 +5574,7 @@ done fi echo $ac_n "checking stack direction for C alloca""... $ac_c" 1>&6 -echo "configure:5535: checking stack direction for C alloca" >&5 +echo "configure:5578: checking stack direction for C alloca" >&5 if eval "test \"`echo '$''{'ac_cv_c_stack_direction'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -5539,7 +5582,7 @@ else ac_cv_c_stack_direction=0 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:5605: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_c_stack_direction=1 else @@ -5615,12 +5658,12 @@ for ac_func in \ do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:5619: checking for $ac_func" >&5 +echo "configure:5662: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:5690: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -5724,17 +5767,17 @@ for ac_hdr in \ do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:5728: checking for $ac_hdr" >&5 +echo "configure:5771: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:5738: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:5781: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -5761,12 +5804,12 @@ fi done echo $ac_n "checking whether stat file-mode macros are broken""... $ac_c" 1>&6 -echo "configure:5765: checking whether stat file-mode macros are broken" >&5 +echo "configure:5808: checking whether stat file-mode macros are broken" >&5 if eval "test \"`echo '$''{'ac_cv_header_stat_broken'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -5819,12 +5862,12 @@ fi echo $ac_n "checking for working const""... $ac_c" 1>&6 -echo "configure:5823: checking for working const" >&5 +echo "configure:5866: checking for working const" >&5 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:5920: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_const=yes else @@ -5894,21 +5937,21 @@ EOF fi echo $ac_n "checking for inline""... $ac_c" 1>&6 -echo "configure:5898: checking for inline" >&5 +echo "configure:5941: checking for inline" >&5 if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_cv_c_inline=no for ac_kw in inline __inline__ __inline; do cat > conftest.$ac_ext <&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:5955: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_inline=$ac_kw; break else @@ -5934,12 +5977,12 @@ EOF esac echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:5938: checking for ANSI C header files" >&5 +echo "configure:5981: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -5947,7 +5990,7 @@ else #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:5951: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:5994: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -5964,7 +6007,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -5982,7 +6025,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -6003,7 +6046,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -6014,7 +6057,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:6018: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:6061: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else @@ -6038,12 +6081,12 @@ EOF fi echo $ac_n "checking for size_t""... $ac_c" 1>&6 -echo "configure:6042: checking for size_t" >&5 +echo "configure:6085: checking for size_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #if STDC_HEADERS @@ -6071,7 +6114,7 @@ EOF fi echo $ac_n "checking size of long long""... $ac_c" 1>&6 -echo "configure:6075: checking size of long long" >&5 +echo "configure:6118: checking size of long long" >&5 if eval "test \"`echo '$''{'ac_cv_sizeof_long_long'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -6079,7 +6122,7 @@ else ac_cv_sizeof_long_long=0 else cat > conftest.$ac_ext < main() @@ -6090,7 +6133,7 @@ main() exit(0); } EOF -if { (eval echo configure:6094: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:6137: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_sizeof_long_long=`cat conftestval` else @@ -6112,12 +6155,12 @@ EOF echo $ac_n "checking "whether we can use re-entrant gethostbyname_r Linux style"""... $ac_c" 1>&6 -echo "configure:6116: checking "whether we can use re-entrant gethostbyname_r Linux style"" >&5 +echo "configure:6159: checking "whether we can use re-entrant gethostbyname_r Linux style"" >&5 if eval "test \"`echo '$''{'wine_cv_linux_gethostbyname_r_6'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -6138,7 +6181,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:6142: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6185: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* wine_cv_linux_gethostbyname_r_6=yes else @@ -6164,12 +6207,12 @@ EOF if test "$ac_cv_header_linux_joystick_h" = "yes" then echo $ac_n "checking "whether linux/joystick.h uses the Linux 2.2+ API"""... $ac_c" 1>&6 -echo "configure:6168: checking "whether linux/joystick.h uses the Linux 2.2+ API"" >&5 +echo "configure:6211: checking "whether linux/joystick.h uses the Linux 2.2+ API"" >&5 if eval "test \"`echo '$''{'wine_cv_linux_joystick_22_api'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -6184,7 +6227,7 @@ int main() { /*empty*/ ; return 0; } EOF -if { (eval echo configure:6188: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6231: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* wine_cv_linux_joystick_22_api=yes else @@ -6211,12 +6254,12 @@ fi if test "$ac_cv_header_sys_vfs_h" = "yes" then echo $ac_n "checking "whether sys/vfs.h defines statfs"""... $ac_c" 1>&6 -echo "configure:6215: checking "whether sys/vfs.h defines statfs"" >&5 +echo "configure:6258: checking "whether sys/vfs.h defines statfs"" >&5 if eval "test \"`echo '$''{'wine_cv_sys_vfs_has_statfs'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -6233,7 +6276,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:6237: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6280: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* wine_cv_sys_vfs_has_statfs=yes else @@ -6260,12 +6303,12 @@ fi if test "$ac_cv_header_sys_statfs_h" = "yes" then echo $ac_n "checking "whether sys/statfs.h defines statfs"""... $ac_c" 1>&6 -echo "configure:6264: checking "whether sys/statfs.h defines statfs"" >&5 +echo "configure:6307: checking "whether sys/statfs.h defines statfs"" >&5 if eval "test \"`echo '$''{'wine_cv_sys_statfs_has_statfs'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -6280,7 +6323,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:6284: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6327: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* wine_cv_sys_statfs_has_statfs=yes else @@ -6307,12 +6350,12 @@ fi if test "$ac_cv_header_sys_mount_h" = "yes" then echo $ac_n "checking "whether sys/mount.h defines statfs"""... $ac_c" 1>&6 -echo "configure:6311: checking "whether sys/mount.h defines statfs"" >&5 +echo "configure:6354: checking "whether sys/mount.h defines statfs"" >&5 if eval "test \"`echo '$''{'wine_cv_sys_mount_has_statfs'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < @@ -6327,7 +6370,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:6331: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6374: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* wine_cv_sys_mount_has_statfs=yes else @@ -6353,7 +6396,7 @@ fi echo $ac_n "checking "for statfs.f_bfree"""... $ac_c" 1>&6 -echo "configure:6357: checking "for statfs.f_bfree"" >&5 +echo "configure:6400: checking "for statfs.f_bfree"" >&5 if eval "test \"`echo '$''{'wine_cv_statfs_bfree'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -6362,7 +6405,7 @@ else wine_cv_statfs_bfree=no else cat > conftest.$ac_ext < @@ -6389,7 +6432,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:6393: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6436: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* wine_cv_statfs_bfree=yes else @@ -6413,7 +6456,7 @@ EOF fi echo $ac_n "checking "for statfs.f_bavail"""... $ac_c" 1>&6 -echo "configure:6417: checking "for statfs.f_bavail"" >&5 +echo "configure:6460: checking "for statfs.f_bavail"" >&5 if eval "test \"`echo '$''{'wine_cv_statfs_bavail'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -6422,7 +6465,7 @@ else wine_cv_statfs_bavail=no else cat > conftest.$ac_ext < @@ -6449,7 +6492,7 @@ int main() { ; return 0; } EOF -if { (eval echo configure:6453: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6496: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* wine_cv_statfs_bavail=yes else @@ -6474,12 +6517,12 @@ fi echo $ac_n "checking "for msg_accrights in struct msghdr"""... $ac_c" 1>&6 -echo "configure:6478: checking "for msg_accrights in struct msghdr"" >&5 +echo "configure:6521: checking "for msg_accrights in struct msghdr"" >&5 if eval "test \"`echo '$''{'ac_cv_c_msg_accrights'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -6487,7 +6530,7 @@ int main() { struct msghdr hdr; hdr.msg_accrights=0 ; return 0; } EOF -if { (eval echo configure:6491: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6534: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_msg_accrights="yes" else @@ -6510,12 +6553,12 @@ fi echo $ac_n "checking "for sun_len in struct sockaddr_un"""... $ac_c" 1>&6 -echo "configure:6514: checking "for sun_len in struct sockaddr_un"" >&5 +echo "configure:6557: checking "for sun_len in struct sockaddr_un"" >&5 if eval "test \"`echo '$''{'ac_cv_c_sun_len'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -6524,7 +6567,7 @@ int main() { static struct sockaddr_un addr; addr.sun_len = 1 ; return 0; } EOF -if { (eval echo configure:6528: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:6571: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_c_sun_len="yes" else @@ -6547,12 +6590,12 @@ fi echo $ac_n "checking "whether we need to define __i386__"""... $ac_c" 1>&6 -echo "configure:6551: checking "whether we need to define __i386__"" >&5 +echo "configure:6594: checking "whether we need to define __i386__"" >&5 if eval "test \"`echo '$''{'ac_cv_cpp_def_i386'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < * */ +#include "wine/port.h" #include "windef.h" #include "winerror.h" #include "winbase.h" diff --git a/dlls/user/exticon.c b/dlls/user/exticon.c index 4089c2ab363..c0a419f1c82 100644 --- a/dlls/user/exticon.c +++ b/dlls/user/exticon.c @@ -9,6 +9,7 @@ #include /* abs() */ #include #include +#include "config.h" #include "winbase.h" #include "windef.h" #include "winerror.h" diff --git a/dlls/version/resource.c b/dlls/version/resource.c index cdd9a1e3cf3..d8a25b436af 100644 --- a/dlls/version/resource.c +++ b/dlls/version/resource.c @@ -11,6 +11,8 @@ #include #include +#include "config.h" + #include "winbase.h" #include "wine/winbase16.h" #include "winnls.h" diff --git a/include/acconfig.h b/include/acconfig.h index d1c7581ffe0..b150a19e904 100644 --- a/include/acconfig.h +++ b/include/acconfig.h @@ -6,6 +6,9 @@ /* Define if bitfields are bigendian */ #undef BITFIELDS_BIGENDIAN +/* Define if unaligned memory access is allowed */ +#undef ALLOW_UNALIGNED_ACCESS + /* Define if .type asm directive must be inside a .def directive */ #undef NEED_TYPE_IN_DEF diff --git a/include/config.h.in b/include/config.h.in index 4226b9c025f..4a37aeb7233 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -50,6 +50,9 @@ /* Define if bitfields are bigendian */ #undef BITFIELDS_BIGENDIAN +/* Define if unaligned memory access is allowed */ +#undef ALLOW_UNALIGNED_ACCESS + /* Define if .type asm directive must be inside a .def directive */ #undef NEED_TYPE_IN_DEF diff --git a/include/windef.h b/include/windef.h index ab98867c76d..1ef09b270bf 100644 --- a/include/windef.h +++ b/include/windef.h @@ -166,33 +166,6 @@ typedef LRESULT CALLBACK (*WNDPROC)(HWND,UINT,WPARAM,LPARAM); #define ADD_LOWORD(dw,val) ((dw) = ((dw) & 0xffff0000) | LOWORD((DWORD)(dw)+(val))) #endif -/* Macros to access unaligned or wrong-endian WORDs and DWORDs. */ -/* Note: These macros are semantically broken, at least for wrc. wrc - spits out data in the platform's current binary format, *not* in - little-endian format. These macros are used throughout the resource - code to load and store data to the resources. Since it is unlikely - that we'll ever be dealing with little-endian resource data, the - byte-swapping nature of these macros has been disabled. Rather than - remove the use of these macros from the resource loading code, the - macros have simply been disabled. In the future, someone may want - to reactivate these macros for other purposes. In that case, the - resource code will have to be modified to use different macros. */ - -#if 1 -#define PUT_WORD(ptr,w) (*(WORD *)(ptr) = (w)) -#define GET_WORD(ptr) (*(WORD *)(ptr)) -#define PUT_DWORD(ptr,dw) (*(DWORD *)(ptr) = (dw)) -#define GET_DWORD(ptr) (*(DWORD *)(ptr)) -#else -#define PUT_WORD(ptr,w) (*(BYTE *)(ptr) = LOBYTE(w), \ - *((BYTE *)(ptr) + 1) = HIBYTE(w)) -#define GET_WORD(ptr) ((WORD)(*(BYTE *)(ptr) | \ - (WORD)(*((BYTE *)(ptr)+1) << 8))) -#define PUT_DWORD(ptr,dw) (PUT_WORD((ptr),LOWORD(dw)), \ - PUT_WORD((WORD *)(ptr)+1,HIWORD(dw))) -#define GET_DWORD(ptr) ((DWORD)(GET_WORD(ptr) | \ - ((DWORD)GET_WORD((WORD *)(ptr)+1) << 16))) -#endif /* 1 */ /* min and max macros */ #define __max(a,b) (((a) > (b)) ? (a) : (b)) diff --git a/include/wine/port.h b/include/wine/port.h index 4465e16ad81..421a9d56bbc 100644 --- a/include/wine/port.h +++ b/include/wine/port.h @@ -142,4 +142,55 @@ extern int wine_dlclose( void *handle, char *error, int errorsize ); #define RTLD_GLOBAL 0x100 #endif + +/* Macros to access unaligned or wrong-endian WORDs and DWORDs. */ + +#define PUT_WORD(ptr, w) (*(WORD *)(ptr) = (w)) +#define GET_WORD(ptr) (*(WORD *)(ptr)) +#define PUT_DWORD(ptr, d) (*(DWORD *)(ptr) = (d)) +#define GET_DWORD(ptr) (*(DWORD *)(ptr)) + +#define PUT_LE_WORD(ptr, w) \ + do { ((BYTE *)(ptr))[0] = LOBYTE(w); \ + ((BYTE *)(ptr))[1] = HIBYTE(w); } while (0) +#define GET_LE_WORD(ptr) \ + MAKEWORD( ((BYTE *)(ptr))[0], \ + ((BYTE *)(ptr))[1] ) +#define PUT_LE_DWORD(ptr, d) \ + do { PUT_LE_WORD(&((WORD *)(ptr))[0], LOWORD(d)); \ + PUT_LE_WORD(&((WORD *)(ptr))[1], HIBYTE(d)); } while (0) +#define GET_LE_DWORD(ptr) \ + ((DWORD)MAKELONG( GET_LE_WORD(&((WORD *)(ptr))[0]), \ + GET_LE_WORD(&((WORD *)(ptr))[1]) )) + +#define PUT_BE_WORD(ptr, w) \ + do { ((BYTE *)(ptr))[1] = LOBYTE(w); \ + ((BYTE *)(ptr))[0] = HIBYTE(w); } while (0) +#define GET_BE_WORD(ptr) \ + MAKEWORD( ((BYTE *)(ptr))[1], \ + ((BYTE *)(ptr))[0] ) +#define PUT_BE_DWORD(ptr, d) \ + do { PUT_BE_WORD(&((WORD *)(ptr))[1], LOWORD(d)); \ + PUT_BE_WORD(&((WORD *)(ptr))[0], HIBYTE(d)); } while (0) +#define GET_BE_DWORD(ptr) \ + ((DWORD)MAKELONG( GET_BE_WORD(&((WORD *)(ptr))[1]), \ + GET_BE_WORD(&((WORD *)(ptr))[0]) )) + +#if defined(ALLOW_UNALIGNED_ACCESS) +#define PUT_UA_WORD(ptr, w) PUT_WORD(ptr, w) +#define GET_UA_WORD(ptr) GET_WORD(ptr) +#define PUT_UA_DWORD(ptr, d) PUT_DWORD(ptr, d) +#define GET_UA_DWORD(ptr) GET_DWORD(ptr) +#elif defined(WORDS_BIGENDIAN) +#define PUT_UA_WORD(ptr, w) PUT_BE_WORD(ptr, w) +#define GET_UA_WORD(ptr) GET_BE_WORD(ptr) +#define PUT_UA_DWORD(ptr, d) PUT_BE_DWORD(ptr, d) +#define GET_UA_DWORD(ptr) GET_BE_DWORD(ptr) +#else +#define PUT_UA_WORD(ptr, w) PUT_LE_WORD(ptr, w) +#define GET_UA_WORD(ptr) GET_LE_WORD(ptr) +#define PUT_UA_DWORD(ptr, d) PUT_LE_DWORD(ptr, d) +#define GET_UA_DWORD(ptr) GET_LE_DWORD(ptr) +#endif + #endif /* !defined(__WINE_WINE_PORT_H) */ diff --git a/loader/pe_resource.c b/loader/pe_resource.c index 65493815542..41aefdd6639 100644 --- a/loader/pe_resource.c +++ b/loader/pe_resource.c @@ -13,6 +13,8 @@ #include #include +#include "config.h" + #include "wine/unicode.h" #include "windef.h" #include "winnls.h" diff --git a/loader/task.c b/loader/task.c index f38f2b2969b..14e140709e0 100644 --- a/loader/task.c +++ b/loader/task.c @@ -9,6 +9,7 @@ #include #include +#include "wine/port.h" #include "wine/winbase16.h" #include "ntddk.h" #include "callback.h" @@ -272,8 +273,8 @@ BOOL TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, TEB *teb, LPCSTR cmdline, pTask->pdb.int20 = 0x20cd; pTask->pdb.dispatcher[0] = 0x9a; /* ljmp */ - PUT_DWORD(&pTask->pdb.dispatcher[1], (DWORD)GetProcAddress16( GetModuleHandle16("KERNEL"), - "DOS3Call" )); + PUT_UA_DWORD(&pTask->pdb.dispatcher[1], + (DWORD)GetProcAddress16( GetModuleHandle16("KERNEL"), "DOS3Call" )); pTask->pdb.savedint22 = INT_GetPMHandler( 0x22 ); pTask->pdb.savedint23 = INT_GetPMHandler( 0x23 ); pTask->pdb.savedint24 = INT_GetPMHandler( 0x24 ); diff --git a/memory/environ.c b/memory/environ.c index 66301378414..e7bf71cc7ce 100644 --- a/memory/environ.c +++ b/memory/environ.c @@ -6,6 +6,7 @@ #include #include +#include "wine/port.h" #include "windef.h" #include "winnls.h" #include "winerror.h" @@ -59,7 +60,7 @@ static const char ENV_program_name[] = "C:\\WINDOWS\\SYSTEM\\KRNL386.EXE"; /* Fill the extra bytes with the program name and stuff */ #define FILL_EXTRA_ENV(p) \ *(p) = '\0'; \ - PUT_WORD( (p) + 1, 1 ); \ + PUT_UA_WORD( (p) + 1, 1 ); \ strcpy( (p) + 3, ENV_program_name ); STARTUPINFOA current_startupinfo = diff --git a/memory/heap.c b/memory/heap.c index 0437a0c9e59..c73d52a99e6 100644 --- a/memory/heap.c +++ b/memory/heap.c @@ -9,6 +9,7 @@ #include #include #include +#include "config.h" #include "wine/winbase16.h" #include "wine/unicode.h" #include "selectors.h" @@ -682,6 +683,16 @@ static BOOL HEAP_ValidateFreeArena( SUBHEAP *subheap, ARENA_FREE *pArena ) { char *heapEnd = (char *)subheap + subheap->size; +#if !defined(ALLOW_UNALIGNED_ACCESS) + /* Check for unaligned pointers */ + if ( (long)pArena % sizeof(void *) != 0 ) + { + ERR( "Heap %08lx: unaligned arena pointer %08lx\n", + (DWORD)subheap->heap, (DWORD)pArena ); + return FALSE; + } +#endif + /* Check magic number */ if (pArena->magic != ARENA_FREE_MAGIC) { @@ -766,6 +777,28 @@ static BOOL HEAP_ValidateInUseArena( SUBHEAP *subheap, ARENA_INUSE *pArena, BOOL { char *heapEnd = (char *)subheap + subheap->size; +#if !defined(ALLOW_UNALIGNED_ACCESS) + /* Check for unaligned pointers */ + if ( (long)pArena % sizeof(void *) != 0 ) + { + if ( quiet == NOISY ) + { + ERR( "Heap %08lx: unaligned arena pointer %08lx\n", + (DWORD)subheap->heap, (DWORD)pArena ); + if ( TRACE_ON(heap) ) + HEAP_Dump( subheap->heap ); + } + else if ( WARN_ON(heap) ) + { + WARN( "Heap %08lx: unaligned arena pointer %08lx\n", + (DWORD)subheap->heap, (DWORD)pArena ); + if ( TRACE_ON(heap) ) + HEAP_Dump( subheap->heap ); + } + return FALSE; + } +#endif + /* Check magic number */ if (pArena->magic != ARENA_INUSE_MAGIC) { diff --git a/windows/class.c b/windows/class.c index e5caf8eb9c8..cf335a268c2 100644 --- a/windows/class.c +++ b/windows/class.c @@ -20,6 +20,7 @@ #include "wingdi.h" #include "wine/winuser16.h" #include "wine/unicode.h" +#include "wine/port.h" #include "heap.h" #include "win.h" #include "controls.h" diff --git a/windows/dialog.c b/windows/dialog.c index 3fb66e27c8b..3dafcf1e2ff 100644 --- a/windows/dialog.c +++ b/windows/dialog.c @@ -20,6 +20,7 @@ #include "wine/winuser16.h" #include "wine/winbase16.h" #include "wine/unicode.h" +#include "wine/port.h" #include "controls.h" #include "heap.h" #include "win.h"