VirtualBox

source: kBuild/trunk/src/lib/nt/nthlp.h@ 3598

Last change on this file since 3598 was 3337, checked in by bird, 5 years ago

kWorker: Intercept GetFileAttributesExA/W for speeding up moc.exe (qt).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.2 KB
Line 
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 <[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)
40void birdResolveImportsWorker(void);
41extern int g_fResolvedNtImports;
42
43void *birdTmpAlloc(size_t cb);
44void birdTmpFree(void *pv);
45
46void *birdMemAlloc(size_t cb);
47void *birdMemAllocZ(size_t cb);
48void birdMemFree(void *pv);
49
50int birdSetErrnoFromNt(MY_NTSTATUS rcNt);
51int birdSetErrnoFromWin32(DWORD dwErr);
52int birdSetErrnoToNoMem(void);
53int birdSetErrnoToInvalidArg(void);
54int birdSetErrnoToBadFileNo(void);
55
56HANDLE birdOpenFile(const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
57 ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
58HANDLE birdOpenFileW(const wchar_t *pwszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
59 ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
60HANDLE birdOpenFileEx(HANDLE hRoot, const char *pszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
61 ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
62HANDLE birdOpenFileExW(HANDLE hRoot, const wchar_t *pwszPath, ACCESS_MASK fDesiredAccess, ULONG fFileAttribs,
63 ULONG fShareAccess, ULONG fCreateDisposition, ULONG fCreateOptions, ULONG fObjAttribs);
64HANDLE 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);
67HANDLE 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);
70MY_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);
73HANDLE birdOpenCurrentDirectory(void);
74void birdCloseFile(HANDLE hFile);
75
76int birdIsPathDirSpec(const char *pszPath);
77int birdDosToNtPath(const char *pszPath, MY_UNICODE_STRING *pNtPath);
78int birdDosToNtPathW(const wchar_t *pwszPath, MY_UNICODE_STRING *pNtPath);
79int birdDosToRelativeNtPath(const char *pszPath, MY_UNICODE_STRING *pNtPath);
80int birdDosToRelativeNtPathW(const wchar_t *pszPath, MY_UNICODE_STRING *pNtPath);
81void birdFreeNtPath(MY_UNICODE_STRING *pNtPath);
82
83
84static __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
92static __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
101static __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
109static __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
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette