Alexandre Julliard : ntdll: Always inline NtCurrentTeb() on ARM.
Alexandre Julliard
julliard at winehq.org
Thu Jan 21 16:19:15 CST 2021
Module: wine
Branch: master
Commit: fc7c3b51ac27b0b4f19c871d0d5e298b5cf535ef
URL: https://source.winehq.org/git/wine.git/?a=commit;h=fc7c3b51ac27b0b4f19c871d0d5e298b5cf535ef
Author: Alexandre Julliard <julliard at winehq.org>
Date: Thu Jan 21 10:37:54 2021 +0100
ntdll: Always inline NtCurrentTeb() on ARM.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/ntdll.spec | 2 +-
dlls/ntdll/signal_arm.c | 8 --------
dlls/ntdll/unix/loader.c | 2 ++
dlls/ntdll/unix/signal_arm.c | 41 ++++++++---------------------------------
dlls/ntdll/unixlib.h | 4 +++-
include/winnt.h | 2 +-
tools/winebuild/import.c | 6 ++----
7 files changed, 17 insertions(+), 48 deletions(-)
diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec
index f3ec8fd9e39..9f7bfae76d3 100644
--- a/dlls/ntdll/ntdll.spec
+++ b/dlls/ntdll/ntdll.spec
@@ -189,7 +189,7 @@
@ stub NtCreateToken
@ stdcall -syscall NtCreateUserProcess(ptr ptr long long ptr ptr long long ptr ptr ptr)
# @ stub NtCreateWaitablePort
-@ stdcall -arch=win32,arm64 NtCurrentTeb()
+@ stdcall -arch=i386,arm64 NtCurrentTeb()
@ stdcall -syscall NtDebugActiveProcess(long long)
# @ stub NtDebugContinue
@ stdcall -syscall NtDelayExecution(long ptr)
diff --git a/dlls/ntdll/signal_arm.c b/dlls/ntdll/signal_arm.c
index 0461183460d..b1544ba15fe 100644
--- a/dlls/ntdll/signal_arm.c
+++ b/dlls/ntdll/signal_arm.c
@@ -304,12 +304,4 @@ __ASM_STDCALL_FUNC( DbgBreakPoint, 0, "bkpt #0; bx lr; nop; nop; nop; nop" );
*/
__ASM_STDCALL_FUNC( DbgUserBreakPoint, 0, "bkpt #0; bx lr; nop; nop; nop; nop" );
-/**********************************************************************
- * NtCurrentTeb (NTDLL.@)
- */
-TEB * WINAPI NtCurrentTeb(void)
-{
- return unix_funcs->NtCurrentTeb();
-}
-
#endif /* __arm__ */
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
index 31cfb43d11f..43c769f2d2a 100644
--- a/dlls/ntdll/unix/loader.c
+++ b/dlls/ntdll/unix/loader.c
@@ -1508,7 +1508,9 @@ static double CDECL ntdll_tan( double d ) { return tan( d ); }
*/
static struct unix_funcs unix_funcs =
{
+#ifdef __aarch64__
NtCurrentTeb,
+#endif
DbgUiIssueRemoteBreakin,
RtlGetSystemTimePrecise,
RtlWaitOnAddress,
diff --git a/dlls/ntdll/unix/signal_arm.c b/dlls/ntdll/unix/signal_arm.c
index 231f23e354a..385e4807990 100644
--- a/dlls/ntdll/unix/signal_arm.c
+++ b/dlls/ntdll/unix/signal_arm.c
@@ -68,8 +68,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(seh);
-static pthread_key_t teb_key;
-
/***********************************************************************
* signal context platform-specific definitions
@@ -584,23 +582,21 @@ static void setup_exception( ucontext_t *sigcontext, EXCEPTION_RECORD *rec )
* call_user_apc_dispatcher
*/
__ASM_GLOBAL_FUNC( call_user_apc_dispatcher,
- "mov r4, r0\n\t" /* context_ptr */
"mov r5, r1\n\t" /* ctx */
"mov r6, r2\n\t" /* arg1 */
"mov r7, r3\n\t" /* arg2 */
"ldr r8, [sp]\n\t" /* func */
"ldr r9, [sp, #4]\n\t" /* dispatcher */
- "bl " __ASM_NAME("NtCurrentTeb") "\n\t"
- "add r10, r0, #0x1d8\n\t" /* arm_thread_data()->syscall_frame */
- "movs r0, r4\n\t"
+ "mrc p15, 0, r10, c13, c0, 2\n\t" /* NtCurrentTeb() */
+ "cmp r0, #0\n\t" /* context_ptr */
"beq 1f\n\t"
"ldr r0, [r0, #0x38]\n\t" /* context_ptr->Sp */
"sub r0, r0, #0x1c8\n\t" /* sizeof(CONTEXT) + offsetof(frame,r4) */
"mov ip, #0\n\t"
- "str ip, [r10]\n\t"
+ "str ip, [r10, #0x1d8]\n\t" /* arm_thread_data()->syscall_frame */
"mov sp, r0\n\t"
"b 2f\n"
- "1:\tldr r0, [r10]\n\t"
+ "1:\tldr r0, [r10, #0x1d8]\n\t"
"sub r0, #0x1a0\n\t"
"mov sp, r0\n\t"
"mov r0, #3\n\t"
@@ -613,7 +609,7 @@ __ASM_GLOBAL_FUNC( call_user_apc_dispatcher,
"str r0, [sp, #4]\n\t" /* context.R0 = STATUS_USER_APC */
"mov r0, sp\n\t"
"mov ip, #0\n\t"
- "str ip, [r10]\n\t"
+ "str ip, [r10, #0x1d8]\n\t"
"2:\tmov r1, r5\n\t" /* ctx */
"mov r2, r6\n\t" /* arg1 */
"mov r3, r7\n\t" /* arg2 */
@@ -634,17 +630,10 @@ __ASM_GLOBAL_FUNC( call_raise_user_exception_dispatcher,
* call_user_exception_dispatcher
*/
__ASM_GLOBAL_FUNC( call_user_exception_dispatcher,
- "mov r4, r0\n\t"
- "mov r5, r1\n\t"
- "mov r6, r2\n\t"
- "bl " __ASM_NAME("NtCurrentTeb") "\n\t"
- "add r7, r0, #0x1d8\n\t" /* arm_thread_data()->syscall_frame */
- "mov r0, r4\n\t"
- "mov r1, r5\n\t"
- "mov r2, r6\n\t"
- "ldr r3, [r7]\n\t"
+ "mrc p15, 0, r7, c13, c0, 2\n\t" /* NtCurrentTeb() */
+ "ldr r3, [r7, #0x1d8]\n\t" /* arm_thread_data()->syscall_frame */
"mov ip, #0\n\t"
- "str ip, [r7]\n\t"
+ "str ip, [r7, #0x1d8]\n\t"
"add r3, r3, #8\n\t"
"ldm r3, {r5-r11}\n\t"
"ldr r4, [r3, #32]\n\t"
@@ -911,7 +900,6 @@ NTSTATUS WINAPI NtSetLdtEntries( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_E
*/
void signal_init_threading(void)
{
- pthread_key_create( &teb_key, NULL );
}
@@ -937,11 +925,7 @@ void signal_free_thread( TEB *teb )
*/
void signal_init_thread( TEB *teb )
{
-#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_8A__)
- /* Win32/ARM applications expect the TEB pointer to be in the TPIDRURW register. */
__asm__ __volatile__( "mcr p15, 0, %0, c13, c0, 2" : : "r" (teb) );
-#endif
- pthread_setspecific( teb_key, teb );
}
@@ -1057,13 +1041,4 @@ void signal_exit_thread( int status, void (*func)(int) )
call_thread_exit_func( status, func, NtCurrentTeb() );
}
-
-/**********************************************************************
- * NtCurrentTeb (NTDLL.@)
- */
-TEB * WINAPI NtCurrentTeb(void)
-{
- return pthread_getspecific( teb_key );
-}
-
#endif /* __arm__ */
diff --git a/dlls/ntdll/unixlib.h b/dlls/ntdll/unixlib.h
index 7ed3148e4c4..0847c7e07ca 100644
--- a/dlls/ntdll/unixlib.h
+++ b/dlls/ntdll/unixlib.h
@@ -27,12 +27,14 @@
struct _DISPATCHER_CONTEXT;
/* increment this when you change the function table */
-#define NTDLL_UNIXLIB_VERSION 106
+#define NTDLL_UNIXLIB_VERSION 107
struct unix_funcs
{
/* Nt* functions */
+#ifdef __aarch64__
TEB * (WINAPI *NtCurrentTeb)(void);
+#endif
/* other Win32 API functions */
NTSTATUS (WINAPI *DbgUiIssueRemoteBreakin)( HANDLE process );
diff --git a/include/winnt.h b/include/winnt.h
index 83f03b62ade..fba721f7f02 100644
--- a/include/winnt.h
+++ b/include/winnt.h
@@ -2801,7 +2801,7 @@ static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void)
{
return (struct _TEB *)__readgsqword(FIELD_OFFSET(NT_TIB, Self));
}
-#elif defined(__arm__) && defined(__MINGW32__)
+#elif defined(__arm__) && defined(__GNUC__)
static FORCEINLINE struct _TEB * WINAPI NtCurrentTeb(void)
{
struct _TEB *teb;
diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c
index f0730aa2fe7..2ff63c2265d 100644
--- a/tools/winebuild/import.c
+++ b/tools/winebuild/import.c
@@ -1577,10 +1577,8 @@ void output_syscalls( DLLSPEC *spec )
output( "\tcmp r4, r5\n" );
output( "\tbcs 5f\n" );
output( "\tsub sp, sp, #8\n" );
- output( "\tpush {r0-r3}\n" );
- output( "\tbl %s\n", asm_name("NtCurrentTeb") );
- output( "\tadd r7, r0, #0x1d8\n" ); /* arm_thread_data()->syscall_frame */
- output( "\tpop {r0-r3}\n" );
+ output( "\tmrc p15, 0, r7, c13, c0, 2\n" ); /* NtCurrentTeb() */
+ output( "\tadd r7, #0x1d8\n" ); /* arm_thread_data()->syscall_frame */
output( "\tmrs ip, CPSR\n" );
output( "\tstr ip, [sp, #4]\n" );
output( "\tstr sp, [r7]\n" ); /* syscall frame */
More information about the wine-cvs
mailing list