summaryrefslogtreecommitdiff
path: root/src/inc/ostype.h
blob: c18d05a5f6b809b77a24bb3d9fe9389b8b5486db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


#include "staticcontract.h"

#ifndef WRAPPER_NO_CONTRACT
#define WRAPPER_NO_CONTRACT             ANNOTATION_WRAPPER
#endif

#ifndef LIMITED_METHOD_CONTRACT
#define LIMITED_METHOD_CONTRACT                ANNOTATION_FN_LEAF
#endif

//*****************************************************************************
// Enum to track which version of the OS we are running
// Note that NT5 (Win2k) is the minimum supported platform. Any code using
// utilcode (which includes the CLR's execution engine) will fail to start 
// on a pre-Win2k platform. This is enforced by InitRunningOnVersionStatus.
// 
// Note: The value is used for data mining from links clicked by user in shim dialog - see code:FWLinkTemplateFromTextID
//   Please do not modify existing values, adding new ones is fine.
//*****************************************************************************
typedef enum {
    RUNNING_ON_STATUS_UNINITED = 0, 
    RUNNING_ON_WINNT5          = 1, 
    RUNNING_ON_WINXP           = 2, 
    RUNNING_ON_WIN2003         = 3, // _WIN64 can assume that all OSes that we're running on will be WIN2003+
    RUNNING_ON_VISTA           = 4, 
    RUNNING_ON_WIN7            = 5, 
    RUNNING_ON_WIN8            = 6
} RunningOnStatusEnum;

extern RunningOnStatusEnum gRunningOnStatus;
extern BOOL                gExInfoAvailable;
extern BOOL                gExInfoIsServer;

void InitRunningOnVersionStatus();

#if defined(FEATURE_COMINTEROP) && !defined(FEATURE_CORESYSTEM)
typedef enum
{
    WINRT_STATUS_UNINITED = 0,
    WINRT_STATUS_UNSUPPORTED,
    WINRT_STATUS_SUPPORTED
}
WinRTStatusEnum;

extern WinRTStatusEnum      gWinRTStatus;

void InitWinRTStatus();
#endif // FEATURE_COMINTEROP && !FEATURE_CORESYSTEM

//*****************************************************************************
//
// List of currently supported platforms:
//
// Win2000 - not supported
// WinXP   - not supported
// Win2k3  - not supported
// Vista   - desktop, CoreCLR
// Win7    - desktop, CoreCLR
// Win8    - desktop, CoreCLR on CoreSystem, ARM
//
//*****************************************************************************

//*****************************************************************************
// Returns true if you are running on Windows 7 or newer.
//*****************************************************************************
inline BOOL RunningOnWin7()
{
    WRAPPER_NO_CONTRACT;
#if defined(_ARM_) || defined(FEATURE_CORESYSTEM)
    return TRUE;
#else
    if (gRunningOnStatus == RUNNING_ON_STATUS_UNINITED)
    {
        InitRunningOnVersionStatus();
    }

    return (gRunningOnStatus >= RUNNING_ON_WIN7) ? TRUE : FALSE;
#endif
}

//*****************************************************************************
// Returns true if you are running on Windows 8 or newer.
//*****************************************************************************
inline BOOL RunningOnWin8()
{
    WRAPPER_NO_CONTRACT;
#if defined(_ARM_) || defined(CROSSGEN_COMPILE)
    return TRUE;
#else
    if (gRunningOnStatus == RUNNING_ON_STATUS_UNINITED)
    {
        InitRunningOnVersionStatus();
    }

    return (gRunningOnStatus >= RUNNING_ON_WIN8) ? TRUE : FALSE;
#endif
}

//*****************************************************************************
// Returns true if extra information is available
//*****************************************************************************
inline BOOL ExOSInfoAvailable()
{
    WRAPPER_NO_CONTRACT;
    if (gRunningOnStatus == RUNNING_ON_STATUS_UNINITED)
    {
        InitRunningOnVersionStatus();
    }

    return gExInfoAvailable;        
}

//*****************************************************************************
// Returns true if we're running on a server OS. Requires ExOSInfoAvailable()
// to be TRUE
//*****************************************************************************
inline BOOL ExOSInfoRunningOnServer()
{
    WRAPPER_NO_CONTRACT;
    /*
      @TODO: _ASSERTE not available here...
    _ASSERTE(ExOSInfoAvailable() && 
        "You should only call this after making sure ExOSInfoAvailable() returned TRUE");
        */
    if (gRunningOnStatus == RUNNING_ON_STATUS_UNINITED)
    {
        InitRunningOnVersionStatus();
    }

    return gExInfoIsServer;
}

#ifdef FEATURE_COMINTEROP

#ifdef FEATURE_CORESYSTEM

inline BOOL WinRTSupported()
{
    return RunningOnWin8();
}
#else
inline BOOL WinRTSupported()
{
    STATIC_CONTRACT_NOTHROW;
    STATIC_CONTRACT_GC_NOTRIGGER;
    STATIC_CONTRACT_CANNOT_TAKE_LOCK;
    STATIC_CONTRACT_SO_TOLERANT;
    
#ifdef CROSSGEN_COMPILE
    return TRUE;
#endif

    if (gWinRTStatus == WINRT_STATUS_UNINITED)
    {
        InitWinRTStatus();
    }

    return gWinRTStatus == WINRT_STATUS_SUPPORTED;
}
#endif // FEATURE_CORESYSTEM

#endif // FEATURE_COMINTEROP

#ifdef _WIN64
inline BOOL RunningInWow64()
{
    return FALSE;
}
#else
BOOL RunningInWow64();
#endif