Commit 32fdffac authored by Alexandre Julliard's avatar Alexandre Julliard

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

This way the same code can be used on all platforms. Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent ff352c6d
......@@ -629,12 +629,12 @@
@ stdcall GetCurrentPackageFamilyName(ptr ptr)
@ stdcall GetCurrentPackageFullName(ptr ptr)
@ stdcall GetCurrentPackageId(ptr ptr)
@ stdcall -norelay GetCurrentProcess()
@ stdcall -norelay GetCurrentProcessId()
@ stdcall -norelay GetCurrentProcess() KERNEL32_GetCurrentProcess
@ stdcall -norelay GetCurrentProcessId() KERNEL32_GetCurrentProcessId
@ stdcall GetCurrentProcessorNumber() ntdll.NtGetCurrentProcessorNumber
@ stdcall GetCurrentProcessorNumberEx(ptr) ntdll.RtlGetCurrentProcessorNumberEx
@ stdcall -norelay GetCurrentThread()
@ stdcall -norelay GetCurrentThreadId()
@ stdcall -norelay GetCurrentThread() KERNEL32_GetCurrentThread
@ stdcall -norelay GetCurrentThreadId() KERNEL32_GetCurrentThreadId
@ stdcall GetCurrentThreadStackLimits(ptr ptr)
@ stdcall -arch=x86_64 GetCurrentUmsThread()
@ stdcall GetDateFormatA(long long ptr str ptr long)
......@@ -700,7 +700,7 @@
@ stub -i386 GetLSCallbackTemplate
@ stdcall GetLargePageMinimum()
@ stdcall GetLargestConsoleWindowSize(long)
@ stdcall GetLastError()
@ stdcall GetLastError() KERNEL32_GetLastError
@ stub GetLinguistLangSize
@ stdcall GetLocalTime(ptr)
@ stdcall GetLocaleInfoA(long long ptr long)
......@@ -780,7 +780,7 @@
@ stdcall GetProcessFlags(long)
# @ stub GetProcessGroupAffinity
@ stdcall GetProcessHandleCount(long ptr)
@ stdcall -norelay GetProcessHeap()
@ stdcall -norelay GetProcessHeap() KERNEL32_GetProcessHeap
@ stdcall GetProcessHeaps(long ptr)
@ stdcall GetProcessId(long)
@ stdcall GetProcessIdOfThread(long)
......@@ -1414,7 +1414,7 @@
@ stdcall SetHandleInformation(long long long)
@ stdcall SetInformationJobObject(long long ptr long)
@ stub SetLastConsoleEventActive
@ stdcall SetLastError(long)
@ stdcall SetLastError(long) KERNEL32_SetLastError
# @ stub SetLocalPrimaryComputerNameA
# @ stub SetLocalPrimaryComputerNameW
@ stdcall SetLocalTime(ptr)
......
......@@ -4258,8 +4258,7 @@ BOOL WINAPI IsWow64Process(HANDLE hProcess, PBOOL Wow64Process)
* RETURNS
* A handle representing the current process.
*/
#undef GetCurrentProcess
HANDLE WINAPI GetCurrentProcess(void)
HANDLE WINAPI KERNEL32_GetCurrentProcess(void)
{
return (HANDLE)~(ULONG_PTR)0;
}
......
......@@ -696,8 +696,7 @@ DWORD WINAPI GetProcessIdOfThread(HANDLE Thread)
* RETURNS
* Pseudohandle for the current thread
*/
#undef GetCurrentThread
HANDLE WINAPI GetCurrentThread(void)
HANDLE WINAPI KERNEL32_GetCurrentThread(void)
{
return (HANDLE)~(ULONG_PTR)1;
}
......@@ -711,113 +710,6 @@ void WINAPI GetCurrentThreadStackLimits(ULONG_PTR *low, ULONG_PTR *high)
*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.@)
*
......@@ -826,7 +718,7 @@ __ASM_STDCALL_FUNC( GetProcessHeap, 0, ".byte 0x65\n\tmovq 0x60,%rax\n\tmovq 0x3
* RETURNS
* 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;
}
......@@ -839,7 +731,7 @@ void WINAPI SetLastError( DWORD error ) /* [in] Per-thread error code */
* RETURNS
* last-error code.
*/
DWORD WINAPI GetLastError(void)
DWORD WINAPI KERNEL32_GetLastError(void)
{
return NtCurrentTeb()->LastErrorValue;
}
......@@ -852,7 +744,7 @@ DWORD WINAPI GetLastError(void)
* RETURNS
* current process identifier
*/
DWORD WINAPI GetCurrentProcessId(void)
DWORD WINAPI KERNEL32_GetCurrentProcessId(void)
{
return HandleToULong(NtCurrentTeb()->ClientId.UniqueProcess);
}
......@@ -865,7 +757,7 @@ DWORD WINAPI GetCurrentProcessId(void)
* RETURNS
* current thread identifier
*/
DWORD WINAPI GetCurrentThreadId(void)
DWORD WINAPI KERNEL32_GetCurrentThreadId(void)
{
return HandleToULong(NtCurrentTeb()->ClientId.UniqueThread);
}
......@@ -873,13 +765,11 @@ DWORD WINAPI GetCurrentThreadId(void)
/***********************************************************************
* GetProcessHeap (KERNEL32.@)
*/
HANDLE WINAPI GetProcessHeap(void)
HANDLE WINAPI KERNEL32_GetProcessHeap(void)
{
return NtCurrentTeb()->Peb->ProcessHeap;
}
#endif /* __i386__ */
/*************************************************************************
* rtlmode_to_win32mode
*/
......
......@@ -122,11 +122,6 @@ extern const WCHAR system_dir[] 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 */
extern NTSTATUS CDROM_DeviceIoControl(HANDLE hDevice,
HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
......
......@@ -2106,10 +2106,8 @@ WINBASEAPI UINT WINAPI GetCurrentDirectoryW(UINT,LPWSTR);
WINADVAPI BOOL WINAPI GetCurrentHwProfileA(LPHW_PROFILE_INFOA);
WINADVAPI BOOL WINAPI GetCurrentHwProfileW(LPHW_PROFILE_INFOW);
#define GetCurrentHwProfile WINELIB_NAME_AW(GetCurrentHwProfile)
WINBASEAPI HANDLE WINAPI GetCurrentProcess(void);
WINBASEAPI DWORD WINAPI GetCurrentProcessorNumber(void);
WINBASEAPI VOID WINAPI GetCurrentProcessorNumberEx(PPROCESSOR_NUMBER);
WINBASEAPI HANDLE WINAPI GetCurrentThread(void);
#define GetCurrentTime() GetTickCount()
WINBASEAPI PUMS_CONTEXT WINAPI GetCurrentUmsThread(void);
WINBASEAPI BOOL WINAPI GetDefaultCommConfigA(LPCSTR,LPCOMMCONFIG,LPDWORD);
......@@ -3076,112 +3074,69 @@ static FORCEINLINE LONG WINAPI InterlockedDecrement( LONG volatile *dest )
#endif /* __i386__ */
/* A few optimizations for gcc */
#if defined(__GNUC__) && !defined(__MINGW32__) && (defined(__i386__) || defined(__x86_64__)) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)))
#ifdef __WINESRC__
static FORCEINLINE DWORD WINAPI GetLastError(void)
static FORCEINLINE HANDLE WINAPI GetCurrentProcess(void)
{
DWORD ret;
#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;
return (HANDLE)~(ULONG_PTR)0;
}
static FORCEINLINE DWORD WINAPI GetCurrentProcessId(void)
{
DWORD ret;
#ifdef __x86_64__
#ifdef __APPLE__
DWORD* teb;
__asm__ __volatile__( ".byte 0x65\n\tmovq 0x30,%0" : "=r" (teb) );
ret = teb[0x40 / sizeof(DWORD)];
#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;
return HandleToULong( ((HANDLE *)NtCurrentTeb())[8] );
}
static FORCEINLINE HANDLE WINAPI GetCurrentThread(void)
{
return (HANDLE)~(ULONG_PTR)1;
}
static FORCEINLINE DWORD WINAPI GetCurrentThreadId(void)
{
DWORD ret;
#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;
return HandleToULong( ((HANDLE *)NtCurrentTeb())[9] );
}
static FORCEINLINE void WINAPI SetLastError( DWORD err )
static FORCEINLINE DWORD WINAPI GetLastError(void)
{
#ifdef __x86_64__
#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
return *(DWORD *)((void **)NtCurrentTeb() + 13);
}
static FORCEINLINE HANDLE WINAPI GetProcessHeap(void)
{
HANDLE *pdb;
#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
return ((HANDLE **)NtCurrentTeb())[12][6];
}
static FORCEINLINE void WINAPI SetLastError( DWORD err )
{
*(DWORD *)((void **)NtCurrentTeb() + 13) = err;
}
#else /* __GNUC__ */
#else /* __WINESRC__ */
WINBASEAPI HANDLE WINAPI GetCurrentProcess(void);
WINBASEAPI DWORD WINAPI GetCurrentProcessId(void);
WINBASEAPI HANDLE WINAPI GetCurrentThread(void);
WINBASEAPI DWORD WINAPI GetCurrentThreadId(void);
WINBASEAPI DWORD WINAPI GetLastError(void);
WINBASEAPI HANDLE WINAPI GetProcessHeap(void);
WINBASEAPI VOID WINAPI SetLastError(DWORD);
#endif /* __GNUC__ */
#endif /* __WINESRC__ */
#ifdef __WINESRC__
#define GetCurrentProcess() ((HANDLE)~(ULONG_PTR)0)
#define GetCurrentThread() ((HANDLE)~(ULONG_PTR)1)
#endif
static FORCEINLINE HANDLE WINAPI GetCurrentProcessToken(void)
{
return (HANDLE)~(ULONG_PTR)3;
}
static FORCEINLINE HANDLE WINAPI GetCurrentThreadToken(void)
{
return (HANDLE)~(ULONG_PTR)4;
}
#define GetCurrentProcessToken() ((HANDLE)~(ULONG_PTR)3)
#define GetCurrentThreadToken() ((HANDLE)~(ULONG_PTR)4)
#define GetCurrentThreadEffectiveToken() ((HANDLE)~(ULONG_PTR)5)
static FORCEINLINE HANDLE WINAPI GetCurrentThreadEffectiveToken(void)
{
return (HANDLE)~(ULONG_PTR)5;
}
/* WinMain(entry point) must be declared in winbase.h. */
/* If this is not declared, we cannot compile many sources written with C++. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment