From 3751ff045ce39b526835265e77f116d1e0ab6bc1 Mon Sep 17 00:00:00 2001 From: Patrik Stridvall Date: Sat, 4 May 2002 18:37:08 +0000 Subject: [PATCH] MS C related changes. --- include/async.h | 2 +- include/winnt.h | 10 +++++++++- memory/selector.c | 32 +++++++++++++++++++++++--------- scheduler/sysdeps.c | 25 +++++++++++++++++-------- tools/winebuild/spec16.c | 6 +++++- 5 files changed, 55 insertions(+), 20 deletions(-) diff --git a/include/async.h b/include/async.h index 6b6359a41a8..ea23e62ecbd 100644 --- a/include/async.h +++ b/include/async.h @@ -31,7 +31,7 @@ struct async_private; typedef void (*async_handler)(struct async_private *ovp); -typedef void CALLBACK (*async_call_completion_func)(ULONG_PTR data); +typedef void (CALLBACK *async_call_completion_func)(ULONG_PTR data); typedef DWORD (*async_get_status)(const struct async_private *ovp); typedef DWORD (*async_get_count)(const struct async_private *ovp); typedef void (*async_set_status)(struct async_private *ovp, const DWORD status); diff --git a/include/winnt.h b/include/winnt.h index 9fd560856e9..645b7e46778 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -1244,7 +1244,7 @@ typedef CONTEXT *PCONTEXT; extern inline void __set_##seg(int val) { __asm__("movw %w0,%%" #seg : : "r" (val)); } # elif defined(_MSC_VER) # define __DEFINE_GET_SEG(seg) \ - extern inline unsigned short __get_##seg(void) { unsigned short res; __asm { mov res, fs } return res; } + extern inline unsigned short __get_##seg(void) { unsigned short res; __asm { mov res, seg } return res; } # define __DEFINE_SET_SEG(seg) \ extern inline void __set_##seg(unsigned short val) { __asm { mov seg, val } } # else /* __GNUC__ || _MSC_VER */ @@ -2360,6 +2360,14 @@ extern inline struct _TEB * WINAPI NtCurrentTeb(void) __asm__(".byte 0x64\n\tmovl (0x18),%0" : "=r" (teb)); return teb; } +#elif defined(__i386__) && defined(_MSC_VER) +extern inline struct _TEB * WINAPI NtCurrentTeb(void) +{ + struct _TEB *teb; + __asm mov eax, fs:[0x18]; + __asm mov teb, eax; + return teb; +} #else extern struct _TEB * WINAPI NtCurrentTeb(void); #endif diff --git a/memory/selector.c b/memory/selector.c index d52989b126d..0e741b696ba 100644 --- a/memory/selector.c +++ b/memory/selector.c @@ -938,12 +938,26 @@ void WINAPI FreeMappedBuffer( CONTEXT86 *context ) } #ifdef __i386__ -__ASM_GLOBAL_FUNC( __get_cs, "movw %cs,%ax\n\tret" ) -__ASM_GLOBAL_FUNC( __get_ds, "movw %ds,%ax\n\tret" ) -__ASM_GLOBAL_FUNC( __get_es, "movw %es,%ax\n\tret" ) -__ASM_GLOBAL_FUNC( __get_fs, "movw %fs,%ax\n\tret" ) -__ASM_GLOBAL_FUNC( __get_gs, "movw %gs,%ax\n\tret" ) -__ASM_GLOBAL_FUNC( __get_ss, "movw %ss,%ax\n\tret" ) -__ASM_GLOBAL_FUNC( __set_fs, "movl 4(%esp),%eax\n\tmovw %ax,%fs\n\tret" ) -__ASM_GLOBAL_FUNC( __set_gs, "movl 4(%esp),%eax\n\tmovw %ax,%gs\n\tret" ) -#endif +#ifdef _MSC_VER +/* Nothing needs to be done. MS C make do with inline versions from the winnt.h */ +#else /* defined(_MSC_VER) */ + +#define __DEFINE_GET_SEG(seg) \ + __ASM_GLOBAL_FUNC( __get_##seg, "movw %" #seg ",%ax\n\tret" ) +#define __DEFINE_SET_SEG(seg) \ + __ASM_GLOBAL_FUNC( __set_##seg, "movl 4(%esp),%eax\n\tmovw %ax,%" #seg "\n\tret" ) + +__DEFINE_GET_SEG(cs) +__DEFINE_GET_SEG(ds) +__DEFINE_GET_SEG(es) +__DEFINE_GET_SEG(fs) +__DEFINE_GET_SEG(gs) +__DEFINE_GET_SEG(ss) +__DEFINE_SET_SEG(fs) +__DEFINE_SET_SEG(gs) + +#undef __DEFINE_GET_SEG +#undef __DEFINE_SET_SEG + +#endif /* defined(_MSC_VER) */ +#endif /* defined(__i386__) */ diff --git a/scheduler/sysdeps.c b/scheduler/sysdeps.c index 9b2689b7b47..96ee8a1e873 100644 --- a/scheduler/sysdeps.c +++ b/scheduler/sysdeps.c @@ -228,6 +228,7 @@ int SYSDEPS_SpawnThread( TEB *teb ) */ void SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg ) WINE_NORETURN; #ifdef __i386__ +#ifdef __GNUC__ __ASM_GLOBAL_FUNC( SYSDEPS_CallOnStack, "movl 4(%esp),%ecx\n\t" /* func */ "movl 8(%esp),%edx\n\t" /* arg */ @@ -236,13 +237,25 @@ __ASM_GLOBAL_FUNC( SYSDEPS_CallOnStack, "xorl %ebp,%ebp\n\t" "call *%ecx\n\t" "int $3" /* we never return here */ ); -#else +#elif defined(_MSC_VER) +__declspec(naked) void SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg ) +{ + __asm mov ecx, 4[esp]; + __asm mov edx, 8[esp]; + __asm mov fs:[0x04], esp; + __asm push edx; + __asm xor ebp, ebp; + __asm call [ecx]; + __asm int 3; +} +#endif /* defined(__GNUC__) || defined(_MSC_VER) */ +#else /* defined(__i386__) */ void SYSDEPS_CallOnStack( void (*func)(LPVOID), LPVOID arg ) { func( arg ); while(1); /* avoid warning */ } -#endif +#endif /* defined(__i386__) */ /*********************************************************************** @@ -279,7 +292,7 @@ void SYSDEPS_ExitThread( int status ) close( teb->reply_fd ); close( teb->request_fd ); teb->stack_low = get_temp_stack(); - teb->stack_top = teb->stack_low + TEMP_STACK_SIZE; + teb->stack_top = (char *) teb->stack_low + TEMP_STACK_SIZE; SYSDEPS_CallOnStack( cleanup_thread, &info ); } @@ -312,11 +325,7 @@ void SYSDEPS_AbortThread( int status ) #if defined(__i386__) && defined(__GNUC__) __ASM_GLOBAL_FUNC( NtCurrentTeb, ".byte 0x64\n\tmovl 0x18,%eax\n\tret" ); #elif defined(__i386__) && defined(_MSC_VER) -__declspec(naked) struct _TEB * WINAPI NtCurrentTeb(void) -{ - __asm mov eax, fs:[0x18]; - __asm ret; -} +/* Nothing needs to be done. MS C "magically" exports the inline version from winnt.h */ #elif defined(HAVE__LWP_CREATE) /*********************************************************************** * NtCurrentTeb (NTDLL.@) diff --git a/tools/winebuild/spec16.c b/tools/winebuild/spec16.c index 23d990f1049..b30723e21bf 100644 --- a/tools/winebuild/spec16.c +++ b/tools/winebuild/spec16.c @@ -36,9 +36,13 @@ #include "build.h" #ifdef __i386__ +#ifdef _MSC_VER +extern unsigned short __get_cs(void) { unsigned short res; __asm { mov res, cs } return res; } +#else extern unsigned short __get_cs(void); __ASM_GLOBAL_FUNC( __get_cs, "movw %cs,%ax\n\tret" ); -#endif /* __i386__ */ +#endif /* defined(_MSC_VER) */ +#endif /* defined(__i386__) */ /*******************************************************************