Chris@16
|
1 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
|
Chris@16
|
4 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 //
|
Chris@16
|
7 // See http://www.boost.org/libs/interprocess for documentation.
|
Chris@16
|
8 //
|
Chris@16
|
9 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
10
|
Chris@101
|
11 #ifndef BOOST_INTERPROCESS_WIN32_API_HPP
|
Chris@101
|
12 #define BOOST_INTERPROCESS_WIN32_API_HPP
|
Chris@101
|
13
|
Chris@101
|
14 #ifndef BOOST_CONFIG_HPP
|
Chris@101
|
15 # include <boost/config.hpp>
|
Chris@101
|
16 #endif
|
Chris@101
|
17 #
|
Chris@101
|
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@101
|
19 # pragma once
|
Chris@101
|
20 #endif
|
Chris@16
|
21
|
Chris@16
|
22 #include <boost/interprocess/detail/config_begin.hpp>
|
Chris@16
|
23 #include <boost/interprocess/detail/workaround.hpp>
|
Chris@16
|
24 #include <boost/date_time/filetime_functions.hpp>
|
Chris@16
|
25 #include <cstddef>
|
Chris@16
|
26 #include <cstring>
|
Chris@16
|
27 #include <cstdlib>
|
Chris@16
|
28 #include <cstdio>
|
Chris@16
|
29
|
Chris@16
|
30 #include <boost/assert.hpp>
|
Chris@16
|
31 #include <string>
|
Chris@16
|
32 #include <vector>
|
Chris@16
|
33
|
Chris@101
|
34 #ifdef BOOST_USE_WINDOWS_H
|
Chris@101
|
35 #include <windows.h>
|
Chris@101
|
36 #include <Wbemidl.h>
|
Chris@101
|
37 #include <Objbase.h>
|
Chris@101
|
38 #include <Shlobj.h>
|
Chris@101
|
39 #endif
|
Chris@16
|
40
|
Chris@101
|
41 #if defined(_MSC_VER)
|
Chris@16
|
42 # pragma once
|
Chris@16
|
43 # pragma comment( lib, "Advapi32.lib" )
|
Chris@16
|
44 # pragma comment( lib, "oleaut32.lib" )
|
Chris@16
|
45 # pragma comment( lib, "Ole32.lib" )
|
Chris@16
|
46 # pragma comment( lib, "Psapi.lib" )
|
Chris@101
|
47 # pragma comment( lib, "Shell32.lib" ) //SHGetSpecialFolderPathA
|
Chris@16
|
48 #endif
|
Chris@16
|
49
|
Chris@101
|
50 #if defined (BOOST_INTERPROCESS_WINDOWS)
|
Chris@16
|
51 # include <cstdarg>
|
Chris@16
|
52 # include <boost/detail/interlocked.hpp>
|
Chris@16
|
53 #else
|
Chris@16
|
54 # error "This file can only be included in Windows OS"
|
Chris@16
|
55 #endif
|
Chris@16
|
56
|
Chris@101
|
57 //////////////////////////////////////////////////////////////////////////////
|
Chris@101
|
58 //
|
Chris@101
|
59 // Declaration of Windows structures or typedefs if BOOST_USE_WINDOWS_H is used
|
Chris@101
|
60 //
|
Chris@101
|
61 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
62
|
Chris@101
|
63 //Ignore -pedantic errors here (anonymous structs, etc.)
|
Chris@101
|
64 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
|
Chris@101
|
65 # pragma GCC diagnostic push
|
Chris@101
|
66 # pragma GCC diagnostic ignored "-pedantic"
|
Chris@101
|
67 #endif
|
Chris@101
|
68
|
Chris@101
|
69 namespace boost {
|
Chris@101
|
70 namespace interprocess {
|
Chris@101
|
71 namespace winapi {
|
Chris@101
|
72
|
Chris@101
|
73 //Own defines
|
Chris@101
|
74 static const unsigned long MaxPath = 260;
|
Chris@101
|
75
|
Chris@101
|
76 #ifndef BOOST_USE_WINDOWS_H
|
Chris@101
|
77
|
Chris@101
|
78 struct GUID_BIPC
|
Chris@101
|
79 {
|
Chris@101
|
80 unsigned long Data1;
|
Chris@101
|
81 unsigned short Data2;
|
Chris@101
|
82 unsigned short Data3;
|
Chris@101
|
83 unsigned char Data4[8];
|
Chris@101
|
84 };
|
Chris@101
|
85
|
Chris@101
|
86 #if defined(_MSC_VER)
|
Chris@101
|
87 #pragma warning (push)
|
Chris@101
|
88 #pragma warning (disable : 4201) // nonstandard extension used
|
Chris@101
|
89 #endif
|
Chris@101
|
90
|
Chris@101
|
91 struct decimal
|
Chris@101
|
92 {
|
Chris@101
|
93 unsigned short wReserved;
|
Chris@101
|
94 union {
|
Chris@101
|
95 struct {
|
Chris@101
|
96 unsigned char scale;
|
Chris@101
|
97 unsigned char sign;
|
Chris@101
|
98 };
|
Chris@101
|
99 unsigned short signscale;
|
Chris@101
|
100 };
|
Chris@101
|
101 unsigned long Hi32;
|
Chris@101
|
102 union {
|
Chris@101
|
103 struct {
|
Chris@101
|
104 unsigned long Lo32;
|
Chris@101
|
105 unsigned long Mid32;
|
Chris@101
|
106 };
|
Chris@101
|
107 ::boost::ulong_long_type Lo64;
|
Chris@101
|
108 };
|
Chris@101
|
109 };
|
Chris@101
|
110
|
Chris@101
|
111 typedef unsigned short *bstr;
|
Chris@101
|
112
|
Chris@101
|
113
|
Chris@101
|
114 struct wchar_variant
|
Chris@101
|
115 {
|
Chris@101
|
116 union
|
Chris@101
|
117 {
|
Chris@101
|
118 struct
|
Chris@101
|
119 {
|
Chris@101
|
120 unsigned short vt;
|
Chris@101
|
121 unsigned short wReserved1;
|
Chris@101
|
122 unsigned short wReserved2;
|
Chris@101
|
123 unsigned short wReserved3;
|
Chris@101
|
124 union
|
Chris@101
|
125 {
|
Chris@101
|
126 bstr bstrVal;
|
Chris@101
|
127 struct
|
Chris@101
|
128 {
|
Chris@101
|
129 void* pvRecord;
|
Chris@101
|
130 void* pRecInfo;
|
Chris@101
|
131 };
|
Chris@101
|
132 };
|
Chris@101
|
133 };
|
Chris@101
|
134 decimal decVal;
|
Chris@101
|
135 };
|
Chris@101
|
136 };
|
Chris@101
|
137
|
Chris@101
|
138 #if defined(_MSC_VER)
|
Chris@101
|
139 #pragma warning (pop)
|
Chris@101
|
140 #endif
|
Chris@101
|
141
|
Chris@101
|
142
|
Chris@101
|
143
|
Chris@101
|
144
|
Chris@101
|
145
|
Chris@101
|
146
|
Chris@101
|
147
|
Chris@101
|
148
|
Chris@101
|
149
|
Chris@101
|
150
|
Chris@101
|
151
|
Chris@101
|
152
|
Chris@101
|
153
|
Chris@101
|
154
|
Chris@101
|
155
|
Chris@101
|
156
|
Chris@101
|
157
|
Chris@101
|
158 struct IUnknown_BIPC
|
Chris@101
|
159 {
|
Chris@101
|
160 public:
|
Chris@101
|
161 virtual long __stdcall QueryInterface(
|
Chris@101
|
162 const GUID_BIPC &riid, // [in]
|
Chris@101
|
163 void **ppvObject) = 0; // [iid_is][out]
|
Chris@101
|
164
|
Chris@101
|
165 virtual unsigned long __stdcall AddRef (void) = 0;
|
Chris@101
|
166 virtual unsigned long __stdcall Release(void) = 0;
|
Chris@101
|
167 };
|
Chris@101
|
168
|
Chris@101
|
169 struct IWbemClassObject_BIPC : public IUnknown_BIPC
|
Chris@101
|
170 {
|
Chris@101
|
171 public:
|
Chris@101
|
172 virtual long __stdcall GetQualifierSet(
|
Chris@101
|
173 /* [out] */ void **ppQualSet) = 0;
|
Chris@101
|
174
|
Chris@101
|
175 virtual long __stdcall Get(
|
Chris@101
|
176 /* [string][in] */ const bstr wszName,
|
Chris@101
|
177 /* [in] */ long lFlags,
|
Chris@101
|
178 /* [unique][in][out] */ wchar_variant *pVal,
|
Chris@101
|
179 /* [unique][in][out] */ long *pType,
|
Chris@101
|
180 /* [unique][in][out] */ long *plFlavor) = 0;
|
Chris@101
|
181
|
Chris@101
|
182 virtual long __stdcall Put(
|
Chris@101
|
183 /* [string][in] */ const bstr wszName,
|
Chris@101
|
184 /* [in] */ long lFlags,
|
Chris@101
|
185 /* [in] */ wchar_variant *pVal,
|
Chris@101
|
186 /* [in] */ long Type) = 0;
|
Chris@101
|
187
|
Chris@101
|
188 virtual long __stdcall Delete(
|
Chris@101
|
189 /* [string][in] */ const bstr wszName) = 0;
|
Chris@101
|
190
|
Chris@101
|
191 virtual long __stdcall GetNames(
|
Chris@101
|
192 /* [string][in] */ const bstr wszQualifierName,
|
Chris@101
|
193 /* [in] */ long lFlags,
|
Chris@101
|
194 /* [in] */ wchar_variant *pQualifierVal,
|
Chris@101
|
195 /* [out] */ void * *pNames) = 0;
|
Chris@101
|
196
|
Chris@101
|
197 virtual long __stdcall BeginEnumeration(
|
Chris@101
|
198 /* [in] */ long lEnumFlags) = 0;
|
Chris@101
|
199
|
Chris@101
|
200 virtual long __stdcall Next(
|
Chris@101
|
201 /* [in] */ long lFlags,
|
Chris@101
|
202 /* [unique][in][out] */ bstr *strName,
|
Chris@101
|
203 /* [unique][in][out] */ wchar_variant *pVal,
|
Chris@101
|
204 /* [unique][in][out] */ long *pType,
|
Chris@101
|
205 /* [unique][in][out] */ long *plFlavor) = 0;
|
Chris@101
|
206
|
Chris@101
|
207 virtual long __stdcall EndEnumeration( void) = 0;
|
Chris@101
|
208
|
Chris@101
|
209 virtual long __stdcall GetPropertyQualifierSet(
|
Chris@101
|
210 /* [string][in] */ const bstr wszProperty,
|
Chris@101
|
211 /* [out] */ void **ppQualSet) = 0;
|
Chris@101
|
212
|
Chris@101
|
213 virtual long __stdcall Clone(
|
Chris@101
|
214 /* [out] */ IWbemClassObject_BIPC **ppCopy) = 0;
|
Chris@101
|
215
|
Chris@101
|
216 virtual long __stdcall GetObjectText(
|
Chris@101
|
217 /* [in] */ long lFlags,
|
Chris@101
|
218 /* [out] */ bstr *pstrObjectText) = 0;
|
Chris@101
|
219
|
Chris@101
|
220 virtual long __stdcall SpawnDerivedClass(
|
Chris@101
|
221 /* [in] */ long lFlags,
|
Chris@101
|
222 /* [out] */ IWbemClassObject_BIPC **ppNewClass) = 0;
|
Chris@101
|
223
|
Chris@101
|
224 virtual long __stdcall SpawnInstance(
|
Chris@101
|
225 /* [in] */ long lFlags,
|
Chris@101
|
226 /* [out] */ IWbemClassObject_BIPC **ppNewInstance) = 0;
|
Chris@101
|
227
|
Chris@101
|
228 virtual long __stdcall CompareTo(
|
Chris@101
|
229 /* [in] */ long lFlags,
|
Chris@101
|
230 /* [in] */ IWbemClassObject_BIPC *pCompareTo) = 0;
|
Chris@101
|
231
|
Chris@101
|
232 virtual long __stdcall GetPropertyOrigin(
|
Chris@101
|
233 /* [string][in] */ const bstr wszName,
|
Chris@101
|
234 /* [out] */ bstr *pstrClassName) = 0;
|
Chris@101
|
235
|
Chris@101
|
236 virtual long __stdcall InheritsFrom(
|
Chris@101
|
237 /* [in] */ const bstr strAncestor) = 0;
|
Chris@101
|
238
|
Chris@101
|
239 virtual long __stdcall GetMethod(
|
Chris@101
|
240 /* [string][in] */ const bstr wszName,
|
Chris@101
|
241 /* [in] */ long lFlags,
|
Chris@101
|
242 /* [out] */ IWbemClassObject_BIPC **ppInSignature,
|
Chris@101
|
243 /* [out] */ IWbemClassObject_BIPC **ppOutSignature) = 0;
|
Chris@101
|
244
|
Chris@101
|
245 virtual long __stdcall PutMethod(
|
Chris@101
|
246 /* [string][in] */ const bstr wszName,
|
Chris@101
|
247 /* [in] */ long lFlags,
|
Chris@101
|
248 /* [in] */ IWbemClassObject_BIPC *pInSignature,
|
Chris@101
|
249 /* [in] */ IWbemClassObject_BIPC *pOutSignature) = 0;
|
Chris@101
|
250
|
Chris@101
|
251 virtual long __stdcall DeleteMethod(
|
Chris@101
|
252 /* [string][in] */ const bstr wszName) = 0;
|
Chris@101
|
253
|
Chris@101
|
254 virtual long __stdcall BeginMethodEnumeration(
|
Chris@101
|
255 /* [in] */ long lEnumFlags) = 0;
|
Chris@101
|
256
|
Chris@101
|
257 virtual long __stdcall NextMethod(
|
Chris@101
|
258 /* [in] */ long lFlags,
|
Chris@101
|
259 /* [unique][in][out] */ bstr *pstrName,
|
Chris@101
|
260 /* [unique][in][out] */ IWbemClassObject_BIPC **ppInSignature,
|
Chris@101
|
261 /* [unique][in][out] */ IWbemClassObject_BIPC **ppOutSignature) = 0;
|
Chris@101
|
262
|
Chris@101
|
263 virtual long __stdcall EndMethodEnumeration( void) = 0;
|
Chris@101
|
264
|
Chris@101
|
265 virtual long __stdcall GetMethodQualifierSet(
|
Chris@101
|
266 /* [string][in] */ const bstr wszMethod,
|
Chris@101
|
267 /* [out] */ void **ppQualSet) = 0;
|
Chris@101
|
268
|
Chris@101
|
269 virtual long __stdcall GetMethodOrigin(
|
Chris@101
|
270 /* [string][in] */ const bstr wszMethodName,
|
Chris@101
|
271 /* [out] */ bstr *pstrClassName) = 0;
|
Chris@101
|
272
|
Chris@101
|
273 };
|
Chris@101
|
274
|
Chris@101
|
275 struct IWbemContext_BIPC : public IUnknown_BIPC
|
Chris@101
|
276 {
|
Chris@101
|
277 public:
|
Chris@101
|
278 virtual long __stdcall Clone(
|
Chris@101
|
279 /* [out] */ IWbemContext_BIPC **ppNewCopy) = 0;
|
Chris@101
|
280
|
Chris@101
|
281 virtual long __stdcall GetNames(
|
Chris@101
|
282 /* [in] */ long lFlags,
|
Chris@101
|
283 /* [out] */ void * *pNames) = 0;
|
Chris@101
|
284
|
Chris@101
|
285 virtual long __stdcall BeginEnumeration(
|
Chris@101
|
286 /* [in] */ long lFlags) = 0;
|
Chris@101
|
287
|
Chris@101
|
288 virtual long __stdcall Next(
|
Chris@101
|
289 /* [in] */ long lFlags,
|
Chris@101
|
290 /* [out] */ bstr *pstrName,
|
Chris@101
|
291 /* [out] */ wchar_variant *pValue) = 0;
|
Chris@101
|
292
|
Chris@101
|
293 virtual long __stdcall EndEnumeration( void) = 0;
|
Chris@101
|
294
|
Chris@101
|
295 virtual long __stdcall SetValue(
|
Chris@101
|
296 /* [string][in] */ const bstr wszName,
|
Chris@101
|
297 /* [in] */ long lFlags,
|
Chris@101
|
298 /* [in] */ wchar_variant *pValue) = 0;
|
Chris@101
|
299
|
Chris@101
|
300 virtual long __stdcall GetValue(
|
Chris@101
|
301 /* [string][in] */ const bstr wszName,
|
Chris@101
|
302 /* [in] */ long lFlags,
|
Chris@101
|
303 /* [out] */ wchar_variant *pValue) = 0;
|
Chris@101
|
304
|
Chris@101
|
305 virtual long __stdcall DeleteValue(
|
Chris@101
|
306 /* [string][in] */ const bstr wszName,
|
Chris@101
|
307 /* [in] */ long lFlags) = 0;
|
Chris@101
|
308
|
Chris@101
|
309 virtual long __stdcall DeleteAll( void) = 0;
|
Chris@101
|
310
|
Chris@101
|
311 };
|
Chris@101
|
312
|
Chris@101
|
313
|
Chris@101
|
314 struct IEnumWbemClassObject_BIPC : public IUnknown_BIPC
|
Chris@101
|
315 {
|
Chris@101
|
316 public:
|
Chris@101
|
317 virtual long __stdcall Reset( void) = 0;
|
Chris@101
|
318
|
Chris@101
|
319 virtual long __stdcall Next(
|
Chris@101
|
320 /* [in] */ long lTimeout,
|
Chris@101
|
321 /* [in] */ unsigned long uCount,
|
Chris@101
|
322 /* [length_is][size_is][out] */ IWbemClassObject_BIPC **apObjects,
|
Chris@101
|
323 /* [out] */ unsigned long *puReturned) = 0;
|
Chris@101
|
324
|
Chris@101
|
325 virtual long __stdcall NextAsync(
|
Chris@101
|
326 /* [in] */ unsigned long uCount,
|
Chris@101
|
327 /* [in] */ void *pSink) = 0;
|
Chris@101
|
328
|
Chris@101
|
329 virtual long __stdcall Clone(
|
Chris@101
|
330 /* [out] */ void **ppEnum) = 0;
|
Chris@101
|
331
|
Chris@101
|
332 virtual long __stdcall Skip(
|
Chris@101
|
333 /* [in] */ long lTimeout,
|
Chris@101
|
334 /* [in] */ unsigned long nCount) = 0;
|
Chris@101
|
335
|
Chris@101
|
336 };
|
Chris@101
|
337
|
Chris@101
|
338 struct IWbemServices_BIPC : public IUnknown_BIPC
|
Chris@101
|
339 {
|
Chris@101
|
340 public:
|
Chris@101
|
341 virtual long __stdcall OpenNamespace(
|
Chris@101
|
342 /* [in] */ const bstr strNamespace,
|
Chris@101
|
343 /* [in] */ long lFlags,
|
Chris@101
|
344 /* [in] */ void *pCtx,
|
Chris@101
|
345 /* [unique][in][out] */ void **ppWorkingNamespace,
|
Chris@101
|
346 /* [unique][in][out] */ void **ppResult) = 0;
|
Chris@101
|
347
|
Chris@101
|
348 virtual long __stdcall CancelAsyncCall(
|
Chris@101
|
349 /* [in] */ void *pSink) = 0;
|
Chris@101
|
350
|
Chris@101
|
351 virtual long __stdcall QueryObjectSink(
|
Chris@101
|
352 /* [in] */ long lFlags,
|
Chris@101
|
353 /* [out] */ void **ppResponseHandler) = 0;
|
Chris@101
|
354
|
Chris@101
|
355 virtual long __stdcall GetObject(
|
Chris@101
|
356 /* [in] */ const bstr strObjectPath,
|
Chris@101
|
357 /* [in] */ long lFlags,
|
Chris@101
|
358 /* [in] */ void *pCtx,
|
Chris@101
|
359 /* [unique][in][out] */ void **ppObject,
|
Chris@101
|
360 /* [unique][in][out] */ void **ppCallResult) = 0;
|
Chris@101
|
361
|
Chris@101
|
362 virtual long __stdcall GetObjectAsync(
|
Chris@101
|
363 /* [in] */ const bstr strObjectPath,
|
Chris@101
|
364 /* [in] */ long lFlags,
|
Chris@101
|
365 /* [in] */ void *pCtx,
|
Chris@101
|
366 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
367
|
Chris@101
|
368 virtual long __stdcall PutClass(
|
Chris@101
|
369 /* [in] */ IWbemClassObject_BIPC *pObject,
|
Chris@101
|
370 /* [in] */ long lFlags,
|
Chris@101
|
371 /* [in] */ void *pCtx,
|
Chris@101
|
372 /* [unique][in][out] */ void **ppCallResult) = 0;
|
Chris@101
|
373
|
Chris@101
|
374 virtual long __stdcall PutClassAsync(
|
Chris@101
|
375 /* [in] */ IWbemClassObject_BIPC *pObject,
|
Chris@101
|
376 /* [in] */ long lFlags,
|
Chris@101
|
377 /* [in] */ void *pCtx,
|
Chris@101
|
378 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
379
|
Chris@101
|
380 virtual long __stdcall DeleteClass(
|
Chris@101
|
381 /* [in] */ const bstr strClass,
|
Chris@101
|
382 /* [in] */ long lFlags,
|
Chris@101
|
383 /* [in] */ void *pCtx,
|
Chris@101
|
384 /* [unique][in][out] */ void **ppCallResult) = 0;
|
Chris@101
|
385
|
Chris@101
|
386 virtual long __stdcall DeleteClassAsync(
|
Chris@101
|
387 /* [in] */ const bstr strClass,
|
Chris@101
|
388 /* [in] */ long lFlags,
|
Chris@101
|
389 /* [in] */ void *pCtx,
|
Chris@101
|
390 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
391
|
Chris@101
|
392 virtual long __stdcall CreateClassEnum(
|
Chris@101
|
393 /* [in] */ const bstr strSuperclass,
|
Chris@101
|
394 /* [in] */ long lFlags,
|
Chris@101
|
395 /* [in] */ void *pCtx,
|
Chris@101
|
396 /* [out] */ void **ppEnum) = 0;
|
Chris@101
|
397
|
Chris@101
|
398 virtual long __stdcall CreateClassEnumAsync(
|
Chris@101
|
399 /* [in] */ const bstr strSuperclass,
|
Chris@101
|
400 /* [in] */ long lFlags,
|
Chris@101
|
401 /* [in] */ void *pCtx,
|
Chris@101
|
402 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
403
|
Chris@101
|
404 virtual long __stdcall PutInstance(
|
Chris@101
|
405 /* [in] */ void *pInst,
|
Chris@101
|
406 /* [in] */ long lFlags,
|
Chris@101
|
407 /* [in] */ void *pCtx,
|
Chris@101
|
408 /* [unique][in][out] */ void **ppCallResult) = 0;
|
Chris@101
|
409
|
Chris@101
|
410 virtual long __stdcall PutInstanceAsync(
|
Chris@101
|
411 /* [in] */ void *pInst,
|
Chris@101
|
412 /* [in] */ long lFlags,
|
Chris@101
|
413 /* [in] */ void *pCtx,
|
Chris@101
|
414 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
415
|
Chris@101
|
416 virtual long __stdcall DeleteInstance(
|
Chris@101
|
417 /* [in] */ const bstr strObjectPath,
|
Chris@101
|
418 /* [in] */ long lFlags,
|
Chris@101
|
419 /* [in] */ void *pCtx,
|
Chris@101
|
420 /* [unique][in][out] */ void **ppCallResult) = 0;
|
Chris@101
|
421
|
Chris@101
|
422 virtual long __stdcall DeleteInstanceAsync(
|
Chris@101
|
423 /* [in] */ const bstr strObjectPath,
|
Chris@101
|
424 /* [in] */ long lFlags,
|
Chris@101
|
425 /* [in] */ void *pCtx,
|
Chris@101
|
426 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
427
|
Chris@101
|
428 virtual long __stdcall CreateInstanceEnum(
|
Chris@101
|
429 /* [in] */ const bstr strFilter,
|
Chris@101
|
430 /* [in] */ long lFlags,
|
Chris@101
|
431 /* [in] */ void *pCtx,
|
Chris@101
|
432 /* [out] */ void **ppEnum) = 0;
|
Chris@101
|
433
|
Chris@101
|
434 virtual long __stdcall CreateInstanceEnumAsync(
|
Chris@101
|
435 /* [in] */ const bstr strFilter,
|
Chris@101
|
436 /* [in] */ long lFlags,
|
Chris@101
|
437 /* [in] */ void *pCtx,
|
Chris@101
|
438 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
439
|
Chris@101
|
440 virtual long __stdcall ExecQuery(
|
Chris@101
|
441 /* [in] */ const bstr strQueryLanguage,
|
Chris@101
|
442 /* [in] */ const bstr strQuery,
|
Chris@101
|
443 /* [in] */ long lFlags,
|
Chris@101
|
444 /* [in] */ IWbemContext_BIPC *pCtx,
|
Chris@101
|
445 /* [out] */ IEnumWbemClassObject_BIPC **ppEnum) = 0;
|
Chris@101
|
446
|
Chris@101
|
447 virtual long __stdcall ExecQueryAsync(
|
Chris@101
|
448 /* [in] */ const bstr strQueryLanguage,
|
Chris@101
|
449 /* [in] */ const bstr strQuery,
|
Chris@101
|
450 /* [in] */ long lFlags,
|
Chris@101
|
451 /* [in] */ IWbemContext_BIPC *pCtx,
|
Chris@101
|
452 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
453
|
Chris@101
|
454 virtual long __stdcall ExecNotificationQuery(
|
Chris@101
|
455 /* [in] */ const bstr strQueryLanguage,
|
Chris@101
|
456 /* [in] */ const bstr strQuery,
|
Chris@101
|
457 /* [in] */ long lFlags,
|
Chris@101
|
458 /* [in] */ IWbemContext_BIPC *pCtx,
|
Chris@101
|
459 /* [out] */ void **ppEnum) = 0;
|
Chris@101
|
460
|
Chris@101
|
461 virtual long __stdcall ExecNotificationQueryAsync(
|
Chris@101
|
462 /* [in] */ const bstr strQueryLanguage,
|
Chris@101
|
463 /* [in] */ const bstr strQuery,
|
Chris@101
|
464 /* [in] */ long lFlags,
|
Chris@101
|
465 /* [in] */ IWbemContext_BIPC *pCtx,
|
Chris@101
|
466 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
467
|
Chris@101
|
468 virtual long __stdcall ExecMethod(
|
Chris@101
|
469 /* [in] */ const bstr strObjectPath,
|
Chris@101
|
470 /* [in] */ const bstr strMethodName,
|
Chris@101
|
471 /* [in] */ long lFlags,
|
Chris@101
|
472 /* [in] */ IWbemContext_BIPC *pCtx,
|
Chris@101
|
473 /* [in] */ IWbemClassObject_BIPC *pInParams,
|
Chris@101
|
474 /* [unique][in][out] */ IWbemClassObject_BIPC **ppOutParams,
|
Chris@101
|
475 /* [unique][in][out] */ void **ppCallResult) = 0;
|
Chris@101
|
476
|
Chris@101
|
477 virtual long __stdcall ExecMethodAsync(
|
Chris@101
|
478 /* [in] */ const bstr strObjectPath,
|
Chris@101
|
479 /* [in] */ const bstr strMethodName,
|
Chris@101
|
480 /* [in] */ long lFlags,
|
Chris@101
|
481 /* [in] */ IWbemContext_BIPC *pCtx,
|
Chris@101
|
482 /* [in] */ IWbemClassObject_BIPC *pInParams,
|
Chris@101
|
483 /* [in] */ void *pResponseHandler) = 0;
|
Chris@101
|
484
|
Chris@101
|
485 };
|
Chris@101
|
486
|
Chris@101
|
487 struct IWbemLocator_BIPC : public IUnknown_BIPC
|
Chris@101
|
488 {
|
Chris@101
|
489 public:
|
Chris@101
|
490 virtual long __stdcall ConnectServer(
|
Chris@101
|
491 /* [in] */ const bstr strNetworkResource,
|
Chris@101
|
492 /* [in] */ const bstr strUser,
|
Chris@101
|
493 /* [in] */ const bstr strPassword,
|
Chris@101
|
494 /* [in] */ const bstr strLocale,
|
Chris@101
|
495 /* [in] */ long lSecurityFlags,
|
Chris@101
|
496 /* [in] */ const bstr strAuthority,
|
Chris@101
|
497 /* [in] */ void *pCtx,
|
Chris@101
|
498 /* [out] */ IWbemServices_BIPC **ppNamespace) = 0;
|
Chris@101
|
499
|
Chris@101
|
500 };
|
Chris@101
|
501
|
Chris@101
|
502 struct interprocess_overlapped
|
Chris@101
|
503 {
|
Chris@101
|
504 unsigned long *internal;
|
Chris@101
|
505 unsigned long *internal_high;
|
Chris@101
|
506 union {
|
Chris@101
|
507 struct {
|
Chris@101
|
508 unsigned long offset;
|
Chris@101
|
509 unsigned long offset_high;
|
Chris@101
|
510 }dummy;
|
Chris@101
|
511 void *pointer;
|
Chris@101
|
512 };
|
Chris@101
|
513
|
Chris@101
|
514 void *h_event;
|
Chris@101
|
515 };
|
Chris@101
|
516
|
Chris@101
|
517
|
Chris@101
|
518 struct interprocess_filetime
|
Chris@101
|
519 {
|
Chris@101
|
520 unsigned long dwLowDateTime;
|
Chris@101
|
521 unsigned long dwHighDateTime;
|
Chris@101
|
522 };
|
Chris@101
|
523
|
Chris@101
|
524 struct win32_find_data
|
Chris@101
|
525 {
|
Chris@101
|
526 unsigned long dwFileAttributes;
|
Chris@101
|
527 interprocess_filetime ftCreationTime;
|
Chris@101
|
528 interprocess_filetime ftLastAccessTime;
|
Chris@101
|
529 interprocess_filetime ftLastWriteTime;
|
Chris@101
|
530 unsigned long nFileSizeHigh;
|
Chris@101
|
531 unsigned long nFileSizeLow;
|
Chris@101
|
532 unsigned long dwReserved0;
|
Chris@101
|
533 unsigned long dwReserved1;
|
Chris@101
|
534 char cFileName[MaxPath];
|
Chris@101
|
535 char cAlternateFileName[14];
|
Chris@101
|
536 };
|
Chris@101
|
537
|
Chris@101
|
538 struct interprocess_security_attributes
|
Chris@101
|
539 {
|
Chris@101
|
540 unsigned long nLength;
|
Chris@101
|
541 void *lpSecurityDescriptor;
|
Chris@101
|
542 int bInheritHandle;
|
Chris@101
|
543 };
|
Chris@101
|
544
|
Chris@101
|
545 struct system_info {
|
Chris@101
|
546 union {
|
Chris@101
|
547 unsigned long dwOemId; // Obsolete field...do not use
|
Chris@101
|
548 struct {
|
Chris@101
|
549 unsigned short wProcessorArchitecture;
|
Chris@101
|
550 unsigned short wReserved;
|
Chris@101
|
551 } dummy;
|
Chris@101
|
552 };
|
Chris@101
|
553 unsigned long dwPageSize;
|
Chris@101
|
554 void * lpMinimumApplicationAddress;
|
Chris@101
|
555 void * lpMaximumApplicationAddress;
|
Chris@101
|
556 unsigned long * dwActiveProcessorMask;
|
Chris@101
|
557 unsigned long dwNumberOfProcessors;
|
Chris@101
|
558 unsigned long dwProcessorType;
|
Chris@101
|
559 unsigned long dwAllocationGranularity;
|
Chris@101
|
560 unsigned short wProcessorLevel;
|
Chris@101
|
561 unsigned short wProcessorRevision;
|
Chris@101
|
562 };
|
Chris@101
|
563
|
Chris@101
|
564 struct interprocess_acl
|
Chris@101
|
565 {
|
Chris@101
|
566 unsigned char AclRevision;
|
Chris@101
|
567 unsigned char Sbz1;
|
Chris@101
|
568 unsigned short AclSize;
|
Chris@101
|
569 unsigned short AceCount;
|
Chris@101
|
570 unsigned short Sbz2;
|
Chris@101
|
571 };
|
Chris@101
|
572
|
Chris@101
|
573 struct interprocess_security_descriptor
|
Chris@101
|
574 {
|
Chris@101
|
575 unsigned char Revision;
|
Chris@101
|
576 unsigned char Sbz1;
|
Chris@101
|
577 unsigned short Control;
|
Chris@101
|
578 void *Owner;
|
Chris@101
|
579 void *Group;
|
Chris@101
|
580 interprocess_acl *Sacl;
|
Chris@101
|
581 interprocess_acl *Dacl;
|
Chris@101
|
582 };
|
Chris@101
|
583
|
Chris@101
|
584 struct interprocess_by_handle_file_information
|
Chris@101
|
585 {
|
Chris@101
|
586 unsigned long dwFileAttributes;
|
Chris@101
|
587 interprocess_filetime ftCreationTime;
|
Chris@101
|
588 interprocess_filetime ftLastAccessTime;
|
Chris@101
|
589 interprocess_filetime ftLastWriteTime;
|
Chris@101
|
590 unsigned long dwVolumeSerialNumber;
|
Chris@101
|
591 unsigned long nFileSizeHigh;
|
Chris@101
|
592 unsigned long nFileSizeLow;
|
Chris@101
|
593 unsigned long nNumberOfLinks;
|
Chris@101
|
594 unsigned long nFileIndexHigh;
|
Chris@101
|
595 unsigned long nFileIndexLow;
|
Chris@101
|
596 };
|
Chris@101
|
597
|
Chris@101
|
598 struct interprocess_eventlogrecord
|
Chris@101
|
599 {
|
Chris@101
|
600 unsigned long Length; // Length of full record
|
Chris@101
|
601 unsigned long Reserved; // Used by the service
|
Chris@101
|
602 unsigned long RecordNumber; // Absolute record number
|
Chris@101
|
603 unsigned long TimeGenerated; // Seconds since 1-1-1970
|
Chris@101
|
604 unsigned long TimeWritten; // Seconds since 1-1-1970
|
Chris@101
|
605 unsigned long EventID;
|
Chris@101
|
606 unsigned short EventType;
|
Chris@101
|
607 unsigned short NumStrings;
|
Chris@101
|
608 unsigned short EventCategory;
|
Chris@101
|
609 unsigned short ReservedFlags; // For use with paired events (auditing)
|
Chris@101
|
610 unsigned long ClosingRecordNumber; // For use with paired events (auditing)
|
Chris@101
|
611 unsigned long StringOffset; // Offset from beginning of record
|
Chris@101
|
612 unsigned long UserSidLength;
|
Chris@101
|
613 unsigned long UserSidOffset;
|
Chris@101
|
614 unsigned long DataLength;
|
Chris@101
|
615 unsigned long DataOffset; // Offset from beginning of record
|
Chris@101
|
616 //
|
Chris@101
|
617 // Then follow:
|
Chris@101
|
618 //
|
Chris@101
|
619 // wchar_t SourceName[]
|
Chris@101
|
620 // wchar_t Computername[]
|
Chris@101
|
621 // SID UserSid
|
Chris@101
|
622 // wchar_t Strings[]
|
Chris@101
|
623 // BYTE Data[]
|
Chris@101
|
624 // CHAR Pad[]
|
Chris@101
|
625 // unsigned long Length;
|
Chris@101
|
626 //
|
Chris@101
|
627 };
|
Chris@101
|
628
|
Chris@101
|
629 union large_integer
|
Chris@101
|
630 {
|
Chris@101
|
631 __int64 QuadPart;
|
Chris@101
|
632 };
|
Chris@101
|
633
|
Chris@101
|
634 struct hinstance_struct { int unused; };
|
Chris@101
|
635 typedef hinstance_struct *hmodule;
|
Chris@101
|
636
|
Chris@101
|
637 struct hkey_struct;
|
Chris@101
|
638 typedef hkey_struct *hkey;
|
Chris@101
|
639
|
Chris@101
|
640 #ifdef _WIN64
|
Chris@101
|
641 typedef __int64 (__stdcall *farproc_t)();
|
Chris@101
|
642 #else
|
Chris@101
|
643 typedef int (__stdcall *farproc_t)();
|
Chris@101
|
644 #endif // _WIN64
|
Chris@101
|
645
|
Chris@101
|
646 #else //#ifndef BOOST_USE_WINDOWS_H
|
Chris@101
|
647
|
Chris@101
|
648 typedef GUID GUID_BIPC;
|
Chris@101
|
649 typedef VARIANT wchar_variant;
|
Chris@101
|
650
|
Chris@101
|
651 typedef IUnknown IUnknown_BIPC;
|
Chris@101
|
652
|
Chris@101
|
653 typedef IWbemClassObject IWbemClassObject_BIPC;
|
Chris@101
|
654
|
Chris@101
|
655 typedef IWbemContext IWbemContext_BIPC;
|
Chris@101
|
656
|
Chris@101
|
657 typedef IEnumWbemClassObject IEnumWbemClassObject_BIPC;
|
Chris@101
|
658
|
Chris@101
|
659 typedef IWbemServices IWbemServices_BIPC;
|
Chris@101
|
660
|
Chris@101
|
661 typedef IWbemLocator IWbemLocator_BIPC;
|
Chris@101
|
662
|
Chris@101
|
663 typedef OVERLAPPED interprocess_overlapped;
|
Chris@101
|
664
|
Chris@101
|
665 typedef FILETIME interprocess_filetime;
|
Chris@101
|
666
|
Chris@101
|
667 typedef WIN32_FIND_DATAA win32_find_data;
|
Chris@101
|
668
|
Chris@101
|
669 typedef SECURITY_ATTRIBUTES interprocess_security_attributes;
|
Chris@101
|
670
|
Chris@101
|
671 typedef SYSTEM_INFO system_info;
|
Chris@101
|
672
|
Chris@101
|
673 typedef ACL interprocess_acl;
|
Chris@101
|
674
|
Chris@101
|
675 typedef SECURITY_DESCRIPTOR interprocess_security_descriptor;
|
Chris@101
|
676
|
Chris@101
|
677 typedef BY_HANDLE_FILE_INFORMATION interprocess_by_handle_file_information;
|
Chris@101
|
678
|
Chris@101
|
679 typedef EVENTLOGRECORD interprocess_eventlogrecord;
|
Chris@101
|
680
|
Chris@101
|
681 typedef LARGE_INTEGER large_integer;
|
Chris@101
|
682
|
Chris@101
|
683 typedef HMODULE hmodule;
|
Chris@101
|
684
|
Chris@101
|
685 typedef HKEY hkey;
|
Chris@101
|
686
|
Chris@101
|
687 typedef BSTR bstr;
|
Chris@101
|
688
|
Chris@101
|
689 typedef FARPROC farproc_t;
|
Chris@101
|
690
|
Chris@101
|
691 #endif //#ifndef BOOST_USE_WINDOWS_H
|
Chris@101
|
692
|
Chris@101
|
693 //////////////////////////////////////////////////////////////////////////////
|
Chris@101
|
694 //
|
Chris@101
|
695 // Nt native structures
|
Chris@101
|
696 //
|
Chris@101
|
697 //////////////////////////////////////////////////////////////////////////////
|
Chris@101
|
698
|
Chris@101
|
699 struct interprocess_semaphore_basic_information
|
Chris@101
|
700 {
|
Chris@101
|
701 unsigned int count; // current semaphore count
|
Chris@101
|
702 unsigned int limit; // max semaphore count
|
Chris@101
|
703 };
|
Chris@101
|
704
|
Chris@101
|
705 struct interprocess_section_basic_information
|
Chris@101
|
706 {
|
Chris@101
|
707 void * base_address;
|
Chris@101
|
708 unsigned long section_attributes;
|
Chris@101
|
709 __int64 section_size;
|
Chris@101
|
710 };
|
Chris@101
|
711
|
Chris@101
|
712 struct file_rename_information_t {
|
Chris@101
|
713 int Replace;
|
Chris@101
|
714 void *RootDir;
|
Chris@101
|
715 unsigned long FileNameLength;
|
Chris@101
|
716 wchar_t FileName[1];
|
Chris@101
|
717 };
|
Chris@101
|
718
|
Chris@101
|
719 struct unicode_string_t {
|
Chris@101
|
720 unsigned short Length;
|
Chris@101
|
721 unsigned short MaximumLength;
|
Chris@101
|
722 wchar_t *Buffer;
|
Chris@101
|
723 };
|
Chris@101
|
724
|
Chris@101
|
725 struct object_attributes_t {
|
Chris@101
|
726 unsigned long Length;
|
Chris@101
|
727 void * RootDirectory;
|
Chris@101
|
728 unicode_string_t *ObjectName;
|
Chris@101
|
729 unsigned long Attributes;
|
Chris@101
|
730 void *SecurityDescriptor;
|
Chris@101
|
731 void *SecurityQualityOfService;
|
Chris@101
|
732 };
|
Chris@101
|
733
|
Chris@101
|
734 struct io_status_block_t {
|
Chris@101
|
735 union {
|
Chris@101
|
736 long Status;
|
Chris@101
|
737 void *Pointer;
|
Chris@101
|
738 };
|
Chris@101
|
739
|
Chris@101
|
740 unsigned long *Information;
|
Chris@101
|
741 };
|
Chris@101
|
742
|
Chris@101
|
743 union system_timeofday_information
|
Chris@101
|
744 {
|
Chris@101
|
745 struct data_t
|
Chris@101
|
746 {
|
Chris@101
|
747 __int64 liKeBootTime;
|
Chris@101
|
748 __int64 liKeSystemTime;
|
Chris@101
|
749 __int64 liExpTimeZoneBias;
|
Chris@101
|
750 unsigned long uCurrentTimeZoneId;
|
Chris@101
|
751 unsigned long dwReserved;
|
Chris@101
|
752 ::boost::ulong_long_type ullBootTimeBias;
|
Chris@101
|
753 ::boost::ulong_long_type ullSleepTimeBias;
|
Chris@101
|
754 } data;
|
Chris@101
|
755 unsigned char Reserved1[sizeof(data_t)];
|
Chris@101
|
756 };
|
Chris@101
|
757
|
Chris@101
|
758 static const long BootstampLength = sizeof(__int64);
|
Chris@101
|
759 static const long BootAndSystemstampLength = sizeof(__int64)*2;
|
Chris@101
|
760 static const long SystemTimeOfDayInfoLength = sizeof(system_timeofday_information::data_t);
|
Chris@101
|
761
|
Chris@101
|
762 struct object_name_information_t
|
Chris@101
|
763 {
|
Chris@101
|
764 unicode_string_t Name;
|
Chris@101
|
765 wchar_t NameBuffer[1];
|
Chris@101
|
766 };
|
Chris@101
|
767
|
Chris@101
|
768 enum file_information_class_t {
|
Chris@101
|
769 file_directory_information = 1,
|
Chris@101
|
770 file_full_directory_information,
|
Chris@101
|
771 file_both_directory_information,
|
Chris@101
|
772 file_basic_information,
|
Chris@101
|
773 file_standard_information,
|
Chris@101
|
774 file_internal_information,
|
Chris@101
|
775 file_ea_information,
|
Chris@101
|
776 file_access_information,
|
Chris@101
|
777 file_name_information,
|
Chris@101
|
778 file_rename_information,
|
Chris@101
|
779 file_link_information,
|
Chris@101
|
780 file_names_information,
|
Chris@101
|
781 file_disposition_information,
|
Chris@101
|
782 file_position_information,
|
Chris@101
|
783 file_full_ea_information,
|
Chris@101
|
784 file_mode_information,
|
Chris@101
|
785 file_alignment_information,
|
Chris@101
|
786 file_all_information,
|
Chris@101
|
787 file_allocation_information,
|
Chris@101
|
788 file_end_of_file_information,
|
Chris@101
|
789 file_alternate_name_information,
|
Chris@101
|
790 file_stream_information,
|
Chris@101
|
791 file_pipe_information,
|
Chris@101
|
792 file_pipe_local_information,
|
Chris@101
|
793 file_pipe_remote_information,
|
Chris@101
|
794 file_mailslot_query_information,
|
Chris@101
|
795 file_mailslot_set_information,
|
Chris@101
|
796 file_compression_information,
|
Chris@101
|
797 file_copy_on_write_information,
|
Chris@101
|
798 file_completion_information,
|
Chris@101
|
799 file_move_cluster_information,
|
Chris@101
|
800 file_quota_information,
|
Chris@101
|
801 file_reparse_point_information,
|
Chris@101
|
802 file_network_open_information,
|
Chris@101
|
803 file_object_id_information,
|
Chris@101
|
804 file_tracking_information,
|
Chris@101
|
805 file_ole_directory_information,
|
Chris@101
|
806 file_content_index_information,
|
Chris@101
|
807 file_inherit_content_index_information,
|
Chris@101
|
808 file_ole_information,
|
Chris@101
|
809 file_maximum_information
|
Chris@101
|
810 };
|
Chris@101
|
811
|
Chris@101
|
812 enum semaphore_information_class {
|
Chris@101
|
813 semaphore_basic_information = 0
|
Chris@101
|
814 };
|
Chris@101
|
815
|
Chris@101
|
816
|
Chris@101
|
817 enum system_information_class {
|
Chris@101
|
818 system_basic_information = 0,
|
Chris@101
|
819 system_performance_information = 2,
|
Chris@101
|
820 system_time_of_day_information = 3,
|
Chris@101
|
821 system_process_information = 5,
|
Chris@101
|
822 system_processor_performance_information = 8,
|
Chris@101
|
823 system_interrupt_information = 23,
|
Chris@101
|
824 system_exception_information = 33,
|
Chris@101
|
825 system_registry_quota_information = 37,
|
Chris@101
|
826 system_lookaside_information = 45
|
Chris@101
|
827 };
|
Chris@101
|
828
|
Chris@101
|
829 enum object_information_class
|
Chris@101
|
830 {
|
Chris@101
|
831 object_basic_information,
|
Chris@101
|
832 object_name_information,
|
Chris@101
|
833 object_type_information,
|
Chris@101
|
834 object_all_information,
|
Chris@101
|
835 object_data_information
|
Chris@101
|
836 };
|
Chris@101
|
837
|
Chris@101
|
838 enum section_information_class
|
Chris@101
|
839 {
|
Chris@101
|
840 section_basic_information,
|
Chris@101
|
841 section_image_information
|
Chris@101
|
842 };
|
Chris@101
|
843
|
Chris@101
|
844 //////////////////////////////////////////////////////////////////////////////
|
Chris@101
|
845 //
|
Chris@101
|
846 // Forward declaration of winapi
|
Chris@101
|
847 //
|
Chris@101
|
848 //////////////////////////////////////////////////////////////////////////////
|
Chris@101
|
849
|
Chris@101
|
850 #ifndef BOOST_USE_WINDOWS_H
|
Chris@101
|
851
|
Chris@101
|
852 //Kernel32.dll
|
Chris@101
|
853
|
Chris@101
|
854 //Some windows API declarations
|
Chris@101
|
855 extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentProcessId();
|
Chris@101
|
856 extern "C" __declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
|
Chris@101
|
857 extern "C" __declspec(dllimport) int __stdcall GetProcessTimes
|
Chris@101
|
858 ( void *hProcess, interprocess_filetime* lpCreationTime
|
Chris@101
|
859 , interprocess_filetime *lpExitTime,interprocess_filetime *lpKernelTime
|
Chris@101
|
860 , interprocess_filetime *lpUserTime );
|
Chris@101
|
861 extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long);
|
Chris@101
|
862 extern "C" __declspec(dllimport) unsigned long __stdcall GetTickCount(void);
|
Chris@101
|
863 extern "C" __declspec(dllimport) int __stdcall SwitchToThread();
|
Chris@101
|
864 extern "C" __declspec(dllimport) unsigned long __stdcall GetLastError();
|
Chris@101
|
865 extern "C" __declspec(dllimport) void __stdcall SetLastError(unsigned long);
|
Chris@101
|
866 extern "C" __declspec(dllimport) void * __stdcall GetCurrentProcess();
|
Chris@101
|
867 extern "C" __declspec(dllimport) int __stdcall CloseHandle(void*);
|
Chris@101
|
868 extern "C" __declspec(dllimport) int __stdcall DuplicateHandle
|
Chris@101
|
869 ( void *hSourceProcessHandle, void *hSourceHandle
|
Chris@101
|
870 , void *hTargetProcessHandle, void **lpTargetHandle
|
Chris@101
|
871 , unsigned long dwDesiredAccess, int bInheritHandle
|
Chris@101
|
872 , unsigned long dwOptions);
|
Chris@101
|
873 extern "C" __declspec(dllimport) long __stdcall GetFileType(void *hFile);
|
Chris@101
|
874 extern "C" __declspec(dllimport) void *__stdcall FindFirstFileA(const char *lpFileName, win32_find_data *lpFindFileData);
|
Chris@101
|
875 extern "C" __declspec(dllimport) int __stdcall FindNextFileA(void *hFindFile, win32_find_data *lpFindFileData);
|
Chris@101
|
876 extern "C" __declspec(dllimport) int __stdcall FindClose(void *hFindFile);
|
Chris@101
|
877 //extern "C" __declspec(dllimport) void __stdcall GetSystemTimeAsFileTime(interprocess_filetime*);
|
Chris@101
|
878 //extern "C" __declspec(dllimport) int __stdcall FileTimeToLocalFileTime(const interprocess_filetime *in, const interprocess_filetime *out);
|
Chris@101
|
879 extern "C" __declspec(dllimport) void * __stdcall CreateMutexA(interprocess_security_attributes*, int, const char *);
|
Chris@101
|
880 extern "C" __declspec(dllimport) void * __stdcall OpenMutexA(unsigned long, int, const char *);
|
Chris@101
|
881 extern "C" __declspec(dllimport) unsigned long __stdcall WaitForSingleObject(void *, unsigned long);
|
Chris@101
|
882 extern "C" __declspec(dllimport) int __stdcall ReleaseMutex(void *);
|
Chris@101
|
883 extern "C" __declspec(dllimport) int __stdcall UnmapViewOfFile(void *);
|
Chris@101
|
884 extern "C" __declspec(dllimport) void * __stdcall CreateSemaphoreA(interprocess_security_attributes*, long, long, const char *);
|
Chris@101
|
885 extern "C" __declspec(dllimport) int __stdcall ReleaseSemaphore(void *, long, long *);
|
Chris@101
|
886 extern "C" __declspec(dllimport) void * __stdcall OpenSemaphoreA(unsigned long, int, const char *);
|
Chris@101
|
887 extern "C" __declspec(dllimport) void * __stdcall CreateFileMappingA (void *, interprocess_security_attributes*, unsigned long, unsigned long, unsigned long, const char *);
|
Chris@101
|
888 extern "C" __declspec(dllimport) void * __stdcall MapViewOfFileEx (void *, unsigned long, unsigned long, unsigned long, std::size_t, void*);
|
Chris@101
|
889 extern "C" __declspec(dllimport) void * __stdcall OpenFileMappingA (unsigned long, int, const char *);
|
Chris@101
|
890 extern "C" __declspec(dllimport) void * __stdcall CreateFileA (const char *, unsigned long, unsigned long, struct interprocess_security_attributes*, unsigned long, unsigned long, void *);
|
Chris@101
|
891 extern "C" __declspec(dllimport) void __stdcall GetSystemInfo (struct system_info *);
|
Chris@101
|
892 extern "C" __declspec(dllimport) int __stdcall FlushViewOfFile (void *, std::size_t);
|
Chris@101
|
893 extern "C" __declspec(dllimport) int __stdcall VirtualUnlock (void *, std::size_t);
|
Chris@101
|
894 extern "C" __declspec(dllimport) int __stdcall VirtualProtect (void *, std::size_t, unsigned long, unsigned long *);
|
Chris@101
|
895 extern "C" __declspec(dllimport) int __stdcall FlushFileBuffers (void *);
|
Chris@101
|
896 extern "C" __declspec(dllimport) int __stdcall GetFileSizeEx (void *, large_integer *size);
|
Chris@101
|
897 extern "C" __declspec(dllimport) unsigned long __stdcall FormatMessageA
|
Chris@101
|
898 (unsigned long dwFlags, const void *lpSource, unsigned long dwMessageId,
|
Chris@101
|
899 unsigned long dwLanguageId, char *lpBuffer, unsigned long nSize,
|
Chris@101
|
900 std::va_list *Arguments);
|
Chris@101
|
901 extern "C" __declspec(dllimport) void *__stdcall LocalFree (void *);
|
Chris@101
|
902 extern "C" __declspec(dllimport) unsigned long __stdcall GetFileAttributesA(const char *);
|
Chris@101
|
903 extern "C" __declspec(dllimport) int __stdcall CreateDirectoryA(const char *, interprocess_security_attributes*);
|
Chris@101
|
904 extern "C" __declspec(dllimport) int __stdcall RemoveDirectoryA(const char *lpPathName);
|
Chris@101
|
905 extern "C" __declspec(dllimport) int __stdcall GetTempPathA(unsigned long length, char *buffer);
|
Chris@101
|
906 extern "C" __declspec(dllimport) int __stdcall CreateDirectory(const char *, interprocess_security_attributes*);
|
Chris@101
|
907 extern "C" __declspec(dllimport) int __stdcall SetFileValidData(void *, __int64 size);
|
Chris@101
|
908 extern "C" __declspec(dllimport) int __stdcall SetEndOfFile(void *);
|
Chris@101
|
909 extern "C" __declspec(dllimport) int __stdcall SetFilePointerEx(void *, large_integer distance, large_integer *new_file_pointer, unsigned long move_method);
|
Chris@101
|
910 extern "C" __declspec(dllimport) int __stdcall LockFile (void *hnd, unsigned long offset_low, unsigned long offset_high, unsigned long size_low, unsigned long size_high);
|
Chris@101
|
911 extern "C" __declspec(dllimport) int __stdcall UnlockFile(void *hnd, unsigned long offset_low, unsigned long offset_high, unsigned long size_low, unsigned long size_high);
|
Chris@101
|
912 extern "C" __declspec(dllimport) int __stdcall LockFileEx(void *hnd, unsigned long flags, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped* overlapped);
|
Chris@101
|
913 extern "C" __declspec(dllimport) int __stdcall UnlockFileEx(void *hnd, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped* overlapped);
|
Chris@101
|
914 extern "C" __declspec(dllimport) int __stdcall WriteFile(void *hnd, const void *buffer, unsigned long bytes_to_write, unsigned long *bytes_written, interprocess_overlapped* overlapped);
|
Chris@101
|
915 extern "C" __declspec(dllimport) int __stdcall ReadFile(void *hnd, void *buffer, unsigned long bytes_to_read, unsigned long *bytes_read, interprocess_overlapped* overlapped);
|
Chris@101
|
916 extern "C" __declspec(dllimport) int __stdcall InitializeSecurityDescriptor(interprocess_security_descriptor *pSecurityDescriptor, unsigned long dwRevision);
|
Chris@101
|
917 extern "C" __declspec(dllimport) int __stdcall SetSecurityDescriptorDacl(interprocess_security_descriptor *pSecurityDescriptor, int bDaclPresent, interprocess_acl *pDacl, int bDaclDefaulted);
|
Chris@101
|
918 extern "C" __declspec(dllimport) hmodule __stdcall LoadLibraryA(const char *);
|
Chris@101
|
919 extern "C" __declspec(dllimport) int __stdcall FreeLibrary(hmodule);
|
Chris@101
|
920 extern "C" __declspec(dllimport) farproc_t __stdcall GetProcAddress(void *, const char*);
|
Chris@101
|
921 extern "C" __declspec(dllimport) hmodule __stdcall GetModuleHandleA(const char*);
|
Chris@101
|
922 extern "C" __declspec(dllimport) void *__stdcall GetFileInformationByHandle(void *, interprocess_by_handle_file_information*);
|
Chris@101
|
923
|
Chris@101
|
924 //Advapi32.dll
|
Chris@101
|
925 extern "C" __declspec(dllimport) long __stdcall RegOpenKeyExA(hkey, const char *, unsigned long, unsigned long, hkey*);
|
Chris@101
|
926 extern "C" __declspec(dllimport) long __stdcall RegQueryValueExA(hkey, const char *, unsigned long*, unsigned long*, unsigned char *, unsigned long*);
|
Chris@101
|
927 extern "C" __declspec(dllimport) long __stdcall RegCloseKey(hkey);
|
Chris@101
|
928
|
Chris@101
|
929 //Ole32.dll
|
Chris@101
|
930 extern "C" __declspec(dllimport) long __stdcall CoInitializeEx(void *pvReserved, unsigned long dwCoInit);
|
Chris@101
|
931 extern "C" __declspec(dllimport) long __stdcall CoInitializeSecurity(
|
Chris@101
|
932 void* pSecDesc,
|
Chris@101
|
933 long cAuthSvc,
|
Chris@101
|
934 void * asAuthSvc,
|
Chris@101
|
935 void *pReserved1,
|
Chris@101
|
936 unsigned long dwAuthnLevel,
|
Chris@101
|
937 unsigned long dwImpLevel,
|
Chris@101
|
938 void *pAuthList,
|
Chris@101
|
939 unsigned long dwCapabilities,
|
Chris@101
|
940 void *pReserved3 );
|
Chris@101
|
941
|
Chris@101
|
942 extern "C" __declspec(dllimport) long __stdcall CoSetProxyBlanket(
|
Chris@101
|
943 IUnknown_BIPC *pProxy,
|
Chris@101
|
944 unsigned long dwAuthnSvc,
|
Chris@101
|
945 unsigned long dwAuthzSvc,
|
Chris@101
|
946 wchar_t *pServerPrincName,
|
Chris@101
|
947 unsigned long dwAuthnLevel,
|
Chris@101
|
948 unsigned long dwImpLevel,
|
Chris@101
|
949 void *pAuthInfo,
|
Chris@101
|
950 unsigned long dwCapabilities);
|
Chris@101
|
951 extern "C" __declspec(dllimport) long __stdcall CoCreateInstance(const GUID_BIPC & rclsid, IUnknown_BIPC *pUnkOuter,
|
Chris@101
|
952 unsigned long dwClsContext, const GUID_BIPC & riid, void** ppv);
|
Chris@101
|
953 extern "C" __declspec(dllimport) void __stdcall CoUninitialize(void);
|
Chris@101
|
954
|
Chris@101
|
955 //OleAut32.dll
|
Chris@101
|
956 extern "C" __declspec(dllimport) long __stdcall VariantClear(wchar_variant * pvarg);
|
Chris@101
|
957
|
Chris@101
|
958 //Shell32.dll
|
Chris@101
|
959 extern "C" __declspec(dllimport) int __stdcall SHGetSpecialFolderPathA
|
Chris@101
|
960 (void* hwnd, const char *pszPath, int csidl, int fCreate);
|
Chris@101
|
961
|
Chris@101
|
962 extern "C" __declspec(dllimport) int __stdcall SHGetFolderPathA(void *hwnd, int csidl, void *hToken, unsigned long dwFlags, const char *pszPath);
|
Chris@101
|
963
|
Chris@101
|
964 //EventLog access functions
|
Chris@101
|
965
|
Chris@101
|
966 extern "C" __declspec(dllimport) void* __stdcall OpenEventLogA
|
Chris@101
|
967 (const char* lpUNCServerName, const char* lpSourceName);
|
Chris@101
|
968
|
Chris@101
|
969 extern "C" __declspec(dllimport) int __stdcall CloseEventLog(void *hEventLog);
|
Chris@101
|
970
|
Chris@101
|
971 extern "C" __declspec(dllimport) int __stdcall ReadEventLogA
|
Chris@101
|
972 (void *hEventLog,
|
Chris@101
|
973 unsigned long dwReadFlags,
|
Chris@101
|
974 unsigned long dwRecordOffset,
|
Chris@101
|
975 void *lpBuffer,
|
Chris@101
|
976 unsigned long nNumberOfBytesToRead,
|
Chris@101
|
977 unsigned long *pnBytesRead,
|
Chris@101
|
978 unsigned long *pnMinNumberOfBytesNeeded
|
Chris@101
|
979 );
|
Chris@101
|
980
|
Chris@101
|
981 #endif //#ifndef BOOST_USE_WINDOWS_H
|
Chris@101
|
982
|
Chris@101
|
983 //kernel32.dll
|
Chris@101
|
984 typedef int (__stdcall *QueryPerformanceCounter_t) (__int64 *lpPerformanceCount);
|
Chris@101
|
985 typedef int (__stdcall *QueryPerformanceFrequency_t)(__int64 *lpFrequency);
|
Chris@101
|
986
|
Chris@101
|
987 //ntdll.dll
|
Chris@101
|
988 typedef long (__stdcall *NtDeleteFile_t)(object_attributes_t *ObjectAttributes);
|
Chris@101
|
989 typedef long (__stdcall *NtSetInformationFile_t)(void *FileHandle, io_status_block_t *IoStatusBlock, void *FileInformation, unsigned long Length, int FileInformationClass );
|
Chris@101
|
990 typedef long (__stdcall *NtOpenFile)(void **FileHandle, unsigned long DesiredAccess, object_attributes_t *ObjectAttributes
|
Chris@101
|
991 , io_status_block_t *IoStatusBlock, unsigned long ShareAccess, unsigned long Length, unsigned long OpenOptions);
|
Chris@101
|
992 typedef long (__stdcall *NtQuerySystemInformation_t)(int, void*, unsigned long, unsigned long *);
|
Chris@101
|
993 typedef long (__stdcall *NtQueryObject_t)(void*, object_information_class, void *, unsigned long, unsigned long *);
|
Chris@101
|
994 typedef long (__stdcall *NtQuerySemaphore_t)(void*, unsigned int info_class, interprocess_semaphore_basic_information *pinfo, unsigned int info_size, unsigned int *ret_len);
|
Chris@101
|
995 typedef long (__stdcall *NtQuerySection_t)(void*, section_information_class, interprocess_section_basic_information *pinfo, unsigned long info_size, unsigned long *ret_len);
|
Chris@101
|
996 typedef long (__stdcall *NtQueryInformationFile_t)(void *,io_status_block_t *,void *, long, int);
|
Chris@101
|
997 typedef long (__stdcall *NtOpenFile_t)(void*,unsigned long ,object_attributes_t*,io_status_block_t*,unsigned long,unsigned long);
|
Chris@101
|
998 typedef long (__stdcall *NtClose_t) (void*);
|
Chris@101
|
999 typedef long (__stdcall *NtQueryTimerResolution_t) (unsigned long* LowestResolution, unsigned long* HighestResolution, unsigned long* CurrentResolution);
|
Chris@101
|
1000 typedef long (__stdcall *NtSetTimerResolution_t) (unsigned long RequestedResolution, int Set, unsigned long* ActualResolution);
|
Chris@101
|
1001
|
Chris@101
|
1002 } //namespace winapi {
|
Chris@101
|
1003 } //namespace interprocess {
|
Chris@101
|
1004 } //namespace boost {
|
Chris@101
|
1005
|
Chris@101
|
1006 //////////////////////////////////////////////////////////////////////////////
|
Chris@101
|
1007 //
|
Chris@101
|
1008 // Forward declaration of constants
|
Chris@101
|
1009 //
|
Chris@101
|
1010 //////////////////////////////////////////////////////////////////////////////
|
Chris@101
|
1011
|
Chris@16
|
1012 namespace boost {
|
Chris@16
|
1013 namespace interprocess {
|
Chris@16
|
1014 namespace winapi {
|
Chris@16
|
1015
|
Chris@16
|
1016 //Some used constants
|
Chris@16
|
1017 static const unsigned long infinite_time = 0xFFFFFFFF;
|
Chris@16
|
1018 static const unsigned long error_already_exists = 183L;
|
Chris@16
|
1019 static const unsigned long error_invalid_handle = 6L;
|
Chris@16
|
1020 static const unsigned long error_sharing_violation = 32L;
|
Chris@16
|
1021 static const unsigned long error_file_not_found = 2u;
|
Chris@16
|
1022 static const unsigned long error_no_more_files = 18u;
|
Chris@16
|
1023 static const unsigned long error_not_locked = 158L;
|
Chris@16
|
1024 //Retries in CreateFile, see http://support.microsoft.com/kb/316609
|
Chris@16
|
1025 static const unsigned long error_sharing_violation_tries = 3L;
|
Chris@16
|
1026 static const unsigned long error_sharing_violation_sleep_ms = 250L;
|
Chris@16
|
1027 static const unsigned long error_file_too_large = 223L;
|
Chris@16
|
1028 static const unsigned long error_insufficient_buffer = 122L;
|
Chris@16
|
1029 static const unsigned long error_handle_eof = 38L;
|
Chris@16
|
1030 static const unsigned long semaphore_all_access = (0x000F0000L)|(0x00100000L)|0x3;
|
Chris@16
|
1031 static const unsigned long mutex_all_access = (0x000F0000L)|(0x00100000L)|0x0001;
|
Chris@16
|
1032
|
Chris@16
|
1033 static const unsigned long page_readonly = 0x02;
|
Chris@16
|
1034 static const unsigned long page_readwrite = 0x04;
|
Chris@16
|
1035 static const unsigned long page_writecopy = 0x08;
|
Chris@16
|
1036 static const unsigned long page_noaccess = 0x01;
|
Chris@16
|
1037
|
Chris@16
|
1038 static const unsigned long standard_rights_required = 0x000F0000L;
|
Chris@16
|
1039 static const unsigned long section_query = 0x0001;
|
Chris@16
|
1040 static const unsigned long section_map_write = 0x0002;
|
Chris@16
|
1041 static const unsigned long section_map_read = 0x0004;
|
Chris@16
|
1042 static const unsigned long section_map_execute = 0x0008;
|
Chris@16
|
1043 static const unsigned long section_extend_size = 0x0010;
|
Chris@16
|
1044 static const unsigned long section_all_access = standard_rights_required |
|
Chris@16
|
1045 section_query |
|
Chris@16
|
1046 section_map_write |
|
Chris@16
|
1047 section_map_read |
|
Chris@16
|
1048 section_map_execute |
|
Chris@16
|
1049 section_extend_size;
|
Chris@16
|
1050
|
Chris@16
|
1051 static const unsigned long file_map_copy = section_query;
|
Chris@16
|
1052 static const unsigned long file_map_write = section_map_write;
|
Chris@16
|
1053 static const unsigned long file_map_read = section_map_read;
|
Chris@16
|
1054 static const unsigned long file_map_all_access = section_all_access;
|
Chris@16
|
1055 static const unsigned long delete_access = 0x00010000L;
|
Chris@16
|
1056 static const unsigned long file_flag_backup_semantics = 0x02000000;
|
Chris@16
|
1057 static const long file_flag_delete_on_close = 0x04000000;
|
Chris@16
|
1058
|
Chris@16
|
1059 //Native API constants
|
Chris@16
|
1060 static const unsigned long file_open_for_backup_intent = 0x00004000;
|
Chris@16
|
1061 static const int file_share_valid_flags = 0x00000007;
|
Chris@16
|
1062 static const long file_delete_on_close = 0x00001000L;
|
Chris@16
|
1063 static const long obj_case_insensitive = 0x00000040L;
|
Chris@16
|
1064 static const long delete_flag = 0x00010000L;
|
Chris@16
|
1065
|
Chris@16
|
1066 static const unsigned long movefile_copy_allowed = 0x02;
|
Chris@16
|
1067 static const unsigned long movefile_delay_until_reboot = 0x04;
|
Chris@16
|
1068 static const unsigned long movefile_replace_existing = 0x01;
|
Chris@16
|
1069 static const unsigned long movefile_write_through = 0x08;
|
Chris@16
|
1070 static const unsigned long movefile_create_hardlink = 0x10;
|
Chris@16
|
1071 static const unsigned long movefile_fail_if_not_trackable = 0x20;
|
Chris@16
|
1072
|
Chris@16
|
1073 static const unsigned long file_share_read = 0x00000001;
|
Chris@16
|
1074 static const unsigned long file_share_write = 0x00000002;
|
Chris@16
|
1075 static const unsigned long file_share_delete = 0x00000004;
|
Chris@16
|
1076
|
Chris@16
|
1077 static const unsigned long file_attribute_readonly = 0x00000001;
|
Chris@16
|
1078 static const unsigned long file_attribute_hidden = 0x00000002;
|
Chris@16
|
1079 static const unsigned long file_attribute_system = 0x00000004;
|
Chris@16
|
1080 static const unsigned long file_attribute_directory = 0x00000010;
|
Chris@16
|
1081 static const unsigned long file_attribute_archive = 0x00000020;
|
Chris@16
|
1082 static const unsigned long file_attribute_device = 0x00000040;
|
Chris@16
|
1083 static const unsigned long file_attribute_normal = 0x00000080;
|
Chris@16
|
1084 static const unsigned long file_attribute_temporary = 0x00000100;
|
Chris@16
|
1085
|
Chris@16
|
1086 static const unsigned long generic_read = 0x80000000L;
|
Chris@16
|
1087 static const unsigned long generic_write = 0x40000000L;
|
Chris@16
|
1088
|
Chris@16
|
1089 static const unsigned long wait_object_0 = 0;
|
Chris@16
|
1090 static const unsigned long wait_abandoned = 0x00000080L;
|
Chris@16
|
1091 static const unsigned long wait_timeout = 258L;
|
Chris@16
|
1092 static const unsigned long wait_failed = (unsigned long)0xFFFFFFFF;
|
Chris@16
|
1093
|
Chris@16
|
1094 static const unsigned long duplicate_close_source = (unsigned long)0x00000001;
|
Chris@16
|
1095 static const unsigned long duplicate_same_access = (unsigned long)0x00000002;
|
Chris@16
|
1096
|
Chris@16
|
1097 static const unsigned long format_message_allocate_buffer
|
Chris@16
|
1098 = (unsigned long)0x00000100;
|
Chris@16
|
1099 static const unsigned long format_message_ignore_inserts
|
Chris@16
|
1100 = (unsigned long)0x00000200;
|
Chris@16
|
1101 static const unsigned long format_message_from_string
|
Chris@16
|
1102 = (unsigned long)0x00000400;
|
Chris@16
|
1103 static const unsigned long format_message_from_hmodule
|
Chris@16
|
1104 = (unsigned long)0x00000800;
|
Chris@16
|
1105 static const unsigned long format_message_from_system
|
Chris@16
|
1106 = (unsigned long)0x00001000;
|
Chris@16
|
1107 static const unsigned long format_message_argument_array
|
Chris@16
|
1108 = (unsigned long)0x00002000;
|
Chris@16
|
1109 static const unsigned long format_message_max_width_mask
|
Chris@16
|
1110 = (unsigned long)0x000000FF;
|
Chris@16
|
1111 static const unsigned long lang_neutral = (unsigned long)0x00;
|
Chris@16
|
1112 static const unsigned long sublang_default = (unsigned long)0x01;
|
Chris@16
|
1113 static const unsigned long invalid_file_size = (unsigned long)0xFFFFFFFF;
|
Chris@16
|
1114 static const unsigned long invalid_file_attributes = ((unsigned long)-1);
|
Chris@16
|
1115 static void * const invalid_handle_value = ((void*)(long)(-1));
|
Chris@16
|
1116
|
Chris@16
|
1117 static const unsigned long file_type_char = 0x0002L;
|
Chris@16
|
1118 static const unsigned long file_type_disk = 0x0001L;
|
Chris@16
|
1119 static const unsigned long file_type_pipe = 0x0003L;
|
Chris@16
|
1120 static const unsigned long file_type_remote = 0x8000L;
|
Chris@16
|
1121 static const unsigned long file_type_unknown = 0x0000L;
|
Chris@16
|
1122
|
Chris@16
|
1123 static const unsigned long create_new = 1;
|
Chris@16
|
1124 static const unsigned long create_always = 2;
|
Chris@16
|
1125 static const unsigned long open_existing = 3;
|
Chris@16
|
1126 static const unsigned long open_always = 4;
|
Chris@16
|
1127 static const unsigned long truncate_existing = 5;
|
Chris@16
|
1128
|
Chris@16
|
1129 static const unsigned long file_begin = 0;
|
Chris@16
|
1130 static const unsigned long file_current = 1;
|
Chris@16
|
1131 static const unsigned long file_end = 2;
|
Chris@16
|
1132
|
Chris@16
|
1133 static const unsigned long lockfile_fail_immediately = 1;
|
Chris@16
|
1134 static const unsigned long lockfile_exclusive_lock = 2;
|
Chris@16
|
1135 static const unsigned long error_lock_violation = 33;
|
Chris@16
|
1136 static const unsigned long security_descriptor_revision = 1;
|
Chris@16
|
1137
|
Chris@16
|
1138 const unsigned long max_record_buffer_size = 0x10000L; // 64K
|
Chris@101
|
1139 const unsigned long max_path = 260;
|
Chris@16
|
1140
|
Chris@16
|
1141 //Keys
|
Chris@101
|
1142 static const hkey hkey_local_machine = (hkey)(unsigned long*)(long)(0x80000002);
|
Chris@16
|
1143 static unsigned long key_query_value = 0x0001;
|
Chris@16
|
1144
|
Chris@16
|
1145 //COM API
|
Chris@16
|
1146 const unsigned long RPC_C_AUTHN_LEVEL_PKT_BIPC = 4;
|
Chris@16
|
1147 const unsigned long RPC_C_AUTHN_DEFAULT_BIPC = 0xffffffffL;
|
Chris@16
|
1148 const unsigned long RPC_C_AUTHZ_DEFAULT_BIPC = 0xffffffffL;
|
Chris@16
|
1149 const unsigned long RPC_C_IMP_LEVEL_IMPERSONATE_BIPC = 3;
|
Chris@16
|
1150 const signed long EOAC_NONE_BIPC = 0;
|
Chris@16
|
1151 const signed long CLSCTX_INPROC_SERVER_BIPC = 0x1;
|
Chris@16
|
1152 const signed long CLSCTX_LOCAL_SERVER_BIPC = 0x4;
|
Chris@16
|
1153 const signed long WBEM_FLAG_RETURN_IMMEDIATELY_BIPC = 0x10;
|
Chris@16
|
1154 const signed long WBEM_FLAG_RETURN_WHEN_COMPLETE_BIPC = 0x0;
|
Chris@16
|
1155 const signed long WBEM_FLAG_FORWARD_ONLY_BIPC = 0x20;
|
Chris@16
|
1156 const signed long WBEM_INFINITE_BIPC = 0xffffffffL;
|
Chris@16
|
1157 const signed long RPC_E_TOO_LATE_BIPC = 0x80010119L;
|
Chris@16
|
1158 const signed long S_OK_BIPC = 0L;
|
Chris@16
|
1159 const signed long S_FALSE_BIPC = 1;
|
Chris@16
|
1160 const signed long RPC_E_CHANGED_MODE_BIPC = 0x80010106L;
|
Chris@16
|
1161 const unsigned long COINIT_APARTMENTTHREADED_BIPC = 0x2;
|
Chris@16
|
1162 const unsigned long COINIT_MULTITHREADED_BIPC = 0x0;
|
Chris@16
|
1163 const unsigned long COINIT_DISABLE_OLE1DDE_BIPC = 0x4;
|
Chris@16
|
1164 const unsigned long COINIT_SPEED_OVER_MEMORY_BIPC = 0x4;
|
Chris@16
|
1165
|
Chris@101
|
1166
|
Chris@16
|
1167 //If the user needs to change default COM initialization model,
|
Chris@16
|
1168 //it can define BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL to one of these:
|
Chris@16
|
1169 //
|
Chris@16
|
1170 // COINIT_APARTMENTTHREADED_BIPC
|
Chris@16
|
1171 // COINIT_MULTITHREADED_BIPC
|
Chris@16
|
1172 // COINIT_DISABLE_OLE1DDE_BIPC
|
Chris@16
|
1173 // COINIT_SPEED_OVER_MEMORY_BIPC
|
Chris@16
|
1174 #if !defined(BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL)
|
Chris@16
|
1175 #define BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL COINIT_APARTMENTTHREADED_BIPC
|
Chris@16
|
1176 #elif (BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL != COINIT_APARTMENTTHREADED_BIPC) &&\
|
Chris@16
|
1177 (BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL != COINIT_MULTITHREADED_BIPC) &&\
|
Chris@16
|
1178 (BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL != COINIT_DISABLE_OLE1DDE_BIPC) &&\
|
Chris@16
|
1179 (BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL != COINIT_SPEED_OVER_MEMORY_BIPC)
|
Chris@16
|
1180 #error "Wrong value for BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL macro"
|
Chris@16
|
1181 #endif
|
Chris@16
|
1182
|
Chris@16
|
1183 const GUID_BIPC CLSID_WbemAdministrativeLocator =
|
Chris@16
|
1184 { 0xcb8555cc, 0x9128, 0x11d1, {0xad, 0x9b, 0x00, 0xc0, 0x4f, 0xd8, 0xfd, 0xff}};
|
Chris@16
|
1185
|
Chris@16
|
1186 const GUID_BIPC IID_IUnknown = { 0x00000000, 0x0000, 0x0000, {0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}};
|
Chris@16
|
1187
|
Chris@16
|
1188 static const unsigned long eventlog_sequential_read = 0x0001;
|
Chris@16
|
1189 static const unsigned long eventlog_backwards_read = 0x0008;
|
Chris@16
|
1190
|
Chris@16
|
1191 } //namespace winapi {
|
Chris@16
|
1192 } //namespace interprocess {
|
Chris@16
|
1193 } //namespace boost {
|
Chris@16
|
1194
|
Chris@101
|
1195
|
Chris@16
|
1196 namespace boost {
|
Chris@16
|
1197 namespace interprocess {
|
Chris@16
|
1198 namespace winapi {
|
Chris@16
|
1199
|
Chris@16
|
1200 inline unsigned long get_last_error()
|
Chris@16
|
1201 { return GetLastError(); }
|
Chris@16
|
1202
|
Chris@16
|
1203 inline void set_last_error(unsigned long err)
|
Chris@16
|
1204 { return SetLastError(err); }
|
Chris@16
|
1205
|
Chris@16
|
1206 inline unsigned long format_message
|
Chris@16
|
1207 (unsigned long dwFlags, const void *lpSource,
|
Chris@16
|
1208 unsigned long dwMessageId, unsigned long dwLanguageId,
|
Chris@16
|
1209 char *lpBuffer, unsigned long nSize, std::va_list *Arguments)
|
Chris@16
|
1210 {
|
Chris@16
|
1211 return FormatMessageA
|
Chris@16
|
1212 (dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);
|
Chris@16
|
1213 }
|
Chris@16
|
1214
|
Chris@16
|
1215 //And now, wrapper functions
|
Chris@16
|
1216 inline void * local_free(void *hmem)
|
Chris@16
|
1217 { return LocalFree(hmem); }
|
Chris@16
|
1218
|
Chris@16
|
1219 inline unsigned long make_lang_id(unsigned long p, unsigned long s)
|
Chris@16
|
1220 { return ((((unsigned short)(s)) << 10) | (unsigned short)(p)); }
|
Chris@16
|
1221
|
Chris@16
|
1222 inline void sched_yield()
|
Chris@16
|
1223 {
|
Chris@16
|
1224 if(!SwitchToThread()){
|
Chris@16
|
1225 Sleep(0);
|
Chris@16
|
1226 }
|
Chris@16
|
1227 }
|
Chris@16
|
1228
|
Chris@16
|
1229 inline void sleep_tick()
|
Chris@16
|
1230 { Sleep(1); }
|
Chris@16
|
1231
|
Chris@16
|
1232 inline void sleep(unsigned long ms)
|
Chris@16
|
1233 { Sleep(ms); }
|
Chris@16
|
1234
|
Chris@16
|
1235 inline unsigned long get_current_thread_id()
|
Chris@16
|
1236 { return GetCurrentThreadId(); }
|
Chris@16
|
1237
|
Chris@16
|
1238 inline bool get_process_times
|
Chris@16
|
1239 ( void *hProcess, interprocess_filetime* lpCreationTime
|
Chris@16
|
1240 , interprocess_filetime *lpExitTime, interprocess_filetime *lpKernelTime
|
Chris@16
|
1241 , interprocess_filetime *lpUserTime )
|
Chris@16
|
1242 { return 0 != GetProcessTimes(hProcess, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime); }
|
Chris@16
|
1243
|
Chris@16
|
1244 inline unsigned long get_current_process_id()
|
Chris@16
|
1245 { return GetCurrentProcessId(); }
|
Chris@16
|
1246
|
Chris@16
|
1247 inline unsigned int close_handle(void* handle)
|
Chris@16
|
1248 { return CloseHandle(handle); }
|
Chris@16
|
1249
|
Chris@101
|
1250 inline void * find_first_file(const char *lpFileName, win32_find_data *lpFindFileData)
|
Chris@16
|
1251 { return FindFirstFileA(lpFileName, lpFindFileData); }
|
Chris@16
|
1252
|
Chris@101
|
1253 inline bool find_next_file(void *hFindFile, win32_find_data *lpFindFileData)
|
Chris@16
|
1254 { return FindNextFileA(hFindFile, lpFindFileData) != 0; }
|
Chris@16
|
1255
|
Chris@16
|
1256 inline bool find_close(void *handle)
|
Chris@16
|
1257 { return FindClose(handle) != 0; }
|
Chris@16
|
1258
|
Chris@16
|
1259 inline bool duplicate_current_process_handle
|
Chris@16
|
1260 (void *hSourceHandle, void **lpTargetHandle)
|
Chris@16
|
1261 {
|
Chris@16
|
1262 return 0 != DuplicateHandle
|
Chris@16
|
1263 ( GetCurrentProcess(), hSourceHandle, GetCurrentProcess()
|
Chris@16
|
1264 , lpTargetHandle, 0, 0
|
Chris@16
|
1265 , duplicate_same_access);
|
Chris@16
|
1266 }
|
Chris@16
|
1267
|
Chris@16
|
1268 inline unsigned long get_file_type(void *hFile)
|
Chris@16
|
1269 {
|
Chris@16
|
1270 return GetFileType(hFile);
|
Chris@16
|
1271 }
|
Chris@16
|
1272
|
Chris@16
|
1273 /*
|
Chris@16
|
1274 inline void get_system_time_as_file_time(interprocess_filetime *filetime)
|
Chris@16
|
1275 { GetSystemTimeAsFileTime(filetime); }
|
Chris@16
|
1276
|
Chris@16
|
1277 inline bool file_time_to_local_file_time
|
Chris@16
|
1278 (const interprocess_filetime *in, const interprocess_filetime *out)
|
Chris@16
|
1279 { return 0 != FileTimeToLocalFileTime(in, out); }
|
Chris@16
|
1280 */
|
Chris@16
|
1281 inline void *open_or_create_mutex(const char *name, bool initial_owner, interprocess_security_attributes *attr)
|
Chris@16
|
1282 { return CreateMutexA(attr, (int)initial_owner, name); }
|
Chris@16
|
1283
|
Chris@16
|
1284 inline unsigned long wait_for_single_object(void *handle, unsigned long time)
|
Chris@16
|
1285 { return WaitForSingleObject(handle, time); }
|
Chris@16
|
1286
|
Chris@16
|
1287 inline int release_mutex(void *handle)
|
Chris@16
|
1288 { return ReleaseMutex(handle); }
|
Chris@16
|
1289
|
Chris@16
|
1290 inline int unmap_view_of_file(void *address)
|
Chris@16
|
1291 { return UnmapViewOfFile(address); }
|
Chris@16
|
1292
|
Chris@16
|
1293 inline void *open_or_create_semaphore(const char *name, long initial_count, long maximum_count, interprocess_security_attributes *attr)
|
Chris@16
|
1294 { return CreateSemaphoreA(attr, initial_count, maximum_count, name); }
|
Chris@16
|
1295
|
Chris@16
|
1296 inline void *open_semaphore(const char *name)
|
Chris@16
|
1297 { return OpenSemaphoreA(semaphore_all_access, 0, name); }
|
Chris@16
|
1298
|
Chris@16
|
1299 inline int release_semaphore(void *handle, long release_count, long *prev_count)
|
Chris@16
|
1300 { return ReleaseSemaphore(handle, release_count, prev_count); }
|
Chris@16
|
1301
|
Chris@16
|
1302 class interprocess_all_access_security
|
Chris@16
|
1303 {
|
Chris@16
|
1304 interprocess_security_attributes sa;
|
Chris@16
|
1305 interprocess_security_descriptor sd;
|
Chris@16
|
1306 bool initialized;
|
Chris@16
|
1307
|
Chris@16
|
1308 public:
|
Chris@16
|
1309 interprocess_all_access_security()
|
Chris@16
|
1310 : initialized(false)
|
Chris@16
|
1311 {
|
Chris@16
|
1312 if(!InitializeSecurityDescriptor(&sd, security_descriptor_revision))
|
Chris@16
|
1313 return;
|
Chris@16
|
1314 if(!SetSecurityDescriptorDacl(&sd, true, 0, false))
|
Chris@16
|
1315 return;
|
Chris@16
|
1316 sa.lpSecurityDescriptor = &sd;
|
Chris@16
|
1317 sa.nLength = sizeof(interprocess_security_attributes);
|
Chris@16
|
1318 sa.bInheritHandle = false;
|
Chris@16
|
1319 initialized = false;
|
Chris@16
|
1320 }
|
Chris@16
|
1321
|
Chris@16
|
1322 interprocess_security_attributes *get_attributes()
|
Chris@16
|
1323 { return &sa; }
|
Chris@16
|
1324 };
|
Chris@16
|
1325
|
Chris@101
|
1326 inline void * create_file_mapping (void * handle, unsigned long access, ::boost::ulong_long_type file_offset, const char * name, interprocess_security_attributes *psec)
|
Chris@16
|
1327 {
|
Chris@16
|
1328 const unsigned long high_size(file_offset >> 32), low_size((boost::uint32_t)file_offset);
|
Chris@16
|
1329 return CreateFileMappingA (handle, psec, access, high_size, low_size, name);
|
Chris@16
|
1330 }
|
Chris@16
|
1331
|
Chris@16
|
1332 inline void * open_file_mapping (unsigned long access, const char *name)
|
Chris@16
|
1333 { return OpenFileMappingA (access, 0, name); }
|
Chris@16
|
1334
|
Chris@101
|
1335 inline void *map_view_of_file_ex(void *handle, unsigned long file_access, ::boost::ulong_long_type offset, std::size_t numbytes, void *base_addr)
|
Chris@16
|
1336 {
|
Chris@101
|
1337 const unsigned long offset_low = (unsigned long)(offset & ((::boost::ulong_long_type)0xFFFFFFFF));
|
Chris@16
|
1338 const unsigned long offset_high = offset >> 32;
|
Chris@16
|
1339 return MapViewOfFileEx(handle, file_access, offset_high, offset_low, numbytes, base_addr);
|
Chris@16
|
1340 }
|
Chris@16
|
1341
|
Chris@16
|
1342 inline void *create_file(const char *name, unsigned long access, unsigned long creation_flags, unsigned long attributes, interprocess_security_attributes *psec)
|
Chris@16
|
1343 {
|
Chris@16
|
1344 for (unsigned int attempt(0); attempt < error_sharing_violation_tries; ++attempt){
|
Chris@16
|
1345 void * const handle = CreateFileA(name, access,
|
Chris@16
|
1346 file_share_read | file_share_write | file_share_delete,
|
Chris@16
|
1347 psec, creation_flags, attributes, 0);
|
Chris@16
|
1348 bool const invalid(invalid_handle_value == handle);
|
Chris@16
|
1349 if (!invalid){
|
Chris@16
|
1350 return handle;
|
Chris@16
|
1351 }
|
Chris@16
|
1352 if (error_sharing_violation != get_last_error()){
|
Chris@16
|
1353 return handle;
|
Chris@16
|
1354 }
|
Chris@16
|
1355 sleep(error_sharing_violation_sleep_ms);
|
Chris@16
|
1356 }
|
Chris@16
|
1357 return invalid_handle_value;
|
Chris@16
|
1358 }
|
Chris@16
|
1359
|
Chris@16
|
1360 inline void get_system_info(system_info *info)
|
Chris@16
|
1361 { GetSystemInfo(info); }
|
Chris@16
|
1362
|
Chris@16
|
1363 inline bool flush_view_of_file(void *base_addr, std::size_t numbytes)
|
Chris@16
|
1364 { return 0 != FlushViewOfFile(base_addr, numbytes); }
|
Chris@16
|
1365
|
Chris@16
|
1366 inline bool virtual_unlock(void *base_addr, std::size_t numbytes)
|
Chris@16
|
1367 { return 0 != VirtualUnlock(base_addr, numbytes); }
|
Chris@16
|
1368
|
Chris@16
|
1369 inline bool virtual_protect(void *base_addr, std::size_t numbytes, unsigned long flNewProtect, unsigned long &lpflOldProtect)
|
Chris@16
|
1370 { return 0 != VirtualProtect(base_addr, numbytes, flNewProtect, &lpflOldProtect); }
|
Chris@16
|
1371
|
Chris@16
|
1372 inline bool flush_file_buffers(void *handle)
|
Chris@16
|
1373 { return 0 != FlushFileBuffers(handle); }
|
Chris@16
|
1374
|
Chris@16
|
1375 inline bool get_file_size(void *handle, __int64 &size)
|
Chris@101
|
1376 { return 0 != GetFileSizeEx(handle, (large_integer*)&size); }
|
Chris@16
|
1377
|
Chris@16
|
1378 inline bool create_directory(const char *name)
|
Chris@16
|
1379 {
|
Chris@16
|
1380 interprocess_all_access_security sec;
|
Chris@16
|
1381 return 0 != CreateDirectoryA(name, sec.get_attributes());
|
Chris@16
|
1382 }
|
Chris@16
|
1383
|
Chris@16
|
1384 inline bool remove_directory(const char *lpPathName)
|
Chris@16
|
1385 { return 0 != RemoveDirectoryA(lpPathName); }
|
Chris@16
|
1386
|
Chris@16
|
1387 inline unsigned long get_temp_path(unsigned long length, char *buffer)
|
Chris@16
|
1388 { return GetTempPathA(length, buffer); }
|
Chris@16
|
1389
|
Chris@16
|
1390 inline int set_end_of_file(void *handle)
|
Chris@16
|
1391 { return 0 != SetEndOfFile(handle); }
|
Chris@16
|
1392
|
Chris@16
|
1393 inline bool set_file_pointer_ex(void *handle, __int64 distance, __int64 *new_file_pointer, unsigned long move_method)
|
Chris@101
|
1394 {
|
Chris@101
|
1395 large_integer d; d.QuadPart = distance;
|
Chris@101
|
1396 return 0 != SetFilePointerEx(handle, d, (large_integer*)new_file_pointer, move_method);
|
Chris@101
|
1397 }
|
Chris@16
|
1398
|
Chris@16
|
1399 inline bool lock_file_ex(void *hnd, unsigned long flags, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped *overlapped)
|
Chris@16
|
1400 { return 0 != LockFileEx(hnd, flags, reserved, size_low, size_high, overlapped); }
|
Chris@16
|
1401
|
Chris@16
|
1402 inline bool unlock_file_ex(void *hnd, unsigned long reserved, unsigned long size_low, unsigned long size_high, interprocess_overlapped *overlapped)
|
Chris@16
|
1403 { return 0 != UnlockFileEx(hnd, reserved, size_low, size_high, overlapped); }
|
Chris@16
|
1404
|
Chris@16
|
1405 inline bool write_file(void *hnd, const void *buffer, unsigned long bytes_to_write, unsigned long *bytes_written, interprocess_overlapped* overlapped)
|
Chris@16
|
1406 { return 0 != WriteFile(hnd, buffer, bytes_to_write, bytes_written, overlapped); }
|
Chris@16
|
1407
|
Chris@16
|
1408 inline bool read_file(void *hnd, void *buffer, unsigned long bytes_to_read, unsigned long *bytes_read, interprocess_overlapped* overlapped)
|
Chris@16
|
1409 { return 0 != ReadFile(hnd, buffer, bytes_to_read, bytes_read, overlapped); }
|
Chris@16
|
1410
|
Chris@16
|
1411 inline bool get_file_information_by_handle(void *hnd, interprocess_by_handle_file_information *info)
|
Chris@16
|
1412 { return 0 != GetFileInformationByHandle(hnd, info); }
|
Chris@16
|
1413
|
Chris@16
|
1414 inline long interlocked_increment(long volatile *addr)
|
Chris@16
|
1415 { return BOOST_INTERLOCKED_INCREMENT(addr); }
|
Chris@16
|
1416
|
Chris@16
|
1417 inline long interlocked_decrement(long volatile *addr)
|
Chris@16
|
1418 { return BOOST_INTERLOCKED_DECREMENT(addr); }
|
Chris@16
|
1419
|
Chris@16
|
1420 inline long interlocked_compare_exchange(long volatile *addr, long val1, long val2)
|
Chris@16
|
1421 { return BOOST_INTERLOCKED_COMPARE_EXCHANGE(addr, val1, val2); }
|
Chris@16
|
1422
|
Chris@16
|
1423 inline long interlocked_exchange_add(long volatile* addend, long value)
|
Chris@16
|
1424 { return BOOST_INTERLOCKED_EXCHANGE_ADD(const_cast<long*>(addend), value); }
|
Chris@16
|
1425
|
Chris@16
|
1426 inline long interlocked_exchange(long volatile* addend, long value)
|
Chris@16
|
1427 { return BOOST_INTERLOCKED_EXCHANGE(const_cast<long*>(addend), value); }
|
Chris@16
|
1428
|
Chris@16
|
1429 //Forward functions
|
Chris@101
|
1430 inline hmodule load_library(const char *name)
|
Chris@16
|
1431 { return LoadLibraryA(name); }
|
Chris@16
|
1432
|
Chris@101
|
1433 inline bool free_library(hmodule module)
|
Chris@16
|
1434 { return 0 != FreeLibrary(module); }
|
Chris@16
|
1435
|
Chris@101
|
1436 inline farproc_t get_proc_address(hmodule module, const char *name)
|
Chris@16
|
1437 { return GetProcAddress(module, name); }
|
Chris@16
|
1438
|
Chris@16
|
1439 inline void *get_current_process()
|
Chris@16
|
1440 { return GetCurrentProcess(); }
|
Chris@16
|
1441
|
Chris@101
|
1442 inline hmodule get_module_handle(const char *name)
|
Chris@16
|
1443 { return GetModuleHandleA(name); }
|
Chris@16
|
1444
|
Chris@101
|
1445 inline long reg_open_key_ex(hkey hKey, const char *lpSubKey, unsigned long ulOptions, unsigned long samDesired, hkey *phkResult)
|
Chris@16
|
1446 { return RegOpenKeyExA(hKey, lpSubKey, ulOptions, samDesired, phkResult); }
|
Chris@16
|
1447
|
Chris@101
|
1448 inline long reg_query_value_ex(hkey hKey, const char *lpValueName, unsigned long*lpReserved, unsigned long*lpType, unsigned char *lpData, unsigned long*lpcbData)
|
Chris@16
|
1449 { return RegQueryValueExA(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData); }
|
Chris@16
|
1450
|
Chris@101
|
1451 inline long reg_close_key(hkey hKey)
|
Chris@16
|
1452 { return RegCloseKey(hKey); }
|
Chris@16
|
1453
|
Chris@16
|
1454 inline void initialize_object_attributes
|
Chris@16
|
1455 ( object_attributes_t *pobject_attr, unicode_string_t *name
|
Chris@16
|
1456 , unsigned long attr, void *rootdir, void *security_descr)
|
Chris@16
|
1457
|
Chris@16
|
1458 {
|
Chris@16
|
1459 pobject_attr->Length = sizeof(object_attributes_t);
|
Chris@16
|
1460 pobject_attr->RootDirectory = rootdir;
|
Chris@16
|
1461 pobject_attr->Attributes = attr;
|
Chris@16
|
1462 pobject_attr->ObjectName = name;
|
Chris@16
|
1463 pobject_attr->SecurityDescriptor = security_descr;
|
Chris@16
|
1464 pobject_attr->SecurityQualityOfService = 0;
|
Chris@16
|
1465 }
|
Chris@16
|
1466
|
Chris@16
|
1467 inline void rtl_init_empty_unicode_string(unicode_string_t *ucStr, wchar_t *buf, unsigned short bufSize)
|
Chris@16
|
1468 {
|
Chris@16
|
1469 ucStr->Buffer = buf;
|
Chris@16
|
1470 ucStr->Length = 0;
|
Chris@16
|
1471 ucStr->MaximumLength = bufSize;
|
Chris@16
|
1472 }
|
Chris@16
|
1473
|
Chris@16
|
1474 //A class that locates and caches loaded DLL function addresses.
|
Chris@16
|
1475 template<int Dummy>
|
Chris@16
|
1476 struct function_address_holder
|
Chris@16
|
1477 {
|
Chris@16
|
1478 enum { NtSetInformationFile
|
Chris@16
|
1479 , NtQuerySystemInformation
|
Chris@16
|
1480 , NtQueryObject
|
Chris@16
|
1481 , NtQuerySemaphore
|
Chris@16
|
1482 , NtQuerySection
|
Chris@16
|
1483 , NtOpenFile
|
Chris@16
|
1484 , NtClose
|
Chris@16
|
1485 , NtQueryTimerResolution
|
Chris@16
|
1486 , NtSetTimerResolution
|
Chris@16
|
1487 , QueryPerformanceCounter
|
Chris@16
|
1488 , QueryPerformanceFrequency
|
Chris@16
|
1489 , NumFunction
|
Chris@16
|
1490 };
|
Chris@16
|
1491 enum { NtDll_dll, Kernel32_dll, NumModule };
|
Chris@16
|
1492
|
Chris@16
|
1493 private:
|
Chris@16
|
1494 static const char *FunctionNames[NumFunction];
|
Chris@16
|
1495 static const char *ModuleNames[NumModule];
|
Chris@101
|
1496 static farproc_t FunctionAddresses[NumFunction];
|
Chris@16
|
1497 static unsigned int FunctionModules[NumFunction];
|
Chris@16
|
1498 static volatile long FunctionStates[NumFunction];
|
Chris@101
|
1499 static hmodule ModuleAddresses[NumModule];
|
Chris@16
|
1500 static volatile long ModuleStates[NumModule];
|
Chris@16
|
1501
|
Chris@101
|
1502 static hmodule get_module_from_id(unsigned int id)
|
Chris@16
|
1503 {
|
Chris@16
|
1504 BOOST_ASSERT(id < (unsigned int)NumModule);
|
Chris@101
|
1505 hmodule addr = get_module_handle(ModuleNames[id]);
|
Chris@16
|
1506 BOOST_ASSERT(addr);
|
Chris@16
|
1507 return addr;
|
Chris@16
|
1508 }
|
Chris@16
|
1509
|
Chris@101
|
1510 static hmodule get_module(const unsigned int id)
|
Chris@16
|
1511 {
|
Chris@16
|
1512 BOOST_ASSERT(id < (unsigned int)NumModule);
|
Chris@16
|
1513 for(unsigned i = 0; ModuleStates[id] < 2; ++i){
|
Chris@16
|
1514 if(interlocked_compare_exchange(&ModuleStates[id], 1, 0) == 0){
|
Chris@16
|
1515 ModuleAddresses[id] = get_module_from_id(id);
|
Chris@16
|
1516 interlocked_increment(&ModuleStates[id]);
|
Chris@16
|
1517 break;
|
Chris@16
|
1518 }
|
Chris@16
|
1519 else if(i & 1){
|
Chris@16
|
1520 sched_yield();
|
Chris@16
|
1521 }
|
Chris@16
|
1522 else{
|
Chris@16
|
1523 sleep_tick();
|
Chris@16
|
1524 }
|
Chris@16
|
1525 }
|
Chris@16
|
1526 return ModuleAddresses[id];
|
Chris@16
|
1527 }
|
Chris@16
|
1528
|
Chris@101
|
1529 static farproc_t get_address_from_dll(const unsigned int id)
|
Chris@16
|
1530 {
|
Chris@16
|
1531 BOOST_ASSERT(id < (unsigned int)NumFunction);
|
Chris@101
|
1532 farproc_t addr = get_proc_address(get_module(FunctionModules[id]), FunctionNames[id]);
|
Chris@16
|
1533 BOOST_ASSERT(addr);
|
Chris@16
|
1534 return addr;
|
Chris@16
|
1535 }
|
Chris@16
|
1536
|
Chris@16
|
1537 public:
|
Chris@101
|
1538 static farproc_t get(const unsigned int id)
|
Chris@16
|
1539 {
|
Chris@16
|
1540 BOOST_ASSERT(id < (unsigned int)NumFunction);
|
Chris@16
|
1541 for(unsigned i = 0; FunctionStates[id] < 2; ++i){
|
Chris@16
|
1542 if(interlocked_compare_exchange(&FunctionStates[id], 1, 0) == 0){
|
Chris@16
|
1543 FunctionAddresses[id] = get_address_from_dll(id);
|
Chris@16
|
1544 interlocked_increment(&FunctionStates[id]);
|
Chris@16
|
1545 break;
|
Chris@16
|
1546 }
|
Chris@16
|
1547 else if(i & 1){
|
Chris@16
|
1548 sched_yield();
|
Chris@16
|
1549 }
|
Chris@16
|
1550 else{
|
Chris@16
|
1551 sleep_tick();
|
Chris@16
|
1552 }
|
Chris@16
|
1553 }
|
Chris@16
|
1554 return FunctionAddresses[id];
|
Chris@16
|
1555 }
|
Chris@16
|
1556 };
|
Chris@16
|
1557
|
Chris@16
|
1558 template<int Dummy>
|
Chris@16
|
1559 const char *function_address_holder<Dummy>::FunctionNames[function_address_holder<Dummy>::NumFunction] =
|
Chris@16
|
1560 {
|
Chris@16
|
1561 "NtSetInformationFile",
|
Chris@16
|
1562 "NtQuerySystemInformation",
|
Chris@16
|
1563 "NtQueryObject",
|
Chris@16
|
1564 "NtQuerySemaphore",
|
Chris@16
|
1565 "NtQuerySection",
|
Chris@16
|
1566 "NtOpenFile",
|
Chris@16
|
1567 "NtClose",
|
Chris@16
|
1568 "NtQueryTimerResolution",
|
Chris@16
|
1569 "NtSetTimerResolution",
|
Chris@16
|
1570 "QueryPerformanceCounter",
|
Chris@16
|
1571 "QueryPerformanceFrequency"
|
Chris@16
|
1572 };
|
Chris@16
|
1573
|
Chris@16
|
1574 template<int Dummy>
|
Chris@101
|
1575 unsigned int function_address_holder<Dummy>::FunctionModules[function_address_holder<Dummy>::NumFunction] =
|
Chris@16
|
1576 {
|
Chris@16
|
1577 NtDll_dll,
|
Chris@16
|
1578 NtDll_dll,
|
Chris@16
|
1579 NtDll_dll,
|
Chris@16
|
1580 NtDll_dll,
|
Chris@16
|
1581 NtDll_dll,
|
Chris@16
|
1582 NtDll_dll,
|
Chris@16
|
1583 NtDll_dll,
|
Chris@16
|
1584 NtDll_dll,
|
Chris@16
|
1585 NtDll_dll,
|
Chris@16
|
1586 Kernel32_dll,
|
Chris@16
|
1587 Kernel32_dll
|
Chris@16
|
1588 };
|
Chris@16
|
1589
|
Chris@16
|
1590 template<int Dummy>
|
Chris@101
|
1591 const char *function_address_holder<Dummy>::ModuleNames[function_address_holder<Dummy>::NumModule] =
|
Chris@16
|
1592 {
|
Chris@16
|
1593 "ntdll.dll",
|
Chris@16
|
1594 "kernel32.dll"
|
Chris@16
|
1595 };
|
Chris@16
|
1596
|
Chris@16
|
1597
|
Chris@16
|
1598 template<int Dummy>
|
Chris@101
|
1599 farproc_t function_address_holder<Dummy>::FunctionAddresses[function_address_holder<Dummy>::NumFunction];
|
Chris@16
|
1600
|
Chris@16
|
1601 template<int Dummy>
|
Chris@16
|
1602 volatile long function_address_holder<Dummy>::FunctionStates[function_address_holder<Dummy>::NumFunction];
|
Chris@16
|
1603
|
Chris@16
|
1604 template<int Dummy>
|
Chris@101
|
1605 hmodule function_address_holder<Dummy>::ModuleAddresses[function_address_holder<Dummy>::NumModule];
|
Chris@16
|
1606
|
Chris@16
|
1607 template<int Dummy>
|
Chris@16
|
1608 volatile long function_address_holder<Dummy>::ModuleStates[function_address_holder<Dummy>::NumModule];
|
Chris@16
|
1609
|
Chris@16
|
1610
|
Chris@16
|
1611 struct dll_func
|
Chris@16
|
1612 : public function_address_holder<0>
|
Chris@16
|
1613 {};
|
Chris@16
|
1614
|
Chris@16
|
1615 //Complex winapi based functions...
|
Chris@16
|
1616 struct library_unloader
|
Chris@16
|
1617 {
|
Chris@101
|
1618 hmodule lib_;
|
Chris@101
|
1619 library_unloader(hmodule module) : lib_(module){}
|
Chris@16
|
1620 ~library_unloader(){ free_library(lib_); }
|
Chris@16
|
1621 };
|
Chris@16
|
1622
|
Chris@16
|
1623
|
Chris@16
|
1624 inline bool get_system_time_of_day_information(system_timeofday_information &info)
|
Chris@16
|
1625 {
|
Chris@16
|
1626 NtQuerySystemInformation_t pNtQuerySystemInformation = (NtQuerySystemInformation_t)
|
Chris@16
|
1627 dll_func::get(dll_func::NtQuerySystemInformation);
|
Chris@16
|
1628 unsigned long res;
|
Chris@16
|
1629 long status = pNtQuerySystemInformation(system_time_of_day_information, &info, sizeof(info), &res);
|
Chris@16
|
1630 if(status){
|
Chris@16
|
1631 return false;
|
Chris@16
|
1632 }
|
Chris@16
|
1633 return true;
|
Chris@16
|
1634 }
|
Chris@16
|
1635
|
Chris@16
|
1636 inline bool get_boot_time(unsigned char (&bootstamp) [BootstampLength])
|
Chris@16
|
1637 {
|
Chris@16
|
1638 system_timeofday_information info;
|
Chris@16
|
1639 bool ret = get_system_time_of_day_information(info);
|
Chris@16
|
1640 if(!ret){
|
Chris@16
|
1641 return false;
|
Chris@16
|
1642 }
|
Chris@16
|
1643 std::memcpy(&bootstamp[0], &info.Reserved1, sizeof(bootstamp));
|
Chris@16
|
1644 return true;
|
Chris@16
|
1645 }
|
Chris@16
|
1646
|
Chris@16
|
1647 inline bool get_boot_and_system_time(unsigned char (&bootsystemstamp) [BootAndSystemstampLength])
|
Chris@16
|
1648 {
|
Chris@16
|
1649 system_timeofday_information info;
|
Chris@16
|
1650 bool ret = get_system_time_of_day_information(info);
|
Chris@16
|
1651 if(!ret){
|
Chris@16
|
1652 return false;
|
Chris@16
|
1653 }
|
Chris@16
|
1654 std::memcpy(&bootsystemstamp[0], &info.Reserved1, sizeof(bootsystemstamp));
|
Chris@16
|
1655 return true;
|
Chris@16
|
1656 }
|
Chris@16
|
1657
|
Chris@101
|
1658 inline bool get_boot_time_str(char *bootstamp_str, std::size_t &s)
|
Chris@101
|
1659 //will write BootstampLength chars
|
Chris@16
|
1660 {
|
Chris@16
|
1661 if(s < (BootstampLength*2))
|
Chris@16
|
1662 return false;
|
Chris@16
|
1663 system_timeofday_information info;
|
Chris@16
|
1664 bool ret = get_system_time_of_day_information(info);
|
Chris@16
|
1665 if(!ret){
|
Chris@16
|
1666 return false;
|
Chris@16
|
1667 }
|
Chris@16
|
1668 const char Characters [] =
|
Chris@16
|
1669 { '0', '1', '2', '3', '4', '5', '6', '7'
|
Chris@16
|
1670 , '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
Chris@16
|
1671 std::size_t char_counter = 0;
|
Chris@16
|
1672 for(std::size_t i = 0; i != static_cast<std::size_t>(BootstampLength); ++i){
|
Chris@16
|
1673 bootstamp_str[char_counter++] = Characters[(info.Reserved1[i]&0xF0)>>4];
|
Chris@16
|
1674 bootstamp_str[char_counter++] = Characters[(info.Reserved1[i]&0x0F)];
|
Chris@16
|
1675 }
|
Chris@16
|
1676 s = BootstampLength*2;
|
Chris@16
|
1677 return true;
|
Chris@16
|
1678 }
|
Chris@16
|
1679
|
Chris@16
|
1680 //Writes the hexadecimal value of the buffer, in the wide character string.
|
Chris@16
|
1681 //str must be twice length
|
Chris@16
|
1682 inline void buffer_to_wide_str(const void *buf, std::size_t length, wchar_t *str)
|
Chris@16
|
1683 {
|
Chris@16
|
1684 const wchar_t Characters [] =
|
Chris@16
|
1685 { L'0', L'1', L'2', L'3', L'4', L'5', L'6', L'7'
|
Chris@16
|
1686 , L'8', L'9', L'A', L'B', L'C', L'D', L'E', L'F' };
|
Chris@16
|
1687 std::size_t char_counter = 0;
|
Chris@16
|
1688 const char *chbuf = static_cast<const char *>(buf);
|
Chris@16
|
1689 for(std::size_t i = 0; i != length; ++i){
|
Chris@16
|
1690 str[char_counter++] = Characters[(chbuf[i]&0xF0)>>4];
|
Chris@16
|
1691 str[char_counter++] = Characters[(chbuf[i]&0x0F)];
|
Chris@16
|
1692 }
|
Chris@16
|
1693 }
|
Chris@16
|
1694
|
Chris@101
|
1695 inline bool get_boot_and_system_time_wstr(wchar_t *bootsystemstamp, std::size_t &s)
|
Chris@101
|
1696 //will write BootAndSystemstampLength chars
|
Chris@16
|
1697 {
|
Chris@16
|
1698 if(s < (BootAndSystemstampLength*2))
|
Chris@16
|
1699 return false;
|
Chris@16
|
1700 system_timeofday_information info;
|
Chris@16
|
1701 bool ret = get_system_time_of_day_information(info);
|
Chris@16
|
1702 if(!ret){
|
Chris@16
|
1703 return false;
|
Chris@16
|
1704 }
|
Chris@16
|
1705
|
Chris@16
|
1706 buffer_to_wide_str(&info.Reserved1[0], BootAndSystemstampLength, bootsystemstamp);
|
Chris@16
|
1707 s = BootAndSystemstampLength*2;
|
Chris@16
|
1708 return true;
|
Chris@16
|
1709 }
|
Chris@16
|
1710
|
Chris@16
|
1711 class handle_closer
|
Chris@16
|
1712 {
|
Chris@16
|
1713 void *handle_;
|
Chris@16
|
1714 handle_closer(const handle_closer &);
|
Chris@16
|
1715 handle_closer& operator=(const handle_closer &);
|
Chris@16
|
1716 public:
|
Chris@16
|
1717 explicit handle_closer(void *handle) : handle_(handle){}
|
Chris@16
|
1718 ~handle_closer()
|
Chris@16
|
1719 { close_handle(handle_); }
|
Chris@16
|
1720 };
|
Chris@16
|
1721
|
Chris@16
|
1722 class eventlog_handle_closer
|
Chris@16
|
1723 {
|
Chris@16
|
1724 void *handle_;
|
Chris@16
|
1725 eventlog_handle_closer(const handle_closer &);
|
Chris@16
|
1726 eventlog_handle_closer& operator=(const eventlog_handle_closer &);
|
Chris@16
|
1727 public:
|
Chris@16
|
1728 explicit eventlog_handle_closer(void *handle) : handle_(handle){}
|
Chris@16
|
1729 ~eventlog_handle_closer()
|
Chris@16
|
1730 { CloseEventLog(handle_); }
|
Chris@16
|
1731 };
|
Chris@16
|
1732
|
Chris@16
|
1733 union ntquery_mem_t
|
Chris@16
|
1734 {
|
Chris@16
|
1735 object_name_information_t name;
|
Chris@16
|
1736 struct ren_t
|
Chris@16
|
1737 {
|
Chris@16
|
1738 file_rename_information_t info;
|
Chris@16
|
1739 wchar_t buf[1];
|
Chris@16
|
1740 } ren;
|
Chris@16
|
1741 };
|
Chris@16
|
1742
|
Chris@16
|
1743 class nt_query_mem_deleter
|
Chris@16
|
1744 {
|
Chris@16
|
1745 static const std::size_t rename_offset = offsetof(ntquery_mem_t, ren.info.FileName) -
|
Chris@16
|
1746 offsetof(ntquery_mem_t, name.Name.Buffer);
|
Chris@16
|
1747 // Timestamp process id atomic count
|
Chris@101
|
1748 static const std::size_t rename_suffix =
|
Chris@101
|
1749 (SystemTimeOfDayInfoLength + sizeof(unsigned long) + sizeof(boost::uint32_t))*2;
|
Chris@16
|
1750
|
Chris@16
|
1751 public:
|
Chris@16
|
1752 nt_query_mem_deleter(std::size_t object_name_information_size)
|
Chris@16
|
1753 : m_size(object_name_information_size + rename_offset + rename_suffix)
|
Chris@16
|
1754 , m_buf(new char [m_size])
|
Chris@16
|
1755 {}
|
Chris@16
|
1756
|
Chris@16
|
1757 ~nt_query_mem_deleter()
|
Chris@16
|
1758 {
|
Chris@16
|
1759 delete[]m_buf;
|
Chris@16
|
1760 }
|
Chris@16
|
1761
|
Chris@16
|
1762 void realloc_mem(std::size_t num_bytes)
|
Chris@16
|
1763 {
|
Chris@16
|
1764 num_bytes += rename_suffix + rename_offset;
|
Chris@16
|
1765 char *buf = m_buf;
|
Chris@16
|
1766 m_buf = new char[num_bytes];
|
Chris@16
|
1767 delete[]buf;
|
Chris@16
|
1768 m_size = num_bytes;
|
Chris@16
|
1769 }
|
Chris@16
|
1770
|
Chris@16
|
1771 ntquery_mem_t *query_mem() const
|
Chris@101
|
1772 { return static_cast<ntquery_mem_t *>(static_cast<void*>(m_buf)); }
|
Chris@16
|
1773
|
Chris@16
|
1774 unsigned long object_name_information_size() const
|
Chris@101
|
1775 {
|
Chris@101
|
1776 return static_cast<unsigned long>(m_size - rename_offset - SystemTimeOfDayInfoLength*2);
|
Chris@101
|
1777 }
|
Chris@16
|
1778
|
Chris@16
|
1779 std::size_t file_rename_information_size() const
|
Chris@16
|
1780 { return static_cast<unsigned long>(m_size); }
|
Chris@16
|
1781
|
Chris@16
|
1782 private:
|
Chris@16
|
1783 std::size_t m_size;
|
Chris@16
|
1784 char *m_buf;
|
Chris@16
|
1785 };
|
Chris@16
|
1786
|
Chris@16
|
1787 class c_heap_deleter
|
Chris@16
|
1788 {
|
Chris@16
|
1789 public:
|
Chris@16
|
1790 c_heap_deleter(std::size_t size)
|
Chris@16
|
1791 : m_buf(::malloc(size))
|
Chris@16
|
1792 {}
|
Chris@16
|
1793
|
Chris@16
|
1794 ~c_heap_deleter()
|
Chris@16
|
1795 {
|
Chris@16
|
1796 if(m_buf) ::free(m_buf);
|
Chris@16
|
1797 }
|
Chris@16
|
1798
|
Chris@16
|
1799 void realloc_mem(std::size_t num_bytes)
|
Chris@16
|
1800 {
|
Chris@16
|
1801 void *buf = ::realloc(m_buf, num_bytes);
|
Chris@16
|
1802 if(!buf){
|
Chris@16
|
1803 free(m_buf);
|
Chris@16
|
1804 m_buf = 0;
|
Chris@16
|
1805 }
|
Chris@16
|
1806 }
|
Chris@16
|
1807
|
Chris@16
|
1808 void *get() const
|
Chris@16
|
1809 { return m_buf; }
|
Chris@16
|
1810
|
Chris@16
|
1811 private:
|
Chris@16
|
1812 void *m_buf;
|
Chris@16
|
1813 };
|
Chris@16
|
1814
|
Chris@16
|
1815 inline bool unlink_file(const char *filename)
|
Chris@16
|
1816 {
|
Chris@16
|
1817 //Don't try to optimize doing a DeleteFile first
|
Chris@16
|
1818 //as there are interactions with permissions and
|
Chris@16
|
1819 //in-use files.
|
Chris@16
|
1820 //
|
Chris@16
|
1821 //if(!delete_file(filename)){
|
Chris@16
|
1822 // (...)
|
Chris@16
|
1823 //
|
Chris@16
|
1824
|
Chris@16
|
1825 //This functions tries to emulate UNIX unlink semantics in windows.
|
Chris@16
|
1826 //
|
Chris@16
|
1827 //- Open the file and mark the handle as delete-on-close
|
Chris@16
|
1828 //- Rename the file to an arbitrary name based on a random number
|
Chris@16
|
1829 //- Close the handle. If there are no file users, it will be deleted.
|
Chris@16
|
1830 // Otherwise it will be used by already connected handles but the
|
Chris@16
|
1831 // file name can't be used to open this file again
|
Chris@16
|
1832 try{
|
Chris@16
|
1833 NtSetInformationFile_t pNtSetInformationFile =
|
Chris@16
|
1834 (NtSetInformationFile_t)dll_func::get(dll_func::NtSetInformationFile);
|
Chris@16
|
1835
|
Chris@16
|
1836 NtQueryObject_t pNtQueryObject = (NtQueryObject_t)dll_func::get(dll_func::NtQueryObject);
|
Chris@16
|
1837
|
Chris@16
|
1838 //First step: Obtain a handle to the file using Win32 rules. This resolves relative paths
|
Chris@16
|
1839 void *fh = create_file(filename, generic_read | delete_access, open_existing, 0, 0);
|
Chris@16
|
1840 if(fh == invalid_handle_value){
|
Chris@16
|
1841 return false;
|
Chris@16
|
1842 }
|
Chris@16
|
1843
|
Chris@16
|
1844 handle_closer h_closer(fh);
|
Chris@16
|
1845 {
|
Chris@16
|
1846 //Obtain name length
|
Chris@16
|
1847 unsigned long size;
|
Chris@16
|
1848 const std::size_t initial_string_mem = 512u;
|
Chris@16
|
1849
|
Chris@16
|
1850 nt_query_mem_deleter nt_query_mem(sizeof(ntquery_mem_t)+initial_string_mem);
|
Chris@16
|
1851 //Obtain file name with guessed length
|
Chris@16
|
1852 if(pNtQueryObject(fh, object_name_information, nt_query_mem.query_mem(), nt_query_mem.object_name_information_size(), &size)){
|
Chris@16
|
1853 //Obtain file name with exact length buffer
|
Chris@16
|
1854 nt_query_mem.realloc_mem(size);
|
Chris@16
|
1855 if(pNtQueryObject(fh, object_name_information, nt_query_mem.query_mem(), nt_query_mem.object_name_information_size(), &size)){
|
Chris@16
|
1856 return false;
|
Chris@16
|
1857 }
|
Chris@16
|
1858 }
|
Chris@16
|
1859 ntquery_mem_t *pmem = nt_query_mem.query_mem();
|
Chris@16
|
1860 file_rename_information_t *pfri = &pmem->ren.info;
|
Chris@16
|
1861 const std::size_t RenMaxNumChars =
|
Chris@16
|
1862 (((char*)(pmem) + nt_query_mem.file_rename_information_size()) - (char*)&pmem->ren.info.FileName[0])/sizeof(wchar_t);
|
Chris@16
|
1863
|
Chris@16
|
1864 //Copy filename to the rename member
|
Chris@16
|
1865 std::memmove(pmem->ren.info.FileName, pmem->name.Name.Buffer, pmem->name.Name.Length);
|
Chris@16
|
1866 std::size_t filename_string_length = pmem->name.Name.Length/sizeof(wchar_t);
|
Chris@16
|
1867
|
Chris@16
|
1868 //Search '\\' character to replace from it
|
Chris@16
|
1869 for(std::size_t i = filename_string_length; i != 0; --filename_string_length){
|
Chris@16
|
1870 if(pmem->ren.info.FileName[--i] == L'\\')
|
Chris@16
|
1871 break;
|
Chris@16
|
1872 }
|
Chris@16
|
1873
|
Chris@16
|
1874 //Add random number
|
Chris@16
|
1875 std::size_t s = RenMaxNumChars - filename_string_length;
|
Chris@16
|
1876 if(!get_boot_and_system_time_wstr(&pfri->FileName[filename_string_length], s)){
|
Chris@16
|
1877 return false;
|
Chris@16
|
1878 }
|
Chris@16
|
1879 filename_string_length += s;
|
Chris@16
|
1880
|
Chris@16
|
1881 //Sometimes the precission of the timestamp is not enough and we need to add another random number.
|
Chris@16
|
1882 //The process id (to exclude concurrent processes) and an atomic count (to exclude concurrent threads).
|
Chris@16
|
1883 //should be enough
|
Chris@16
|
1884 const unsigned long pid = get_current_process_id();
|
Chris@16
|
1885 buffer_to_wide_str(&pid, sizeof(pid), &pfri->FileName[filename_string_length]);
|
Chris@16
|
1886 filename_string_length += sizeof(pid)*2;
|
Chris@16
|
1887
|
Chris@16
|
1888 static volatile boost::uint32_t u32_count = 0;
|
Chris@16
|
1889 interlocked_decrement(reinterpret_cast<volatile long*>(&u32_count));
|
Chris@16
|
1890 buffer_to_wide_str(const_cast<const boost::uint32_t *>(&u32_count), sizeof(boost::uint32_t), &pfri->FileName[filename_string_length]);
|
Chris@16
|
1891 filename_string_length += sizeof(boost::uint32_t)*2;
|
Chris@16
|
1892
|
Chris@16
|
1893 //Fill rename information (FileNameLength is in bytes)
|
Chris@16
|
1894 pfri->FileNameLength = static_cast<unsigned long>(sizeof(wchar_t)*(filename_string_length));
|
Chris@16
|
1895 pfri->Replace = 1;
|
Chris@16
|
1896 pfri->RootDir = 0;
|
Chris@16
|
1897
|
Chris@16
|
1898 //Cange the name of the in-use file...
|
Chris@16
|
1899 io_status_block_t io;
|
Chris@16
|
1900 if(0 != pNtSetInformationFile(fh, &io, pfri, nt_query_mem.file_rename_information_size(), file_rename_information)){
|
Chris@16
|
1901 return false;
|
Chris@16
|
1902 }
|
Chris@16
|
1903 }
|
Chris@16
|
1904 //...and mark it as delete-on-close
|
Chris@16
|
1905 {
|
Chris@16
|
1906 //Don't use pNtSetInformationFile with file_disposition_information as it can return STATUS_CANNOT_DELETE
|
Chris@16
|
1907 //if the file is still mapped. Reopen it with NtOpenFile and file_delete_on_close
|
Chris@16
|
1908 NtOpenFile_t pNtOpenFile = (NtOpenFile_t)dll_func::get(dll_func::NtOpenFile);
|
Chris@16
|
1909 NtClose_t pNtClose = (NtClose_t)dll_func::get(dll_func::NtClose);
|
Chris@16
|
1910 const wchar_t empty_str [] = L"";
|
Chris@16
|
1911 unicode_string_t ustring = { sizeof(empty_str) - sizeof (wchar_t) //length in bytes without null
|
Chris@16
|
1912 , sizeof(empty_str) //total size in bytes of memory allocated for Buffer.
|
Chris@16
|
1913 , const_cast<wchar_t*>(empty_str)
|
Chris@16
|
1914 };
|
Chris@16
|
1915 object_attributes_t object_attr;
|
Chris@101
|
1916 initialize_object_attributes(&object_attr, &ustring, 0, fh, 0);
|
Chris@16
|
1917 void* fh2 = 0;
|
Chris@16
|
1918 io_status_block_t io;
|
Chris@16
|
1919 pNtOpenFile( &fh2, delete_flag, &object_attr, &io
|
Chris@16
|
1920 , file_share_read | file_share_write | file_share_delete, file_delete_on_close);
|
Chris@16
|
1921 pNtClose(fh2);
|
Chris@16
|
1922 //Even if NtOpenFile fails, the file was renamed and the original no longer exists, so return a success status
|
Chris@16
|
1923 return true;
|
Chris@16
|
1924 }
|
Chris@16
|
1925 }
|
Chris@16
|
1926 catch(...){
|
Chris@16
|
1927 return false;
|
Chris@16
|
1928 }
|
Chris@16
|
1929 return true;
|
Chris@16
|
1930 }
|
Chris@16
|
1931
|
Chris@16
|
1932 struct reg_closer
|
Chris@16
|
1933 {
|
Chris@101
|
1934 hkey key_;
|
Chris@101
|
1935 reg_closer(hkey key) : key_(key){}
|
Chris@16
|
1936 ~reg_closer(){ reg_close_key(key_); }
|
Chris@16
|
1937 };
|
Chris@16
|
1938
|
Chris@16
|
1939 inline void get_shared_documents_folder(std::string &s)
|
Chris@16
|
1940 {
|
Chris@101
|
1941 #if 1 //Original registry search code
|
Chris@16
|
1942 s.clear();
|
Chris@101
|
1943 hkey key;
|
Chris@16
|
1944 if (reg_open_key_ex( hkey_local_machine
|
Chris@16
|
1945 , "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"
|
Chris@16
|
1946 , 0
|
Chris@16
|
1947 , key_query_value
|
Chris@16
|
1948 , &key) == 0){
|
Chris@16
|
1949 reg_closer key_closer(key);
|
Chris@16
|
1950
|
Chris@16
|
1951 //Obtain the value
|
Chris@16
|
1952 unsigned long size;
|
Chris@16
|
1953 unsigned long type;
|
Chris@16
|
1954 const char *const reg_value = "Common AppData";
|
Chris@16
|
1955 //long err = (*pRegQueryValue)( key, reg_value, 0, &type, 0, &size);
|
Chris@16
|
1956 long err = reg_query_value_ex( key, reg_value, 0, &type, 0, &size);
|
Chris@16
|
1957 if(!err){
|
Chris@16
|
1958 //Size includes terminating NULL
|
Chris@16
|
1959 s.resize(size);
|
Chris@16
|
1960 //err = (*pRegQueryValue)( key, reg_value, 0, &type, (unsigned char*)(&s[0]), &size);
|
Chris@16
|
1961 err = reg_query_value_ex( key, reg_value, 0, &type, (unsigned char*)(&s[0]), &size);
|
Chris@16
|
1962 if(!err)
|
Chris@16
|
1963 s.erase(s.end()-1);
|
Chris@16
|
1964 (void)err;
|
Chris@16
|
1965 }
|
Chris@16
|
1966 }
|
Chris@101
|
1967 #else //registry alternative: SHGetSpecialFolderPathA
|
Chris@101
|
1968 const int BIPC_CSIDL_COMMON_APPDATA = 0x0023; // All Users\Application Data
|
Chris@101
|
1969 const int BIPC_CSIDL_FLAG_CREATE = 0x8000; // new for Win2K, or this in to force creation of folder
|
Chris@101
|
1970 const int BIPC_SHGFP_TYPE_CURRENT = 0; // current value for user, verify it exists
|
Chris@101
|
1971
|
Chris@101
|
1972 s.clear();
|
Chris@101
|
1973 char szPath[max_path];
|
Chris@101
|
1974 if(0 == SHGetFolderPathA(0, BIPC_CSIDL_COMMON_APPDATA | BIPC_CSIDL_FLAG_CREATE, 0, BIPC_SHGFP_TYPE_CURRENT, szPath)){
|
Chris@101
|
1975 s = szPath;
|
Chris@101
|
1976 }
|
Chris@101
|
1977
|
Chris@101
|
1978 #endif
|
Chris@16
|
1979 }
|
Chris@16
|
1980
|
Chris@16
|
1981 inline void get_registry_value(const char *folder, const char *value_key, std::vector<unsigned char> &s)
|
Chris@16
|
1982 {
|
Chris@16
|
1983 s.clear();
|
Chris@101
|
1984 hkey key;
|
Chris@16
|
1985 if (reg_open_key_ex( hkey_local_machine
|
Chris@16
|
1986 , folder
|
Chris@16
|
1987 , 0
|
Chris@16
|
1988 , key_query_value
|
Chris@16
|
1989 , &key) == 0){
|
Chris@16
|
1990 reg_closer key_closer(key);
|
Chris@16
|
1991
|
Chris@16
|
1992 //Obtain the value
|
Chris@16
|
1993 unsigned long size;
|
Chris@16
|
1994 unsigned long type;
|
Chris@16
|
1995 const char *const reg_value = value_key;
|
Chris@16
|
1996 //long err = (*pRegQueryValue)( key, reg_value, 0, &type, 0, &size);
|
Chris@16
|
1997 long err = reg_query_value_ex( key, reg_value, 0, &type, 0, &size);
|
Chris@16
|
1998 if(!err){
|
Chris@16
|
1999 //Size includes terminating NULL
|
Chris@16
|
2000 s.resize(size);
|
Chris@16
|
2001 //err = (*pRegQueryValue)( key, reg_value, 0, &type, (unsigned char*)(&s[0]), &size);
|
Chris@16
|
2002 err = reg_query_value_ex( key, reg_value, 0, &type, (unsigned char*)(&s[0]), &size);
|
Chris@16
|
2003 if(!err)
|
Chris@16
|
2004 s.erase(s.end()-1);
|
Chris@16
|
2005 (void)err;
|
Chris@16
|
2006 }
|
Chris@16
|
2007 }
|
Chris@16
|
2008 }
|
Chris@16
|
2009
|
Chris@16
|
2010 struct co_uninitializer
|
Chris@16
|
2011 {
|
Chris@16
|
2012 co_uninitializer(bool b_uninitialize)
|
Chris@16
|
2013 : m_b_uninitialize(b_uninitialize)
|
Chris@16
|
2014 {}
|
Chris@16
|
2015
|
Chris@16
|
2016 ~co_uninitializer()
|
Chris@16
|
2017 {
|
Chris@16
|
2018 if(m_b_uninitialize){
|
Chris@16
|
2019 CoUninitialize();
|
Chris@16
|
2020 }
|
Chris@16
|
2021 }
|
Chris@16
|
2022
|
Chris@16
|
2023 private:
|
Chris@16
|
2024 const bool m_b_uninitialize;
|
Chris@16
|
2025 };
|
Chris@16
|
2026
|
Chris@16
|
2027 template<class Object>
|
Chris@16
|
2028 struct com_releaser
|
Chris@16
|
2029 {
|
Chris@16
|
2030 Object *&object_;
|
Chris@16
|
2031 com_releaser(Object *&object) : object_(object) {}
|
Chris@16
|
2032 ~com_releaser() { object_->Release(); object_ = 0; }
|
Chris@16
|
2033 };
|
Chris@16
|
2034
|
Chris@16
|
2035 inline bool get_wmi_class_attribute( std::wstring& strValue, const wchar_t *wmi_class, const wchar_t *wmi_class_var)
|
Chris@16
|
2036 {
|
Chris@16
|
2037 //See example http://msdn.microsoft.com/en-us/library/aa390423%28v=VS.85%29.aspx
|
Chris@16
|
2038 //
|
Chris@16
|
2039 //See BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL definition if you need to change the
|
Chris@16
|
2040 //default value of this macro in your application
|
Chris@16
|
2041 long co_init_ret = CoInitializeEx(0, BOOST_INTERPROCESS_WINDOWS_COINIT_MODEL);
|
Chris@16
|
2042 if(co_init_ret != S_OK_BIPC && co_init_ret != S_FALSE_BIPC && co_init_ret != RPC_E_CHANGED_MODE_BIPC)
|
Chris@16
|
2043 return false;
|
Chris@16
|
2044 co_uninitializer co_initialize_end(co_init_ret != RPC_E_CHANGED_MODE_BIPC);
|
Chris@16
|
2045 (void)co_initialize_end;
|
Chris@16
|
2046
|
Chris@16
|
2047 bool bRet = false;
|
Chris@16
|
2048 long sec_init_ret = CoInitializeSecurity
|
Chris@16
|
2049 ( 0 //pVoid
|
Chris@16
|
2050 ,-1 //cAuthSvc
|
Chris@16
|
2051 , 0 //asAuthSvc
|
Chris@16
|
2052 , 0 //pReserved1
|
Chris@16
|
2053 , RPC_C_AUTHN_LEVEL_PKT_BIPC //dwAuthnLevel
|
Chris@16
|
2054 , RPC_C_IMP_LEVEL_IMPERSONATE_BIPC //dwImpLevel
|
Chris@16
|
2055 , 0 //pAuthList
|
Chris@16
|
2056 , EOAC_NONE_BIPC //dwCapabilities
|
Chris@16
|
2057 , 0 //pReserved3
|
Chris@16
|
2058 );
|
Chris@16
|
2059 if( 0 == sec_init_ret || RPC_E_TOO_LATE_BIPC == sec_init_ret)
|
Chris@16
|
2060 {
|
Chris@16
|
2061 IWbemLocator_BIPC * pIWbemLocator = 0;
|
Chris@16
|
2062 const wchar_t * bstrNamespace = L"root\\cimv2";
|
Chris@16
|
2063
|
Chris@16
|
2064 if( 0 != CoCreateInstance(
|
Chris@16
|
2065 CLSID_WbemAdministrativeLocator,
|
Chris@16
|
2066 0,
|
Chris@16
|
2067 CLSCTX_INPROC_SERVER_BIPC | CLSCTX_LOCAL_SERVER_BIPC,
|
Chris@16
|
2068 IID_IUnknown, (void **)&pIWbemLocator)){
|
Chris@16
|
2069 return false;
|
Chris@16
|
2070 }
|
Chris@16
|
2071
|
Chris@16
|
2072 com_releaser<IWbemLocator_BIPC> IWbemLocator_releaser(pIWbemLocator);
|
Chris@16
|
2073
|
Chris@16
|
2074 IWbemServices_BIPC *pWbemServices = 0;
|
Chris@16
|
2075
|
Chris@16
|
2076 if( 0 != pIWbemLocator->ConnectServer(
|
Chris@101
|
2077 (bstr)bstrNamespace, // Namespace
|
Chris@16
|
2078 0, // Userid
|
Chris@16
|
2079 0, // PW
|
Chris@16
|
2080 0, // Locale
|
Chris@16
|
2081 0, // flags
|
Chris@16
|
2082 0, // Authority
|
Chris@16
|
2083 0, // Context
|
Chris@16
|
2084 &pWbemServices
|
Chris@16
|
2085 )
|
Chris@16
|
2086 ){
|
Chris@16
|
2087 return false;
|
Chris@16
|
2088 }
|
Chris@16
|
2089
|
Chris@16
|
2090 if( S_OK_BIPC != CoSetProxyBlanket(
|
Chris@16
|
2091 pWbemServices,
|
Chris@16
|
2092 RPC_C_AUTHN_DEFAULT_BIPC,
|
Chris@16
|
2093 RPC_C_AUTHZ_DEFAULT_BIPC,
|
Chris@16
|
2094 0,
|
Chris@16
|
2095 RPC_C_AUTHN_LEVEL_PKT_BIPC,
|
Chris@16
|
2096 RPC_C_IMP_LEVEL_IMPERSONATE_BIPC,
|
Chris@16
|
2097 0,
|
Chris@16
|
2098 EOAC_NONE_BIPC
|
Chris@16
|
2099 )
|
Chris@16
|
2100 ){
|
Chris@16
|
2101 return false;
|
Chris@16
|
2102 }
|
Chris@16
|
2103
|
Chris@16
|
2104 com_releaser<IWbemServices_BIPC> IWbemServices_releaser(pWbemServices);
|
Chris@16
|
2105
|
Chris@16
|
2106 strValue.clear();
|
Chris@16
|
2107 strValue += L"Select ";
|
Chris@16
|
2108 strValue += wmi_class_var;
|
Chris@16
|
2109 strValue += L" from ";
|
Chris@16
|
2110 strValue += wmi_class;
|
Chris@16
|
2111
|
Chris@16
|
2112 IEnumWbemClassObject_BIPC * pEnumObject = 0;
|
Chris@16
|
2113
|
Chris@16
|
2114 if ( 0 != pWbemServices->ExecQuery(
|
Chris@101
|
2115 (bstr)L"WQL",
|
Chris@101
|
2116 (bstr)strValue.c_str(),
|
Chris@16
|
2117 //WBEM_FLAG_RETURN_IMMEDIATELY_BIPC,
|
Chris@16
|
2118 WBEM_FLAG_RETURN_WHEN_COMPLETE_BIPC | WBEM_FLAG_FORWARD_ONLY_BIPC,
|
Chris@16
|
2119 0,
|
Chris@16
|
2120 &pEnumObject
|
Chris@16
|
2121 )
|
Chris@16
|
2122 ){
|
Chris@16
|
2123 return false;
|
Chris@16
|
2124 }
|
Chris@16
|
2125
|
Chris@16
|
2126 com_releaser<IEnumWbemClassObject_BIPC> IEnumWbemClassObject_releaser(pEnumObject);
|
Chris@16
|
2127
|
Chris@16
|
2128 //WBEM_FLAG_FORWARD_ONLY_BIPC incompatible with Reset
|
Chris@16
|
2129 //if ( 0 != pEnumObject->Reset() ){
|
Chris@16
|
2130 //return false;
|
Chris@16
|
2131 //}
|
Chris@16
|
2132
|
Chris@16
|
2133 wchar_variant vwchar;
|
Chris@16
|
2134 unsigned long uCount = 1, uReturned;
|
Chris@16
|
2135 IWbemClassObject_BIPC * pClassObject = 0;
|
Chris@16
|
2136 while( 0 == pEnumObject->Next( WBEM_INFINITE_BIPC, uCount, &pClassObject, &uReturned ) )
|
Chris@16
|
2137 {
|
Chris@16
|
2138 com_releaser<IWbemClassObject_BIPC> IWbemClassObject_releaser(pClassObject);
|
Chris@101
|
2139 if ( 0 == pClassObject->Get( (bstr)L"LastBootUpTime", 0, &vwchar, 0, 0 ) ){
|
Chris@16
|
2140 bRet = true;
|
Chris@101
|
2141 strValue = (wchar_t*)vwchar.bstrVal;
|
Chris@16
|
2142 VariantClear(&vwchar );
|
Chris@16
|
2143 break;
|
Chris@16
|
2144 }
|
Chris@16
|
2145 }
|
Chris@16
|
2146 }
|
Chris@16
|
2147 return bRet;
|
Chris@16
|
2148 }
|
Chris@16
|
2149
|
Chris@16
|
2150 #ifdef BOOST_INTERPROCESS_BOOTSTAMP_IS_LASTBOOTUPTIME
|
Chris@16
|
2151
|
Chris@16
|
2152 //Obtains the bootup time from WMI LastBootUpTime.
|
Chris@16
|
2153 //This time seems to change with hibernation and clock synchronization so avoid it.
|
Chris@16
|
2154 inline bool get_last_bootup_time( std::wstring& strValue )
|
Chris@16
|
2155 {
|
Chris@16
|
2156 bool ret = get_wmi_class_attribute(strValue, L"Win32_OperatingSystem", L"LastBootUpTime");
|
Chris@16
|
2157 std::size_t timezone = strValue.find(L'+');
|
Chris@16
|
2158 if(timezone != std::wstring::npos){
|
Chris@16
|
2159 strValue.erase(timezone);
|
Chris@16
|
2160 }
|
Chris@16
|
2161 timezone = strValue.find(L'-');
|
Chris@16
|
2162 if(timezone != std::wstring::npos){
|
Chris@16
|
2163 strValue.erase(timezone);
|
Chris@16
|
2164 }
|
Chris@16
|
2165 return ret;
|
Chris@16
|
2166 }
|
Chris@16
|
2167
|
Chris@16
|
2168 inline bool get_last_bootup_time( std::string& str )
|
Chris@16
|
2169 {
|
Chris@16
|
2170 std::wstring wstr;
|
Chris@16
|
2171 bool ret = get_last_bootup_time(wstr);
|
Chris@16
|
2172 str.resize(wstr.size());
|
Chris@16
|
2173 for(std::size_t i = 0, max = str.size(); i != max; ++i){
|
Chris@16
|
2174 str[i] = '0' + (wstr[i]-L'0');
|
Chris@16
|
2175 }
|
Chris@16
|
2176 return ret;
|
Chris@16
|
2177 }
|
Chris@16
|
2178
|
Chris@16
|
2179 #else
|
Chris@16
|
2180
|
Chris@16
|
2181 // Loop through the buffer and obtain the contents of the
|
Chris@16
|
2182 // requested record in the buffer.
|
Chris@16
|
2183 inline bool find_record_in_buffer( const void* pBuffer, unsigned long dwBytesRead, const char *provider_name
|
Chris@16
|
2184 , unsigned int id_to_find, interprocess_eventlogrecord *&pevent_log_record)
|
Chris@16
|
2185 {
|
Chris@16
|
2186 const unsigned char * pRecord = static_cast<const unsigned char*>(pBuffer);
|
Chris@16
|
2187 const unsigned char * pEndOfRecords = pRecord + dwBytesRead;
|
Chris@16
|
2188
|
Chris@16
|
2189 while (pRecord < pEndOfRecords){
|
Chris@16
|
2190 interprocess_eventlogrecord *pTypedRecord = (interprocess_eventlogrecord*)pRecord;
|
Chris@16
|
2191 // Check provider, written at the end of the fixed-part of the record
|
Chris@16
|
2192 if (0 == std::strcmp(provider_name, (char*)(pRecord + sizeof(interprocess_eventlogrecord))))
|
Chris@16
|
2193 {
|
Chris@16
|
2194 // Check event id
|
Chris@16
|
2195 if(id_to_find == (pTypedRecord->EventID & 0xFFFF)){
|
Chris@16
|
2196 pevent_log_record = pTypedRecord;
|
Chris@16
|
2197 return true;
|
Chris@16
|
2198 }
|
Chris@16
|
2199 }
|
Chris@16
|
2200
|
Chris@16
|
2201 pRecord += pTypedRecord->Length;
|
Chris@16
|
2202 }
|
Chris@16
|
2203 pevent_log_record = 0;
|
Chris@16
|
2204 return false;
|
Chris@16
|
2205 }
|
Chris@16
|
2206
|
Chris@16
|
2207 //Obtains the bootup time from the System Event Log,
|
Chris@16
|
2208 //event ID == 6005 (event log started).
|
Chris@16
|
2209 //Adapted from http://msdn.microsoft.com/en-us/library/windows/desktop/bb427356.aspx
|
Chris@16
|
2210 inline bool get_last_bootup_time(std::string &stamp)
|
Chris@16
|
2211 {
|
Chris@16
|
2212 const char *source_name = "System";
|
Chris@16
|
2213 const char *provider_name = "EventLog";
|
Chris@16
|
2214 const unsigned short event_id = 6005u;
|
Chris@16
|
2215
|
Chris@16
|
2216 unsigned long status = 0;
|
Chris@16
|
2217 unsigned long dwBytesToRead = 0;
|
Chris@16
|
2218 unsigned long dwBytesRead = 0;
|
Chris@16
|
2219 unsigned long dwMinimumBytesToRead = 0;
|
Chris@16
|
2220
|
Chris@16
|
2221 // The source name (provider) must exist as a subkey of Application.
|
Chris@16
|
2222 void *hEventLog = OpenEventLogA(0, source_name);
|
Chris@16
|
2223 if (hEventLog){
|
Chris@16
|
2224 eventlog_handle_closer hnd_closer(hEventLog); (void)hnd_closer;
|
Chris@101
|
2225 // Allocate an initial block of memory used to read event records. The number
|
Chris@16
|
2226 // of records read into the buffer will vary depending on the size of each event.
|
Chris@16
|
2227 // The size of each event will vary based on the size of the user-defined
|
Chris@101
|
2228 // data included with each event, the number and length of insertion
|
Chris@16
|
2229 // strings, and other data appended to the end of the event record.
|
Chris@16
|
2230 dwBytesToRead = max_record_buffer_size;
|
Chris@16
|
2231 c_heap_deleter heap_deleter(dwBytesToRead);
|
Chris@16
|
2232
|
Chris@101
|
2233 // Read blocks of records until you reach the end of the log or an
|
Chris@16
|
2234 // error occurs. The records are read from newest to oldest. If the buffer
|
Chris@16
|
2235 // is not big enough to hold a complete event record, reallocate the buffer.
|
Chris@16
|
2236 if (heap_deleter.get() != 0){
|
Chris@16
|
2237 while (0 == status){
|
Chris@101
|
2238 if (!ReadEventLogA(hEventLog,
|
Chris@16
|
2239 eventlog_sequential_read | eventlog_backwards_read,
|
Chris@101
|
2240 0,
|
Chris@16
|
2241 heap_deleter.get(),
|
Chris@16
|
2242 dwBytesToRead,
|
Chris@16
|
2243 &dwBytesRead,
|
Chris@16
|
2244 &dwMinimumBytesToRead)) {
|
Chris@16
|
2245 status = get_last_error();
|
Chris@16
|
2246 if (error_insufficient_buffer == status) {
|
Chris@16
|
2247 status = 0;
|
Chris@16
|
2248 dwBytesToRead = dwMinimumBytesToRead;
|
Chris@16
|
2249 heap_deleter.realloc_mem(dwMinimumBytesToRead);
|
Chris@16
|
2250 if (!heap_deleter.get()){
|
Chris@16
|
2251 return false;
|
Chris@16
|
2252 }
|
Chris@16
|
2253 }
|
Chris@16
|
2254 else{ //Not found or EOF
|
Chris@16
|
2255 return false;
|
Chris@16
|
2256 }
|
Chris@16
|
2257 }
|
Chris@16
|
2258 else
|
Chris@16
|
2259 {
|
Chris@16
|
2260 interprocess_eventlogrecord *pTypedRecord;
|
Chris@16
|
2261 // Print the contents of each record in the buffer.
|
Chris@16
|
2262 if(find_record_in_buffer(heap_deleter.get(), dwBytesRead, provider_name, event_id, pTypedRecord)){
|
Chris@16
|
2263 char stamp_str[sizeof(unsigned long)*3+1];
|
Chris@16
|
2264 std::sprintf(&stamp_str[0], "%u", ((unsigned int)pTypedRecord->TimeGenerated));
|
Chris@16
|
2265 stamp = stamp_str;
|
Chris@16
|
2266 break;
|
Chris@16
|
2267 }
|
Chris@16
|
2268 }
|
Chris@16
|
2269 }
|
Chris@16
|
2270 }
|
Chris@16
|
2271 }
|
Chris@16
|
2272 return true;
|
Chris@16
|
2273 }
|
Chris@16
|
2274
|
Chris@16
|
2275 #endif
|
Chris@16
|
2276
|
Chris@16
|
2277 inline bool is_directory(const char *path)
|
Chris@16
|
2278 {
|
Chris@101
|
2279 unsigned long attrib = GetFileAttributesA(path);
|
Chris@16
|
2280
|
Chris@101
|
2281 return (attrib != invalid_file_attributes &&
|
Chris@101
|
2282 (attrib & file_attribute_directory));
|
Chris@16
|
2283 }
|
Chris@16
|
2284
|
Chris@16
|
2285 inline bool get_file_mapping_size(void *file_mapping_hnd, __int64 &size)
|
Chris@16
|
2286 {
|
Chris@16
|
2287 NtQuerySection_t pNtQuerySection =
|
Chris@16
|
2288 (NtQuerySection_t)dll_func::get(dll_func::NtQuerySection);
|
Chris@16
|
2289 //Obtain file name
|
Chris@16
|
2290 interprocess_section_basic_information info;
|
Chris@16
|
2291 unsigned long ntstatus =
|
Chris@16
|
2292 pNtQuerySection(file_mapping_hnd, section_basic_information, &info, sizeof(info), 0);
|
Chris@16
|
2293 size = info.section_size;
|
Chris@16
|
2294 return !ntstatus;
|
Chris@16
|
2295 }
|
Chris@16
|
2296
|
Chris@16
|
2297 inline bool get_semaphore_info(void *handle, long &count, long &limit)
|
Chris@16
|
2298 {
|
Chris@16
|
2299 winapi::interprocess_semaphore_basic_information info;
|
Chris@16
|
2300 winapi::NtQuerySemaphore_t pNtQuerySemaphore =
|
Chris@16
|
2301 (winapi::NtQuerySemaphore_t)dll_func::get(winapi::dll_func::NtQuerySemaphore);
|
Chris@16
|
2302 unsigned int ret_len;
|
Chris@16
|
2303 long status = pNtQuerySemaphore(handle, winapi::semaphore_basic_information, &info, sizeof(info), &ret_len);
|
Chris@16
|
2304 count = info.count;
|
Chris@16
|
2305 limit = info.limit;
|
Chris@16
|
2306 return !status;
|
Chris@16
|
2307 }
|
Chris@16
|
2308
|
Chris@101
|
2309 inline bool query_timer_resolution(unsigned long *lowres, unsigned long *highres, unsigned long *curres)
|
Chris@16
|
2310 {
|
Chris@16
|
2311 winapi::NtQueryTimerResolution_t pNtQueryTimerResolution =
|
Chris@16
|
2312 (winapi::NtQueryTimerResolution_t)dll_func::get(winapi::dll_func::NtQueryTimerResolution);
|
Chris@16
|
2313 return !pNtQueryTimerResolution(lowres, highres, curres);
|
Chris@16
|
2314 }
|
Chris@16
|
2315
|
Chris@16
|
2316 inline bool set_timer_resolution(unsigned long RequestedResolution, int Set, unsigned long* ActualResolution)
|
Chris@16
|
2317 {
|
Chris@16
|
2318 winapi::NtSetTimerResolution_t pNtSetTimerResolution =
|
Chris@16
|
2319 (winapi::NtSetTimerResolution_t)dll_func::get(winapi::dll_func::NtSetTimerResolution);
|
Chris@16
|
2320 return !pNtSetTimerResolution(RequestedResolution, Set, ActualResolution);
|
Chris@16
|
2321 }
|
Chris@16
|
2322
|
Chris@16
|
2323 inline bool query_performance_counter(__int64 *lpPerformanceCount)
|
Chris@16
|
2324 {
|
Chris@16
|
2325 QueryPerformanceCounter_t pQueryPerformanceCounter = (QueryPerformanceCounter_t)
|
Chris@16
|
2326 dll_func::get(dll_func::QueryPerformanceCounter);
|
Chris@16
|
2327 return 0 != pQueryPerformanceCounter(lpPerformanceCount);
|
Chris@16
|
2328 }
|
Chris@16
|
2329
|
Chris@16
|
2330 inline bool query_performance_frequency(__int64 *lpFrequency)
|
Chris@16
|
2331 {
|
Chris@16
|
2332 QueryPerformanceCounter_t pQueryPerformanceFrequency = (QueryPerformanceFrequency_t)
|
Chris@16
|
2333 dll_func::get(dll_func::QueryPerformanceFrequency);
|
Chris@16
|
2334 return 0 != pQueryPerformanceFrequency(lpFrequency);
|
Chris@16
|
2335 }
|
Chris@16
|
2336
|
Chris@16
|
2337 inline unsigned long get_tick_count()
|
Chris@16
|
2338 { return GetTickCount(); }
|
Chris@16
|
2339
|
Chris@16
|
2340 } //namespace winapi
|
Chris@16
|
2341 } //namespace interprocess
|
Chris@16
|
2342 } //namespace boost
|
Chris@16
|
2343
|
Chris@101
|
2344 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
|
Chris@101
|
2345 # pragma GCC diagnostic pop
|
Chris@101
|
2346 #endif
|
Chris@101
|
2347
|
Chris@16
|
2348 #include <boost/interprocess/detail/config_end.hpp>
|
Chris@16
|
2349
|
Chris@101
|
2350 #endif //#ifdef BOOST_INTERPROCESS_WIN32_API_HPP
|