--- Comment #14 from Norimasa Yamamoto <> ---
I thought a concept how to fix this issue.
(If prnsrv.exe really need to change jvm.dll's environment block.)

Before look a concept, important thing should be known.

- Where is a environment block (compiled with shared C runtime)?

compiled by MSVS 2015-2019
MODULE(exe, dll, so, ...)
  ==> api-ms-win-crt-environment-l1-1-0.dll!_wputenv (forwarder)
  ==> ucrtbase.dll!_wputenv (HERE!)

compiled by MSVC 7 to 12
  ==> msvcrXXX.dll!_wputenv (HERE!)
(XXX is one of 70, 80, 90, 100, 110, 120 (release)
 or with postfix "d" (debug))

Other compilers...
compiled by MSVC 6, MinGW w32api+GCC
  held in "msvcrt.dll"
compiled by compiled by Enbarcadero/Borland C++ Builder
  held in "ccYYXXXmt.dll"
compiled by Cygwin
  held in "cygwin1.dll"

On the other hand, without shared C runtime,
every modules hold in itself.

compiled by any compiler (include MSVS 2015-2019)
MODULE (HERE! (=builtin))

If MODULE did not export _wputenv or similar function,
it is impossible to change from OUTER MODULEs.
If OUTER MODULEs knew its address, it may can change
but it is very danger way.

-- end of section

Because prunsrv.exe is currently static linked with C runtime,
prunsrv.exe does not depending any shared C runtime.
So jvm.dll was loaded in prunsrv.exe process, prunsrv.exe can guess
jvm.dll's C runtime by GetModuleHandle.
(If prunsrv.exe were compiled with shared C runtime,
 prunsrv.exe may parse jvm.dll's Import Table in PE section,
 use CreateToolhelp32Snapshot related funtions to find loaded snapshot,
 ... From my experience, these are hard.)

(concept code)

- before
hmodUcrt = LoadLibraryExA("ucrtbase.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (hmodUcrt != NULL) {
  wputenv_ucrt =  (WPUTENV) GetProcAddress(hmodUcrt, "_wputenv");

- after
// jvm.dll should be loaded at this point.
// Guess jvm.dll was compiled by known compilers.
putenv_ucrt = NULL;
if (
     ((hmodUcrt = GetModuleHandle("ucrtbase.dll")) != NULL) // MSVC 14.0x-14.2x
  || ((hmodUcrt = GetModuleHandle("msvcr120.dll")) != NULL) // MSVC 12.0
  || ((hmodUcrt = GetModuleHandle("msvcr110.dll")) != NULL) // MSVC 10.0
  || ((hmodUcrt = GetModuleHandle("msvcr100.dll")) != NULL) // MSVC 10.0
  : (...)
  || ((hmodUcrt = GetModuleHandle("msvcrt.dll")) != NULL) // MSVC 6.0, GCC
) {
  putenv_ucrt =  (WPUTENV) GetProcAddress(hmodUcrt, "_wputenv");
} else {
  // jvm.dll was not compiled by known compilers.

You are receiving this mail because:
You are the assignee for the bug.
To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to