Release 980201
[wine.git] / misc / version.c
blobc07d01398159f44b7229a8f32495a6effc4f05d2
1 /*
2 * Windows version functions
4 * Copyright 1997 Alexandre Julliard
5 * Copyright 1997 Marcus Meissner
6 */
8 #include <stdio.h>
9 #include "windows.h"
10 #include "winbase.h"
11 #include "process.h"
12 #include "options.h"
14 typedef enum
16 WIN31, /* Windows 3.1 */
17 WIN95, /* Windows 95 */
18 NT351, /* Windows NT 3.51 */
19 NT40, /* Windows NT 4.0 */
20 NB_VERSIONS
21 } VERSION;
23 typedef struct
25 LONG getVersion16;
26 LONG getVersion32;
27 OSVERSIONINFO32A getVersionEx;
28 } VERSION_DATA;
31 /* FIXME: compare values below with original and fix */
32 static const VERSION_DATA VersionData[NB_VERSIONS] =
34 /* WIN31 */
36 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
37 MAKELONG( 0x0a03, 0x8000 ),
39 sizeof(OSVERSIONINFO32A), 3, 10, 0,
40 VER_PLATFORM_WIN32s, "Win32s 1.3"
43 /* WIN95 */
45 0x07005F03,
46 0xC0000004,
48 sizeof(OSVERSIONINFO32A), 4, 0, 0x40003B6,
49 VER_PLATFORM_WIN32_WINDOWS, "Win95"
52 /* NT351 */
54 0x05000A03,
55 0x04213303,
57 sizeof(OSVERSIONINFO32A), 3, 51, 0x421,
58 VER_PLATFORM_WIN32_NT, "Service Pack 2"
61 /* NT40 */
63 0x05000A03,
64 0x05650004,
66 sizeof(OSVERSIONINFO32A), 4, 0, 0x565,
67 VER_PLATFORM_WIN32_NT, "Service Pack 3"
72 static const char *VersionNames[NB_VERSIONS] =
74 "win31",
75 "win95",
76 "nt351",
77 "nt40"
80 /* the current version has not been autodetected but forced via cmdline */
81 static BOOL32 versionForced = FALSE;
82 static VERSION defaultVersion = WIN31;
85 /**********************************************************************
86 * VERSION_ParseVersion
88 void VERSION_ParseVersion( char *arg )
90 int i;
91 for (i = 0; i < NB_VERSIONS; i++)
93 if (!strcmp( VersionNames[i], arg ))
95 defaultVersion = (VERSION)i;
96 versionForced = TRUE;
97 return;
100 fprintf( stderr, "Invalid winver value '%s' specified.\n", arg );
101 fprintf( stderr, "Valid versions are:" );
102 for (i = 0; i < NB_VERSIONS; i++)
103 fprintf( stderr, " '%s'%c", VersionNames[i],
104 (i == NB_VERSIONS - 1) ? '\n' : ',' );
108 /**********************************************************************
109 * VERSION_get_version
111 static VERSION VERSION_GetVersion(void)
113 LPIMAGE_NT_HEADERS peheader;
115 if (versionForced) /* user has overridden any sensible checks */
116 return defaultVersion;
117 if (!PROCESS_Current()->exe_modref)
119 /* HACK: if we have loaded a PE image into this address space,
120 * we are probably using thunks, so Win95 is our best bet
122 if (PROCESS_Current()->modref_list) return WIN95;
123 return WIN31; /* FIXME: hmm, look at DDB.version ? */
125 peheader = PE_HEADER(PROCESS_Current()->exe_modref->module);
126 if (peheader->OptionalHeader.MajorSubsystemVersion == 4)
127 /* FIXME: NT4 has the same majorversion; add a check here for it. */
128 return WIN95;
129 if (peheader->OptionalHeader.MajorSubsystemVersion == 3)
131 /* Win3.10 */
132 if (peheader->OptionalHeader.MinorSubsystemVersion <= 11) return WIN31;
133 /* NT 3.51 */
134 if (peheader->OptionalHeader.MinorSubsystemVersion == 51) return NT351;
136 fprintf(stderr,"VERSION_GetVersion: unknown subsystem version: %04x.%04x, please report.\n",
137 peheader->OptionalHeader.MajorSubsystemVersion,
138 peheader->OptionalHeader.MinorSubsystemVersion );
139 return defaultVersion;
143 /***********************************************************************
144 * GetVersion16 (KERNEL.3)
146 LONG WINAPI GetVersion16(void)
148 VERSION ver = VERSION_GetVersion();
149 return VersionData[ver].getVersion16;
153 /***********************************************************************
154 * GetVersion32 (KERNEL32.427)
156 LONG WINAPI GetVersion32(void)
158 VERSION ver = VERSION_GetVersion();
159 return VersionData[ver].getVersion32;
163 /***********************************************************************
164 * GetVersionEx32A (KERNEL32.428)
166 BOOL32 WINAPI GetVersionEx32A(OSVERSIONINFO32A *v)
168 VERSION ver = VERSION_GetVersion();
169 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO32A))
171 fprintf(stderr,"wrong OSVERSIONINFO size from app");
172 return FALSE;
174 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
175 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
176 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
177 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
178 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
179 return TRUE;
183 /***********************************************************************
184 * GetVersionEx32W (KERNEL32.429)
186 BOOL32 WINAPI GetVersionEx32W(OSVERSIONINFO32W *v)
188 VERSION ver = VERSION_GetVersion();
189 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFO32W))
191 fprintf(stderr,"wrong OSVERSIONINFO size from app");
192 return FALSE;
194 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
195 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
196 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
197 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
198 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
199 return TRUE;
203 /***********************************************************************
204 * GetWinFlags (KERNEL.132)
206 DWORD WINAPI GetWinFlags(void)
208 static const long cpuflags[5] =
209 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
210 SYSTEM_INFO si;
211 OSVERSIONINFO32A ovi;
212 DWORD result;
214 GetSystemInfo(&si);
216 /* There doesn't seem to be any Pentium flag. */
217 result = cpuflags[MIN (si.wProcessorLevel, 4)];
219 switch(Options.mode)
221 case MODE_STANDARD:
222 result |= WF_STANDARD | WF_PMODE | WF_80x87;
223 break;
225 case MODE_ENHANCED:
226 result |= WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
227 break;
229 default:
230 fprintf(stderr, "Unknown mode set? This shouldn't happen. Check GetWinFlags()!\n");
231 break;
233 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
234 ovi.dwOSVersionInfoSize = sizeof(ovi);
235 GetVersionEx32A(&ovi);
236 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
237 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
238 return result;
242 /***********************************************************************
243 * GetWinDebugInfo (KERNEL.355)
245 BOOL16 WINAPI GetWinDebugInfo(WINDEBUGINFO *lpwdi, UINT16 flags)
247 printf("GetWinDebugInfo(%8lx,%d) stub returning 0\n",
248 (unsigned long)lpwdi, flags);
249 /* 0 means not in debugging mode/version */
250 /* Can this type of debugging be used in wine ? */
251 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
252 return 0;
256 /***********************************************************************
257 * SetWinDebugInfo (KERNEL.356)
259 BOOL16 WINAPI SetWinDebugInfo(WINDEBUGINFO *lpwdi)
261 printf("SetWinDebugInfo(%8lx) stub returning 0\n", (unsigned long)lpwdi);
262 /* 0 means not in debugging mode/version */
263 /* Can this type of debugging be used in wine ? */
264 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
265 return 0;
269 /***********************************************************************
270 * DebugFillBuffer (KERNEL.329)
272 * TODO:
273 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
275 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
277 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
280 /***********************************************************************
281 * DiagQuery (KERNEL.339)
283 * returns TRUE if Win called with "/b" (bootlog.txt)
285 BOOL16 WINAPI DiagQuery()
287 /* perhaps implement a Wine "/b" command line flag sometime ? */
288 return FALSE;
291 /***********************************************************************
292 * DiagOutput (KERNEL.340)
294 * writes a debug string into <windir>\bootlog.txt
296 void WINAPI DiagOutput()