8278753: Runtime crashes with access violation during JNI_CreateJavaVM call

Reviewed-by: dholmes, stuefe
This commit is contained in:
Yumin Qi 2022-02-03 18:02:40 +00:00
parent 86c24b319e
commit cda9c3011b
6 changed files with 35 additions and 31 deletions

View File

@ -1,5 +1,5 @@
#
# Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@ -158,6 +158,7 @@ JVM_IsSupportedJNIVersion
JVM_IsThreadAlive
JVM_IsVMGeneratedMethodIx
JVM_LatestUserDefinedLoader
JVM_LoadZipLibrary
JVM_LoadLibrary
JVM_LookupDefineClass
JVM_LookupLambdaProxyClassFromArchive

View File

@ -99,7 +99,8 @@ static FindEntry_t FindEntry = NULL;
static ReadEntry_t ReadEntry = NULL;
static GetNextEntry_t GetNextEntry = NULL;
static Crc32_t Crc32 = NULL;
int ClassLoader::_libzip_loaded = 0;
int ClassLoader::_libzip_loaded = 0;
void* ClassLoader::_zip_handle = NULL;
// Entry points for jimage.dll for loading jimage file entries
@ -942,20 +943,19 @@ void ClassLoader::load_zip_library() {
assert(ZipOpen == NULL, "should not load zip library twice");
char path[JVM_MAXPATHLEN];
char ebuf[1024];
void* handle = NULL;
if (os::dll_locate_lib(path, sizeof(path), Arguments::get_dll_dir(), "zip")) {
handle = os::dll_load(path, ebuf, sizeof ebuf);
_zip_handle = os::dll_load(path, ebuf, sizeof ebuf);
}
if (handle == NULL) {
if (_zip_handle == NULL) {
vm_exit_during_initialization("Unable to load zip library", path);
}
ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, dll_lookup(handle, "ZIP_Open", path));
ZipClose = CAST_TO_FN_PTR(ZipClose_t, dll_lookup(handle, "ZIP_Close", path));
FindEntry = CAST_TO_FN_PTR(FindEntry_t, dll_lookup(handle, "ZIP_FindEntry", path));
ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, dll_lookup(handle, "ZIP_ReadEntry", path));
GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, dll_lookup(handle, "ZIP_GetNextEntry", path));
Crc32 = CAST_TO_FN_PTR(Crc32_t, dll_lookup(handle, "ZIP_CRC32", path));
ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, dll_lookup(_zip_handle, "ZIP_Open", path));
ZipClose = CAST_TO_FN_PTR(ZipClose_t, dll_lookup(_zip_handle, "ZIP_Close", path));
FindEntry = CAST_TO_FN_PTR(FindEntry_t, dll_lookup(_zip_handle, "ZIP_FindEntry", path));
ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, dll_lookup(_zip_handle, "ZIP_ReadEntry", path));
GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, dll_lookup(_zip_handle, "ZIP_GetNextEntry", path));
Crc32 = CAST_TO_FN_PTR(Crc32_t, dll_lookup(_zip_handle, "ZIP_CRC32", path));
}
void ClassLoader::load_jimage_library() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -229,6 +229,9 @@ class ClassLoader: AllStatic {
bool check_for_duplicates);
CDS_ONLY(static void add_to_module_path_entries(const char* path,
ClassPathEntry* entry);)
// cache the zip library handle
static void* _zip_handle;
public:
CDS_ONLY(static ClassPathEntry* app_classpath_entries() {return _app_classpath_entries;})
CDS_ONLY(static ClassPathEntry* module_path_entries() {return _module_path_entries;})
@ -253,9 +256,10 @@ class ClassLoader: AllStatic {
private:
static int _libzip_loaded; // used to sync loading zip.
static void release_load_zip_library();
static inline void load_zip_library_if_needed();
public:
static inline void load_zip_library_if_needed();
static void* zip_library_handle() { return _zip_handle; }
static jzfile* open_zip_file(const char* canonical_path, char** error_msg, JavaThread* thread);
static ClassPathEntry* create_class_path_entry(JavaThread* current,
const char *path, const struct stat* st,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -150,6 +150,9 @@ JVM_ActiveProcessorCount(void);
JNIEXPORT jboolean JNICALL
JVM_IsUseContainerSupport(void);
JNIEXPORT void * JNICALL
JVM_LoadZipLibrary();
JNIEXPORT void * JNICALL
JVM_LoadLibrary(const char *name, jboolean throwException);

View File

@ -30,7 +30,7 @@
#include "cds/heapShared.hpp"
#include "cds/lambdaFormInvokers.hpp"
#include "classfile/classFileStream.hpp"
#include "classfile/classLoader.hpp"
#include "classfile/classLoader.inline.hpp"
#include "classfile/classLoaderData.hpp"
#include "classfile/classLoaderData.inline.hpp"
#include "classfile/classLoadInfo.hpp"
@ -3373,6 +3373,11 @@ JVM_END
// Library support ///////////////////////////////////////////////////////////////////////////
JVM_LEAF(void*, JVM_LoadZipLibrary())
ClassLoader::load_zip_library_if_needed();
return ClassLoader::zip_library_handle();
JVM_END
JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name, jboolean throwException))
//%note jvm_ct
char ebuf[1024];

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@ -30,6 +30,7 @@
*/
#include "jni.h"
#include "jvm.h"
#include "imageDecompressor.hpp"
#include "endian.hpp"
#ifdef WIN32
@ -57,24 +58,14 @@ static ZipInflateFully_t ZipInflateFully = NULL;
* @return the address of the entry point or NULL
*/
static void* findEntry(const char* name) {
void *addr = NULL;
#ifdef WIN32
HMODULE handle = GetModuleHandle("zip.dll");
if (handle == NULL) {
handle = LoadLibrary("zip.dll");
}
if (handle == NULL) {
return NULL;
}
addr = (void*) GetProcAddress(handle, name);
return addr;
#else
addr = dlopen(JNI_LIB_PREFIX "zip" JNI_LIB_SUFFIX, RTLD_GLOBAL|RTLD_LAZY);
void *addr = JVM_LoadZipLibrary();
if (addr == NULL) {
return NULL;
}
addr = dlsym(addr, name);
return addr;
#ifdef WIN32
return (void*) GetProcAddress(static_cast<HMODULE>(addr), name);
#else
return dlsym(addr, name);
#endif
}