Kaydet (Commit) b21f2439 authored tarafından Juergen Funk's avatar Juergen Funk Kaydeden (comit) Stephan Bergmann

fdo#86745 - Possible exception/segfault in jurt jpipe.dll under Windows ...

- Remove the LoadLibrary from DLLMain (from windows not recommended)
   see http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583(v=vs.85).aspx
   in section Remarks
- Improve the comment why we need two dll's (jpipe.dll and jpipx.dll)
- Integrate CriticalSection, init in DllMain see link
   http://msdn.microsoft.com/en-us/library/windows/desktop/dn633971(v=vs.85).aspx#general_best_practices

Signed-off-by: Stephan Bergmann <sbergman@redhat.com>: removed the unsafe module
== NULL check around the critical section in getFunction

Change-Id: I6d5f655a4942437f6dc722236f6c371063e2c407
üst 86b44e8e
...@@ -21,15 +21,15 @@ ...@@ -21,15 +21,15 @@
#include "osl/security.h" #include "osl/security.h"
#include <osl/pipe.h> #include <osl/pipe.h>
/* On Windows, jpipe.dll must not have dependencies on any other URE DLLs, as /* On Windows, jpipe.dll must not have static dependencies on any other URE DLLs
Java System.LoadLibrary could otherwise not load it. Therefore, on Windows, (sal3.dll, uwinapi.dll), as Java System.LoadLibrary could otherwise not load
this code goes into a jpipx.dll that the jpipe.dll wrapper loads with it. Therefore, on Windows, this code goes into a jpipx.dll that the jpipe.dll
LoadLibraryEx(LOAD_WITH_ALTERED_SEARCH_PATH). The function names in this wrapper loads with LoadLibraryEx(LOAD_WITH_ALTERED_SEARCH_PATH).
wrapped code are truncated from the long JNICALL names, as JNICALL causes The function names in this wrapped code are truncated from the long JNICALL
some "@N" with different numeric values for N (and probably different across names, as JNICALL causes some "@N" with different numeric values for
32 and 64 bit) to be added to the symbol names, which the calls to N (and probably different across 32 and 64 bit) to be added to the symbol
GetProcAddress in wrapper/wrapper.c would otheriwse have to take into names, which the calls to GetProcAddress in wrapper/wrapper.c would otherwise
account. have to take into account.
*/ */
/*****************************************************************************/ /*****************************************************************************/
......
...@@ -26,27 +26,50 @@ ...@@ -26,27 +26,50 @@
#include "jni.h" #include "jni.h"
#include "sal/types.h" #include "sal/types.h"
static HMODULE module;
static FARPROC getFunction(char const * name) { static HMODULE module = NULL;
return GetProcAddress(module, name); static HINSTANCE hInstDLL = NULL;
} static CRITICAL_SECTION CriticalSection;
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { void InitWrapper(void) {
(void) lpvReserved; #define MAXPATH 512
if (fdwReason == DLL_PROCESS_ATTACH) { wchar_t path[MAXPATH];
wchar_t path[32767];
DWORD size; DWORD size;
size = GetModuleFileNameW(hinstDLL, path, 32767);
size = GetModuleFileNameW(hInstDLL, path, MAXPATH);
if (size == 0) { if (size == 0) {
return FALSE; abort();
} }
path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */ path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */
module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (module == NULL) { if (module == NULL) {
return FALSE; abort();
} }
}
static FARPROC getFunction(char const * name)
{
{
EnterCriticalSection(&CriticalSection);
if(module == NULL)
InitWrapper();
LeaveCriticalSection(&CriticalSection);
} }
return GetProcAddress(module, name);
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
(void) lpvReserved;
if (fdwReason == DLL_PROCESS_ATTACH)
{
InitializeCriticalSection(&CriticalSection);
hInstDLL = hinstDLL;
}
return TRUE; return TRUE;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment