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 sizeof(OSVERSIONINFOA
), 4, 0, 0x40003B6,
82 VER_PLATFORM_WIN32_WINDOWS
, "Win95"
90 sizeof(OSVERSIONINFOA
), 4, 10, 0x40A07CE,
91 VER_PLATFORM_WIN32_WINDOWS
, "Win98"
99 sizeof(OSVERSIONINFOA
), 3, 51, 0x421,
100 VER_PLATFORM_WIN32_NT
, "Service Pack 2"
108 sizeof(OSVERSIONINFOA
), 4, 0, 0x565,
109 VER_PLATFORM_WIN32_NT
, "Service Pack 6"
112 /* NT2K FIXME: verify values */
115 0x08930005, /* better build ? using 2195 (final) for now */
117 sizeof(OSVERSIONINFOA
), 5, 0, 0x893,
118 VER_PLATFORM_WIN32_NT
, "FIXME: OS version string not known yet"
123 static const char *WinVersionNames
[NB_WINDOWS_VERSIONS
] =
124 { /* no spaces in here ! */
132 "win2000,win2k,nt2k,nt2000"
135 /* if one of the following dlls is importing ntdll the windows
136 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
137 static char * special_dlls
[] =
147 /* the current version has not been autodetected but forced via cmdline */
148 static BOOL versionForced
= FALSE
;
149 static WINDOWS_VERSION defaultWinVersion
= WIN31
;
151 /**********************************************************************
152 * VERSION_ParseWinVersion
154 void VERSION_ParseWinVersion( const char *arg
)
157 const char *pCurr
, *p
;
158 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
160 pCurr
= WinVersionNames
[i
];
161 /* iterate through all winver aliases separated by comma */
163 p
= strchr(pCurr
, ',');
164 len
= p
? (int)p
- (int)pCurr
: strlen(pCurr
);
165 if ( (!strncmp( pCurr
, arg
, len
)) && (arg
[len
] == '\0') )
167 defaultWinVersion
= (WINDOWS_VERSION
)i
;
168 versionForced
= TRUE
;
174 MESSAGE("Invalid winver value '%s' specified.\n", arg
);
175 MESSAGE("Valid versions are:" );
176 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
178 /* only list the first, "official" alias in case of aliases */
179 pCurr
= WinVersionNames
[i
];
180 p
= strchr(pCurr
, ',');
181 len
= (p
) ? (int)p
- (int)pCurr
: strlen(pCurr
);
183 MESSAGE(" '%.*s'%c", len
, pCurr
,
184 (i
== NB_WINDOWS_VERSIONS
- 1) ? '\n' : ',' );
190 /**********************************************************************
191 * VERSION_ParseDosVersion
193 void VERSION_ParseDosVersion( const char *arg
)
196 if (sscanf( arg
, "%d.%d", &hi
, &lo
) == 2)
198 VersionData
[WIN31
].getVersion16
=
199 MAKELONG(LOWORD(VersionData
[WIN31
].getVersion16
),
204 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
209 /**********************************************************************
210 * VERSION_GetSystemDLLVersion
212 * This function tries to figure out if a given (native) dll comes from
213 * win95/98 or winnt. Since all values in the OptionalHeader are not a
214 * usable hint, we test if a dll imports the ntdll.
215 * This is at least working for all system dlls like comctl32, comdlg32 and
217 * If you have a better idea to figure this out...
219 static DWORD
VERSION_GetSystemDLLVersion( HMODULE hmod
)
221 IMAGE_DATA_DIRECTORY
*dir
= PE_HEADER(hmod
)->OptionalHeader
.DataDirectory
222 + IMAGE_DIRECTORY_ENTRY_IMPORT
;
223 if (dir
->Size
&& dir
->VirtualAddress
)
225 IMAGE_IMPORT_DESCRIPTOR
*pe_imp
= (IMAGE_IMPORT_DESCRIPTOR
*)((char *)hmod
+ dir
->VirtualAddress
);
226 for ( ; pe_imp
->Name
; pe_imp
++)
228 char * name
= (char *)hmod
+ (unsigned int)pe_imp
->Name
;
231 if (!strncasecmp(name
, "ntdll", 5))
233 if (3 == PE_HEADER(hmod
)->OptionalHeader
.MajorOperatingSystemVersion
)
242 /**********************************************************************
243 * VERSION_GetLinkedDllVersion
245 * Some version data (not reliable!):
246 * linker/OS/image/subsys
248 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
249 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
250 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
251 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
252 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
253 * 2.xx/1.00/0.00/4.00 Win95 system files
254 * x.xx/4.00/0.00/4.00 Win95 most applications
255 * 3.10/4.00/0.00/4.00 Win98 notepad
256 * x.xx/5.00/5.00/4.00 Win98 system dlls
257 * x.xx/4.00/4.00/4.00 NT 4 most apps
258 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
259 * 5.12/5.00/5.00/4.00 Win98 calc
260 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
262 DWORD
VERSION_GetLinkedDllVersion(PDB
*pdb
)
265 DWORD WinVersion
= NB_WINDOWS_VERSIONS
;
266 PIMAGE_OPTIONAL_HEADER ophd
;
268 if (!pdb
->exe_modref
)
270 if (!pdb
->modref_list
)
273 /* FIXME: The above condition will never trigger, since all our
274 * standard dlls load their win32 equivalents. We have usually at
275 * this point: kernel32.dll and ntdll.dll.
279 /* First check the native dlls provided. These have to be
280 from one windows version */
281 for ( wm
= pdb
->modref_list
; wm
; wm
=wm
->next
)
283 ophd
= &(PE_HEADER(wm
->module
)->OptionalHeader
);
285 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
287 ophd
->MajorLinkerVersion
, ophd
->MinorLinkerVersion
,
288 ophd
->MajorOperatingSystemVersion
, ophd
->MinorOperatingSystemVersion
,
289 ophd
->MajorImageVersion
, ophd
->MinorImageVersion
,
290 ophd
->MajorSubsystemVersion
, ophd
->MinorSubsystemVersion
);
292 /* test if it is an external (native) dll */
293 if (!(wm
->flags
& WINE_MODREF_INTERNAL
))
296 for (i
= 0; special_dlls
[i
]; i
++)
298 /* test if it is a special dll */
299 if (!strncasecmp(wm
->modname
, special_dlls
[i
], strlen(special_dlls
[i
]) ))
301 DWORD DllVersion
= VERSION_GetSystemDLLVersion(wm
->module
);
302 if (WinVersion
== NB_WINDOWS_VERSIONS
)
303 WinVersion
= DllVersion
;
305 if (WinVersion
!= DllVersion
) {
306 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
308 VersionData
[WinVersion
].getVersionEx
.szCSDVersion
,
309 VersionData
[DllVersion
].getVersionEx
.szCSDVersion
);
310 return WIN31
; /* this may let the exe exiting */
319 if(WinVersion
!= NB_WINDOWS_VERSIONS
) return WinVersion
;
321 /* we are using no external system dlls, look at the exe */
322 ophd
= &(PE_HEADER(pdb
->exe_modref
->module
)->OptionalHeader
);
324 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
325 pdb
->exe_modref
->modname
,
326 ophd
->MajorLinkerVersion
, ophd
->MinorLinkerVersion
,
327 ophd
->MajorOperatingSystemVersion
, ophd
->MinorOperatingSystemVersion
,
328 ophd
->MajorImageVersion
, ophd
->MinorImageVersion
,
329 ophd
->MajorSubsystemVersion
, ophd
->MinorSubsystemVersion
);
331 /* special nt 3.51 */
332 if (3 == ophd
->MajorOperatingSystemVersion
&& 51 == ophd
->MinorOperatingSystemVersion
)
337 /* the MajorSubsystemVersion is the only usable sign */
338 if (ophd
->MajorSubsystemVersion
< 4)
340 if ( ophd
->MajorOperatingSystemVersion
== 1
341 && ophd
->MinorOperatingSystemVersion
== 0)
343 return WIN31
; /* win32s */
346 if (ophd
->Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_CUI
)
347 return NT351
; /* FIXME: NT 3.1, not tested */
355 /**********************************************************************
359 * Don't call this function too early during the Wine init,
360 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
361 * be NULL in such cases, which causes the winver to ALWAYS be detected
363 * And as we cache the winver once it has been determined, this is bad.
364 * This can happen much easier than you might think, as this function
365 * is called by EVERY GetVersion*() API !
368 static WINDOWS_VERSION
VERSION_GetVersion(void)
370 static WORD winver
= 0xffff;
372 if (versionForced
) /* user has overridden any sensible checks */
373 return defaultWinVersion
;
375 if (winver
== 0xffff) /* to be determined */ {
376 WINDOWS_VERSION retver
= VERSION_GetLinkedDllVersion( PROCESS_Current() );
378 if (retver
!= WIN31
) winver
= retver
;
385 /***********************************************************************
386 * GetVersion16 (KERNEL.3)
388 LONG WINAPI
GetVersion16(void)
390 WINDOWS_VERSION ver
= VERSION_GetVersion();
391 return VersionData
[ver
].getVersion16
;
395 /***********************************************************************
396 * GetVersion (KERNEL32.427)
398 LONG WINAPI
GetVersion(void)
400 WINDOWS_VERSION ver
= VERSION_GetVersion();
401 return VersionData
[ver
].getVersion32
;
405 /***********************************************************************
406 * GetVersionEx16 (KERNEL.149)
408 BOOL16 WINAPI
GetVersionEx16(OSVERSIONINFO16
*v
)
410 WINDOWS_VERSION ver
= VERSION_GetVersion();
411 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFO16
))
413 WARN("wrong OSVERSIONINFO size from app");
414 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
417 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
418 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
419 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
420 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
421 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
426 /***********************************************************************
427 * GetVersionExA (KERNEL32.428)
429 BOOL WINAPI
GetVersionExA(OSVERSIONINFOA
*v
)
431 WINDOWS_VERSION ver
= VERSION_GetVersion();
432 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFOA
))
434 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
435 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOA
));
436 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
439 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
440 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
441 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
442 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
443 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
448 /***********************************************************************
449 * GetVersionExW (KERNEL32.429)
451 BOOL WINAPI
GetVersionExW(OSVERSIONINFOW
*v
)
453 WINDOWS_VERSION ver
= VERSION_GetVersion();
455 if (v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFOW
))
457 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
458 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOW
));
459 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
462 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
463 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
464 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
465 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
466 MultiByteToWideChar( CP_ACP
, 0, VersionData
[ver
].getVersionEx
.szCSDVersion
, -1,
467 v
->szCSDVersion
, sizeof(v
->szCSDVersion
)/sizeof(WCHAR
) );
472 /***********************************************************************
473 * GetWinFlags (KERNEL.132)
475 DWORD WINAPI
GetWinFlags16(void)
477 static const long cpuflags
[5] =
478 { WF_CPU086
, WF_CPU186
, WF_CPU286
, WF_CPU386
, WF_CPU486
};
485 /* There doesn't seem to be any Pentium flag. */
486 result
= cpuflags
[min(si
.wProcessorLevel
, 4)] | WF_ENHANCED
| WF_PMODE
| WF_80x87
| WF_PAGING
;
487 if (si
.wProcessorLevel
>= 4) result
|= WF_HASCPUID
;
488 ovi
.dwOSVersionInfoSize
= sizeof(ovi
);
490 if (ovi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
491 result
|= WF_WIN32WOW
; /* undocumented WF_WINNT */
496 /***********************************************************************
497 * GetWinDebugInfo (KERNEL.355)
499 BOOL16 WINAPI
GetWinDebugInfo16(WINDEBUGINFO
*lpwdi
, UINT16 flags
)
501 FIXME("(%8lx,%d): stub returning 0\n",
502 (unsigned long)lpwdi
, flags
);
503 /* 0 means not in debugging mode/version */
504 /* Can this type of debugging be used in wine ? */
505 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
510 /***********************************************************************
511 * SetWinDebugInfo (KERNEL.356)
513 BOOL16 WINAPI
SetWinDebugInfo16(WINDEBUGINFO
*lpwdi
)
515 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi
);
516 /* 0 means not in debugging mode/version */
517 /* Can this type of debugging be used in wine ? */
518 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
523 /***********************************************************************
524 * DebugFillBuffer (KERNEL.329)
527 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
529 void WINAPI
DebugFillBuffer(LPSTR lpBuffer
, WORD wBytes
)
531 memset(lpBuffer
, DBGFILL_BUFFER
, wBytes
);
534 /***********************************************************************
535 * DiagQuery (KERNEL.339)
537 * returns TRUE if Win called with "/b" (bootlog.txt)
539 BOOL16 WINAPI
DiagQuery16()
541 /* perhaps implement a Wine "/b" command line flag sometime ? */
545 /***********************************************************************
546 * DiagOutput (KERNEL.340)
548 * writes a debug string into <windir>\bootlog.txt
550 void WINAPI
DiagOutput16(LPCSTR str
)
553 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str
));