1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sal/config.h"
26 #include <osl/process.h>
28 #include <sal/types.h>
35 void sal_initGlobalTimer();
37 // _set_invalid_parameter_handler appears unavailable with MinGW:
41 extern "C" void invalidParameterHandler(
42 wchar_t const * expression
, wchar_t const * function
, wchar_t const * file
,
43 unsigned int line
, SAL_UNUSED_PARAMETER
uintptr_t)
46 << L
"Invalid parameter in \"" << (expression
? expression
: L
"???")
47 << L
"\" (" << (function
? function
: L
"???") << ") at "
48 << (file
? file
: L
"???") << L
':' << line
<< std::endl
;
54 // Prototypes for initialization and deinitialization of SAL library
56 void sal_detail_initialize(int argc
, char ** argv
)
58 sal_initGlobalTimer();
59 // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
60 // SetDllDirectoryW(L"");
62 // BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
63 HMODULE h
= GetModuleHandleW(L
"kernel32.dll");
67 p
= GetProcAddress(h
, "SetProcessDEPPolicy");
69 reinterpret_cast< BOOL (WINAPI
*)(DWORD
) >(p
)(0x00000001);
72 p
= GetProcAddress(h
, "SetDllDirectoryW");
74 reinterpret_cast< BOOL (WINAPI
*)(LPCWSTR
) >(p
)(L
"");
76 p
= GetProcAddress(h
, "SetSearchPathMode");
78 reinterpret_cast< BOOL (WINAPI
*)(DWORD
) >(p
)(0x8001);
84 WORD wVersionRequested
;
86 wVersionRequested
= MAKEWORD(1, 1);
88 error
= WSAStartup(wVersionRequested
, &wsaData
);
91 WORD wMajorVersionRequired
= 1;
92 WORD wMinorVersionRequired
= 1;
94 if ((LOBYTE(wsaData
.wVersion
) < wMajorVersionRequired
) ||
95 ((LOBYTE(wsaData
.wVersion
) == wMajorVersionRequired
) &&
96 ((HIBYTE(wsaData
.wVersion
) < wMinorVersionRequired
))))
98 // How to handle a very unlikely error ???
103 // How to handle a very unlikely error ???
106 #if defined _MSC_VER // appears unavailable with MinGW
107 // It appears that at least some jvm.dll versions can cause calls to
108 // _fileno(NULL), which leads to a call of the invalid parameter handler,
109 // and the default handler causes the application to crash, so install a
110 // "harmless" one (cf. fdo#38913):
111 _set_invalid_parameter_handler(&invalidParameterHandler
);
114 osl_setCommandArgs(argc
, argv
);
117 void sal_detail_deinitialize()
119 if ( SOCKET_ERROR
== WSACleanup() )
121 // We should never reach this point or we did wrong elsewhere
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */