include: Implement some inline functions in C instead of assembly.

This way the same code can be used on all platforms.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-06-26 12:41:22 +02:00
parent ff352c6d01
commit 32fdffac42
5 changed files with 49 additions and 210 deletions

View File

@ -629,12 +629,12 @@
@ stdcall GetCurrentPackageFamilyName(ptr ptr) @ stdcall GetCurrentPackageFamilyName(ptr ptr)
@ stdcall GetCurrentPackageFullName(ptr ptr) @ stdcall GetCurrentPackageFullName(ptr ptr)
@ stdcall GetCurrentPackageId(ptr ptr) @ stdcall GetCurrentPackageId(ptr ptr)
@ stdcall -norelay GetCurrentProcess() @ stdcall -norelay GetCurrentProcess() KERNEL32_GetCurrentProcess
@ stdcall -norelay GetCurrentProcessId() @ stdcall -norelay GetCurrentProcessId() KERNEL32_GetCurrentProcessId
@ stdcall GetCurrentProcessorNumber() ntdll.NtGetCurrentProcessorNumber @ stdcall GetCurrentProcessorNumber() ntdll.NtGetCurrentProcessorNumber
@ stdcall GetCurrentProcessorNumberEx(ptr) ntdll.RtlGetCurrentProcessorNumberEx @ stdcall GetCurrentProcessorNumberEx(ptr) ntdll.RtlGetCurrentProcessorNumberEx
@ stdcall -norelay GetCurrentThread() @ stdcall -norelay GetCurrentThread() KERNEL32_GetCurrentThread
@ stdcall -norelay GetCurrentThreadId() @ stdcall -norelay GetCurrentThreadId() KERNEL32_GetCurrentThreadId
@ stdcall GetCurrentThreadStackLimits(ptr ptr) @ stdcall GetCurrentThreadStackLimits(ptr ptr)
@ stdcall -arch=x86_64 GetCurrentUmsThread() @ stdcall -arch=x86_64 GetCurrentUmsThread()
@ stdcall GetDateFormatA(long long ptr str ptr long) @ stdcall GetDateFormatA(long long ptr str ptr long)
@ -700,7 +700,7 @@
@ stub -i386 GetLSCallbackTemplate @ stub -i386 GetLSCallbackTemplate
@ stdcall GetLargePageMinimum() @ stdcall GetLargePageMinimum()
@ stdcall GetLargestConsoleWindowSize(long) @ stdcall GetLargestConsoleWindowSize(long)
@ stdcall GetLastError() @ stdcall GetLastError() KERNEL32_GetLastError
@ stub GetLinguistLangSize @ stub GetLinguistLangSize
@ stdcall GetLocalTime(ptr) @ stdcall GetLocalTime(ptr)
@ stdcall GetLocaleInfoA(long long ptr long) @ stdcall GetLocaleInfoA(long long ptr long)
@ -780,7 +780,7 @@
@ stdcall GetProcessFlags(long) @ stdcall GetProcessFlags(long)
# @ stub GetProcessGroupAffinity # @ stub GetProcessGroupAffinity
@ stdcall GetProcessHandleCount(long ptr) @ stdcall GetProcessHandleCount(long ptr)
@ stdcall -norelay GetProcessHeap() @ stdcall -norelay GetProcessHeap() KERNEL32_GetProcessHeap
@ stdcall GetProcessHeaps(long ptr) @ stdcall GetProcessHeaps(long ptr)
@ stdcall GetProcessId(long) @ stdcall GetProcessId(long)
@ stdcall GetProcessIdOfThread(long) @ stdcall GetProcessIdOfThread(long)
@ -1414,7 +1414,7 @@
@ stdcall SetHandleInformation(long long long) @ stdcall SetHandleInformation(long long long)
@ stdcall SetInformationJobObject(long long ptr long) @ stdcall SetInformationJobObject(long long ptr long)
@ stub SetLastConsoleEventActive @ stub SetLastConsoleEventActive
@ stdcall SetLastError(long) @ stdcall SetLastError(long) KERNEL32_SetLastError
# @ stub SetLocalPrimaryComputerNameA # @ stub SetLocalPrimaryComputerNameA
# @ stub SetLocalPrimaryComputerNameW # @ stub SetLocalPrimaryComputerNameW
@ stdcall SetLocalTime(ptr) @ stdcall SetLocalTime(ptr)

View File

@ -4258,8 +4258,7 @@ BOOL WINAPI IsWow64Process(HANDLE hProcess, PBOOL Wow64Process)
* RETURNS * RETURNS
* A handle representing the current process. * A handle representing the current process.
*/ */
#undef GetCurrentProcess HANDLE WINAPI KERNEL32_GetCurrentProcess(void)
HANDLE WINAPI GetCurrentProcess(void)
{ {
return (HANDLE)~(ULONG_PTR)0; return (HANDLE)~(ULONG_PTR)0;
} }

View File

@ -696,8 +696,7 @@ DWORD WINAPI GetProcessIdOfThread(HANDLE Thread)
* RETURNS * RETURNS
* Pseudohandle for the current thread * Pseudohandle for the current thread
*/ */
#undef GetCurrentThread HANDLE WINAPI KERNEL32_GetCurrentThread(void)
HANDLE WINAPI GetCurrentThread(void)
{ {
return (HANDLE)~(ULONG_PTR)1; return (HANDLE)~(ULONG_PTR)1;
} }
@ -711,113 +710,6 @@ void WINAPI GetCurrentThreadStackLimits(ULONG_PTR *low, ULONG_PTR *high)
*high = (ULONG_PTR)NtCurrentTeb()->Tib.StackBase; *high = (ULONG_PTR)NtCurrentTeb()->Tib.StackBase;
} }
#ifdef __i386__
/***********************************************************************
* SetLastError (KERNEL32.@)
*/
/* void WINAPI SetLastError( DWORD error ); */
__ASM_STDCALL_FUNC( SetLastError, 4,
"movl 4(%esp),%eax\n\t"
".byte 0x64\n\t"
"movl %eax,0x34\n\t"
"ret $4" )
/***********************************************************************
* GetLastError (KERNEL32.@)
*/
/* DWORD WINAPI GetLastError(void); */
__ASM_STDCALL_FUNC( GetLastError, 0, ".byte 0x64\n\tmovl 0x34,%eax\n\tret" )
/***********************************************************************
* GetCurrentProcessId (KERNEL32.@)
*/
/* DWORD WINAPI GetCurrentProcessId(void) */
__ASM_STDCALL_FUNC( GetCurrentProcessId, 0, ".byte 0x64\n\tmovl 0x20,%eax\n\tret" )
/***********************************************************************
* GetCurrentThreadId (KERNEL32.@)
*/
/* DWORD WINAPI GetCurrentThreadId(void) */
__ASM_STDCALL_FUNC( GetCurrentThreadId, 0, ".byte 0x64\n\tmovl 0x24,%eax\n\tret" )
/***********************************************************************
* GetProcessHeap (KERNEL32.@)
*/
/* HANDLE WINAPI GetProcessHeap(void) */
__ASM_STDCALL_FUNC( GetProcessHeap, 0, ".byte 0x64\n\tmovl 0x30,%eax\n\tmovl 0x18(%eax),%eax\n\tret");
#elif defined(__x86_64__)
#ifdef __APPLE__
/***********************************************************************
* SetLastError (KERNEL32.@)
*/
/* void WINAPI SetLastError( DWORD error ); */
__ASM_STDCALL_FUNC( SetLastError, 8, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovl %ecx,0x68(%rax)\n\tret" );
/***********************************************************************
* GetLastError (KERNEL32.@)
*/
/* DWORD WINAPI GetLastError(void); */
__ASM_STDCALL_FUNC( GetLastError, 0, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovl 0x68(%rax),%eax\n\tret" );
/***********************************************************************
* GetCurrentProcessId (KERNEL32.@)
*/
/* DWORD WINAPI GetCurrentProcessId(void) */
__ASM_STDCALL_FUNC( GetCurrentProcessId, 0, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovl 0x40(%rax),%eax\n\tret" );
/***********************************************************************
* GetCurrentThreadId (KERNEL32.@)
*/
/* DWORD WINAPI GetCurrentThreadId(void) */
__ASM_STDCALL_FUNC( GetCurrentThreadId, 0, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovl 0x48(%rax),%eax\n\tret" );
/***********************************************************************
* GetProcessHeap (KERNEL32.@)
*/
/* HANDLE WINAPI GetProcessHeap(void) */
__ASM_STDCALL_FUNC( GetProcessHeap, 0, ".byte 0x65\n\tmovq 0x30,%rax\n\tmovq 0x60(%rax),%rax\n\tmovq 0x30(%rax),%rax\n\tret");
#else
/***********************************************************************
* SetLastError (KERNEL32.@)
*/
/* void WINAPI SetLastError( DWORD error ); */
__ASM_STDCALL_FUNC( SetLastError, 8, ".byte 0x65\n\tmovl %ecx,0x68\n\tret" );
/***********************************************************************
* GetLastError (KERNEL32.@)
*/
/* DWORD WINAPI GetLastError(void); */
__ASM_STDCALL_FUNC( GetLastError, 0, ".byte 0x65\n\tmovl 0x68,%eax\n\tret" );
/***********************************************************************
* GetCurrentProcessId (KERNEL32.@)
*/
/* DWORD WINAPI GetCurrentProcessId(void) */
__ASM_STDCALL_FUNC( GetCurrentProcessId, 0, ".byte 0x65\n\tmovl 0x40,%eax\n\tret" );
/***********************************************************************
* GetCurrentThreadId (KERNEL32.@)
*/
/* DWORD WINAPI GetCurrentThreadId(void) */
__ASM_STDCALL_FUNC( GetCurrentThreadId, 0, ".byte 0x65\n\tmovl 0x48,%eax\n\tret" );
/***********************************************************************
* GetProcessHeap (KERNEL32.@)
*/
/* HANDLE WINAPI GetProcessHeap(void) */
__ASM_STDCALL_FUNC( GetProcessHeap, 0, ".byte 0x65\n\tmovq 0x60,%rax\n\tmovq 0x30(%rax),%rax\n\tret");
#endif /* __APPLE__ */
#else /* __x86_64__ */
/********************************************************************** /**********************************************************************
* SetLastError (KERNEL32.@) * SetLastError (KERNEL32.@)
* *
@ -826,7 +718,7 @@ __ASM_STDCALL_FUNC( GetProcessHeap, 0, ".byte 0x65\n\tmovq 0x60,%rax\n\tmovq 0x3
* RETURNS * RETURNS
* Nothing. * Nothing.
*/ */
void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */ void WINAPI KERNEL32_SetLastError( DWORD error ) /* [in] Per-thread error code */
{ {
NtCurrentTeb()->LastErrorValue = error; NtCurrentTeb()->LastErrorValue = error;
} }
@ -839,7 +731,7 @@ void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
* RETURNS * RETURNS
* last-error code. * last-error code.
*/ */
DWORD WINAPI GetLastError(void) DWORD WINAPI KERNEL32_GetLastError(void)
{ {
return NtCurrentTeb()->LastErrorValue; return NtCurrentTeb()->LastErrorValue;
} }
@ -852,7 +744,7 @@ DWORD WINAPI GetLastError(void)
* RETURNS * RETURNS
* current process identifier * current process identifier
*/ */
DWORD WINAPI GetCurrentProcessId(void) DWORD WINAPI KERNEL32_GetCurrentProcessId(void)
{ {
return HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess); return HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess);
} }
@ -865,7 +757,7 @@ DWORD WINAPI GetCurrentProcessId(void)
* RETURNS * RETURNS
* current thread identifier * current thread identifier
*/ */
DWORD WINAPI GetCurrentThreadId(void) DWORD WINAPI KERNEL32_GetCurrentThreadId(void)
{ {
return HandleToULong(NtCurrentTeb()->ClientId.UniqueThread); return HandleToULong(NtCurrentTeb()->ClientId.UniqueThread);
} }
@ -873,13 +765,11 @@ DWORD WINAPI GetCurrentThreadId(void)
/*********************************************************************** /***********************************************************************
* GetProcessHeap (KERNEL32.@) * GetProcessHeap (KERNEL32.@)
*/ */
HANDLE WINAPI GetProcessHeap(void) HANDLE WINAPI KERNEL32_GetProcessHeap(void)
{ {
return NtCurrentTeb()->Peb->ProcessHeap; return NtCurrentTeb()->Peb->ProcessHeap;
} }
#endif /* __i386__ */
/************************************************************************* /*************************************************************************
* rtlmode_to_win32mode * rtlmode_to_win32mode
*/ */

View File

@ -122,11 +122,6 @@ extern const WCHAR system_dir[] DECLSPEC_HIDDEN;
extern void (WINAPI *kernel32_start_process)(LPTHREAD_START_ROUTINE,void*) DECLSPEC_HIDDEN; extern void (WINAPI *kernel32_start_process)(LPTHREAD_START_ROUTINE,void*) DECLSPEC_HIDDEN;
/* redefine these to make sure we don't reference kernel symbols */
#define GetProcessHeap() (NtCurrentTeb()->Peb->ProcessHeap)
#define GetCurrentProcessId() (HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess))
#define GetCurrentThreadId() (HandleToULong(NtCurrentTeb()->ClientId.UniqueThread))
/* Device IO */ /* Device IO */
extern NTSTATUS CDROM_DeviceIoControl(HANDLE hDevice, extern NTSTATUS CDROM_DeviceIoControl(HANDLE hDevice,
HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine, HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,

View File

@ -2106,10 +2106,8 @@ WINBASEAPI UINT WINAPI GetCurrentDirectoryW(UINT,LPWSTR);
WINADVAPI BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA); WINADVAPI BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA);
WINADVAPI BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW); WINADVAPI BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW);
#define GetCurrentHwProfile WINELIB_NAME_AW(GetCurrentHwProfile) #define GetCurrentHwProfile WINELIB_NAME_AW(GetCurrentHwProfile)
WINBASEAPI HANDLE WINAPI GetCurrentProcess(void);
WINBASEAPI DWORD WINAPI GetCurrentProcessorNumber(void); WINBASEAPI DWORD WINAPI GetCurrentProcessorNumber(void);
WINBASEAPI VOID WINAPI GetCurrentProcessorNumberEx(PPROCESSOR_NUMBER); WINBASEAPI VOID WINAPI GetCurrentProcessorNumberEx(PPROCESSOR_NUMBER);
WINBASEAPI HANDLE WINAPI GetCurrentThread(void);
#define GetCurrentTime() GetTickCount() #define GetCurrentTime() GetTickCount()
WINBASEAPI PUMS_CONTEXT WINAPI GetCurrentUmsThread(void); WINBASEAPI PUMS_CONTEXT WINAPI GetCurrentUmsThread(void);
WINBASEAPI BOOL WINAPI GetDefaultCommConfigA(LPCSTR,LPCOMMCONFIG,LPDWORD); WINBASEAPI BOOL WINAPI GetDefaultCommConfigA(LPCSTR,LPCOMMCONFIG,LPDWORD);
@ -3076,112 +3074,69 @@ static FORCEINLINE LONG WINAPI InterlockedDecrement( LONG volatile *dest )
#endif /* __i386__ */ #endif /* __i386__ */
/* A few optimizations for gcc */ #ifdef __WINESRC__
#if defined(__GNUC__) && !defined(__MINGW32__) && (defined(__i386__) || defined(__x86_64__)) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2))) static FORCEINLINE HANDLE WINAPI GetCurrentProcess(void)
static FORCEINLINE DWORD WINAPI GetLastError(void)
{ {
DWORD ret; return (HANDLE)~(ULONG_PTR)0;
#ifdef __x86_64__
#ifdef __APPLE__
DWORD* teb;
__asm__ __volatile__( ".byte 0x65\n\tmovq 0x30,%0" : "=r" (teb) );
ret = teb[0x68 / sizeof(DWORD)];
#else
__asm__ __volatile__( ".byte 0x65\n\tmovl 0x68,%0" : "=r" (ret) );
#endif
#else
__asm__ __volatile__( ".byte 0x64\n\tmovl 0x34,%0" : "=r" (ret) );
#endif
return ret;
} }
static FORCEINLINE DWORD WINAPI GetCurrentProcessId(void) static FORCEINLINE DWORD WINAPI GetCurrentProcessId(void)
{ {
DWORD ret; return HandleToULong( ((HANDLE *)NtCurrentTeb())[8] );
#ifdef __x86_64__ }
#ifdef __APPLE__
DWORD* teb; static FORCEINLINE HANDLE WINAPI GetCurrentThread(void)
__asm__ __volatile__( ".byte 0x65\n\tmovq 0x30,%0" : "=r" (teb) ); {
ret = teb[0x40 / sizeof(DWORD)]; return (HANDLE)~(ULONG_PTR)1;
#else
__asm__ __volatile__( ".byte 0x65\n\tmovl 0x40,%0" : "=r" (ret) );
#endif
#else
__asm__ __volatile__( ".byte 0x64\n\tmovl 0x20,%0" : "=r" (ret) );
#endif
return ret;
} }
static FORCEINLINE DWORD WINAPI GetCurrentThreadId(void) static FORCEINLINE DWORD WINAPI GetCurrentThreadId(void)
{ {
DWORD ret; return HandleToULong( ((HANDLE *)NtCurrentTeb())[9] );
#ifdef __x86_64__
#ifdef __APPLE__
DWORD* teb;
__asm__ __volatile__( ".byte 0x65\n\tmovq 0x30,%0" : "=r" (teb) );
ret = teb[0x48 / sizeof(DWORD)];
#else
__asm__ __volatile__( ".byte 0x65\n\tmovl 0x48,%0" : "=r" (ret) );
#endif
#else
__asm__ __volatile__( ".byte 0x64\n\tmovl 0x24,%0" : "=r" (ret) );
#endif
return ret;
} }
static FORCEINLINE void WINAPI SetLastError( DWORD err ) static FORCEINLINE DWORD WINAPI GetLastError(void)
{ {
#ifdef __x86_64__ return *(DWORD *)((void **)NtCurrentTeb() + 13);
#ifdef __APPLE__
DWORD* teb;
__asm__ __volatile__( ".byte 0x65\n\tmovq 0x30,%0" : "=r" (teb) );
teb[0x68 / sizeof(DWORD)] = err;
#else
__asm__ __volatile__( ".byte 0x65\n\tmovl %0,0x68" : : "r" (err) : "memory" );
#endif
#else
__asm__ __volatile__( ".byte 0x64\n\tmovl %0,0x34" : : "r" (err) : "memory" );
#endif
} }
static FORCEINLINE HANDLE WINAPI GetProcessHeap(void) static FORCEINLINE HANDLE WINAPI GetProcessHeap(void)
{ {
HANDLE *pdb; return ((HANDLE **)NtCurrentTeb())[12][6];
#ifdef __x86_64__
#ifdef __APPLE__
HANDLE** teb;
__asm__ __volatile__( ".byte 0x65\n\tmovq 0x30,%0" : "=r" (teb) );
pdb = teb[0x60 / sizeof(HANDLE*)];
#else
__asm__ __volatile__( ".byte 0x65\n\tmovq 0x60,%0" : "=r" (pdb) );
#endif
return pdb[0x30 / sizeof(HANDLE)]; /* get dword at offset 0x30 in pdb */
#else
__asm__ __volatile__( ".byte 0x64\n\tmovl 0x30,%0" : "=r" (pdb) );
return pdb[0x18 / sizeof(HANDLE)]; /* get dword at offset 0x18 in pdb */
#endif
} }
#else /* __GNUC__ */ static FORCEINLINE void WINAPI SetLastError( DWORD err )
{
*(DWORD *)((void **)NtCurrentTeb() + 13) = err;
}
#else /* __WINESRC__ */
WINBASEAPI HANDLE WINAPI GetCurrentProcess(void);
WINBASEAPI DWORD WINAPI GetCurrentProcessId(void); WINBASEAPI DWORD WINAPI GetCurrentProcessId(void);
WINBASEAPI HANDLE WINAPI GetCurrentThread(void);
WINBASEAPI DWORD WINAPI GetCurrentThreadId(void); WINBASEAPI DWORD WINAPI GetCurrentThreadId(void);
WINBASEAPI DWORD WINAPI GetLastError(void); WINBASEAPI DWORD WINAPI GetLastError(void);
WINBASEAPI HANDLE WINAPI GetProcessHeap(void); WINBASEAPI HANDLE WINAPI GetProcessHeap(void);
WINBASEAPI VOID WINAPI SetLastError(DWORD); WINBASEAPI VOID WINAPI SetLastError(DWORD);
#endif /* __GNUC__ */ #endif /* __WINESRC__ */
#ifdef __WINESRC__ static FORCEINLINE HANDLE WINAPI GetCurrentProcessToken(void)
#define GetCurrentProcess() ((HANDLE)~(ULONG_PTR)0) {
#define GetCurrentThread() ((HANDLE)~(ULONG_PTR)1) return (HANDLE)~(ULONG_PTR)3;
#endif }
#define GetCurrentProcessToken() ((HANDLE)~(ULONG_PTR)3) static FORCEINLINE HANDLE WINAPI GetCurrentThreadToken(void)
#define GetCurrentThreadToken() ((HANDLE)~(ULONG_PTR)4) {
#define GetCurrentThreadEffectiveToken() ((HANDLE)~(ULONG_PTR)5) return (HANDLE)~(ULONG_PTR)4;
}
static FORCEINLINE HANDLE WINAPI GetCurrentThreadEffectiveToken(void)
{
return (HANDLE)~(ULONG_PTR)5;
}
/* WinMain(entry point) must be declared in winbase.h. */ /* WinMain(entry point) must be declared in winbase.h. */
/* If this is not declared, we cannot compile many sources written with C++. */ /* If this is not declared, we cannot compile many sources written with C++. */