1*87d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*87d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*87d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*87d2adbcSAndrew Rist * distributed with this work for additional information
6*87d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*87d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*87d2adbcSAndrew Rist * "License"); you may not use this file except in compliance
9*87d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*87d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*87d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*87d2adbcSAndrew Rist * software distributed under the License is distributed on an
15*87d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*87d2adbcSAndrew Rist * KIND, either express or implied. See the License for the
17*87d2adbcSAndrew Rist * specific language governing permissions and limitations
18*87d2adbcSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*87d2adbcSAndrew Rist *************************************************************/
21*87d2adbcSAndrew Rist
22*87d2adbcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sal.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "system.h"
28cdf0e10cSrcweir #include <osl/process.h>
29cdf0e10cSrcweir #include <sal/types.h>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #ifdef __cplusplus
32cdf0e10cSrcweir extern "C" {
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir
35cdf0e10cSrcweir // Prototypes for initialization and deinitialization of SAL library
36cdf0e10cSrcweir
sal_detail_initialize(int argc,char ** argv)37cdf0e10cSrcweir void SAL_CALL sal_detail_initialize(int argc, char ** argv)
38cdf0e10cSrcweir {
39cdf0e10cSrcweir // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
40cdf0e10cSrcweir // SetDllDirectoryW(L"");
41cdf0e10cSrcweir // SetSearchPathMode(
42cdf0e10cSrcweir // BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
43cdf0e10cSrcweir HMODULE h = GetModuleHandleW(L"kernel32.dll");
44cdf0e10cSrcweir if (h != 0) {
45cdf0e10cSrcweir FARPROC p = GetProcAddress(h, "SetProcessDEPPolicy");
46cdf0e10cSrcweir if (p != 0) {
47cdf0e10cSrcweir reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x00000001);
48cdf0e10cSrcweir }
49cdf0e10cSrcweir p = GetProcAddress(h, "SetDllDirectoryW");
50cdf0e10cSrcweir if (p != 0) {
51cdf0e10cSrcweir reinterpret_cast< BOOL (WINAPI *)(LPCWSTR) >(p)(L"");
52cdf0e10cSrcweir }
53cdf0e10cSrcweir p = GetProcAddress(h, "SetSearchPathMode");
54cdf0e10cSrcweir if (p != 0) {
55cdf0e10cSrcweir reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x8001);
56cdf0e10cSrcweir }
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
59cdf0e10cSrcweir WSADATA wsaData;
60cdf0e10cSrcweir int error;
61cdf0e10cSrcweir WORD wVersionRequested;
62cdf0e10cSrcweir
63cdf0e10cSrcweir wVersionRequested = MAKEWORD(1, 1);
64cdf0e10cSrcweir
65cdf0e10cSrcweir error = WSAStartup(wVersionRequested, &wsaData);
66cdf0e10cSrcweir if ( 0 == error )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir WORD wMajorVersionRequired = 1;
69cdf0e10cSrcweir WORD wMinorVersionRequired = 1;
70cdf0e10cSrcweir
71cdf0e10cSrcweir if ((LOBYTE(wsaData.wVersion) < wMajorVersionRequired) ||
72cdf0e10cSrcweir (LOBYTE(wsaData.wVersion) == wMajorVersionRequired) &&
73cdf0e10cSrcweir ((HIBYTE(wsaData.wVersion) < wMinorVersionRequired)))
74cdf0e10cSrcweir {
75cdf0e10cSrcweir // How to handle a very unlikely error ???
76cdf0e10cSrcweir }
77cdf0e10cSrcweir }
78cdf0e10cSrcweir else
79cdf0e10cSrcweir {
80cdf0e10cSrcweir // How to handle a very unlikely error ???
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
83cdf0e10cSrcweir osl_setCommandArgs(argc, argv);
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
sal_detail_deinitialize()86cdf0e10cSrcweir void SAL_CALL sal_detail_deinitialize()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir if ( SOCKET_ERROR == WSACleanup() )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir // We should never reach this point or we did wrong elsewhere
91cdf0e10cSrcweir }
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir
95cdf0e10cSrcweir
96cdf0e10cSrcweir #ifdef __cplusplus
97cdf0e10cSrcweir } // extern "C"
98cdf0e10cSrcweir #endif
99