Skip to content

Commit

Permalink
8316421: libjava should load shell32.dll eagerly
Browse files Browse the repository at this point in the history
Reviewed-by: erikj, jwaters, jvernee
  • Loading branch information
djelinski committed Sep 21, 2023
1 parent 378bcd5 commit 8cbe42b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
3 changes: 1 addition & 2 deletions make/modules/java.base/lib/CoreLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,14 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJAVA, \
LDFLAGS := $(LDFLAGS_JDKLIB) \
$(call SET_SHARED_LIBRARY_ORIGIN), \
LDFLAGS_macosx := -L$(SUPPORT_OUTPUTDIR)/native/$(MODULE)/, \
LDFLAGS_windows := -delayload:shell32.dll, \
LIBS_unix := -ljvm, \
LIBS_linux := $(LIBDL), \
LIBS_aix := $(LIBDL) $(LIBM),\
LIBS_macosx := -framework CoreFoundation \
-framework Foundation \
-framework SystemConfiguration, \
LIBS_windows := jvm.lib \
shell32.lib delayimp.lib \
shell32.lib ole32.lib \
advapi32.lib version.lib, \
))

Expand Down
40 changes: 5 additions & 35 deletions src/java.base/windows/native/libjava/java_props_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@
#include "locale_str.h"
#include "java_props.h"

#ifndef VER_PLATFORM_WIN32_WINDOWS
#define VER_PLATFORM_WIN32_WINDOWS 1
#endif

#ifndef PROCESSOR_ARCHITECTURE_AMD64
#define PROCESSOR_ARCHITECTURE_AMD64 9
#endif
Expand Down Expand Up @@ -213,39 +209,13 @@ getHomeFromShell32()
*/
static WCHAR *u_path = NULL;
if (u_path == NULL) {
HRESULT hr;

/*
* SHELL32 DLL is delay load DLL and we can use the trick with
* __try/__except block.
*/
__try {
/*
* For Windows Vista and later (or patched MS OS) we need to use
* [SHGetKnownFolderPath] call to avoid MAX_PATH length limitation.
* Shell32.dll (version 6.0.6000 or later)
*/
hr = SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DONT_VERIFY, NULL, &u_path);
} __except(EXCEPTION_EXECUTE_HANDLER) {
/* Exception: no [SHGetKnownFolderPath] entry */
hr = E_FAIL;
}
WCHAR *tmpPath = NULL;
HRESULT hr = SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DONT_VERIFY, NULL, &tmpPath);

if (FAILED(hr)) {
WCHAR path[MAX_PATH+1];

/* fallback solution for WinXP and Windows 2000 */
hr = SHGetFolderPathW(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, path);
if (FAILED(hr)) {
/* we can't find the shell folder. */
u_path = NULL;
} else {
/* Just to be sure about the path length until Windows Vista approach.
* [S_FALSE] could not be returned due to [CSIDL_FLAG_DONT_VERIFY] flag and UNICODE version.
*/
path[MAX_PATH] = 0;
u_path = _wcsdup(path);
}
CoTaskMemFree(tmpPath);
} else {
u_path = tmpPath;
}
}
return u_path;
Expand Down

1 comment on commit 8cbe42b

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.