From 9534d4f0feb43f1eacd21a577bb1d57f18a920e9 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 18 Oct 2002 00:27:38 +0000 Subject: [PATCH] Added wine_memcpy_unaligned function to avoid gcc memcpy optimizations. --- include/wine/port.h | 8 +++++++- library/port.c | 15 ++++++++++++++- loader/ne/resource.c | 8 ++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/include/wine/port.h b/include/wine/port.h index 8baa5bfdc53..a23ea534b76 100644 --- a/include/wine/port.h +++ b/include/wine/port.h @@ -190,7 +190,7 @@ int mkstemp(char *tmpfn); #endif /* HAVE_MKSTEMP */ #ifndef HAVE_MEMMOVE -void *memmove(void *dest, const void *src, unsigned int len); +void *memmove(void *dest, const void *src, size_t len); #endif /* !defined(HAVE_MEMMOVE) */ #ifndef HAVE_PREAD @@ -229,6 +229,12 @@ int strcasecmp(const char *str1, const char *str2); int usleep (unsigned int useconds); #endif /* !defined(HAVE_USLEEP) */ +#ifdef __i386__ +#define wine_memcpy_unaligned memcpy +#else +extern void *wine_memcpy_unaligned( void *dst, const void *src, size_t size ); +#endif /* __i386__ */ + /* Interlocked functions */ #if defined(__i386__) && defined(__GNUC__) diff --git a/library/port.c b/library/port.c index 0f21e8390dc..25fd4b73960 100644 --- a/library/port.c +++ b/library/port.c @@ -94,7 +94,7 @@ int usleep (unsigned int useconds) * memmove */ #ifndef HAVE_MEMMOVE -void *memmove( void *dest, const void *src, unsigned int len ) +void *memmove( void *dest, const void *src, size_t len ) { register char *dst = dest; @@ -666,6 +666,19 @@ char *gcvt (double number, size_t ndigit, char *buff) #endif /* HAVE_ECVT */ +#ifndef wine_memcpy_unaligned +/*********************************************************************** + * wine_memcpy_unaligned + * + * This is necessary to defeat optimizations of memcpy by gcc. + */ +void *wine_memcpy_unaligned( void *dst, const void *src, size_t size ) +{ + return memcpy( dst, src, size ); +} +#endif + + /*********************************************************************** * interlocked functions */ diff --git a/loader/ne/resource.c b/loader/ne/resource.c index 1a48c7791c0..dd236bd5eaf 100644 --- a/loader/ne/resource.c +++ b/loader/ne/resource.c @@ -277,7 +277,7 @@ BOOL NE_InitResourceHandler( HMODULE16 hModule ) while(pTypeInfo->type_id) { - memcpy( &pTypeInfo->resloader, &DefResourceHandlerProc, sizeof(FARPROC16) ); + wine_memcpy_unaligned( &pTypeInfo->resloader, &DefResourceHandlerProc, sizeof(FARPROC16) ); pTypeInfo = NEXT_TYPEINFO(pTypeInfo); } return TRUE; @@ -303,8 +303,8 @@ FARPROC16 WINAPI SetResourceHandler16( HMODULE16 hModule, LPCSTR typeId, { if (!(pTypeInfo = NE_FindTypeSection( pResTab, pTypeInfo, typeId ))) break; - memcpy( &prevHandler, &pTypeInfo->resloader, sizeof(FARPROC16) ); - memcpy( &pTypeInfo->resloader, &resourceHandler, sizeof(FARPROC16) ); + wine_memcpy_unaligned( &prevHandler, &pTypeInfo->resloader, sizeof(FARPROC16) ); + wine_memcpy_unaligned( &pTypeInfo->resloader, &resourceHandler, sizeof(FARPROC16) ); pTypeInfo = NEXT_TYPEINFO(pTypeInfo); } return prevHandler; @@ -507,7 +507,7 @@ HGLOBAL16 NE_LoadResource( NE_MODULE *pModule, HRSRC16 hRsrc ) else { FARPROC16 resloader; - memcpy( &resloader, &pTypeInfo->resloader, sizeof(FARPROC16) ); + wine_memcpy_unaligned( &resloader, &pTypeInfo->resloader, sizeof(FARPROC16) ); if ( resloader && resloader != DefResourceHandlerProc ) pNameInfo->handle = NE_CallTo16_word_www( resloader, pNameInfo->handle, pModule->self, hRsrc );