1 | /* $Id: nthlp.h 2997 2016-11-01 23:28:02Z bird $ */
|
---|
2 | /** @file
|
---|
3 | * MSC + NT helper functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2005-2013 knut st. osmundsen <[email protected]>
|
---|
8 | *
|
---|
9 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
10 | * copy of this software and associated documentation files (the "Software"),
|
---|
11 | * to deal in the Software without restriction, including without limitation
|
---|
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
13 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
14 | * Software is furnished to do so, subject to the following conditions:
|
---|
15 | *
|
---|
16 | * The above copyright notice and this permission notice shall be included
|
---|
17 | * in all copies or substantial portions of the Software.
|
---|
18 | *
|
---|
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
---|
22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
---|
25 | * IN THE SOFTWARE.
|
---|
26 | *
|
---|
27 | * Alternatively, the content of this file may be used under the terms of the
|
---|
28 | * GPL version 2 or later, or LGPL version 2.1 or later.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifndef ___nt_nthlp_h
|
---|
32 | #define ___nt_nthlp_h
|
---|
33 |
|
---|
34 | #include "ntstuff.h"
|
---|
35 | #include "nttypes.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | /** Lazy resolving of the NTDLL imports. */
|
---|
39 | #define birdResolveImports() do { if (g_fResolvedNtImports) {} else birdResolveImportsWorker(); } while (0)
|
---|
40 | void birdResolveImportsWorker(void);
|
---|
41 | extern int g_fResolvedNtImports;
|
---|
42 |
|
---|
43 | void *birdTmpAlloc(size_t cb);
|
---|
44 | void birdTmpFree(void *pv);
|
---|
45 |
|
---|
46 | void *birdMemAlloc(size_t cb);
|
---|
47 | void *birdMemAllocZ(size_t cb);
|
---|
48 | void birdMemFree(void *pv);
|
---|
49 |
|
---|
50 | int birdSetErrnoFromNt(MY_NTSTATUS rcNt);
|
---|
51 | int birdSetErrnoFromWin32(DWORD dwErr);
|
---|
52 | int birdSetErrnoToNoMem(void);
|
---|
53 | int birdSetErrnoToInvalidArg(void);
|
---|
54 | int birdSetErrnoToBadFileNo(void);
|
---|
55 |
|
---|
56 |
|
---|
57 | HANDLE birdOpenFile(const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
---|
58 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
|
---|
59 | HANDLE birdOpenFileW(const wchar_t *pwszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
---|
60 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
|
---|
61 | HANDLE birdOpenFileEx(HANDLE hRoot, const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
---|
62 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
|
---|
63 | HANDLE birdOpenFileExW(HANDLE hRoot, const wchar_t *pwszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
---|
64 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
|
---|
65 | HANDLE birdOpenParentDir(HANDLE hRoot, const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
---|
66 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
|
---|
67 | MY_UNICODE_STRING *pNameUniStr);
|
---|
68 | HANDLE birdOpenParentDirW(HANDLE hRoot, const wchar_t *pwszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
---|
69 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
|
---|
70 | MY_UNICODE_STRING *pNameUniStr);
|
---|
71 | MY_NTSTATUS birdOpenFileUniStr(HANDLE hRoot, MY_UNICODE_STRING *pNtPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
---|
72 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
|
---|
73 | HANDLE *phFile);
|
---|
74 | HANDLE birdOpenCurrentDirectory(void);
|
---|
75 | void birdCloseFile(HANDLE hFile);
|
---|
76 | int birdDosToNtPath(const char *pszPath, MY_UNICODE_STRING *pNtPath);
|
---|
77 | int birdDosToRelativeNtPath(const char *pszPath, MY_UNICODE_STRING *pNtPath);
|
---|
78 | void birdFreeNtPath(MY_UNICODE_STRING *pNtPath);
|
---|
79 |
|
---|
80 |
|
---|
81 | static __inline void birdNtTimeToTimeSpec(__int64 iNtTime, BirdTimeSpec_T *pTimeSpec)
|
---|
82 | {
|
---|
83 | iNtTime -= BIRD_NT_EPOCH_OFFSET_UNIX_100NS;
|
---|
84 | pTimeSpec->tv_sec = iNtTime / 10000000;
|
---|
85 | pTimeSpec->tv_nsec = (iNtTime % 10000000) * 100;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | #endif
|
---|
90 |
|
---|