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"
18 #include "wine/winestring.h"
21 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(ver
);
29 WIN31
, /* Windows 3.1 */
30 WIN95
, /* Windows 95 */
31 WIN98
, /* Windows 98 */
32 NT351
, /* Windows NT 3.51 */
33 NT40
, /* Windows NT 4.0 */
41 OSVERSIONINFOA getVersionEx
;
44 /* FIXME: compare values below with original and fix */
45 static VERSION_DATA VersionData
[NB_WINDOWS_VERSIONS
] =
49 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
50 MAKELONG( 0x0a03, 0x8000 ),
52 sizeof(OSVERSIONINFOA
), 3, 10, 0,
53 VER_PLATFORM_WIN32s
, "Win32s 1.3"
61 sizeof(OSVERSIONINFOA
), 4, 0, 0x40003B6,
62 VER_PLATFORM_WIN32_WINDOWS
, "Win95"
70 sizeof(OSVERSIONINFOA
), 4, 10, 0x40A07CE,
71 VER_PLATFORM_WIN32_WINDOWS
, "Win98"
79 sizeof(OSVERSIONINFOA
), 3, 51, 0x421,
80 VER_PLATFORM_WIN32_NT
, "Service Pack 2"
88 sizeof(OSVERSIONINFOA
), 4, 0, 0x565,
89 VER_PLATFORM_WIN32_NT
, "Service Pack 3"
94 static const char *WinVersionNames
[NB_WINDOWS_VERSIONS
] =
103 /* if one of the following dlls is importing ntdll the windows
104 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
105 static char * special_dlls
[] =
115 /* the current version has not been autodetected but forced via cmdline */
116 static BOOL versionForced
= FALSE
;
117 static WINDOWS_VERSION defaultWinVersion
= WIN31
;
119 /**********************************************************************
120 * VERSION_ParseWinVersion
122 void VERSION_ParseWinVersion( const char *arg
)
125 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
127 if (!strcmp( WinVersionNames
[i
], arg
))
129 defaultWinVersion
= (WINDOWS_VERSION
)i
;
130 versionForced
= TRUE
;
134 MESSAGE("Invalid winver value '%s' specified.\n", arg
);
135 MESSAGE("Valid versions are:" );
136 for (i
= 0; i
< NB_WINDOWS_VERSIONS
; i
++)
137 MESSAGE(" '%s'%c", WinVersionNames
[i
],
138 (i
== NB_WINDOWS_VERSIONS
- 1) ? '\n' : ',' );
143 /**********************************************************************
144 * VERSION_ParseDosVersion
146 void VERSION_ParseDosVersion( const char *arg
)
149 if (sscanf( arg
, "%d.%d", &hi
, &lo
) == 2)
151 VersionData
[WIN31
].getVersion16
=
152 MAKELONG(LOWORD(VersionData
[WIN31
].getVersion16
),
157 MESSAGE("--dosver: Wrong version format. Use \"--dosver x.xx\"\n");
162 /**********************************************************************
163 * VERSION_GetSystemDLLVersion
165 * This function tryes to figure out if a given (native) dll comes from
166 * win95/98 or winnt. Since all values in the OptionalHeader are not a
167 * usable hint, we test if a dll imports the ntdll.
168 * This is at least working for all system-dlls like comctl32, comdlg32 and
170 * If you have a better idea to figure this out...
172 static DWORD
VERSION_GetSystemDLLVersion( HMODULE hmod
)
174 IMAGE_DATA_DIRECTORY
*dir
= PE_HEADER(hmod
)->OptionalHeader
.DataDirectory
175 + IMAGE_DIRECTORY_ENTRY_IMPORT
;
176 if (dir
->Size
&& dir
->VirtualAddress
)
178 IMAGE_IMPORT_DESCRIPTOR
*pe_imp
= (IMAGE_IMPORT_DESCRIPTOR
*)((char *)hmod
+ dir
->VirtualAddress
);
179 for ( ; pe_imp
->Name
; pe_imp
++)
181 char * name
= (char *)hmod
+ (unsigned int)pe_imp
->Name
;
184 if (!strncasecmp(name
, "ntdll", 5))
186 if (3 == PE_HEADER(hmod
)->OptionalHeader
.MajorOperatingSystemVersion
)
195 /**********************************************************************
196 * VERSION_GetLinkedDllVersion
198 * Some version data (not reliable!):
199 * linker/OS/image/subsys
201 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
202 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
203 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
204 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
205 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
206 * 2.xx/1.00/0.00/4.00 Win95 system files
207 * x.xx/4.00/0.00/4.00 Win95 most applications
208 * 3.10/4.00/0.00/4.00 Win98 notepad
209 * x.xx/5.00/5.00/4.00 Win98 system dlls
210 * x.xx/4.00/4.00/4.00 NT 4 most apps
211 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
212 * 5.12/5.00/5.00/4.00 Win98 calc
213 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
215 DWORD
VERSION_GetLinkedDllVersion(PDB
*pdb
)
218 DWORD WinVersion
= NB_WINDOWS_VERSIONS
;
219 PIMAGE_OPTIONAL_HEADER ophd
;
221 if (!pdb
->exe_modref
)
223 if (!pdb
->modref_list
)
226 /* FIXME: The above condition will never trigger, since all our
227 * standard dlls load their win32 equivalents. We have usually at
228 * this point: kernel32.dll and ntdll.dll.
232 /* First check the native dlls provided. These have to be
233 from one windows version */
234 for ( wm
= pdb
->modref_list
; wm
; wm
=wm
->next
)
236 ophd
= &(PE_HEADER(wm
->module
)->OptionalHeader
);
238 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
240 ophd
->MajorLinkerVersion
, ophd
->MinorLinkerVersion
,
241 ophd
->MajorOperatingSystemVersion
, ophd
->MinorOperatingSystemVersion
,
242 ophd
->MajorImageVersion
, ophd
->MinorImageVersion
,
243 ophd
->MajorSubsystemVersion
, ophd
->MinorSubsystemVersion
);
245 /* test if it is a external (native) dll */
246 if (!(wm
->flags
& WINE_MODREF_INTERNAL
))
249 for (i
= 0; special_dlls
[i
]; i
++)
251 /* test if it a special dll */
252 if (!strncasecmp(wm
->modname
, special_dlls
[i
], strlen(special_dlls
[i
]) ))
254 DWORD DllVersion
= VERSION_GetSystemDLLVersion(wm
->module
);
255 if (WinVersion
== NB_WINDOWS_VERSIONS
)
256 WinVersion
= DllVersion
;
258 if (WinVersion
!= DllVersion
) {
259 ERR("You mixed system dlls from different windows versions! Expect a crash! (%s: expected version '%s', but is '%s')\n",
261 VersionData
[WinVersion
].getVersionEx
.szCSDVersion
,
262 VersionData
[DllVersion
].getVersionEx
.szCSDVersion
);
263 return WIN31
; /* this may let the exe exiting */
272 if(WinVersion
!= NB_WINDOWS_VERSIONS
) return WinVersion
;
274 /* we are using no external system dlls, look at the exe */
275 ophd
= &(PE_HEADER(pdb
->exe_modref
->module
)->OptionalHeader
);
277 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
278 pdb
->exe_modref
->modname
,
279 ophd
->MajorLinkerVersion
, ophd
->MinorLinkerVersion
,
280 ophd
->MajorOperatingSystemVersion
, ophd
->MinorOperatingSystemVersion
,
281 ophd
->MajorImageVersion
, ophd
->MinorImageVersion
,
282 ophd
->MajorSubsystemVersion
, ophd
->MinorSubsystemVersion
);
284 /* special nt 3.51 */
285 if (3 == ophd
->MajorOperatingSystemVersion
&& 51 == ophd
->MinorOperatingSystemVersion
)
290 /* the MajorSubsystemVersion is the only usable singn */
291 if (ophd
->MajorSubsystemVersion
< 4)
293 if ( ophd
->MajorOperatingSystemVersion
== 1
294 && ophd
->MinorOperatingSystemVersion
== 0)
296 return WIN31
; /* win32s */
299 if (ophd
->Subsystem
== IMAGE_SUBSYSTEM_WINDOWS_CUI
)
300 return NT351
; /* FIXME: NT 3.1, not tested */
308 /**********************************************************************
312 * Don't call this function too early during the Wine init,
313 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
314 * be NULL in such cases, which causes the winver to ALWAYS be detected
316 * And as we cache the winver once it has been determined, this is bad.
317 * This can happen much easier than you might think, as this function
318 * is called by EVERY GetVersion*() API !
321 static WINDOWS_VERSION
VERSION_GetVersion(void)
323 static WORD winver
= 0xffff;
325 if (versionForced
) /* user has overridden any sensible checks */
326 return defaultWinVersion
;
328 if (winver
== 0xffff) /* to be determined */ {
329 WINDOWS_VERSION retver
= VERSION_GetLinkedDllVersion( PROCESS_Current() );
331 if (retver
!= WIN31
) winver
= retver
;
338 /***********************************************************************
339 * GetVersion16 (KERNEL.3)
341 LONG WINAPI
GetVersion16(void)
343 WINDOWS_VERSION ver
= VERSION_GetVersion();
344 return VersionData
[ver
].getVersion16
;
348 /***********************************************************************
349 * GetVersion (KERNEL32.427)
351 LONG WINAPI
GetVersion(void)
353 WINDOWS_VERSION ver
= VERSION_GetVersion();
354 return VersionData
[ver
].getVersion32
;
358 /***********************************************************************
359 * GetVersionEx16 (KERNEL.149)
361 BOOL16 WINAPI
GetVersionEx16(OSVERSIONINFO16
*v
)
363 WINDOWS_VERSION ver
= VERSION_GetVersion();
364 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFO16
))
366 WARN("wrong OSVERSIONINFO size from app");
367 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
370 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
371 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
372 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
373 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
374 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
379 /***********************************************************************
380 * GetVersionExA (KERNEL32.428)
382 BOOL WINAPI
GetVersionExA(OSVERSIONINFOA
*v
)
384 WINDOWS_VERSION ver
= VERSION_GetVersion();
385 if (v
->dwOSVersionInfoSize
!= sizeof(OSVERSIONINFOA
))
387 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
388 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOA
));
389 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
392 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
393 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
394 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
395 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
396 strcpy( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
401 /***********************************************************************
402 * GetVersionExW (KERNEL32.429)
404 BOOL WINAPI
GetVersionExW(OSVERSIONINFOW
*v
)
406 WINDOWS_VERSION ver
= VERSION_GetVersion();
408 if (v
->dwOSVersionInfoSize
!=sizeof(OSVERSIONINFOW
))
410 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
411 v
->dwOSVersionInfoSize
, sizeof(OSVERSIONINFOW
));
412 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
415 v
->dwMajorVersion
= VersionData
[ver
].getVersionEx
.dwMajorVersion
;
416 v
->dwMinorVersion
= VersionData
[ver
].getVersionEx
.dwMinorVersion
;
417 v
->dwBuildNumber
= VersionData
[ver
].getVersionEx
.dwBuildNumber
;
418 v
->dwPlatformId
= VersionData
[ver
].getVersionEx
.dwPlatformId
;
419 lstrcpyAtoW( v
->szCSDVersion
, VersionData
[ver
].getVersionEx
.szCSDVersion
);
424 /***********************************************************************
425 * GetWinFlags (KERNEL.132)
427 DWORD WINAPI
GetWinFlags16(void)
429 static const long cpuflags
[5] =
430 { WF_CPU086
, WF_CPU186
, WF_CPU286
, WF_CPU386
, WF_CPU486
};
437 /* There doesn't seem to be any Pentium flag. */
438 result
= cpuflags
[min(si
.wProcessorLevel
, 4)] | WF_ENHANCED
| WF_PMODE
| WF_80x87
| WF_PAGING
;
439 if (si
.wProcessorLevel
>= 4) result
|= WF_HASCPUID
;
440 ovi
.dwOSVersionInfoSize
= sizeof(ovi
);
442 if (ovi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
)
443 result
|= WF_WIN32WOW
; /* undocumented WF_WINNT */
448 /***********************************************************************
449 * GetWinDebugInfo (KERNEL.355)
451 BOOL16 WINAPI
GetWinDebugInfo16(WINDEBUGINFO
*lpwdi
, UINT16 flags
)
453 FIXME("(%8lx,%d): stub returning 0\n",
454 (unsigned long)lpwdi
, flags
);
455 /* 0 means not in debugging mode/version */
456 /* Can this type of debugging be used in wine ? */
457 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
462 /***********************************************************************
463 * SetWinDebugInfo (KERNEL.356)
465 BOOL16 WINAPI
SetWinDebugInfo16(WINDEBUGINFO
*lpwdi
)
467 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi
);
468 /* 0 means not in debugging mode/version */
469 /* Can this type of debugging be used in wine ? */
470 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
475 /***********************************************************************
476 * DebugFillBuffer (KERNEL.329)
479 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
481 void WINAPI
DebugFillBuffer(LPSTR lpBuffer
, WORD wBytes
)
483 memset(lpBuffer
, DBGFILL_BUFFER
, wBytes
);
486 /***********************************************************************
487 * DiagQuery (KERNEL.339)
489 * returns TRUE if Win called with "/b" (bootlog.txt)
491 BOOL16 WINAPI
DiagQuery16()
493 /* perhaps implement a Wine "/b" command line flag sometime ? */
497 /***********************************************************************
498 * DiagOutput (KERNEL.340)
500 * writes a debug string into <windir>\bootlog.txt
502 void WINAPI
DiagOutput16(LPCSTR str
)
505 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str
));