Got rid of PROFILE_ functions, now accessing Wine config options
[wine.git] / misc / version.c
blob7a4a223239f253a1fcb22c9677ffd6d11a10fc2f
1 /*
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
8 */
10 #include <string.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include "windef.h"
14 #include "winbase.h"
15 #include "wingdi.h"
16 #include "winuser.h"
17 #include "wine/winbase16.h"
18 #include "process.h"
19 #include "options.h"
20 #include "debugtools.h"
21 #include "neexe.h"
22 #include "winversion.h"
23 #include "winerror.h"
25 DEFAULT_DEBUG_CHANNEL(ver)
27 typedef struct
29 LONG getVersion16;
30 LONG getVersion32;
31 OSVERSIONINFOA getVersionEx;
32 } VERSION_DATA;
35 /* FIXME: compare values below with original and fix */
36 static VERSION_DATA VersionData[NB_WINDOWS_VERSIONS] =
38 /* WIN31 */
40 MAKELONG( 0x0a03, 0x0616 ), /* DOS 6.22 */
41 MAKELONG( 0x0a03, 0x8000 ),
43 sizeof(OSVERSIONINFOA), 3, 10, 0,
44 VER_PLATFORM_WIN32s, "Win32s 1.3"
47 /* WIN95 */
49 0x07005F03,
50 0xC0000004,
52 sizeof(OSVERSIONINFOA), 4, 0, 0x40003B6,
53 VER_PLATFORM_WIN32_WINDOWS, "Win95"
56 /* WIN98 */
58 0x07005F03, /* FIXME: need DOS value from real Win98 */
59 0xC0000A04,
61 sizeof(OSVERSIONINFOA), 4, 10, 0x40A07CE,
62 VER_PLATFORM_WIN32_WINDOWS, "Win98"
65 /* NT351 */
67 0x05000A03,
68 0x04213303,
70 sizeof(OSVERSIONINFOA), 3, 51, 0x421,
71 VER_PLATFORM_WIN32_NT, "Service Pack 2"
74 /* NT40 */
76 0x05000A03,
77 0x05650004,
79 sizeof(OSVERSIONINFOA), 4, 0, 0x565,
80 VER_PLATFORM_WIN32_NT, "Service Pack 3"
85 static const char *WinVersionNames[NB_WINDOWS_VERSIONS] =
87 "win31",
88 "win95",
89 "win98",
90 "nt351",
91 "nt40"
94 /* if one of the following dlls is importing ntdll the windows
95 version autodetection switches wine to unicode (nt 3.51 or 4.0) */
96 static char * special_dlls[] =
98 "COMDLG32",
99 "COMCTL32",
100 "SHELL32",
101 "USER32",
102 "OLE32",
103 "RPCRT4",
104 NULL
107 /* the current version has not been autodetected but forced via cmdline */
108 static BOOL versionForced = FALSE;
109 static WINDOWS_VERSION defaultWinVersion = WIN31;
111 /**********************************************************************
112 * VERSION_ParseWinVersion
114 void VERSION_ParseWinVersion( const char *arg )
116 int i;
117 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
119 if (!strcmp( WinVersionNames[i], arg ))
121 defaultWinVersion = (WINDOWS_VERSION)i;
122 versionForced = TRUE;
123 return;
126 MESSAGE("Invalid winver value '%s' specified.\n", arg );
127 MESSAGE("Valid versions are:" );
128 for (i = 0; i < NB_WINDOWS_VERSIONS; i++)
129 MESSAGE(" '%s'%c", WinVersionNames[i],
130 (i == NB_WINDOWS_VERSIONS - 1) ? '\n' : ',' );
134 /**********************************************************************
135 * VERSION_ParseDosVersion
137 void VERSION_ParseDosVersion( const char *arg )
139 int hi, lo;
140 if (sscanf( arg, "%d.%d", &hi, &lo ) == 2)
142 VersionData[WIN31].getVersion16 =
143 MAKELONG(LOWORD(VersionData[WIN31].getVersion16),
144 (hi<<8) + lo);
146 else
147 fprintf( stderr, "-dosver: Wrong version format. Use \"-dosver x.xx\"\n");
150 /**********************************************************************
151 * VERSION_GetSystemDLLVersion
153 * This function tryes to figure out if a given (native) dll comes from
154 * win95/98 or winnt. Since all values in the OptionalHeader are not a
155 * usable hint, we test if a dll imports the ntdll.
156 * This is at least working for all system-dlls like comctl32, comdlg32 and
157 * shell32.
158 * If you have a better idea to figure this out...
160 DWORD VERSION_GetSystemDLLVersion (WINE_MODREF * wm)
162 PE_MODREF * pem = &(wm->binfmt.pe);
164 if (pem->pe_import)
166 IMAGE_IMPORT_DESCRIPTOR * pe_imp;
168 for ( pe_imp = pem->pe_import; pe_imp->Name; pe_imp++)
170 char * name = (char*)((unsigned int)wm->module+(unsigned int)(pe_imp->Name));
171 TRACE("%s\n", name);
173 if (!lstrncmpiA(name, "ntdll", 5))
175 if (3 == PE_HEADER(wm->module)->OptionalHeader.MajorOperatingSystemVersion)
176 return NT351;
177 else
178 return NT40;
182 return WIN95;
184 /**********************************************************************
185 * VERSION_GetLinkedDllVersion
187 * Some version data (not reliable!):
188 * linker/OS/image/subsys
190 * x.xx/1.00/0.00/3.10 Win32s (any version ?)
191 * 2.39/1.00/0.00/3.10 Win32s freecell.exe (any version)
192 * 2.50/1.00/4.00/4.00 Win32s 1.30 winhlp32.exe
193 * 2.60/3.51/3.51/3.51 NT351SP5 system dlls
194 * 2.60/3.51/3.51/4.00 NT351SP5 comctl32 dll
195 * 2.xx/1.00/0.00/4.00 Win95 system files
196 * x.xx/4.00/0.00/4.00 Win95 most applications
197 * 3.10/4.00/0.00/4.00 Win98 notepad
198 * x.xx/5.00/5.00/4.00 Win98 system dlls
199 * x.xx/4.00/4.00/4.00 NT 4 most apps
200 * 5.12/5.00/5.00/4.00 NT4+IE5 comctl32.dll
201 * 5.12/5.00/5.00/4.00 Win98 calc
202 * x.xx/5.00/5.00/4.00 win95/win98/NT4 IE5 files
204 DWORD VERSION_GetLinkedDllVersion(PDB *pdb)
206 WINE_MODREF *wm;
207 DWORD WinVersion = NB_WINDOWS_VERSIONS;
208 PIMAGE_OPTIONAL_HEADER ophd;
210 if (!pdb->exe_modref)
212 if (!pdb->modref_list)
213 return WIN31;
215 /* FIXME: The above condition will never trigger, since all our
216 * standard dlls load their win32 equivalents. We have usually at
217 * this point: kernel32.dll and ntdll.dll.
219 return WIN95;
221 /* First check the native dlls provided. These have to be
222 from one windows version */
223 for ( wm = pdb->modref_list; wm; wm=wm->next )
225 ophd = &(PE_HEADER(wm->module)->OptionalHeader);
227 TRACE("%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
228 wm->modname,
229 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
230 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
231 ophd->MajorImageVersion, ophd->MinorImageVersion,
232 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
234 /* test if it is a external (native) dll */
235 if ( !(wm->flags & WINE_MODREF_INTERNAL) && wm->type==MODULE32_PE)
237 int i;
238 for (i = 0; special_dlls[i]; i++)
240 /* test if it a special dll */
241 if (!lstrncmpiA(wm->modname, special_dlls[i], strlen(special_dlls[i]) ))
243 DWORD DllVersion = VERSION_GetSystemDLLVersion(wm);
244 if (WinVersion == NB_WINDOWS_VERSIONS)
245 WinVersion = DllVersion;
246 else {
247 if (WinVersion != DllVersion) {
248 ERR("You mixed system dlls from different windows versions! Expect a crash!\n");
249 return WIN31; /* this may let the exe exiting */
252 break;
258 if(WinVersion != NB_WINDOWS_VERSIONS) return WinVersion;
260 /* we are using no external system dlls, look at the exe */
261 ophd = &(PE_HEADER(pdb->exe_modref->module)->OptionalHeader);
263 TRACE("-%s: %02x.%02x/%02x.%02x/%02x.%02x/%02x.%02x\n",
264 pdb->exe_modref->modname,
265 ophd->MajorLinkerVersion, ophd->MinorLinkerVersion,
266 ophd->MajorOperatingSystemVersion, ophd->MinorOperatingSystemVersion,
267 ophd->MajorImageVersion, ophd->MinorImageVersion,
268 ophd->MajorSubsystemVersion, ophd->MinorSubsystemVersion);
270 /* special nt 3.51 */
271 if (3 == ophd->MajorOperatingSystemVersion && 51 == ophd->MinorOperatingSystemVersion)
273 return NT351;
276 /* the MajorSubsystemVersion is the only usable singn */
277 if (ophd->MajorSubsystemVersion < 4)
279 if ( ophd->MajorOperatingSystemVersion == 1
280 && ophd->MinorOperatingSystemVersion == 0)
282 return WIN31; /* win32s */
285 if (ophd->Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
286 return NT351; /* FIXME: NT 3.1, not tested */
287 else
288 return WIN95;
291 return WIN95;
294 /**********************************************************************
295 * VERSION_GetVersion
297 * WARNING !!!
298 * Don't call this function too early during the Wine init,
299 * as pdb->exe_modref (required by VERSION_GetImageVersion()) might still
300 * be NULL in such cases, which causes the winver to ALWAYS be detected
301 * as WIN31.
302 * And as we cache the winver once it has been determined, this is bad.
303 * This can happen much easier than you might think, as this function
304 * is called by EVERY GetVersion*() API !
307 WINDOWS_VERSION VERSION_GetVersion(void)
309 PDB *pdb = PROCESS_Current();
310 if (versionForced) /* user has overridden any sensible checks */
311 return defaultWinVersion;
313 if (pdb->winver == 0xffff) /* to be determined */ {
314 WINDOWS_VERSION retver = VERSION_GetLinkedDllVersion(pdb);
316 if (retver != WIN31)
317 pdb->winver = retver;
318 return retver;
320 return pdb->winver;
323 /**********************************************************************
324 * VERSION_AppWinVer
325 * Returns the window version in case Wine emulates a later version
326 * of windows then the application expects.
328 * In a number of cases when windows runs an application that was
329 * designed for an earlier windows version, windows reverts
330 * to "old" behaviour of that earlier version.
332 * An example is a disabled edit control that needs to be painted.
333 * Old style behaviour is to send a WM_CTLCOLOREDIT message. This was
334 * changed in Win95, NT4.0 by a WM_CTLCOLORSTATIC message _only_ for
335 * applications with an expected version 0f 4.0 or higher.
338 DWORD VERSION_AppWinVer(void)
340 WINDOWS_VERSION ver = VERSION_GetVersion();
341 DWORD dwEmulatedVersion=MAKELONG( VersionData[ver].getVersionEx.dwMinorVersion,
342 VersionData[ver].getVersionEx.dwMajorVersion);
343 /* fixme: this may not be 100% correct; see discussion on the
344 * wine developer list in Nov 1999 */
345 DWORD dwProcVersion = GetProcessVersion(0);
346 return dwProcVersion < dwEmulatedVersion ? dwProcVersion : dwEmulatedVersion;
350 /**********************************************************************
351 * VERSION_GetVersionName
353 char *VERSION_GetVersionName()
355 WINDOWS_VERSION ver = VERSION_GetVersion();
356 switch(ver)
358 case WIN31:
359 return "Windows 3.1";
360 case WIN95:
361 return "Windows 95";
362 case WIN98:
363 return "Windows 98";
364 case NT351:
365 return "Windows NT 3.51";
366 case NT40:
367 return "Windows NT 4.0";
368 default:
369 FIXME("Windows version %d not named",ver);
370 return "Windows <Unknown>";
374 /***********************************************************************
375 * GetVersion16 (KERNEL.3)
377 LONG WINAPI GetVersion16(void)
379 WINDOWS_VERSION ver = VERSION_GetVersion();
380 return VersionData[ver].getVersion16;
384 /***********************************************************************
385 * GetVersion32 (KERNEL32.427)
387 LONG WINAPI GetVersion(void)
389 WINDOWS_VERSION ver = VERSION_GetVersion();
390 return VersionData[ver].getVersion32;
394 /***********************************************************************
395 * GetVersionEx16 (KERNEL.149)
397 BOOL16 WINAPI GetVersionEx16(OSVERSIONINFO16 *v)
399 WINDOWS_VERSION ver = VERSION_GetVersion();
400 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFO16))
402 WARN("wrong OSVERSIONINFO size from app");
403 SetLastError(ERROR_INSUFFICIENT_BUFFER);
404 return FALSE;
406 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
407 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
408 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
409 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
410 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
411 return TRUE;
415 /***********************************************************************
416 * GetVersionEx32A (KERNEL32.428)
418 BOOL WINAPI GetVersionExA(OSVERSIONINFOA *v)
420 WINDOWS_VERSION ver = VERSION_GetVersion();
421 if (v->dwOSVersionInfoSize != sizeof(OSVERSIONINFOA))
423 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
424 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOA));
425 SetLastError(ERROR_INSUFFICIENT_BUFFER);
426 return FALSE;
428 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
429 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
430 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
431 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
432 strcpy( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
433 return TRUE;
437 /***********************************************************************
438 * GetVersionEx32W (KERNEL32.429)
440 BOOL WINAPI GetVersionExW(OSVERSIONINFOW *v)
442 WINDOWS_VERSION ver = VERSION_GetVersion();
444 if (v->dwOSVersionInfoSize!=sizeof(OSVERSIONINFOW))
446 WARN("wrong OSVERSIONINFO size from app (got: %ld, expected: %d)",
447 v->dwOSVersionInfoSize, sizeof(OSVERSIONINFOW));
448 SetLastError(ERROR_INSUFFICIENT_BUFFER);
449 return FALSE;
451 v->dwMajorVersion = VersionData[ver].getVersionEx.dwMajorVersion;
452 v->dwMinorVersion = VersionData[ver].getVersionEx.dwMinorVersion;
453 v->dwBuildNumber = VersionData[ver].getVersionEx.dwBuildNumber;
454 v->dwPlatformId = VersionData[ver].getVersionEx.dwPlatformId;
455 lstrcpyAtoW( v->szCSDVersion, VersionData[ver].getVersionEx.szCSDVersion );
456 return TRUE;
460 /***********************************************************************
461 * GetWinFlags (KERNEL.132)
463 DWORD WINAPI GetWinFlags16(void)
465 static const long cpuflags[5] =
466 { WF_CPU086, WF_CPU186, WF_CPU286, WF_CPU386, WF_CPU486 };
467 SYSTEM_INFO si;
468 OSVERSIONINFOA ovi;
469 DWORD result;
471 GetSystemInfo(&si);
473 /* There doesn't seem to be any Pentium flag. */
474 result = cpuflags[MIN (si.wProcessorLevel, 4)] | WF_ENHANCED | WF_PMODE | WF_80x87 | WF_PAGING;
475 if (si.wProcessorLevel >= 4) result |= WF_HASCPUID;
476 ovi.dwOSVersionInfoSize = sizeof(ovi);
477 GetVersionExA(&ovi);
478 if (ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
479 result |= WF_WIN32WOW; /* undocumented WF_WINNT */
480 return result;
484 /***********************************************************************
485 * GetWinDebugInfo (KERNEL.355)
487 BOOL16 WINAPI GetWinDebugInfo16(WINDEBUGINFO *lpwdi, UINT16 flags)
489 FIXME("(%8lx,%d): stub returning 0\n",
490 (unsigned long)lpwdi, flags);
491 /* 0 means not in debugging mode/version */
492 /* Can this type of debugging be used in wine ? */
493 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
494 return 0;
498 /***********************************************************************
499 * SetWinDebugInfo (KERNEL.356)
501 BOOL16 WINAPI SetWinDebugInfo16(WINDEBUGINFO *lpwdi)
503 FIXME("(%8lx): stub returning 0\n", (unsigned long)lpwdi);
504 /* 0 means not in debugging mode/version */
505 /* Can this type of debugging be used in wine ? */
506 /* Constants: WDI_OPTIONS WDI_FILTER WDI_ALLOCBREAK */
507 return 0;
511 /***********************************************************************
512 * DebugFillBuffer (KERNEL.329)
514 * TODO:
515 * Should fill lpBuffer only if DBO_BUFFERFILL has been set by SetWinDebugInfo()
517 void WINAPI DebugFillBuffer(LPSTR lpBuffer, WORD wBytes)
519 memset(lpBuffer, DBGFILL_BUFFER, wBytes);
522 /***********************************************************************
523 * DiagQuery (KERNEL.339)
525 * returns TRUE if Win called with "/b" (bootlog.txt)
527 BOOL16 WINAPI DiagQuery16()
529 /* perhaps implement a Wine "/b" command line flag sometime ? */
530 return FALSE;
533 /***********************************************************************
534 * DiagOutput (KERNEL.340)
536 * writes a debug string into <windir>\bootlog.txt
538 void WINAPI DiagOutput16(LPCSTR str)
540 /* FIXME */
541 DPRINTF("DIAGOUTPUT:%s\n", debugstr_a(str));
544 /***********************************************************************
545 * VERSION_OsIsUnicode [internal]
547 * NOTES
548 * some functions getting sometimes LPSTR sometimes LPWSTR...
551 BOOL VERSION_OsIsUnicode(void)
553 switch(VERSION_GetVersion())
555 case NT351:
556 case NT40:
557 return TRUE;
558 default:
559 return FALSE;