2 * Windows and DOS version functions
4 * Copyright 1997 Alexandre Julliard
5 * Copyright 1997 Marcus Meissner
6 * Copyright 1998 Patrik Stridvall
7 * Copyright 1998 Andreas Mohr
17 #include "wine/winbase16.h"
20 #include "debugtools.h"
23 DEFAULT_DEBUG_CHANNEL(ver);
27 WIN20, /* Windows 2.0 */
28 WIN30, /* Windows 3.0 */
29 WIN31, /* Windows 3.1 */
30 WIN95, /* Windows 95 */
31 WIN98, /* Windows 98 */
32 /* insert Windows ME here as WINME if needed */
33 NT351, /* Windows NT 3.51 */
34 NT40, /* Windows NT 4.0 */
35 NT2K, /* Windows 2000 */
43 OSVERSIONINFOA getVersionEx;
46 /* FIXME: compare values below with original and fix */
47 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
49 /* WIN20 FIXME: verify values */
51 MAKELONG( 0x0002, 0x0303 ), /* assume DOS 3.3 */
52 MAKELONG( 0x0003, 0x8000 ),
54 sizeof(OSVERSIONINFOA), 2, 0, 0,
55 VER_PLATFORM_WIN32s, "Win32s 1.3"
58 /* WIN30 FIXME: verify values */
60 MAKELONG( 0x0003, 0x0500 ), /* assume DOS 5.00 */
61 MAKELONG( 0x0003, 0x8000 ),
63 sizeof(OSVERSIONINFOA), 3, 0, 0,
64 VER_PLATFORM_WIN32s, "Win32s 1.3"
69 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
70 MAKELONG( 0x0a03, 0x8000 ),
72 sizeof(OSVERSIONINFOA), 3, 10, 0,
73 VER_PLATFORM_WIN32s, "Win32s 1.3"
81 /* 0x40003B6 == 4.00.950 == Win95 orig. release and Win95a
82 * 0x4000457 == 4.00.1111 == Win95B aka Win95 OSR2
83 * Win95a/B can be discerned via regkey SubVersionNumber */
84 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
85 VER_PLATFORM_WIN32_WINDOWS, "Win95"
93 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
94 VER_PLATFORM_WIN32_WINDOWS, "Win98"
102 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
103 VER_PLATFORM_WIN32_NT, "Service Pack 2"
111 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
112 VER_PLATFORM_WIN32_NT, "Service Pack 6"
115 /* NT2K FIXME: verify values */
118 0x08930005, /* better build ? using 2195 (final) for now */
120 sizeof(OSVERSIONINFOA), 5, 0, 0x893,
121 VER_PLATFORM_WIN32_NT, "FIXME: OS version string not known yet"
126 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
127 { /* no spaces in here ! */
135 "win2000,win2k,nt2k,nt2000"
138 /* if one of the following dlls is importing ntdll the windows
139 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
140 static char * special_dlls[] =
150 /* the current version has not been autodetected but forced via cmdline */
151 static BOOL versionForced = FALSE;
152 static WINDOWS_VERSION defaultWinVersion = WIN31;
154 /**********************************************************************
155 * VERSION_ParseWinVersion
157 void VERSION_ParseWinVersion( const char *arg )
160 const char *pCurr, *p;
161 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
163 pCurr = WinVersionNames[i];
164 /* iterate through all winver aliases separated by comma */
166 p = strchr(pCurr, ',');
167 len = p ? (int)p - (int)pCurr : strlen(pCurr);
168 if ( (!strncmp( pCurr, arg, len )) && (arg[len] == '\0') )
170 defaultWinVersion = (WINDOWS_VERSION)i;
171 versionForced = TRUE;
177 MESSAGE("Invalid winver value '%s' specified.\n", arg );
178 MESSAGE("Valid versions are:" );
179 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
181 /* only list the first, "official" alias in case of aliases */
182 pCurr = WinVersionNames[i];
183 p = strchr(pCurr, ',');
184 len = (p) ? (int)p - (int)pCurr : strlen(pCurr);
186 MESSAGE(" '%.*s'%c", len, pCurr,
187 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
193 /**********************************************************************
194 * VERSION_ParseDosVersion
196 void VERSION_ParseDosVersion( const char *arg )
199 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
201 VersionData[WIN31].getVersion16 =
202 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
207 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
212 /**********************************************************************
213 * VERSION_GetSystemDLLVersion
215 * This function tries to figure out if a given (native) dll comes from
216 * win95/98 or winnt. Since all values in the OptionalHeader are not a
217 * usable hint, we test if a dll imports the ntdll.
218 * This is at least working for all system dlls like comctl32, comdlg32 and
220 * If you have a better idea to figure this out...
222 static DWORD VERSION_GetSystemDLLVersion( HMODULE hmod )
224 IMAGE_DATA_DIRECTORY *dir = PE_HEADER(hmod)->OptionalHeader.DataDirectory
225 + IMAGE_DIRECTORY_ENTRY_IMPORT;
226 if (dir->Size && dir->VirtualAddress)
228 IMAGE_IMPORT_DESCRIPTOR *pe_imp = (IMAGE_IMPORT_DESCRIPTOR *)((char *)hmod + dir->VirtualAddress);
229 for ( ; pe_imp->Name; pe_imp++)
231 char * name = (char *)hmod + (unsigned int)pe_imp->Name;
234 if (!strncasecmp(name, "ntdll", 5))
236 if (3 == PE_HEADER(hmod)->OptionalHeader.MajorOperatingSystemVersion)
245 /**********************************************************************
246 * VERSION_GetLinkedDllVersion
248 * Some version data (not reliable!):
249 * linker/OS/image/subsys
251 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
252 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
253 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
254 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
255 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
256 * 2.xx/1.00/0.00/4.00 Win95 system files
257 * x.xx/4.00/0.00/4.00 Win95 most applications
258 * 3.10/4.00/0.00/4.00 Win98 notepad
259 * x.xx/5.00/5.00/4.00 Win98 system dlls
260 * x.xx/4.00/4.00/4.00 NT 4 most apps
261 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
262 * 5.12/5.00/5.00/4.00 Win98 calc
263 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
265 DWORD VERSION_GetLinkedDllVersion(void)
268 DWORD WinVersion = NB_WINDOWS_VERSIONS;
269 PIMAGE_OPTIONAL_HEADER ophd;
271 /* First check the native dlls provided. These have to be
272 from one windows version */
273 for ( wm = MODULE_modref_list; wm; wm=wm->next )
275 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
277 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
279 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
280 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
281 ophd->MajorImageVersion, ophd->MinorImageVersion,
282 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
284 /* test if it is an external (native) dll */
285 if (!(wm->flags & WINE_MODREF_INTERNAL))
288 for (i = 0; special_dlls[i]; i++)
290 /* test if it is a special dll */
291 if (!strncasecmp(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
293 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm->module);
294 if (WinVersion == NB_WINDOWS_VERSIONS)
295 WinVersion = DllVersion;
297 if (WinVersion != DllVersion) {
298 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
300 VersionData[WinVersion].getVersionEx.szCSDVersion,
301 VersionData[DllVersion].getVersionEx.szCSDVersion);
302 return WIN31; /* this may let the exe exiting */
311 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
313 /* we are using no external system dlls, look at the exe */
314 ophd = &(PE_HEADER(GetModuleHandleA(NULL))->OptionalHeader);
316 TRACE("%02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
317 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
318 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
319 ophd->MajorImageVersion, ophd->MinorImageVersion,
320 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
322 /* special nt 3.51 */
323 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
328 /* the MajorSubsystemVersion is the only usable sign */
329 if (ophd->MajorSubsystemVersion < 4)
331 if ( ophd->MajorOperatingSystemVersion == 1
332 && ophd->MinorOperatingSystemVersion == 0)
334 return WIN31; /* win32s */
337 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
338 return NT351; /* FIXME: NT 3.1, not tested */
346 /**********************************************************************
350 * Don't call this function too early during the Wine init,
351 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
352 * be NULL in such cases, which causes the winver to ALWAYS be detected
354 * And as we cache the winver once it has been determined, this is bad.
355 * This can happen much easier than you might think, as this function
356 * is called by EVERY GetVersion*() API !
359 static WINDOWS_VERSION VERSION_GetVersion(void)
361 static WORD winver = 0xffff;
363 if (winver == 0xffff) /* to be determined */
365 WINDOWS_VERSION retver;
367 if (versionForced) /* user has overridden any sensible checks */
368 winver = defaultWinVersion;
371 retver = VERSION_GetLinkedDllVersion();
373 /* cache determined value, but do not store in case of WIN31 */
374 if (retver != WIN31) winver = retver;
384 /***********************************************************************
385 * GetVersion (KERNEL.3)
387 LONG WINAPI GetVersion16(void)
389 WINDOWS_VERSION ver = VERSION_GetVersion();
390 return VersionData[ver].getVersion16;
394 /***********************************************************************
395 * GetVersion (KERNEL32.@)
397 LONG WINAPI GetVersion(void)
399 WINDOWS_VERSION ver = VERSION_GetVersion();
400 return VersionData[ver].getVersion32;
404 /***********************************************************************
405 * GetVersionEx (KERNEL.149)
407 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
409 WINDOWS_VERSION ver = VERSION_GetVersion();
410 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFO16))
412 WARN("wrong OSVERSIONINFO size from app\n");
413 SetLastError(ERROR_INSUFFICIENT_BUFFER);
416 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
417 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
418 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
419 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
420 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
425 /***********************************************************************
426 * GetVersionExA (KERNEL32.@)
428 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
430 WINDOWS_VERSION ver = VERSION_GetVersion();
431 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOA))
433 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
434 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
435 SetLastError(ERROR_INSUFFICIENT_BUFFER);
438 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
439 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
440 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
441 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
442 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
447 /***********************************************************************
448 * GetVersionExW (KERNEL32.@)
450 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
452 WINDOWS_VERSION ver = VERSION_GetVersion();
454 if (v->dwOSVersionInfoSize < sizeof(OSVERSIONINFOW))
456 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)\n",
457 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
458 SetLastError(ERROR_INSUFFICIENT_BUFFER);
461 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
462 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
463 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
464 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
465 MultiByteToWideChar( CP_ACP, 0, VersionData[ver].getVersionEx.szCSDVersion, -1,
466 v->szCSDVersion, sizeof(v->szCSDVersion)/sizeof(WCHAR) );
471 /***********************************************************************
472 * GetWinFlags (KERNEL.132)
474 DWORD WINAPI GetWinFlags16(void)
476 static const long cpuflags[5] =
477 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
484 /* There doesn't seem to be any Pentium flag. */
485 result = cpuflags[min(si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
486 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
487 ovi.dwOSVersionInfoSize = sizeof(ovi);
489 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
490 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
496 /* Not used at this time. This is here for documentation only */
498 /* WINDEBUGINFO flags values */
499 #define WDI_OPTIONS 0x0001
500 #define WDI_FILTER 0x0002
501 #define WDI_ALLOCBREAK 0x0004
503 /* dwOptions values */
504 #define DBO_CHECKHEAP 0x0001
505 #define DBO_BUFFERFILL 0x0004
506 #define DBO_DISABLEGPTRAPPING 0x0010
507 #define DBO_CHECKFREE 0x0020
509 #define DBO_SILENT 0x8000
511 #define DBO_TRACEBREAK 0x2000
512 #define DBO_WARNINGBREAK 0x1000
513 #define DBO_NOERRORBREAK 0x0800
514 #define DBO_NOFATALBREAK 0x0400
515 #define DBO_INT3BREAK 0x0100
517 /* DebugOutput flags values */
518 #define DBF_TRACE 0x0000
519 #define DBF_WARNING 0x4000
520 #define DBF_ERROR 0x8000
521 #define DBF_FATAL 0xc000
523 /* dwFilter values */
524 #define DBF_KERNEL 0x1000
525 #define DBF_KRN_MEMMAN 0x0001
526 #define DBF_KRN_LOADMODULE 0x0002
527 #define DBF_KRN_SEGMENTLOAD 0x0004
528 #define DBF_USER 0x0800
529 #define DBF_GDI 0x0400
530 #define DBF_MMSYSTEM 0x0040
531 #define DBF_PENWIN 0x0020
532 #define DBF_APPLICATION 0x0008
533 #define DBF_DRIVER 0x0010
535 #endif /* NOLOGERROR */
538 /***********************************************************************
539 * GetWinDebugInfo (KERNEL.355)
541 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO16 *lpwdi, UINT16 flags)
543 FIXME("(%8lx,%d): stub returning 0\n",
544 (unsigned long)lpwdi, flags);
545 /* 0 means not in debugging mode/version */
546 /* Can this type of debugging be used in wine ? */
547 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
552 /***********************************************************************
553 * SetWinDebugInfo (KERNEL.356)
555 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO16 *lpwdi)
557 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
558 /* 0 means not in debugging mode/version */
559 /* Can this type of debugging be used in wine ? */
560 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
565 /***********************************************************************
569 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
571 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
573 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
576 /***********************************************************************
577 * DiagQuery (KERNEL.339)
579 * returns TRUE if Win called with "/b" (bootlog.txt)
581 BOOL16 WINAPI DiagQuery16()
583 /* perhaps implement a Wine "/b" command line flag sometime ? */
587 /***********************************************************************
588 * DiagOutput (KERNEL.340)
590 * writes a debug string into <windir>\bootlog.txt
592 void WINAPI DiagOutput16(LPCSTR str)
595 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));