kernel32: Test LdrShutdownProcess behaviour only after NtTerminateProcess(0) call.
[wine] / dlls / kernel32 / version.c
1 /*
2  * Windows and DOS version functions
3  *
4  * Copyright 1997 Marcus Meissner
5  * Copyright 1998 Patrik Stridvall
6  * Copyright 1998, 2003 Andreas Mohr
7  * Copyright 1997, 2003 Alexandre Julliard
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #include "config.h"
25 #include "wine/port.h"
26
27 #include <string.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include "ntstatus.h"
32 #define WIN32_NO_STATUS
33 #include "windef.h"
34 #include "winbase.h"
35 #include "wingdi.h"
36 #include "winuser.h"
37 #include "winternl.h"
38 #include "winerror.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(ver);
43
44
45 /***********************************************************************
46  *         GetVersion   (KERNEL32.@)
47  *
48  * Win31   0x80000a03
49  * Win95   0xc0000004
50  * Win98   0xc0000a04
51  * WinME   0xc0005a04
52  * NT351   0x04213303
53  * NT4     0x05650004
54  * Win2000 0x08930005
55  * WinXP   0x0a280105
56  */
57 DWORD WINAPI GetVersion(void)
58 {
59     DWORD result = MAKELONG( MAKEWORD( NtCurrentTeb()->Peb->OSMajorVersion,
60                                        NtCurrentTeb()->Peb->OSMinorVersion ),
61                              (NtCurrentTeb()->Peb->OSPlatformId ^ 2) << 14 );
62     if (NtCurrentTeb()->Peb->OSPlatformId == VER_PLATFORM_WIN32_NT)
63         result |= LOWORD(NtCurrentTeb()->Peb->OSBuildNumber) << 16;
64     return result;
65 }
66
67
68 /***********************************************************************
69  *         GetVersionExA   (KERNEL32.@)
70  */
71 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
72 {
73     RTL_OSVERSIONINFOEXW infoW;
74
75     if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA) &&
76         v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXA))
77     {
78         WARN("wrong OSVERSIONINFO size from app (got: %d)\n",
79                         v->dwOSVersionInfoSize );
80         SetLastError(ERROR_INSUFFICIENT_BUFFER);
81         return FALSE;
82     }
83
84     infoW.dwOSVersionInfoSize = sizeof(infoW);
85     if (RtlGetVersion( &infoW ) != STATUS_SUCCESS) return FALSE;
86
87     v->dwMajorVersion = infoW.dwMajorVersion;
88     v->dwMinorVersion = infoW.dwMinorVersion;
89     v->dwBuildNumber  = infoW.dwBuildNumber;
90     v->dwPlatformId   = infoW.dwPlatformId;
91     WideCharToMultiByte( CP_ACP, 0, infoW.szCSDVersion, -1,
92                          v->szCSDVersion, sizeof(v->szCSDVersion), NULL, NULL );
93
94     if(v->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))
95     {
96         LPOSVERSIONINFOEXA vex = (LPOSVERSIONINFOEXA) v;
97         vex->wServicePackMajor = infoW.wServicePackMajor;
98         vex->wServicePackMinor = infoW.wServicePackMinor;
99         vex->wSuiteMask        = infoW.wSuiteMask;
100         vex->wProductType      = infoW.wProductType;
101     }
102     return TRUE;
103 }
104
105
106 /***********************************************************************
107  *         GetVersionExW   (KERNEL32.@)
108  */
109 BOOL WINAPI GetVersionExW( OSVERSIONINFOW *info )
110 {
111     if (info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOW) &&
112         info->dwOSVersionInfoSize != sizeof(OSVERSIONINFOEXW))
113     {
114         WARN("wrong OSVERSIONINFO size from app (got: %d)\n",
115                         info->dwOSVersionInfoSize);
116         return FALSE;
117     }
118     return (RtlGetVersion( (RTL_OSVERSIONINFOEXW *)info ) == STATUS_SUCCESS);
119 }
120
121
122 /******************************************************************************
123  *        VerifyVersionInfoA   (KERNEL32.@)
124  */
125 BOOL WINAPI VerifyVersionInfoA( LPOSVERSIONINFOEXA lpVersionInfo, DWORD dwTypeMask,
126                                 DWORDLONG dwlConditionMask)
127 {
128     OSVERSIONINFOEXW verW;
129
130     verW.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXW);
131     verW.dwMajorVersion = lpVersionInfo->dwMajorVersion;
132     verW.dwMinorVersion = lpVersionInfo->dwMinorVersion;
133     verW.dwBuildNumber = lpVersionInfo->dwBuildNumber;
134     verW.dwPlatformId = lpVersionInfo->dwPlatformId;
135     verW.wServicePackMajor = lpVersionInfo->wServicePackMajor;
136     verW.wServicePackMinor = lpVersionInfo->wServicePackMinor;
137     verW.wSuiteMask = lpVersionInfo->wSuiteMask;
138     verW.wProductType = lpVersionInfo->wProductType;
139     verW.wReserved = lpVersionInfo->wReserved;
140
141     return VerifyVersionInfoW(&verW, dwTypeMask, dwlConditionMask);
142 }
143
144
145 /******************************************************************************
146  *        VerifyVersionInfoW   (KERNEL32.@)
147  */
148 BOOL WINAPI VerifyVersionInfoW( LPOSVERSIONINFOEXW lpVersionInfo, DWORD dwTypeMask,
149                                 DWORDLONG dwlConditionMask)
150 {
151     switch(RtlVerifyVersionInfo( lpVersionInfo, dwTypeMask, dwlConditionMask ))
152     {
153     case STATUS_INVALID_PARAMETER:
154         SetLastError( ERROR_BAD_ARGUMENTS );
155         return FALSE;
156     case STATUS_REVISION_MISMATCH:
157         SetLastError( ERROR_OLD_WIN_VERSION );
158         return FALSE;
159     }
160     return TRUE;
161 }
162
163 /***********************************************************************
164  *           TermsrvAppInstallMode       (KERNEL32.@)
165  *
166  * Find out whether the terminal server is in INSTALL or EXECUTE mode.
167  */
168 BOOL WINAPI TermsrvAppInstallMode(void)
169 {
170     FIXME("stub\n");
171     return FALSE;
172 }
173
174 /***********************************************************************
175  *           SetTermsrvAppInstallMode       (KERNEL32.@)
176  *
177  * This function is said to switch between the INSTALL (TRUE) or
178  * EXECUTE (FALSE) terminal server modes.
179  *
180  * This function always returns zero on WinXP Home so it's probably
181  * safe to return that value in most cases. However, if a terminal
182  * server is running it will probably return something else.
183  */
184 DWORD WINAPI SetTermsrvAppInstallMode(BOOL bInstallMode)
185 {
186     FIXME("(%d): stub\n", bInstallMode);
187     return 0;
188 }
189
190 /***********************************************************************
191  *           GetProductInfo       (KERNEL32.@)
192  *
193  * Gives info about the current Windows product type, in a format compatible
194  * with the given Windows version
195  *
196  * Returns TRUE if the input is valid, FALSE otherwise
197  */
198 BOOL WINAPI GetProductInfo(DWORD dwOSMajorVersion, DWORD dwOSMinorVersion, DWORD dwSpMajorVersion,
199                            DWORD dwSpMinorVersion, PDWORD pdwReturnedProductType)
200 {
201     return RtlGetProductInfo(dwOSMajorVersion, dwOSMinorVersion,
202                              dwSpMajorVersion, dwSpMinorVersion, pdwReturnedProductType);
203 }
204
205 LONG WINAPI GetCurrentPackageId(UINT32 *len, BYTE *buffer)
206 {
207     FIXME("(%p %p): stub\n", len, buffer);
208     return APPMODEL_ERROR_NO_PACKAGE;
209 }