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"
24 DEFAULT_DEBUG_CHANNEL(ver
);
28 WIN31
, /* Windows 3.1 */
29 WIN95
, /* Windows 95 */
30 WIN98
, /* Windows 98 */
31 NT351
, /* Windows NT 3.51 */
32 NT40
, /* Windows NT 4.0 */
40 OSVERSIONINFOA getVersionEx
;
43 /* FIXME: compare values below with original and fix */
44 static VERSION_DATA VersionData
[NB_WINDOWS_VERSIONS
] =
48 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
49 MAKELONG( 0x0a03, 0x8000 ),
51 sizeof(OSVERSIONINFOA
), 3, 10, 0,
52 VER_PLATFORM_WIN32s
, "Win32s 1.3"
60 sizeof(OSVERSIONINFOA
), 4, 0, 0x40003B6,
61 VER_PLATFORM_WIN32_WINDOWS
, "Win95"
66 0x07005F03, /* FIXME: need DOS value from real Win98 */
69 sizeof(OSVERSIONINFOA
), 4, 10, 0x40A07CE,
70 VER_PLATFORM_WIN32_WINDOWS
, "Win98"
78 sizeof(OSVERSIONINFOA
), 3, 51, 0x421,
79 VER_PLATFORM_WIN32_NT
, "Service Pack 2"
87 sizeof(OSVERSIONINFOA
), 4, 0, 0x565,
88 VER_PLATFORM_WIN32_NT
, "Service Pack 3"
93 static const char *WinVersionNames
[NB_WINDOWS_VERSIONS
] =
102 /* if one of the following dlls is importing ntdll the windows
103 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
104 static char * special_dlls
[] =
114 /* the current version has not been autodetected but forced via cmdline */
115 static BOOL versionForced
= FALSE
;
116 static WINDOWS_VERSION defaultWinVersion
= WIN31
;
118 /**********************************************************************
119 * VERSION_ParseWinVersion
121 void VERSION_ParseWinVersion( const char *arg
)
124 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
126 if (!strcmp( WinVersionNames
[i
], arg
))
128 defaultWinVersion
= (WINDOWS_VERSION
)i
;
129 versionForced
= TRUE
;
133 MESSAGE("Invalid winver value '%s' specified.\n", arg
);
134 MESSAGE("Valid versions are:" );
135 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
136 MESSAGE(" '%s'%c", WinVersionNames
[i
],
137 (i
== NB_WINDOWS_VERSIONS
- 1) ? '\n' : ',' );
142 /**********************************************************************
143 * VERSION_ParseDosVersion
145 void VERSION_ParseDosVersion( const char *arg
)
148 if (sscanf( arg
, "%d.%d", &hi
, &lo
) == 2)
150 VersionData
[WIN31
].getVersion16
=
151 MAKELONG(LOWORD(VersionData
[WIN31
].getVersion16
),
156 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
161 /**********************************************************************
162 * VERSION_GetSystemDLLVersion
164 * This function tryes to figure out if a given (native) dll comes from
165 * win95/98 or winnt. Since all values in the OptionalHeader are not a
166 * usable hint, we test if a dll imports the ntdll.
167 * This is at least working for all system-dlls like comctl32, comdlg32 and
169 * If you have a better idea to figure this out...
171 static DWORD
VERSION_GetSystemDLLVersion( HMODULE hmod
)
173 IMAGE_DATA_DIRECTORY
*dir
= PE_HEADER(hmod
)->OptionalHeader
.DataDirectory
174 + IMAGE_DIRECTORY_ENTRY_IMPORT
;
175 if (dir
->Size
&& dir
->VirtualAddress
)
177 IMAGE_IMPORT_DESCRIPTOR
*pe_imp
= (IMAGE_IMPORT_DESCRIPTOR
*)((char *)hmod
+ dir
->VirtualAddress
);
178 for ( ; pe_imp
->Name
; pe_imp
++)
180 char * name
= (char *)hmod
+ (unsigned int)pe_imp
->Name
;
183 if (!strncasecmp(name
, "ntdll", 5))
185 if (3 == PE_HEADER(hmod
)->OptionalHeader
.MajorOperatingSystemVersion
)
194 /**********************************************************************
195 * VERSION_GetLinkedDllVersion
197 * Some version data (not reliable!):
198 * linker/OS/image/subsys
200 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
201 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
202 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
203 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
204 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
205 * 2.xx/1.00/0.00/4.00 Win95 system files
206 * x.xx/4.00/0.00/4.00 Win95 most applications
207 * 3.10/4.00/0.00/4.00 Win98 notepad
208 * x.xx/5.00/5.00/4.00 Win98 system dlls
209 * x.xx/4.00/4.00/4.00 NT 4 most apps
210 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
211 * 5.12/5.00/5.00/4.00 Win98 calc
212 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
214 DWORD
VERSION_GetLinkedDllVersion(PDB
*pdb
)
217 DWORD WinVersion
= NB_WINDOWS_VERSIONS
;
218 PIMAGE_OPTIONAL_HEADER ophd
;
220 if (!pdb
->exe_modref
)
222 if (!pdb
->modref_list
)
225 /* FIXME: The above condition will never trigger, since all our
226 * standard dlls load their win32 equivalents. We have usually at
227 * this point: kernel32.dll and ntdll.dll.
231 /* First check the native dlls provided. These have to be
232 from one windows version */
233 for ( wm
= pdb
->modref_list
; wm
; wm
=wm
->next
)
235 ophd
= &(PE_HEADER(wm
->module
)->OptionalHeader
);
237 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
239 ophd
->MajorLinkerVersion
, ophd
->MinorLinkerVersion
,
240 ophd
->MajorOperatingSystemVersion
, ophd
->MinorOperatingSystemVersion
,
241 ophd
->MajorImageVersion
, ophd
->MinorImageVersion
,
242 ophd
->MajorSubsystemVersion
, ophd
->MinorSubsystemVersion
);
244 /* test if it is a external (native) dll */
245 if (!(wm
->flags
& WINE_MODREF_INTERNAL
))
248 for (i
= 0; special_dlls
[i
]; i
++)
250 /* test if it a special dll */
251 if (!strncasecmp(wm
->modname
, special_dlls
[i
], strlen(special_dlls
[i
]) ))
253 DWORD DllVersion
= VERSION_GetSystemDLLVersion(wm
->module
);
254 if (WinVersion
== NB_WINDOWS_VERSIONS
)
255 WinVersion
= DllVersion
;
257 if (WinVersion
!= DllVersion
) {
258 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
260 VersionData
[WinVersion
].getVersionEx
.szCSDVersion
,
261 VersionData
[DllVersion
].getVersionEx
.szCSDVersion
);
262 return WIN31
; /* this may let the exe exiting */
271 if(WinVersion
!= NB_WINDOWS_VERSIONS
) return WinVersion
;
273 /* we are using no external system dlls, look at the exe */
274 ophd
= &(PE_HEADER(pdb
->exe_modref
->module
)->OptionalHeader
);
276 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
277 pdb
->exe_modref
->modname
,
278 ophd
->MajorLinkerVersion
, ophd
->MinorLinkerVersion
,
279 ophd
->MajorOperatingSystemVersion
, ophd
->MinorOperatingSystemVersion
,
280 ophd
->MajorImageVersion
, ophd
->MinorImageVersion
,
281 ophd
->MajorSubsystemVersion
, ophd
->MinorSubsystemVersion
);
283 /* special nt 3.51 */
284 if (3 == ophd
->MajorOperatingSystemVersion
&& 51 == ophd
->MinorOperatingSystemVersion
)
289 /* the MajorSubsystemVersion is the only usable singn */
290 if (ophd
->MajorSubsystemVersion
< 4)
292 if ( ophd
->MajorOperatingSystemVersion
== 1
293 && ophd
->MinorOperatingSystemVersion
== 0)
295 return WIN31
; /* win32s */
298 if (ophd
->Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_CUI
)
299 return NT351
; /* FIXME: NT 3.1, not tested */
307 /**********************************************************************
311 * Don't call this function too early during the Wine init,
312 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
313 * be NULL in such cases, which causes the winver to ALWAYS be detected
315 * And as we cache the winver once it has been determined, this is bad.
316 * This can happen much easier than you might think, as this function
317 * is called by EVERY GetVersion*() API !
320 static WINDOWS_VERSION
VERSION_GetVersion(void)
322 static WORD winver
= 0xffff;
324 if (versionForced
) /* user has overridden any sensible checks */
325 return defaultWinVersion
;
327 if (winver
== 0xffff) /* to be determined */ {
328 WINDOWS_VERSION retver
= VERSION_GetLinkedDllVersion( PROCESS_Current() );
330 if (retver
!= WIN31
) winver
= retver
;
337 /***********************************************************************
338 * GetVersion16 (KERNEL.3)
340 LONG WINAPI
GetVersion16(void)
342 WINDOWS_VERSION ver
= VERSION_GetVersion();
343 return VersionData
[ver
].getVersion16
;
347 /***********************************************************************
348 * GetVersion (KERNEL32.427)
350 LONG WINAPI
GetVersion(void)
352 WINDOWS_VERSION ver
= VERSION_GetVersion();
353 return VersionData
[ver
].getVersion32
;
357 /***********************************************************************
358 * GetVersionEx16 (KERNEL.149)
360 BOOL16 WINAPI
GetVersionEx16(OSVERSIONINFO16
*v
)
362 WINDOWS_VERSION ver
= VERSION_GetVersion();
363 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFO16
))
365 WARN("wrong OSVERSIONINFO size from app");
366 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
369 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
370 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
371 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
372 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
373 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
378 /***********************************************************************
379 * GetVersionExA (KERNEL32.428)
381 BOOL WINAPI
GetVersionExA(OSVERSIONINFOA
*v
)
383 WINDOWS_VERSION ver
= VERSION_GetVersion();
384 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFOA
))
386 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
387 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOA
));
388 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
391 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
392 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
393 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
394 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
395 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
400 /***********************************************************************
401 * GetVersionExW (KERNEL32.429)
403 BOOL WINAPI
GetVersionExW(OSVERSIONINFOW
*v
)
405 WINDOWS_VERSION ver
= VERSION_GetVersion();
407 if (v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFOW
))
409 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
410 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOW
));
411 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
414 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
415 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
416 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
417 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
418 lstrcpyAtoW( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
423 /***********************************************************************
424 * GetWinFlags (KERNEL.132)
426 DWORD WINAPI
GetWinFlags16(void)
428 static const long cpuflags
[5] =
429 { WF_CPU086
, WF_CPU186
, WF_CPU286
, WF_CPU386
, WF_CPU486
};
436 /* There doesn't seem to be any Pentium flag. */
437 result
= cpuflags
[min(si
.wProcessorLevel
, 4)] | WF_ENHANCED
| WF_PMODE
| WF_80x87
| WF_PAGING
;
438 if (si
.wProcessorLevel
>= 4) result
|= WF_HASCPUID
;
439 ovi
.dwOSVersionInfoSize
= sizeof(ovi
);
441 if (ovi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
442 result
|= WF_WIN32WOW
; /* undocumented WF_WINNT */
447 /***********************************************************************
448 * GetWinDebugInfo (KERNEL.355)
450 BOOL16 WINAPI
GetWinDebugInfo16(WINDEBUGINFO
*lpwdi
, UINT16 flags
)
452 FIXME("(%8lx,%d): stub returning 0\n",
453 (unsigned long)lpwdi
, flags
);
454 /* 0 means not in debugging mode/version */
455 /* Can this type of debugging be used in wine ? */
456 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
461 /***********************************************************************
462 * SetWinDebugInfo (KERNEL.356)
464 BOOL16 WINAPI
SetWinDebugInfo16(WINDEBUGINFO
*lpwdi
)
466 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi
);
467 /* 0 means not in debugging mode/version */
468 /* Can this type of debugging be used in wine ? */
469 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
474 /***********************************************************************
475 * DebugFillBuffer (KERNEL.329)
478 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
480 void WINAPI
DebugFillBuffer(LPSTR lpBuffer
, WORD wBytes
)
482 memset(lpBuffer
, DBGFILL_BUFFER
, wBytes
);
485 /***********************************************************************
486 * DiagQuery (KERNEL.339)
488 * returns TRUE if Win called with "/b" (bootlog.txt)
490 BOOL16 WINAPI
DiagQuery16()
492 /* perhaps implement a Wine "/b" command line flag sometime ? */
496 /***********************************************************************
497 * DiagOutput (KERNEL.340)
499 * writes a debug string into <windir>\bootlog.txt
501 void WINAPI
DiagOutput16(LPCSTR str
)
504 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str
));