From: Twaik Yont <9674930+twaik@users.noreply.github.com> Wine frequently failed early during startup with: ``` err:virtual:virtual_alloc_first_teb wine: failed to map the shared user data: c0000018 ``` This appears to happen because the JVM can reserve address space that Wine later needs at a fixed address for the shared user data mapping. Initializing the virtual memory subsystem earlier reduces the chance of the JVM taking that range. Move `virtual_init()` from `wine_init_jni()` to `JNI_OnLoad()`, so it runs before other JNI activity during library load. Note that this change does not attempt to handle `virtual_init()` reentrance. When starting from an Activity `onCreate()` this is more likely due to the Android activity lifecycle, while calling it from `JNI_OnLoad()` is much less likely since it is only executed during library/class load. Signed-off-by: Twaik Yont <9674930+twaik@users.noreply.github.com> --- dlls/ntdll/unix/loader.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 28fc09cd354..31aab7cc314 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -1960,7 +1960,6 @@ static jstring wine_init_jni( JNIEnv *env, jobject obj, jobjectArray cmdline, jo main_argv = argv; init_paths(); - virtual_init(); init_environment(); #ifdef __i386__ @@ -1988,6 +1987,8 @@ jint JNI_OnLoad( JavaVM *vm, void *reserved ) JNIEnv *env; jclass class; + virtual_init(); + java_vm = vm; if ((*vm)->AttachCurrentThread( vm, &env, NULL ) != JNI_OK) return JNI_ERR; if (!(class = (*env)->FindClass( env, WINE_JAVA_CLASS ))) return JNI_ERR; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9874