From: Martin Storsjo Subject: [PATCH] RFC: ntdll: Restore x18 right before handing over control to new processes and threads Message-Id: <20190514131436.28498-1-martin@martin.st> Date: Tue, 14 May 2019 16:14:36 +0300 If building with a compiler that backs up and restores x18 on entry to MS ABI functions (clang patched with https://reviews.llvm.org/D61892), function calls to the libc can still clobber x18 after signal_init_thread, before handing control over to the native code. Alternatively, if built with a compiler that restores x18 after function calls to functions in other translation units (in order to protect the value of x18, see https://reviews.llvm.org/D61894), the function call to signal_init_thread will have x18 restored on return. Signed-off-by: Martin Storsjo --- dlls/ntdll/signal_arm64.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dlls/ntdll/signal_arm64.c b/dlls/ntdll/signal_arm64.c index 94520c95ce..1c3a49a80a 100644 --- a/dlls/ntdll/signal_arm64.c +++ b/dlls/ntdll/signal_arm64.c @@ -1126,6 +1126,7 @@ static void thread_startup( void *param ) void signal_start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend ) { struct startup_info info = { call_thread_entry_point, entry, arg, suspend }; + __asm__ __volatile__( "mov x18, %0" : : "r" (NtCurrentTeb()) ); wine_switch_to_stack( thread_startup, &info, NtCurrentTeb()->Tib.StackBase ); } @@ -1140,6 +1141,7 @@ void signal_start_thread( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend void signal_start_process( LPTHREAD_START_ROUTINE entry, BOOL suspend ) { struct startup_info info = { kernel32_start_process, entry, NtCurrentTeb()->Peb, suspend }; + __asm__ __volatile__( "mov x18, %0" : : "r" (NtCurrentTeb()) ); wine_switch_to_stack( thread_startup, &info, NtCurrentTeb()->Tib.StackBase ); } -- 2.17.1