From 7f088b0b1387a3b54c438b839046afadf7948ef5 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 29 May 2023 23:09:59 +0200 Subject: [PATCH] ntdll: Use x18 for the TEB on ARM64. --- dlls/ntdll/ntdll.spec | 3 +-- dlls/ntdll/signal_arm64.c | 10 ---------- dlls/ntdll/unix/loader.c | 7 ------- dlls/ntdll/unix/signal_arm64.c | 24 ------------------------ include/winnt.h | 12 ++++++++++++ 5 files changed, 13 insertions(+), 43 deletions(-) diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 4ae544cdbb4..80277005672 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -196,7 +196,7 @@ @ stdcall -syscall NtCreateTransaction(ptr long ptr ptr long long long long ptr ptr) @ stdcall -syscall NtCreateUserProcess(ptr ptr long long ptr ptr long long ptr ptr ptr) # @ stub NtCreateWaitablePort -@ stdcall -arch=i386,arm64 NtCurrentTeb() +@ stdcall -arch=i386 NtCurrentTeb() @ stdcall -syscall NtDebugActiveProcess(long long) @ stdcall -syscall NtDebugContinue(long ptr long) @ stdcall -syscall NtDelayExecution(long ptr) @@ -1704,7 +1704,6 @@ @ extern -private __wine_syscall_dispatcher @ extern -private __wine_unix_call_dispatcher @ extern -private __wine_unixlib_handle -@ extern -arch=arm64 __wine_current_teb # Debugging @ stdcall -norelay __wine_dbg_write(ptr long) diff --git a/dlls/ntdll/signal_arm64.c b/dlls/ntdll/signal_arm64.c index 231660367b7..a19aa2f54b0 100644 --- a/dlls/ntdll/signal_arm64.c +++ b/dlls/ntdll/signal_arm64.c @@ -38,8 +38,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(seh); WINE_DECLARE_DEBUG_CHANNEL(threadname); -TEB * (* WINAPI __wine_current_teb)(void) = NULL; - typedef struct _SCOPE_TABLE { ULONG Count; @@ -1548,12 +1546,4 @@ __ASM_STDCALL_FUNC( DbgUserBreakPoint, 0, "brk #0xf000; ret" "\n\tnop; nop; nop; nop; nop; nop; nop; nop" "\n\tnop; nop; nop; nop; nop; nop" ); -/********************************************************************** - * NtCurrentTeb (NTDLL.@) - */ -TEB * WINAPI NtCurrentTeb(void) -{ - return __wine_current_teb(); -} - #endif /* __aarch64__ */ diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index dba8e2f614e..380ff18696f 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1834,13 +1834,6 @@ static void load_ntdll_functions( HMODULE module ) GET_FUNC( __wine_unixlib_handle ); *p__wine_unix_call_dispatcher = __wine_unix_call_dispatcher; *p__wine_unixlib_handle = (UINT_PTR)unix_call_funcs; -#ifdef __aarch64__ - { - void **p__wine_current_teb; - GET_FUNC( __wine_current_teb ); - *p__wine_current_teb = NtCurrentTeb; - } -#endif #undef GET_FUNC } diff --git a/dlls/ntdll/unix/signal_arm64.c b/dlls/ntdll/unix/signal_arm64.c index f232ecf92a9..dd492fef8fe 100644 --- a/dlls/ntdll/unix/signal_arm64.c +++ b/dlls/ntdll/unix/signal_arm64.c @@ -1694,22 +1694,6 @@ __ASM_GLOBAL_FUNC( signal_exit_thread, * __wine_syscall_dispatcher */ __ASM_GLOBAL_FUNC( __wine_syscall_dispatcher, - /* FIXME: use x18 directly instead */ - "stp x0, x1, [sp, #-96]!\n\t" - "stp x2, x3, [sp, #16]\n\t" - "stp x4, x5, [sp, #32]\n\t" - "stp x6, x7, [sp, #48]\n\t" - "stp x8, x9, [sp, #64]\n\t" - "str x30, [sp, #80]\n\t" - "bl " __ASM_NAME("NtCurrentTeb") "\n\t" - "mov x18, x0\n\t" - "ldp x2, x3, [sp, #16]\n\t" - "ldp x4, x5, [sp, #32]\n\t" - "ldp x6, x7, [sp, #48]\n\t" - "ldp x8, x9, [sp, #64]\n\t" - "ldr x30, [sp, #80]\n\t" - "ldp x0, x1, [sp], #96\n\t" - "ldr x10, [x18, #0x2f8]\n\t" /* arm64_thread_data()->syscall_frame */ "stp x18, x19, [x10, #0x90]\n\t" "stp x20, x21, [x10, #0xa0]\n\t" @@ -1822,14 +1806,6 @@ __ASM_GLOBAL_FUNC( __wine_syscall_dispatcher, * __wine_unix_call_dispatcher */ __ASM_GLOBAL_FUNC( __wine_unix_call_dispatcher, - /* FIXME: use x18 directly instead */ - "stp x0, x1, [sp, #-32]!\n\t" - "stp x2, x30,[sp, #16]\n\t" - "bl " __ASM_NAME("NtCurrentTeb") "\n\t" - "mov x18, x0\n\t" - "ldp x2, x30,[sp, #16]\n\t" - "ldp x0, x1, [sp], #32\n\t" - "ldr x10, [x18, #0x2f8]\n\t" /* arm64_thread_data()->syscall_frame */ "stp x18, x19, [x10, #0x90]\n\t" "stp x20, x21, [x10, #0xa0]\n\t" diff --git a/include/winnt.h b/include/winnt.h index 66746d7f6ae..1a7f65776a7 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -2398,6 +2398,18 @@ static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) { return (struct _TEB *)(ULONG_PTR)_MoveFromCoprocessor(15, 0, 13, 0, 2); } +#elif defined(__aarch64__) && defined(__MINGW32__) +register struct _TEB *__wine_current_teb __asm__("x18"); +static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) +{ + return __wine_current_teb; +} +#elif defined(__aarch64__) && defined(_MSC_VER) +#pragma intrinsic(__getReg) +static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void) +{ + return (struct _TEB *)__getReg(18); +} #elif defined(__GNUC__) extern struct _TEB * WINAPI NtCurrentTeb(void) __attribute__((pure)); #else -- 2.11.4.GIT