| 1 | /* $Id: nthlp.h 3337 2020-04-22 17:56:36Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | * MSC + NT helper functions.
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | /*
|
|---|
| 7 | * Copyright (c) 2005-2013 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
|---|
| 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 | HANDLE birdOpenFile(const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
|---|
| 57 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
|
|---|
| 58 | HANDLE birdOpenFileW(const wchar_t *pwszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
|---|
| 59 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
|
|---|
| 60 | HANDLE birdOpenFileEx(HANDLE hRoot, const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
|---|
| 61 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
|
|---|
| 62 | HANDLE birdOpenFileExW(HANDLE hRoot, const wchar_t *pwszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
|---|
| 63 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
|
|---|
| 64 | HANDLE birdOpenParentDir(HANDLE hRoot, const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
|---|
| 65 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
|
|---|
| 66 | MY_UNICODE_STRING *pNameUniStr);
|
|---|
| 67 | HANDLE birdOpenParentDirW(HANDLE hRoot, const wchar_t *pwszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
|---|
| 68 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
|
|---|
| 69 | MY_UNICODE_STRING *pNameUniStr);
|
|---|
| 70 | MY_NTSTATUS birdOpenFileUniStr(HANDLE hRoot, MY_UNICODE_STRING *pNtPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
|
|---|
| 71 | ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs,
|
|---|
| 72 | HANDLE *phFile);
|
|---|
| 73 | HANDLE birdOpenCurrentDirectory(void);
|
|---|
| 74 | void birdCloseFile(HANDLE hFile);
|
|---|
| 75 |
|
|---|
| 76 | int birdIsPathDirSpec(const char *pszPath);
|
|---|
| 77 | int birdDosToNtPath(const char *pszPath, MY_UNICODE_STRING *pNtPath);
|
|---|
| 78 | int birdDosToNtPathW(const wchar_t *pwszPath, MY_UNICODE_STRING *pNtPath);
|
|---|
| 79 | int birdDosToRelativeNtPath(const char *pszPath, MY_UNICODE_STRING *pNtPath);
|
|---|
| 80 | int birdDosToRelativeNtPathW(const wchar_t *pszPath, MY_UNICODE_STRING *pNtPath);
|
|---|
| 81 | void birdFreeNtPath(MY_UNICODE_STRING *pNtPath);
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 | static __inline void birdNtTimeToTimeSpec(__int64 iNtTime, BirdTimeSpec_T *pTimeSpec)
|
|---|
| 85 | {
|
|---|
| 86 | iNtTime -= BIRD_NT_EPOCH_OFFSET_UNIX_100NS;
|
|---|
| 87 | pTimeSpec->tv_sec = iNtTime / 10000000;
|
|---|
| 88 | pTimeSpec->tv_nsec = (iNtTime % 10000000) * 100;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | static __inline __int64 birdNtTimeFromTimeSpec(BirdTimeSpec_T const *pTimeSpec)
|
|---|
| 93 | {
|
|---|
| 94 | __int64 iNtTime = pTimeSpec->tv_sec * 10000000;
|
|---|
| 95 | iNtTime += pTimeSpec->tv_nsec / 100;
|
|---|
| 96 | iNtTime += BIRD_NT_EPOCH_OFFSET_UNIX_100NS;
|
|---|
| 97 | return iNtTime;
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 | static __inline void birdNtTimeToTimeVal(__int64 iNtTime, BirdTimeVal_T *pTimeVal)
|
|---|
| 102 | {
|
|---|
| 103 | iNtTime -= BIRD_NT_EPOCH_OFFSET_UNIX_100NS;
|
|---|
| 104 | pTimeVal->tv_sec = iNtTime / 10000000;
|
|---|
| 105 | pTimeVal->tv_usec = (iNtTime % 10000000) / 10;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 | static __inline __int64 birdNtTimeFromTimeVal(BirdTimeVal_T const *pTimeVal)
|
|---|
| 110 | {
|
|---|
| 111 | __int64 iNtTime = pTimeVal->tv_sec * 10000000;
|
|---|
| 112 | iNtTime += pTimeVal->tv_usec * 10;
|
|---|
| 113 | iNtTime += BIRD_NT_EPOCH_OFFSET_UNIX_100NS;
|
|---|
| 114 | return iNtTime;
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 |
|
|---|
| 118 | #endif
|
|---|
| 119 |
|
|---|