gssapi/mech: mech_locl.h roken.h must be included earlier
[heimdal.git] / lib / roken / versionsupport.h
blob09adce3bf15a8d63d78937cf5938fccc43dd356e
1 /*
2 * Copyright (c) 2018-2019, AuriStor, Inc.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _VERSIONSUPPORT_H_
33 #define _VERSIONSUPPORT_H_ 1
36 * IsWindowsVersionOrGreater() is provided by Windows SDK 8.1 or greater.
37 * As AuriStorFS supports building with SDK 7.0 and greater we must
38 * provide our own. VerifyVersionInfoW() is present on Windows XP and
39 * later.
42 #ifndef _WIN32_WINNT_WIN7
43 #define _WIN32_WINNT_WIN7 0x0601
44 #endif
46 #ifndef _WIN32_WINNT_WIN8
47 #define _WIN32_WINNT_WIN8 0x0602
48 #endif
50 #ifndef _WIN32_WINNT_WINBLUE
51 #define _WIN32_WINNT_WINBLUE 0x0603
52 #endif
54 /* Based upon VersionHelpers.h */
55 FORCEINLINE BOOL
56 IsWindowsVersionOrGreater(WORD wMajorVersion,
57 WORD wMinorVersion,
58 WORD wServicePackMajor)
60 OSVERSIONINFOEXW osvi;
61 DWORDLONG dwlConditionMask = 0;
63 dwlConditionMask = VerSetConditionMask(dwlConditionMask,
64 VER_MAJORVERSION,
65 VER_GREATER_EQUAL);
66 dwlConditionMask = VerSetConditionMask(dwlConditionMask,
67 VER_MINORVERSION,
68 VER_GREATER_EQUAL);
69 dwlConditionMask = VerSetConditionMask(dwlConditionMask,
70 VER_SERVICEPACKMAJOR,
71 VER_GREATER_EQUAL);
73 memset(&osvi, 0, sizeof(OSVERSIONINFOEXW));
74 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
75 osvi.dwMajorVersion = wMajorVersion;
76 osvi.dwMinorVersion = wMinorVersion;
77 osvi.wServicePackMajor = wServicePackMajor;
79 return VerifyVersionInfoW(&osvi,
80 (VER_MAJORVERSION |
81 VER_MINORVERSION |
82 VER_SERVICEPACKMAJOR),
83 dwlConditionMask);
86 FORCEINLINE BOOL
87 IsWindowsXPOrGreater(VOID)
89 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP),
90 LOBYTE(_WIN32_WINNT_WINXP),
91 0);
94 FORCEINLINE BOOL
95 IsWindows7OrGreater(VOID)
97 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7),
98 LOBYTE(_WIN32_WINNT_WIN7),
99 0);
102 FORCEINLINE BOOL
103 IsWindows8OrGreater(VOID)
105 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN8),
106 LOBYTE(_WIN32_WINNT_WIN8),
110 FORCEINLINE BOOL
111 IsWindows8Point1OrGreater(VOID)
113 return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINBLUE),
114 LOBYTE(_WIN32_WINNT_WINBLUE),
118 #define IS_WINDOWS_VERSION_OR_GREATER_CACHED(fn) \
120 FORCEINLINE BOOL \
121 fn##Cached(VOID) \
123 static LONG lIsVersionOrGreater = -1; \
125 if (lIsVersionOrGreater == -1) { \
126 LONG lResult = fn(); \
127 InterlockedCompareExchangeRelease(&lIsVersionOrGreater, \
128 lResult, -1); \
131 return lIsVersionOrGreater == 1; \
134 IS_WINDOWS_VERSION_OR_GREATER_CACHED(IsWindowsXPOrGreater)
135 IS_WINDOWS_VERSION_OR_GREATER_CACHED(IsWindows7OrGreater)
136 IS_WINDOWS_VERSION_OR_GREATER_CACHED(IsWindows8OrGreater)
137 IS_WINDOWS_VERSION_OR_GREATER_CACHED(IsWindows8Point1OrGreater)
139 #endif /* _VERSIONSUPPORT_H_ */