1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
35 #include <osl/process.h>
36 #include <sal/types.h>
42 // _set_invalid_parameter_handler appears unavailable with MinGW:
46 extern "C" void invalidParameterHandler(
47 wchar_t const * expression
, wchar_t const * function
, wchar_t const * file
,
48 unsigned int line
, SAL_UNUSED_PARAMETER
uintptr_t)
51 << L
"Invalid parameter in \"" << (expression
? expression
: L
"???")
52 << L
"\" (" << (function
? function
: L
"???") << ") at "
53 << (file
? file
: L
"???") << L
':' << line
<< std::endl
;
59 // Prototypes for initialization and deinitialization of SAL library
61 SAL_DLLPUBLIC
void SAL_CALL
sal_detail_initialize(int argc
, char ** argv
)
63 // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
64 // SetDllDirectoryW(L"");
66 // BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
67 HMODULE h
= GetModuleHandleW(L
"kernel32.dll");
71 p
= GetProcAddress(h
, "SetProcessDEPPolicy");
73 reinterpret_cast< BOOL (WINAPI
*)(DWORD
) >(p
)(0x00000001);
76 p
= GetProcAddress(h
, "SetDllDirectoryW");
78 reinterpret_cast< BOOL (WINAPI
*)(LPCWSTR
) >(p
)(L
"");
80 p
= GetProcAddress(h
, "SetSearchPathMode");
82 reinterpret_cast< BOOL (WINAPI
*)(DWORD
) >(p
)(0x8001);
88 WORD wVersionRequested
;
90 wVersionRequested
= MAKEWORD(1, 1);
92 error
= WSAStartup(wVersionRequested
, &wsaData
);
95 WORD wMajorVersionRequired
= 1;
96 WORD wMinorVersionRequired
= 1;
98 if ((LOBYTE(wsaData
.wVersion
) < wMajorVersionRequired
) ||
99 ((LOBYTE(wsaData
.wVersion
) == wMajorVersionRequired
) &&
100 ((HIBYTE(wsaData
.wVersion
) < wMinorVersionRequired
))))
102 // How to handle a very unlikely error ???
107 // How to handle a very unlikely error ???
110 #if defined _MSC_VER // appears unavailable with MinGW
111 // It appears that at least some jvm.dll versions can cause calls to
112 // _fileno(NULL), which leads to a call of the invalid parameter handler,
113 // and the default handler causes the application to crash, so install a
114 // "harmless" one (cf. fdo#38913):
115 _set_invalid_parameter_handler(&invalidParameterHandler
);
118 osl_setCommandArgs(argc
, argv
);
121 SAL_DLLPUBLIC
void SAL_CALL
sal_detail_deinitialize()
123 if ( SOCKET_ERROR
== WSACleanup() )
125 // We should never reach this point or we did wrong elsewhere
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */