summaryrefslogtreecommitdiff
path: root/jurt
diff options
context:
space:
mode:
authorJuergen Funk <juergen.funk_ml@cib.de>2014-11-27 11:35:57 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-12-05 14:18:26 +0100
commitb21f2439ad2681f906c63c2192ef141d9abb9e37 (patch)
tree321989ba6691988d6cf33f88605dacee7494ac74 /jurt
parent86b44e8e78716fbfc1783d692debcbb201fb9bd4 (diff)
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
Diffstat (limited to 'jurt')
-rw-r--r--jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c18
-rw-r--r--jurt/source/pipe/wrapper/wrapper.c51
2 files changed, 46 insertions, 23 deletions
diff --git a/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c
index d47bfa035c1f..6cdb2d1c1e4f 100644
--- a/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c
+++ b/jurt/source/pipe/com_sun_star_lib_connections_pipe_PipeConnection.c
@@ -21,15 +21,15 @@
#include "osl/security.h"
#include <osl/pipe.h>
-/* On Windows, jpipe.dll must not have dependencies on any other URE DLLs, as
- Java System.LoadLibrary could otherwise not load it. Therefore, on Windows,
- this code goes into a jpipx.dll that the jpipe.dll wrapper loads with
- LoadLibraryEx(LOAD_WITH_ALTERED_SEARCH_PATH). The function names in this
- wrapped code are truncated from the long JNICALL names, as JNICALL causes
- some "@N" with different numeric values for N (and probably different across
- 32 and 64 bit) to be added to the symbol names, which the calls to
- GetProcAddress in wrapper/wrapper.c would otheriwse have to take into
- account.
+/* On Windows, jpipe.dll must not have static dependencies on any other URE DLLs
+ (sal3.dll, uwinapi.dll), as Java System.LoadLibrary could otherwise not load
+ it. Therefore, on Windows, this code goes into a jpipx.dll that the jpipe.dll
+ wrapper loads with LoadLibraryEx(LOAD_WITH_ALTERED_SEARCH_PATH).
+ The function names in this wrapped code are truncated from the long JNICALL
+ names, as JNICALL causes some "@N" with different numeric values for
+ N (and probably different across 32 and 64 bit) to be added to the symbol
+ names, which the calls to GetProcAddress in wrapper/wrapper.c would otherwise
+ have to take into account.
*/
/*****************************************************************************/
diff --git a/jurt/source/pipe/wrapper/wrapper.c b/jurt/source/pipe/wrapper/wrapper.c
index e9969bc99378..632b19afa08a 100644
--- a/jurt/source/pipe/wrapper/wrapper.c
+++ b/jurt/source/pipe/wrapper/wrapper.c
@@ -26,27 +26,50 @@
#include "jni.h"
#include "sal/types.h"
-static HMODULE module;
-static FARPROC getFunction(char const * name) {
+static HMODULE module = NULL;
+static HINSTANCE hInstDLL = NULL;
+static CRITICAL_SECTION CriticalSection;
+
+void InitWrapper(void) {
+ #define MAXPATH 512
+ wchar_t path[MAXPATH];
+ DWORD size;
+
+ size = GetModuleFileNameW(hInstDLL, path, MAXPATH);
+ if (size == 0) {
+ abort();
+ }
+ path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */
+ module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
+ if (module == NULL) {
+ 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) {
- wchar_t path[32767];
- DWORD size;
- size = GetModuleFileNameW(hinstDLL, path, 32767);
- if (size == 0) {
- return FALSE;
- }
- path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */
- module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
- if (module == NULL) {
- return FALSE;
- }
+
+ if (fdwReason == DLL_PROCESS_ATTACH)
+ {
+ InitializeCriticalSection(&CriticalSection);
+ hInstDLL = hinstDLL;
}
+
return TRUE;
}