Replaced the GET/PUT_UA macros by memcpy. Fixed a few big-endian

issues.
This commit is contained in:
Alexandre Julliard 2002-05-23 02:53:10 +00:00
parent 5852f7a185
commit 7fbd74ea55
12 changed files with 45 additions and 105 deletions

View file

@ -4077,10 +4077,8 @@ static HMODULE DP_LoadSP( LPCGUID lpcGuid, LPSPINITDATA lpSpData, LPBOOL lpbIsDp
}
if( i == 0 )
{
lpSpData->dwReserved1 = GET_DWORD( returnBuffer );
}
memcpy( &lpSpData->dwReserved1, returnBuffer, sizeof(lpSpData->dwReserved1) );
sizeOfReturnBuffer = 255;
/* Get dwReserved2 */
@ -4093,9 +4091,7 @@ static HMODULE DP_LoadSP( LPCGUID lpcGuid, LPSPINITDATA lpSpData, LPBOOL lpbIsDp
}
if( i == 0 )
{
lpSpData->dwReserved2 = GET_DWORD( returnBuffer );
}
memcpy( &lpSpData->dwReserved2, returnBuffer, sizeof(lpSpData->dwReserved2) );
sizeOfReturnBuffer = 255;
@ -5267,8 +5263,7 @@ HRESULT WINAPI DirectPlayEnumerateA( LPDPENUMDPCALLBACKA lpEnumCallback,
ERR(": missing dwReserved1 registry data members\n") ;
continue;
}
majVersionNum = GET_DWORD( returnBuffer );
memcpy( &majVersionNum, returnBuffer, sizeof(majVersionNum) );
sizeOfReturnBuffer = 50;
if( RegQueryValueExA( hkServiceProvider, minVerDataSubKey,
@ -5278,8 +5273,7 @@ HRESULT WINAPI DirectPlayEnumerateA( LPDPENUMDPCALLBACKA lpEnumCallback,
ERR(": missing dwReserved2 registry data members\n") ;
continue;
}
minVersionNum = GET_DWORD( returnBuffer );
memcpy( &minVersionNum, returnBuffer, sizeof(minVersionNum) );
/* The enumeration will return FALSE if we are not to continue */

View file

@ -99,6 +99,8 @@ MAKE_FUNCPTR(FT_Sin)
MAKE_FUNCPTR(FT_Vector_Rotate)
#undef MAKE_FUNCPTR
#define GET_BE_WORD(ptr) MAKEWORD( ((BYTE *)(ptr))[1], ((BYTE *)(ptr))[0] )
typedef struct tagFace {
WCHAR *StyleName;
char *file;

View file

@ -660,7 +660,6 @@ 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 )
{
@ -668,7 +667,6 @@ static BOOL HEAP_ValidateFreeArena( SUBHEAP *subheap, ARENA_FREE *pArena )
(DWORD)subheap->heap, (DWORD)pArena );
return FALSE;
}
#endif
/* Check magic number */
if (pArena->magic != ARENA_FREE_MAGIC)
@ -754,7 +752,6 @@ 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 )
{
@ -774,7 +771,6 @@ static BOOL HEAP_ValidateInUseArena( SUBHEAP *subheap, ARENA_INUSE *pArena, BOOL
}
return FALSE;
}
#endif
/* Check magic number */
if (pArena->magic != ARENA_INUSE_MAGIC)

View file

@ -185,7 +185,7 @@ static BOOL MSTTStrToSz(const FT_SfntName *name, LPSTR *p_sz)
{
FT_UShort i;
INT len;
USHORT *wsz;
BYTE *wsz;
LPSTR sz;
len = name->string_len / 2; /* # of 16-bit chars */
@ -194,15 +194,12 @@ static BOOL MSTTStrToSz(const FT_SfntName *name, LPSTR *p_sz)
if (sz == NULL)
return FALSE;
wsz = (USHORT *)(name->string);
for (i = 0; i < len; ++i, ++sz, ++wsz)
wsz = (BYTE *)name->string;
for (i = 0; i < len; ++i, ++sz)
{
USHORT wc = *wsz;
#ifndef WORDS_BIGENDIAN
wc = (wc >> 8) | (wc << 8);
#endif
USHORT wc = (wsz[0] << 8) + wsz[1];
wsz += 2;
if (wc > 127)
{

View file

@ -38,6 +38,9 @@ extern WORD USER_HeapSel;
#define USER_HEAP_LIN_ADDR(handle) \
((handle) ? MapSL(MAKESEGPTR(USER_HeapSel, (handle))) : NULL)
#define GET_WORD(ptr) (*(WORD *)(ptr))
#define GET_DWORD(ptr) (*(DWORD *)(ptr))
#define USUD_LOCALALLOC 0x0001
#define USUD_LOCALFREE 0x0002
#define USUD_LOCALCOMPACT 0x0003

View file

@ -162,57 +162,6 @@ struct statfs;
#endif /* __GNUC__ */
/* 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], HIWORD(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], HIWORD(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
/****************************************************************
* Function definitions (only when using libwine)
*/

View file

@ -278,7 +278,8 @@ WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
{
if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
{
WORD ordinal = GET_UA_WORD( cpnt + *cpnt + 1 );
WORD ordinal;
memcpy( &ordinal, cpnt + *cpnt + 1, sizeof(ordinal) );
TRACE(" Found: ordinal=%d\n", ordinal );
return ordinal;
}
@ -296,7 +297,8 @@ WORD NE_GetOrdinal( HMODULE16 hModule, const char *name )
{
if (((BYTE)*cpnt == len) && !memcmp( cpnt+1, buffer, len ))
{
WORD ordinal = GET_UA_WORD( cpnt + *cpnt + 1 );
WORD ordinal;
memcpy( &ordinal, cpnt + *cpnt + 1, sizeof(ordinal) );
TRACE(" Found: ordinal=%d\n", ordinal );
return ordinal;
}
@ -353,7 +355,7 @@ FARPROC16 NE_GetEntryPointEx( HMODULE16 hModule, WORD ordinal, BOOL16 snoop )
entry++;
sel = entry->segnum;
offset = GET_UA_WORD( &entry->offs );
memcpy( &offset, &entry->offs, sizeof(WORD) );
if (sel == 0xfe) sel = 0xffff; /* constant entry */
else sel = GlobalHandleToSel16(NE_SEG_TABLE(pModule)[sel-1].hSeg);
@ -394,7 +396,7 @@ BOOL16 NE_SetEntryPoint( HMODULE16 hModule, WORD ordinal, WORD offset )
for (i=0; i < (ordinal - bundle->first - 1); i++)
entry++;
PUT_UA_WORD( &entry->offs, offset );
memcpy( &entry->offs, &offset, sizeof(WORD) );
return TRUE;
}

View file

@ -274,7 +274,7 @@ BOOL NE_InitResourceHandler( HMODULE16 hModule )
while(pTypeInfo->type_id)
{
PUT_UA_DWORD( &pTypeInfo->resloader, (DWORD)DefResourceHandlerProc );
memcpy( &pTypeInfo->resloader, &DefResourceHandlerProc, sizeof(FARPROC16) );
pTypeInfo = NEXT_TYPEINFO(pTypeInfo);
}
return TRUE;
@ -300,8 +300,8 @@ FARPROC16 WINAPI SetResourceHandler16( HMODULE16 hModule, LPCSTR typeId,
{
if (!(pTypeInfo = NE_FindTypeSection( pResTab, pTypeInfo, typeId )))
break;
prevHandler = (FARPROC16)GET_UA_DWORD( &pTypeInfo->resloader );
PUT_UA_DWORD( &pTypeInfo->resloader, (DWORD)resourceHandler );
memcpy( &prevHandler, &pTypeInfo->resloader, sizeof(FARPROC16) );
memcpy( &pTypeInfo->resloader, &resourceHandler, sizeof(FARPROC16) );
pTypeInfo = NEXT_TYPEINFO(pTypeInfo);
}
return prevHandler;
@ -503,7 +503,8 @@ HGLOBAL16 NE_LoadResource( NE_MODULE *pModule, HRSRC16 hRsrc )
}
else
{
FARPROC16 resloader = (FARPROC16)GET_UA_DWORD( &pTypeInfo->resloader );
FARPROC16 resloader;
memcpy( &resloader, &pTypeInfo->resloader, sizeof(FARPROC16) );
if ( resloader && resloader != DefResourceHandlerProc )
pNameInfo->handle = NE_CallTo16_word_www(
resloader, pNameInfo->handle, pModule->self, hRsrc );

View file

@ -258,6 +258,7 @@ static TDB *TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, TEB *teb, LPCSTR cm
HTASK16 hTask;
TDB *pTask;
char name[10];
FARPROC16 proc;
/* Allocate the task structure */
@ -308,8 +309,8 @@ static TDB *TASK_Create( NE_MODULE *pModule, UINT16 cmdShow, TEB *teb, LPCSTR cm
pTask->pdb.int20 = 0x20cd;
pTask->pdb.dispatcher[0] = 0x9a; /* ljmp */
PUT_UA_DWORD(&pTask->pdb.dispatcher[1],
(DWORD)GetProcAddress16( GetModuleHandle16("KERNEL"), "DOS3Call" ));
proc = GetProcAddress16( GetModuleHandle16("KERNEL"), "DOS3Call" );
memcpy( &pTask->pdb.dispatcher[1], &proc, sizeof(proc) );
pTask->pdb.savedint22 = INT_GetPMHandler( 0x22 );
pTask->pdb.savedint23 = INT_GetPMHandler( 0x23 );
pTask->pdb.savedint24 = INT_GetPMHandler( 0x24 );

View file

@ -74,15 +74,6 @@ static const char ENV_program_name[] = "C:\\WINDOWS\\SYSTEM\\KRNL386.EXE";
/* Maximum length of a Win16 environment string (including NULL) */
#define MAX_WIN16_LEN 128
/* Extra bytes to reserve at the end of an environment */
#define EXTRA_ENV_SIZE (sizeof(BYTE) + sizeof(WORD) + sizeof(ENV_program_name))
/* Fill the extra bytes with the program name and stuff */
#define FILL_EXTRA_ENV(p) \
*(p) = '\0'; \
PUT_UA_WORD( (p) + 1, 1 ); \
strcpy( (p) + 3, ENV_program_name );
STARTUPINFOA current_startupinfo =
{
sizeof(STARTUPINFOA), /* cb */
@ -154,12 +145,13 @@ static LPCSTR ENV_FindVariable( LPCSTR env, LPCSTR name, INT len )
static BOOL build_environment(void)
{
extern char **environ;
static const WORD one = 1;
LPSTR p, *e;
int size;
/* Compute the total size of the Unix environment */
size = EXTRA_ENV_SIZE;
size = sizeof(BYTE) + sizeof(WORD) + sizeof(ENV_program_name);
for (e = environ; *e; e++) size += strlen(*e) + 1;
/* Now allocate the environment */
@ -178,7 +170,9 @@ static BOOL build_environment(void)
/* Now add the program name */
FILL_EXTRA_ENV( p );
*p++ = 0;
memcpy( p, &one, sizeof(WORD) );
strcpy( p + sizeof(WORD), ENV_program_name );
return TRUE;
}

View file

@ -200,18 +200,19 @@ static int BuildModule16( FILE *outfile, int max_code_offset,
*pstr = strlen( DLLName );
strcpy( pstr + 1, DLLName );
pstr += *pstr + 1;
PUT_UA_WORD( pstr, 0 );
pstr += sizeof(WORD);
*pstr++ = 0;
*pstr++ = 0;
/* Store all ordinals */
for (i = 1; i <= Limit; i++)
{
ORDDEF *odp = Ordinals[i];
WORD ord = i;
if (!odp || !odp->name[0]) continue;
*pstr = strlen( odp->name );
strcpy( pstr + 1, odp->name );
strupper( pstr + 1 );
pstr += *pstr + 1;
PUT_UA_WORD( pstr, i );
memcpy( pstr, &ord, sizeof(WORD) );
pstr += sizeof(WORD);
}
*pstr++ = 0;

View file

@ -795,7 +795,7 @@ WORD WINAPI GetClassWord( HWND hwnd, INT offset )
if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
if (offset <= class->cbClsExtra - sizeof(WORD))
retvalue = GET_WORD((char *)(class + 1) + offset);
memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
else
SetLastError( ERROR_INVALID_INDEX );
release_class_ptr( class );
@ -847,7 +847,7 @@ LONG WINAPI GetClassLongA( HWND hwnd, INT offset )
if (offset >= 0)
{
if (offset <= class->cbClsExtra - sizeof(LONG))
retvalue = GET_DWORD((char *)(class + 1) + offset);
memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
else
SetLastError( ERROR_INVALID_INDEX );
release_class_ptr( class );
@ -940,8 +940,8 @@ WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
if (offset <= class->cbClsExtra - sizeof(WORD))
{
void *ptr = (char *)(class + 1) + offset;
retval = GET_WORD(ptr);
PUT_WORD( ptr, newval );
memcpy( &retval, ptr, sizeof(retval) );
memcpy( ptr, &newval, sizeof(newval) );
}
else SetLastError( ERROR_INVALID_INDEX );
@ -994,8 +994,8 @@ LONG WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
if (offset <= class->cbClsExtra - sizeof(LONG))
{
void *ptr = (char *)(class + 1) + offset;
retval = GET_DWORD(ptr);
PUT_DWORD( ptr, newval );
memcpy( &retval, ptr, sizeof(retval) );
memcpy( ptr, &newval, sizeof(newval) );
}
else SetLastError( ERROR_INVALID_INDEX );
}