From 09570edaa5b564ccc1a76ecfcbe29d929bfb0344 Mon Sep 17 00:00:00 2001 From: Patrik Stridvall Date: Sat, 17 Aug 2002 01:22:59 +0000 Subject: [PATCH] MSVC compatibility fixes. --- dlls/advapi32/advapi.c | 15 ++++++----- dlls/advapi32/registry.c | 1 - library/debug.c | 1 - library/loader.c | 1 - library/port.c | 57 ++++++++++++++++++++++++++++++++++++++-- memory/instr.c | 6 ++--- 6 files changed, 67 insertions(+), 14 deletions(-) diff --git a/dlls/advapi32/advapi.c b/dlls/advapi32/advapi.c index 5496205e78e..f4dea242bca 100644 --- a/dlls/advapi32/advapi.c +++ b/dlls/advapi32/advapi.c @@ -23,9 +23,10 @@ #include #include -#include #include -#include +#ifdef HAVE_PWD_H +# include +#endif #include "winbase.h" #include "windef.h" @@ -48,15 +49,17 @@ GetUserNameA( LPSTR lpszName, LPDWORD lpSize ) size_t len; char *name; +#ifdef HAVE_GETPWUID struct passwd *pwd = getpwuid( getuid() ); - if (!pwd) - { + name = pwd ? pwd->pw_name : NULL; +#else + name = getenv("USER"); +#endif + if (!name) { ERR("Username lookup failed: %s\n", strerror(errno)); return 0; } - name = pwd->pw_name; - /* We need to include the null character when determining the size of the buffer. */ len = strlen(name) + 1; if (len > *lpSize) diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c index 3efb3ce1665..725d02bbb37 100644 --- a/dlls/advapi32/registry.c +++ b/dlls/advapi32/registry.c @@ -28,7 +28,6 @@ #include #include -#include #include "winbase.h" #include "winreg.h" diff --git a/library/debug.c b/library/debug.c index 42926d053d7..ab80b014dbd 100644 --- a/library/debug.c +++ b/library/debug.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include "wine/debug.h" diff --git a/library/loader.c b/library/loader.c index 556295256a8..54e01fba831 100644 --- a/library/loader.c +++ b/library/loader.c @@ -26,7 +26,6 @@ #include #include #include -#include #ifdef HAVE_SYS_MMAN_H #include #endif diff --git a/library/port.c b/library/port.c index 01effca3dde..78e51a93560 100644 --- a/library/port.c +++ b/library/port.c @@ -31,7 +31,10 @@ #include #include #include -#include +#include +#ifdef HAVE_UNISTD_H +# include +#endif #include #ifdef HAVE_SYS_INTTYPES_H # include @@ -101,7 +104,7 @@ void *memmove( void *dest, const void *src, unsigned int len ) memcpy( dst, src, len ); } /* Otherwise do it the hard way (FIXME: could do better than this) */ - else if (dst < src) + else if (dst < (char *)src) { while (len--) *dst++ = *((char *)src)++; } @@ -668,6 +671,8 @@ char *gcvt (double number, size_t ndigit, char *buff) */ #ifdef __i386__ +#ifdef __GNUC__ + __ASM_GLOBAL_FUNC(interlocked_cmpxchg, "movl 12(%esp),%eax\n\t" "movl 8(%esp),%ecx\n\t" @@ -696,6 +701,54 @@ __ASM_GLOBAL_FUNC(interlocked_xchg_add, "lock; xaddl %eax,(%edx)\n\t" "ret"); +#elif defined(_MSC_VER) + +__declspec(naked) long interlocked_cmpxchg( long *dest, long xchg, long compare ) +{ + __asm mov eax, 12[esp]; + __asm mov ecx, 8[esp]; + __asm mov edx, 4[esp]; + __asm lock cmpxchg [edx], ecx; + __asm ret; +} + +__declspec(naked) void *interlocked_cmpxchg_ptr( void **dest, void *xchg, void *compare ) +{ + __asm mov eax, 12[esp]; + __asm mov ecx, 8[esp]; + __asm mov edx, 4[esp]; + __asm lock cmpxchg [edx], ecx; + __asm ret; +} + +__declspec(naked) long interlocked_xchg( long *dest, long val ) +{ + __asm mov eax, 8[esp]; + __asm mov edx, 4[esp]; + __asm lock xchg [edx], eax; + __asm ret; +} + +__declspec(naked) void *interlocked_xchg_ptr( void **dest, void *val ) +{ + __asm mov eax, 8[esp]; + __asm mov edx, 4[esp]; + __asm lock xchg [edx], eax; + __asm ret; +} + +__declspec(naked) long interlocked_xchg_add( long *dest, long incr ) +{ + __asm mov eax, 8[esp]; + __asm mov edx, 4[esp]; + __asm lock xadd [edx], eax; + __asm ret; +} + +#else +# error You must implement the interlocked* functions for your compiler +#endif + #elif defined(__powerpc__) void* interlocked_cmpxchg_ptr( void **dest, void* xchg, void* compare) { diff --git a/memory/instr.c b/memory/instr.c index bbea64aba1f..f1a30d24fbb 100644 --- a/memory/instr.c +++ b/memory/instr.c @@ -44,7 +44,7 @@ inline static void *make_ptr( CONTEXT86 *context, DWORD seg, DWORD off, int long if (ISV86(context)) return PTR_REAL_TO_LIN( seg, off ); if (IS_SELECTOR_SYSTEM(seg)) return (void *)off; if (!long_addr) off = LOWORD(off); - return MapSL( MAKESEGPTR( seg, 0 ) ) + off; + return (char *) MapSL( MAKESEGPTR( seg, 0 ) ) + off; } inline static void *get_stack( CONTEXT86 *context ) @@ -54,7 +54,7 @@ inline static void *get_stack( CONTEXT86 *context ) if (IS_SELECTOR_SYSTEM(context->SegSs)) return (void *)context->Esp; if (IS_SELECTOR_32BIT(context->SegSs)) - return MapSL( MAKESEGPTR( context->SegSs, 0 ) ) + context->Esp; + return (char *) MapSL( MAKESEGPTR( context->SegSs, 0 ) ) + context->Esp; return MapSL( MAKESEGPTR( context->SegSs, LOWORD(context->Esp) ) ); } @@ -249,7 +249,7 @@ static BYTE *INSTR_GetOperandAddr( CONTEXT86 *context, BYTE *instr, if (IS_SELECTOR_SYSTEM(seg)) return (BYTE *)(base + (index << ss)); if (((seg & 7) != 7) || IS_SELECTOR_FREE(seg)) return NULL; if (wine_ldt_copy.limit[seg >> 3] < (base + (index << ss))) return NULL; - return MapSL( MAKESEGPTR( seg, 0 ) ) + base + (index << ss); + return (char *) MapSL( MAKESEGPTR( seg, 0 ) ) + base + (index << ss); #undef GET_VAL }