From: Chip Davis Subject: [PATCH 1/2] include: Use __fastcall directly in winelib builds, too. Message-Id: <20191125013635.48644-1-cdavis@codeweavers.com> Date: Sun, 24 Nov 2019 19:36:34 -0600 It's still not safe to call a __fastcall function from Wine source, though, since we can't rely on this being present. winebuild still wants the old wrapper names, so for now we define aliases. Signed-off-by: Chip Davis --- dlls/hal/hal.c | 2 +- include/ddk/wdm.h | 6 +++--- include/windef.h | 21 +++++++++++++++------ include/wine/asm.h | 26 +++++++++++++++++++------- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/dlls/hal/hal.c b/dlls/hal/hal.c index 21ce6e12c99..2365cac57d0 100644 --- a/dlls/hal/hal.c +++ b/dlls/hal/hal.c @@ -34,7 +34,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(ntoskrnl); #ifdef __i386__ -#ifndef _WIN32 +#if !defined(_WIN32) && ((__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 4)) extern void * WINAPI wrap_fastcall_func1( void *func, const void *a ); __ASM_STDCALL_FUNC( wrap_fastcall_func1, 8, diff --git a/include/ddk/wdm.h b/include/ddk/wdm.h index a092216b824..3094fdbe42d 100644 --- a/include/ddk/wdm.h +++ b/include/ddk/wdm.h @@ -1554,9 +1554,9 @@ ULONG WINAPI ExGetSharedWaiterCount(ERESOURCE*); void WINAPI ExInitializeNPagedLookasideList(PNPAGED_LOOKASIDE_LIST,PALLOCATE_FUNCTION,PFREE_FUNCTION,ULONG,SIZE_T,ULONG,USHORT); void WINAPI ExInitializePagedLookasideList(PPAGED_LOOKASIDE_LIST,PALLOCATE_FUNCTION,PFREE_FUNCTION,ULONG,SIZE_T,ULONG,USHORT); NTSTATUS WINAPI ExInitializeResourceLite(ERESOURCE*); -PSLIST_ENTRY WINAPI ExInterlockedFlushSList(PSLIST_HEADER); -PSLIST_ENTRY WINAPI ExInterlockedPopEntrySList(PSLIST_HEADER,PKSPIN_LOCK); -PSLIST_ENTRY WINAPI ExInterlockedPushEntrySList(PSLIST_HEADER,PSLIST_ENTRY,PKSPIN_LOCK); +PSLIST_ENTRY FASTCALL ExInterlockedFlushSList(PSLIST_HEADER); +PSLIST_ENTRY FASTCALL ExInterlockedPopEntrySList(PSLIST_HEADER,PKSPIN_LOCK); +PSLIST_ENTRY FASTCALL ExInterlockedPushEntrySList(PSLIST_HEADER,PSLIST_ENTRY,PKSPIN_LOCK); LIST_ENTRY * WINAPI ExInterlockedRemoveHeadList(LIST_ENTRY*,KSPIN_LOCK*); BOOLEAN WINAPI ExIsResourceAcquiredExclusiveLite(ERESOURCE*); ULONG WINAPI ExIsResourceAcquiredSharedLite(ERESOURCE*); diff --git a/include/windef.h b/include/windef.h index 0074d5cf6c4..b52f5eb836c 100644 --- a/include/windef.h +++ b/include/windef.h @@ -101,10 +101,22 @@ extern "C" { #endif /* __cdecl */ #ifndef __fastcall -# ifndef _MSC_VER +# ifdef __i386__ +# ifdef __GNUC__ +# if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 2)) || defined(__APPLE__) +# define __fastcall __attribute__((__fastcall__)) __attribute__((__force_align_arg_pointer__)) +# elif (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)) +# define __fastcall __attribute__((__fastcall__)) +# else +# define __fastcall __stdcall +# endif +# elif !defined(_MSC_VER) +# define __fastcall __stdcall +# endif +# else # define __fastcall __stdcall # endif -#endif +#endif /* __fastcall */ #ifndef __thiscall # define __thiscall __stdcall @@ -150,10 +162,7 @@ extern "C" { #define _stdcall __ONLY_IN_WINELIB(__stdcall) #endif #ifndef _fastcall -#define _fastcall __ONLY_IN_WINELIB(__stdcall) -#endif -#ifndef __fastcall -#define __fastcall __ONLY_IN_WINELIB(__stdcall) +#define _fastcall __ONLY_IN_WINELIB(__fastcall) #endif #ifndef __export #define __export __ONLY_IN_WINELIB(__stdcall) diff --git a/include/wine/asm.h b/include/wine/asm.h index 8c664476ef1..c45d84c7307 100644 --- a/include/wine/asm.h +++ b/include/wine/asm.h @@ -29,8 +29,10 @@ #if defined(_WIN32) && defined(__i386__) # define __ASM_STDCALL(name,args) __ASM_NAME(name) "@" #args +# define __ASM_FASTCALL(name, args) "@" name "@" #args #else # define __ASM_STDCALL(name,args) __ASM_NAME(name) +# define __ASM_FASTCALL(name, args) __ASM_NAME(name) #endif #if defined(__GCC_HAVE_DWARF2_CFI_ASM) || defined(__APPLE__) @@ -56,22 +58,22 @@ #endif #ifdef __GNUC__ -# define __ASM_DEFINE_FUNC(name,code) \ - asm(".text\n\t.align 4\n\t.globl " name "\n\t" __ASM_FUNC_TYPE(name) __ASM_SEH("\n\t.seh_proc " name) "\n" name ":\n\t" \ - __ASM_CFI(".cfi_startproc\n\t") code __ASM_CFI("\n\t.cfi_endproc") __ASM_SEH("\n\t.seh_endproc") ); +# define __ASM_GLOBAL(code) asm(code); #else -# define __ASM_DEFINE_FUNC(name,code) void __asm_dummy_##__LINE__(void) { \ - asm(".text\n\t.align 4\n\t.globl " name "\n\t" __ASM_FUNC_TYPE(name) __ASM_SEH("\n\t.seh_proc " name) "\n" name ":\n\t" \ - __ASM_CFI(".cfi_startproc\n\t") code __ASM_CFI("\n\t.cfi_endproc") __ASM_SEH("\n\t.seh_endproc") ); } +# define __ASM_GLOBAL(code) void __asm_dummy_##__LINE__(void) { asm(code); } #endif +#define __ASM_DEFINE_FUNC(name,code) \ + __ASM_GLOBAL( ".text\n\t.align 4\n\t.globl " name "\n\t" __ASM_FUNC_TYPE(name) __ASM_SEH("\n\t.seh_proc " name) "\n" name ":\n\t" \ + __ASM_CFI(".cfi_startproc\n\t") code __ASM_CFI("\n\t.cfi_endproc") __ASM_SEH("\n\t.seh_endproc") ); + #define __ASM_GLOBAL_FUNC(name,code) __ASM_DEFINE_FUNC(__ASM_NAME(#name),code) #define __ASM_STDCALL_FUNC(name,args,code) __ASM_DEFINE_FUNC(__ASM_STDCALL(#name,args),code) /* fastcall support */ -#if defined(__i386__) && !defined(_WIN32) +#if defined(__i386__) && !defined(_WIN32) && ((__GNUC__ < 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 4))) # define DEFINE_FASTCALL1_WRAPPER(func) \ __ASM_STDCALL_FUNC( __fastcall_ ## func, 4, \ @@ -87,6 +89,16 @@ "pushl %eax\n\t" \ "jmp " __ASM_STDCALL(#func,args) ) +#elif defined(__i386__) && !defined(_WIN32) + +/* winebuild still uses the thunk names, so provide them */ +# define DEFINE_FASTCALL1_WRAPPER(func) \ + __ASM_GLOBAL( ".globl " __ASM_STDCALL("__fastcall_" #func, 4) "\n\t" \ + __ASM_STDCALL("__fastcall_" #func, 4) " = " __ASM_FASTCALL(#func, 4) "\n\t" ); +# define DEFINE_FASTCALL_WRAPPER(func,args) \ + __ASM_GLOBAL( ".globl " __ASM_STDCALL("__fastcall_" #func, args) "\n\t" \ + __ASM_STDCALL("__fastcall_" #func, args) " = " __ASM_FASTCALL(#func, args) "\n\t" ); + #else /* __i386__ */ # define DEFINE_FASTCALL1_WRAPPER(func) /* nothing */ -- 2.21.0