From 6ddd6e836cf0c1f592845296428dde28df851e50 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 8 Dec 2020 12:46:17 +0100 Subject: [PATCH] ntdll: Support the Android Java %fs register being a GDT selector. Signed-off-by: Alexandre Julliard --- dlls/ntdll/unix/loader.c | 1 + dlls/wineandroid.drv/device.c | 4 +++- dlls/wineandroid.drv/init.c | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 676027fe516..31cfb43d11f 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1671,6 +1671,7 @@ static jstring wine_init_jni( JNIEnv *env, jobject obj, jobjectArray cmdline, jo { unsigned short java_fs; __asm__( "mov %%fs,%0" : "=r" (java_fs) ); + if (!(java_fs & 4)) java_gdt_sel = java_fs; __asm__( "mov %0,%%fs" :: "r" (0) ); start_main_thread(); __asm__( "mov %0,%%fs" :: "r" (java_fs) ); diff --git a/dlls/wineandroid.drv/device.c b/dlls/wineandroid.drv/device.c index 45ceb0a5c0b..5bebc5c7901 100644 --- a/dlls/wineandroid.drv/device.c +++ b/dlls/wineandroid.drv/device.c @@ -258,9 +258,11 @@ static inline void wrap_java_call(void) { __asm__( "mov %0,%%fs" :: "r" (java_ static inline void unwrap_java_call(void) { __asm__( "mov %0,%%fs" :: "r" (orig_fs) ); } static inline void init_java_thread( JavaVM *java_vm ) { + java_fs = *p_java_gdt_sel; __asm__( "mov %%fs,%0" : "=r" (orig_fs) ); + __asm__( "mov %0,%%fs" :: "r" (java_fs) ); (*java_vm)->AttachCurrentThread( java_vm, &jni_env, 0 ); - __asm__( "mov %%fs,%0" : "=r" (java_fs) ); + if (!*p_java_gdt_sel) __asm__( "mov %%fs,%0" : "=r" (java_fs) ); __asm__( "mov %0,%%fs" :: "r" (orig_fs) ); } diff --git a/dlls/wineandroid.drv/init.c b/dlls/wineandroid.drv/init.c index 638fb5726c1..d6ca79a1416 100644 --- a/dlls/wineandroid.drv/init.c +++ b/dlls/wineandroid.drv/init.c @@ -622,6 +622,7 @@ static void load_android_libs(void) JavaVM **p_java_vm = NULL; jobject *p_java_object = NULL; +unsigned short *p_java_gdt_sel = NULL; static BOOL process_attach(void) { @@ -635,6 +636,7 @@ static BOOL process_attach(void) p_java_vm = dlsym( ntdll, "java_vm" ); p_java_object = dlsym( ntdll, "java_object" ); + p_java_gdt_sel = dlsym( ntdll, "java_gdt_sel" ); object = *p_java_object;