1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731
|
/*
* Copyright (C) 2002 Andreas Mohr
* Copyright (C) 2002 Shachar Shemesh
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* Wine "bootup" handler application
*
* This app handles the various "hooks" windows allows for applications to perform
* as part of the bootstrap process. These are roughly divided into three types.
* Knowledge base articles that explain this are 137367, 179365, 232487 and 232509.
* Also, 119941 has some info on grpconv.exe
* The operations performed are (by order of execution):
*
* Preboot (prior to fully loading the Windows kernel):
* - wininit.exe (rename operations left in wininit.ini - Win 9x only)
* - PendingRenameOperations (rename operations left in the registry - Win NT+ only)
*
* Startup (before the user logs in)
* - Services (NT)
* - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce (9x, asynch)
* - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices (9x, asynch)
*
* After log in
* - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce (all, synch)
* - HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run (all, asynch)
* - HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run (all, asynch)
* - Startup folders (all, ?asynch?)
* - HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce (all, asynch)
*
* Somewhere in there is processing the RunOnceEx entries (also no imp)
*
* Bugs:
* - If a pending rename registry does not start with \??\ the entry is
* processed anyways. I'm not sure that is the Windows behaviour.
* - Need to check what is the windows behaviour when trying to delete files
* and directories that are read-only
* - In the pending rename registry processing - there are no traces of the files
* processed (requires translations from Unicode to Ansi).
*/
#define COBJMACROS
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <intrin.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ntstatus.h>
#define WIN32_NO_STATUS
#include <windows.h>
#include <ws2tcpip.h>
#include <winternl.h>
#include <ddk/wdm.h>
#include <sddl.h>
#include <wine/svcctl.h>
#include <wine/asm.h>
#include <wine/debug.h>
#include <shlobj.h>
#include <shobjidl.h>
#include <shlwapi.h>
#include <shellapi.h>
#include <setupapi.h>
#include <newdev.h>
#include "resource.h"
WINE_DEFAULT_DEBUG_CHANNEL(wineboot);
extern BOOL shutdown_close_windows( BOOL force );
extern BOOL shutdown_all_desktops( BOOL force );
extern void kill_processes( BOOL kill_desktop );
static WCHAR windowsdir[MAX_PATH];
static const BOOL is_64bit = sizeof(void *) > sizeof(int);
/* retrieve the path to the wine.inf file */
static WCHAR *get_wine_inf_path(void)
{
WCHAR *dir, *name = NULL;
if ((dir = _wgetenv( L"WINEBUILDDIR" )))
{
if (!(name = HeapAlloc( GetProcessHeap(), 0,
sizeof(L"\\loader\\wine.inf") + lstrlenW(dir) * sizeof(WCHAR) )))
return NULL;
lstrcpyW( name, dir );
lstrcatW( name, L"\\loader" );
}
else if ((dir = _wgetenv( L"WINEDATADIR" )))
{
if (!(name = HeapAlloc( GetProcessHeap(), 0, sizeof(L"\\wine.inf") + lstrlenW(dir) * sizeof(WCHAR) )))
return NULL;
lstrcpyW( name, dir );
}
else return NULL;
lstrcatW( name, L"\\wine.inf" );
name[1] = '\\'; /* change \??\ to \\?\ */
return name;
}
/* update the timestamp if different from the reference time */
static BOOL update_timestamp( const WCHAR *config_dir, unsigned long timestamp )
{
BOOL ret = FALSE;
int fd, count;
char buffer[100];
WCHAR *file = HeapAlloc( GetProcessHeap(), 0, lstrlenW(config_dir) * sizeof(WCHAR) + sizeof(L"\\.update-timestamp") );
if (!file) return FALSE;
lstrcpyW( file, config_dir );
lstrcatW( file, L"\\.update-timestamp" );
if ((fd = _wopen( file, O_RDWR )) != -1)
{
if ((count = read( fd, buffer, sizeof(buffer) - 1 )) >= 0)
{
buffer[count] = 0;
if (!strncmp( buffer, "disable", sizeof("disable")-1 )) goto done;
if (timestamp == strtoul( buffer, NULL, 10 )) goto done;
}
lseek( fd, 0, SEEK_SET );
chsize( fd, 0 );
}
else
{
if (errno != ENOENT) goto done;
if ((fd = _wopen( file, O_WRONLY | O_CREAT | O_TRUNC, 0666 )) == -1) goto done;
}
count = sprintf( buffer, "%lu\n", timestamp );
if (write( fd, buffer, count ) != count)
{
WINE_WARN( "failed to update timestamp in %s\n", debugstr_w(file) );
chsize( fd, 0 );
}
else ret = TRUE;
done:
if (fd != -1) close( fd );
HeapFree( GetProcessHeap(), 0, file );
return ret;
}
/* print the config directory in a more Unix-ish way */
static const WCHAR *prettyprint_configdir(void)
{
static WCHAR buffer[MAX_PATH];
WCHAR *p, *path = _wgetenv( L"WINECONFIGDIR" );
lstrcpynW( buffer, path, ARRAY_SIZE(buffer) );
if (lstrlenW( path ) >= ARRAY_SIZE(buffer) )
lstrcpyW( buffer + ARRAY_SIZE(buffer) - 4, L"..." );
if (!wcsncmp( buffer, L"\\??\\unix\\", 9 ))
{
for (p = buffer + 9; *p; p++) if (*p == '\\') *p = '/';
return buffer + 9;
}
else if (!wcsncmp( buffer, L"\\??\\Z:\\", 7 ))
{
for (p = buffer + 6; *p; p++) if (*p == '\\') *p = '/';
return buffer + 6;
}
else return buffer + 4;
}
/* wrapper for RegSetValueExW */
static DWORD set_reg_value( HKEY hkey, const WCHAR *name, const WCHAR *value )
{
return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, (lstrlenW(value) + 1) * sizeof(WCHAR) );
}
static DWORD set_reg_value_dword( HKEY hkey, const WCHAR *name, DWORD value )
{
return RegSetValueExW( hkey, name, 0, REG_DWORD, (const BYTE *)&value, sizeof(value) );
}
#if defined(__i386__) || defined(__x86_64__)
static void initialize_xstate_features(struct _KUSER_SHARED_DATA *data)
{
XSTATE_CONFIGURATION *xstate = &data->XState;
unsigned int i;
int regs[4];
if (!data->ProcessorFeatures[PF_AVX_INSTRUCTIONS_AVAILABLE])
return;
__cpuidex(regs, 0, 0);
TRACE("Max cpuid level %#x.\n", regs[0]);
if (regs[0] < 0xd)
return;
__cpuidex(regs, 1, 0);
TRACE("CPU features %#x, %#x, %#x, %#x.\n", regs[0], regs[1], regs[2], regs[3]);
if (!(regs[2] & (0x1 << 27))) /* xsave OS enabled */
return;
__cpuidex(regs, 0xd, 0);
TRACE("XSAVE details %#x, %#x, %#x, %#x.\n", regs[0], regs[1], regs[2], regs[3]);
if (!(regs[0] & XSTATE_AVX))
return;
xstate->EnabledFeatures = (1 << XSTATE_LEGACY_FLOATING_POINT) | (1 << XSTATE_LEGACY_SSE) | (1 << XSTATE_AVX);
xstate->EnabledVolatileFeatures = xstate->EnabledFeatures;
xstate->Size = sizeof(XSAVE_FORMAT) + sizeof(XSTATE);
xstate->AllFeatureSize = regs[1];
xstate->AllFeatures[0] = offsetof(XSAVE_FORMAT, XmmRegisters);
xstate->AllFeatures[1] = sizeof(M128A) * 16;
xstate->AllFeatures[2] = sizeof(YMMCONTEXT);
for (i = 0; i < 3; ++i)
xstate->Features[i].Size = xstate->AllFeatures[i];
xstate->Features[1].Offset = xstate->Features[0].Size;
xstate->Features[2].Offset = sizeof(XSAVE_FORMAT) + offsetof(XSTATE, YmmContext);
__cpuidex(regs, 0xd, 1);
xstate->OptimizedSave = regs[0] & 1;
xstate->CompactionEnabled = !!(regs[0] & 2);
__cpuidex(regs, 0xd, 2);
TRACE("XSAVE feature 2 %#x, %#x, %#x, %#x.\n", regs[0], regs[1], regs[2], regs[3]);
}
#else
static void initialize_xstate_features(struct _KUSER_SHARED_DATA *data)
{
}
#endif
static void create_user_shared_data(void)
{
struct _KUSER_SHARED_DATA *data;
RTL_OSVERSIONINFOEXW version;
SYSTEM_CPU_INFORMATION sci;
SYSTEM_BASIC_INFORMATION sbi;
BOOLEAN *features;
OBJECT_ATTRIBUTES attr = {sizeof(attr)};
UNICODE_STRING name;
NTSTATUS status;
HANDLE handle;
RtlInitUnicodeString( &name, L"\\KernelObjects\\__wine_user_shared_data" );
InitializeObjectAttributes( &attr, &name, OBJ_OPENIF, NULL, NULL );
if ((status = NtOpenSection( &handle, SECTION_ALL_ACCESS, &attr )))
{
ERR( "cannot open __wine_user_shared_data: %lx\n", status );
return;
}
data = MapViewOfFile( handle, FILE_MAP_WRITE, 0, 0, sizeof(*data) );
CloseHandle( handle );
if (!data)
{
ERR( "cannot map __wine_user_shared_data\n" );
return;
}
version.dwOSVersionInfoSize = sizeof(version);
RtlGetVersion( &version );
NtQuerySystemInformation( SystemBasicInformation, &sbi, sizeof(sbi), NULL );
NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );
data->TickCountMultiplier = 1 << 24;
data->LargePageMinimum = 2 * 1024 * 1024;
data->NtBuildNumber = version.dwBuildNumber;
data->NtProductType = version.wProductType;
data->ProductTypeIsValid = TRUE;
data->NativeProcessorArchitecture = sci.ProcessorArchitecture;
data->NtMajorVersion = version.dwMajorVersion;
data->NtMinorVersion = version.dwMinorVersion;
data->SuiteMask = version.wSuiteMask;
data->NumberOfPhysicalPages = sbi.MmNumberOfPhysicalPages;
data->NXSupportPolicy = NX_SUPPORT_POLICY_OPTIN;
wcscpy( data->NtSystemRoot, L"C:\\windows" );
features = data->ProcessorFeatures;
switch (sci.ProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_INTEL:
case PROCESSOR_ARCHITECTURE_AMD64:
features[PF_COMPARE_EXCHANGE_DOUBLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_CX8);
features[PF_MMX_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_MMX);
features[PF_XMMI_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_SSE);
features[PF_3DNOW_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_3DNOW);
features[PF_RDTSC_INSTRUCTION_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_TSC);
features[PF_PAE_ENABLED] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_PAE);
features[PF_XMMI64_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_SSE2);
features[PF_SSE3_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_SSE3);
features[PF_SSSE3_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_SSSE3);
features[PF_XSAVE_ENABLED] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_XSAVE);
features[PF_COMPARE_EXCHANGE128] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_CX128);
features[PF_SSE_DAZ_MODE_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_DAZ);
features[PF_NX_ENABLED] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_NX);
features[PF_SECOND_LEVEL_ADDRESS_TRANSLATION] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_2NDLEV);
features[PF_VIRT_FIRMWARE_ENABLED] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_VIRT);
features[PF_RDWRFSGSBASE_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_RDFS);
features[PF_FASTFAIL_AVAILABLE] = TRUE;
features[PF_SSE4_1_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_SSE41);
features[PF_SSE4_2_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_SSE42);
features[PF_AVX_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_AVX);
features[PF_AVX2_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_AVX2);
break;
case PROCESSOR_ARCHITECTURE_ARM:
features[PF_ARM_VFP_32_REGISTERS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_ARM_VFP_32);
features[PF_ARM_NEON_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_ARM_NEON);
features[PF_ARM_V8_INSTRUCTIONS_AVAILABLE] = (sci.ProcessorLevel >= 8);
break;
case PROCESSOR_ARCHITECTURE_ARM64:
features[PF_ARM_V8_INSTRUCTIONS_AVAILABLE] = TRUE;
features[PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_ARM_V8_CRC32);
features[PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE] = !!(sci.ProcessorFeatureBits & CPU_FEATURE_ARM_V8_CRYPTO);
break;
}
data->ActiveProcessorCount = NtCurrentTeb()->Peb->NumberOfProcessors;
data->ActiveGroupCount = 1;
initialize_xstate_features( data );
UnmapViewOfFile( data );
}
#if defined(__i386__) || defined(__x86_64__)
static void regs_to_str( int *regs, unsigned int len, WCHAR *buffer )
{
unsigned int i;
unsigned char *p = (unsigned char *)regs;
for (i = 0; i < len; i++) { buffer[i] = *p++; }
buffer[i] = 0;
}
static unsigned int get_model( unsigned int reg0, unsigned int *stepping, unsigned int *family )
{
unsigned int model, family_id = (reg0 & (0x0f << 8)) >> 8;
model = (reg0 & (0x0f << 4)) >> 4;
if (family_id == 6 || family_id == 15) model |= (reg0 & (0x0f << 16)) >> 12;
*family = family_id;
if (family_id == 15) *family += (reg0 & (0xff << 20)) >> 20;
*stepping = reg0 & 0x0f;
return model;
}
static void get_identifier( WCHAR *buf, size_t size, const WCHAR *arch )
{
unsigned int family, model, stepping;
int regs[4] = {0, 0, 0, 0};
__cpuid( regs, 1 );
model = get_model( regs[0], &stepping, &family );
swprintf( buf, size, L"%s Family %u Model %u Stepping %u", arch, family, model, stepping );
}
static void get_vendorid( WCHAR *buf )
{
int tmp, regs[4] = {0, 0, 0, 0};
__cpuid( regs, 0 );
tmp = regs[2]; /* swap edx and ecx */
regs[2] = regs[3];
regs[3] = tmp;
regs_to_str( regs + 1, 12, buf );
}
static void get_namestring( WCHAR *buf )
{
int regs[4] = {0, 0, 0, 0};
int i;
__cpuid( regs, 0x80000000 );
if (regs[0] >= 0x80000004)
{
__cpuid( regs, 0x80000002 );
regs_to_str( regs, 16, buf );
__cpuid( regs, 0x80000003 );
regs_to_str( regs, 16, buf + 16 );
__cpuid( regs, 0x80000004 );
regs_to_str( regs, 16, buf + 32 );
}
for (i = lstrlenW(buf) - 1; i >= 0 && buf[i] == ' '; i--) buf[i] = 0;
}
#else /* __i386__ || __x86_64__ */
static void get_identifier( WCHAR *buf, size_t size, const WCHAR *arch ) { }
static void get_vendorid( WCHAR *buf ) { }
static void get_namestring( WCHAR *buf ) { }
#endif /* __i386__ || __x86_64__ */
#include "pshpack1.h"
struct smbios_prologue
{
BYTE calling_method;
BYTE major_version;
BYTE minor_version;
BYTE revision;
DWORD length;
};
enum smbios_type
{
SMBIOS_TYPE_BIOS,
SMBIOS_TYPE_SYSTEM,
SMBIOS_TYPE_BASEBOARD,
};
struct smbios_header
{
BYTE type;
BYTE length;
WORD handle;
};
struct smbios_baseboard
{
struct smbios_header hdr;
BYTE vendor;
BYTE product;
BYTE version;
BYTE serial;
};
struct smbios_bios
{
struct smbios_header hdr;
BYTE vendor;
BYTE version;
WORD start;
BYTE date;
BYTE size;
UINT64 characteristics;
BYTE characteristics_ext[2];
BYTE system_bios_major_release;
BYTE system_bios_minor_release;
BYTE ec_firmware_major_release;
BYTE ec_firmware_minor_release;
};
struct smbios_system
{
struct smbios_header hdr;
BYTE vendor;
BYTE product;
BYTE version;
BYTE serial;
BYTE uuid[16];
BYTE wake_up_type;
BYTE sku;
BYTE family;
};
#include "poppack.h"
#define RSMB (('R' << 24) | ('S' << 16) | ('M' << 8) | 'B')
static const struct smbios_header *find_smbios_entry( enum smbios_type type, const char *buf, UINT len )
{
const char *ptr, *start;
const struct smbios_prologue *prologue;
const struct smbios_header *hdr;
if (len < sizeof(struct smbios_prologue)) return NULL;
prologue = (const struct smbios_prologue *)buf;
if (prologue->length > len - sizeof(*prologue) || prologue->length < sizeof(*hdr)) return NULL;
start = (const char *)(prologue + 1);
hdr = (const struct smbios_header *)start;
for (;;)
{
if ((const char *)hdr - start >= prologue->length - sizeof(*hdr)) return NULL;
if (!hdr->length)
{
WARN( "invalid entry\n" );
return NULL;
}
if (hdr->type == type)
{
if ((const char *)hdr - start + hdr->length > prologue->length) return NULL;
break;
}
else /* skip other entries and their strings */
{
for (ptr = (const char *)hdr + hdr->length; ptr - buf < len && *ptr; ptr++)
{
for (; ptr - buf < len; ptr++) if (!*ptr) break;
}
if (ptr == (const char *)hdr + hdr->length) ptr++;
hdr = (const struct smbios_header *)(ptr + 1);
}
}
return hdr;
}
static inline WCHAR *heap_strdupAW( const char *src )
{
int len;
WCHAR *dst;
if (!src) return NULL;
len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
if ((dst = HeapAlloc( GetProcessHeap(), 0, len * sizeof(*dst) ))) MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
return dst;
}
static WCHAR *get_smbios_string( BYTE id, const char *buf, UINT offset, UINT buflen )
{
const char *ptr = buf + offset;
UINT i = 0;
if (!id || offset >= buflen) return NULL;
for (ptr = buf + offset; ptr - buf < buflen && *ptr; ptr++)
{
if (++i == id) return heap_strdupAW( ptr );
for (; ptr - buf < buflen; ptr++) if (!*ptr) break;
}
return NULL;
}
static void set_value_from_smbios_string( HKEY key, const WCHAR *value, BYTE id, const char *buf, UINT offset, UINT buflen )
{
WCHAR *str;
str = get_smbios_string( id, buf, offset, buflen );
set_reg_value( key, value, str ? str : L"" );
HeapFree( GetProcessHeap(), 0, str );
}
static void create_bios_baseboard_values( HKEY bios_key, const char *buf, UINT len )
{
const struct smbios_header *hdr;
const struct smbios_baseboard *baseboard;
UINT offset;
if (!(hdr = find_smbios_entry( SMBIOS_TYPE_BASEBOARD, buf, len ))) return;
baseboard = (const struct smbios_baseboard *)hdr;
offset = (const char *)baseboard - buf + baseboard->hdr.length;
set_value_from_smbios_string( bios_key, L"BaseBoardManufacturer", baseboard->vendor, buf, offset, len );
set_value_from_smbios_string( bios_key, L"BaseBoardProduct", baseboard->product, buf, offset, len );
set_value_from_smbios_string( bios_key, L"BaseBoardVersion", baseboard->version, buf, offset, len );
}
static void create_bios_bios_values( HKEY bios_key, const char *buf, UINT len )
{
const struct smbios_header *hdr;
const struct smbios_bios *bios;
UINT offset;
if (!(hdr = find_smbios_entry( SMBIOS_TYPE_BIOS, buf, len ))) return;
bios = (const struct smbios_bios *)hdr;
offset = (const char *)bios - buf + bios->hdr.length;
set_value_from_smbios_string( bios_key, L"BIOSVendor", bios->vendor, buf, offset, len );
set_value_from_smbios_string( bios_key, L"BIOSVersion", bios->version, buf, offset, len );
set_value_from_smbios_string( bios_key, L"BIOSReleaseDate", bios->date, buf, offset, len );
if (bios->hdr.length >= 0x18)
{
set_reg_value_dword( bios_key, L"BiosMajorRelease", bios->system_bios_major_release );
set_reg_value_dword( bios_key, L"BiosMinorRelease", bios->system_bios_minor_release );
set_reg_value_dword( bios_key, L"ECFirmwareMajorVersion", bios->ec_firmware_major_release );
set_reg_value_dword( bios_key, L"ECFirmwareMinorVersion", bios->ec_firmware_minor_release );
}
else
{
set_reg_value_dword( bios_key, L"BiosMajorRelease", 0xFF );
set_reg_value_dword( bios_key, L"BiosMinorRelease", 0xFF );
set_reg_value_dword( bios_key, L"ECFirmwareMajorVersion", 0xFF );
set_reg_value_dword( bios_key, L"ECFirmwareMinorVersion", 0xFF );
}
}
static void create_bios_system_values( HKEY bios_key, const char *buf, UINT len )
{
const struct smbios_header *hdr;
const struct smbios_system *system;
UINT offset;
if (!(hdr = find_smbios_entry( SMBIOS_TYPE_SYSTEM, buf, len ))) return;
system = (const struct smbios_system *)hdr;
offset = (const char *)system - buf + system->hdr.length;
set_value_from_smbios_string( bios_key, L"SystemManufacturer", system->vendor, buf, offset, len );
set_value_from_smbios_string( bios_key, L"SystemProductName", system->product, buf, offset, len );
set_value_from_smbios_string( bios_key, L"SystemVersion", system->version, buf, offset, len );
if (system->hdr.length >= 0x1B)
{
set_value_from_smbios_string( bios_key, L"SystemSKU", system->sku, buf, offset, len );
set_value_from_smbios_string( bios_key, L"SystemFamily", system->family, buf, offset, len );
}
else
{
set_value_from_smbios_string( bios_key, L"SystemSKU", 0, buf, offset, len );
set_value_from_smbios_string( bios_key, L"SystemFamily", 0, buf, offset, len );
}
}
static void create_bios_key( HKEY system_key )
{
HKEY bios_key;
UINT len;
char *buf;
if (RegCreateKeyExW( system_key, L"BIOS", 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &bios_key, NULL ))
return;
len = GetSystemFirmwareTable( RSMB, 0, NULL, 0 );
if (!(buf = HeapAlloc( GetProcessHeap(), 0, len ))) goto done;
len = GetSystemFirmwareTable( RSMB, 0, buf, len );
create_bios_baseboard_values( bios_key, buf, len );
create_bios_bios_values( bios_key, buf, len );
create_bios_system_values( bios_key, buf, len );
done:
HeapFree( GetProcessHeap(), 0, buf );
RegCloseKey( bios_key );
}
/* create the volatile hardware registry keys */
static void create_hardware_registry_keys(void)
{
unsigned int i;
HKEY hkey, system_key, cpu_key, fpu_key;
SYSTEM_CPU_INFORMATION sci;
PROCESSOR_POWER_INFORMATION* power_info;
ULONG sizeof_power_info = sizeof(PROCESSOR_POWER_INFORMATION) * NtCurrentTeb()->Peb->NumberOfProcessors;
WCHAR id[60], namestr[49], vendorid[13];
get_namestring( namestr );
get_vendorid( vendorid );
NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );
power_info = HeapAlloc( GetProcessHeap(), 0, sizeof_power_info );
if (power_info == NULL)
return;
if (NtPowerInformation( ProcessorInformation, NULL, 0, power_info, sizeof_power_info ))
memset( power_info, 0, sizeof_power_info );
switch (sci.ProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_ARM:
case PROCESSOR_ARCHITECTURE_ARM64:
swprintf( id, ARRAY_SIZE(id), L"ARM Family %u Model %u Revision %u",
sci.ProcessorLevel, HIBYTE(sci.ProcessorRevision), LOBYTE(sci.ProcessorRevision) );
break;
case PROCESSOR_ARCHITECTURE_AMD64:
get_identifier( id, ARRAY_SIZE(id), !wcscmp(vendorid, L"AuthenticAMD") ? L"AMD64" : L"Intel64" );
break;
case PROCESSOR_ARCHITECTURE_INTEL:
default:
get_identifier( id, ARRAY_SIZE(id), L"x86" );
break;
}
if (RegCreateKeyExW( HKEY_LOCAL_MACHINE, L"Hardware\\Description\\System", 0, NULL,
REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &system_key, NULL ))
{
HeapFree( GetProcessHeap(), 0, power_info );
return;
}
switch (sci.ProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_ARM:
case PROCESSOR_ARCHITECTURE_ARM64:
set_reg_value( system_key, L"Identifier", L"ARM processor family" );
break;
case PROCESSOR_ARCHITECTURE_INTEL:
case PROCESSOR_ARCHITECTURE_AMD64:
default:
set_reg_value( system_key, L"Identifier", L"AT compatible" );
break;
}
if (sci.ProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM ||
sci.ProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM64 ||
RegCreateKeyExW( system_key, L"FloatingPointProcessor", 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &fpu_key, NULL ))
fpu_key = 0;
if (RegCreateKeyExW( system_key, L"CentralProcessor", 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &cpu_key, NULL ))
cpu_key = 0;
for (i = 0; i < NtCurrentTeb()->Peb->NumberOfProcessors; i++)
{
WCHAR numW[10];
swprintf( numW, ARRAY_SIZE(numW), L"%u", i );
if (!RegCreateKeyExW( cpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &hkey, NULL ))
{
RegSetValueExW( hkey, L"FeatureSet", 0, REG_DWORD, (BYTE *)&sci.ProcessorFeatureBits, sizeof(DWORD) );
set_reg_value( hkey, L"Identifier", id );
/* TODO: report ARM properly */
set_reg_value( hkey, L"ProcessorNameString", namestr );
set_reg_value( hkey, L"VendorIdentifier", vendorid );
RegSetValueExW( hkey, L"~MHz", 0, REG_DWORD, (BYTE *)&power_info[i].MaxMhz, sizeof(DWORD) );
RegCloseKey( hkey );
}
if (sci.ProcessorArchitecture != PROCESSOR_ARCHITECTURE_ARM &&
sci.ProcessorArchitecture != PROCESSOR_ARCHITECTURE_ARM64 &&
!RegCreateKeyExW( fpu_key, numW, 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &hkey, NULL ))
{
set_reg_value( hkey, L"Identifier", id );
RegCloseKey( hkey );
}
}
create_bios_key( system_key );
RegCloseKey( fpu_key );
RegCloseKey( cpu_key );
RegCloseKey( system_key );
HeapFree( GetProcessHeap(), 0, power_info );
}
/* create the DynData registry keys */
static void create_dynamic_registry_keys(void)
{
HKEY key;
if (!RegCreateKeyExW( HKEY_DYN_DATA, L"PerfStats\\StatData", 0, NULL, 0, KEY_WRITE, NULL, &key, NULL ))
RegCloseKey( key );
if (!RegCreateKeyExW( HKEY_DYN_DATA, L"Config Manager\\Enum", 0, NULL, 0, KEY_WRITE, NULL, &key, NULL ))
RegCloseKey( key );
}
/* create the platform-specific environment registry keys */
static void create_environment_registry_keys( void )
{
HKEY env_key;
SYSTEM_CPU_INFORMATION sci;
WCHAR buffer[60], vendorid[13];
const WCHAR *arch, *parch;
if (RegCreateKeyW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Session Manager\\Environment", &env_key )) return;
get_vendorid( vendorid );
NtQuerySystemInformation( SystemCpuInformation, &sci, sizeof(sci), NULL );
swprintf( buffer, ARRAY_SIZE(buffer), L"%u", NtCurrentTeb()->Peb->NumberOfProcessors );
set_reg_value( env_key, L"NUMBER_OF_PROCESSORS", buffer );
switch (sci.ProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_AMD64:
arch = L"AMD64";
parch = !wcscmp(vendorid, L"AuthenticAMD") ? L"AMD64" : L"Intel64";
break;
case PROCESSOR_ARCHITECTURE_INTEL:
default:
arch = parch = L"x86";
break;
}
set_reg_value( env_key, L"PROCESSOR_ARCHITECTURE", arch );
switch (sci.ProcessorArchitecture)
{
case PROCESSOR_ARCHITECTURE_ARM:
case PROCESSOR_ARCHITECTURE_ARM64:
swprintf( buffer, ARRAY_SIZE(buffer), L"ARM Family %u Model %u Revision %u",
sci.ProcessorLevel, HIBYTE(sci.ProcessorRevision), LOBYTE(sci.ProcessorRevision) );
break;
case PROCESSOR_ARCHITECTURE_AMD64:
case PROCESSOR_ARCHITECTURE_INTEL:
default:
get_identifier( buffer, ARRAY_SIZE(buffer), parch );
lstrcatW( buffer, L", " );
lstrcatW( buffer, vendorid );
break;
}
set_reg_value( env_key, L"PROCESSOR_IDENTIFIER", buffer );
swprintf( buffer, ARRAY_SIZE(buffer), L"%u", sci.ProcessorLevel );
set_reg_value( env_key, L"PROCESSOR_LEVEL", buffer );
swprintf( buffer, ARRAY_SIZE(buffer), L"%04x", sci.ProcessorRevision );
set_reg_value( env_key, L"PROCESSOR_REVISION", buffer );
RegCloseKey( env_key );
}
/* create the ComputerName registry keys */
static void create_computer_name_keys(void)
{
struct addrinfo hints = {0}, *res;
char *dot, buffer[256], *name = buffer;
HKEY key, subkey;
if (gethostname( buffer, sizeof(buffer) )) return;
hints.ai_flags = AI_CANONNAME;
if (!getaddrinfo( buffer, NULL, &hints, &res ) &&
res->ai_canonname && strcasecmp(res->ai_canonname, "localhost") != 0)
name = res->ai_canonname;
dot = strchr( name, '.' );
if (dot) *dot++ = 0;
else dot = name + strlen(name);
SetComputerNameExA( ComputerNamePhysicalDnsDomain, dot );
SetComputerNameExA( ComputerNamePhysicalDnsHostname, name );
if (name != buffer) freeaddrinfo( res );
if (RegOpenKeyW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\ComputerName", &key ))
return;
if (!RegOpenKeyW( key, L"ComputerName", &subkey ))
{
DWORD type, size = sizeof(buffer);
if (RegQueryValueExW( subkey, L"ComputerName", NULL, &type, (BYTE *)buffer, &size )) size = 0;
RegCloseKey( subkey );
if (size && !RegCreateKeyExW( key, L"ActiveComputerName", 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &subkey, NULL ))
{
RegSetValueExW( subkey, L"ComputerName", 0, type, (const BYTE *)buffer, size );
RegCloseKey( subkey );
}
}
RegCloseKey( key );
}
static void create_volatile_environment_registry_key(void)
{
WCHAR path[MAX_PATH];
WCHAR computername[MAX_COMPUTERNAME_LENGTH + 1 + 2];
DWORD size;
HKEY hkey;
HRESULT hr;
if (RegCreateKeyExW( HKEY_CURRENT_USER, L"Volatile Environment", 0, NULL, REG_OPTION_VOLATILE,
KEY_ALL_ACCESS, NULL, &hkey, NULL ))
return;
hr = SHGetFolderPathW( NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, path );
if (SUCCEEDED(hr)) set_reg_value( hkey, L"APPDATA", path );
set_reg_value( hkey, L"CLIENTNAME", L"Console" );
/* Write the profile path's drive letter and directory components into
* HOMEDRIVE and HOMEPATH respectively. */
hr = SHGetFolderPathW( NULL, CSIDL_PROFILE | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, path );
if (SUCCEEDED(hr))
{
set_reg_value( hkey, L"USERPROFILE", path );
set_reg_value( hkey, L"HOMEPATH", path + 2 );
path[2] = '\0';
set_reg_value( hkey, L"HOMEDRIVE", path );
}
size = ARRAY_SIZE(path);
if (GetUserNameW( path, &size )) set_reg_value( hkey, L"USERNAME", path );
set_reg_value( hkey, L"HOMESHARE", L"" );
hr = SHGetFolderPathW( NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, path );
if (SUCCEEDED(hr))
set_reg_value( hkey, L"LOCALAPPDATA", path );
size = ARRAY_SIZE(computername) - 2;
if (GetComputerNameW(&computername[2], &size))
{
set_reg_value( hkey, L"USERDOMAIN", &computername[2] );
computername[0] = computername[1] = '\\';
set_reg_value( hkey, L"LOGONSERVER", computername );
}
set_reg_value( hkey, L"SESSIONNAME", L"Console" );
RegCloseKey( hkey );
}
/* Performs the rename operations dictated in %SystemRoot%\Wininit.ini.
* Returns FALSE if there was an error, or otherwise if all is ok.
*/
static BOOL wininit(void)
{
WCHAR initial_buffer[1024];
WCHAR *str, *buffer = initial_buffer;
DWORD size = ARRAY_SIZE(initial_buffer);
DWORD res;
for (;;)
{
if (!(res = GetPrivateProfileSectionW( L"rename", buffer, size, L"wininit.ini" ))) return TRUE;
if (res < size - 2) break;
if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
size *= 2;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size * sizeof(WCHAR) ))) return FALSE;
}
for (str = buffer; *str; str += lstrlenW(str) + 1)
{
WCHAR *value;
if (*str == ';') continue; /* comment */
if (!(value = wcschr( str, '=' ))) continue;
/* split the line into key and value */
*value++ = 0;
if (!lstrcmpiW( L"NUL", str ))
{
WINE_TRACE("Deleting file %s\n", wine_dbgstr_w(value) );
if( !DeleteFileW( value ) )
WINE_WARN("Error deleting file %s\n", wine_dbgstr_w(value) );
}
else
{
WINE_TRACE("Renaming file %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
if( !MoveFileExW(value, str, MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING) )
WINE_WARN("Error renaming %s to %s\n", wine_dbgstr_w(value), wine_dbgstr_w(str) );
}
str = value;
}
if (buffer != initial_buffer) HeapFree( GetProcessHeap(), 0, buffer );
if( !MoveFileExW( L"wininit.ini", L"wininit.bak", MOVEFILE_REPLACE_EXISTING) )
{
WINE_ERR("Couldn't rename wininit.ini, error %ld\n", GetLastError() );
return FALSE;
}
return TRUE;
}
static void pendingRename(void)
{
WCHAR *buffer=NULL;
const WCHAR *src=NULL, *dst=NULL;
DWORD dataLength=0;
HKEY hSession;
if (RegOpenKeyExW( HKEY_LOCAL_MACHINE, L"System\\CurrentControlSet\\Control\\Session Manager",
0, KEY_ALL_ACCESS, &hSession ))
return;
if (RegQueryValueExW( hSession, L"PendingFileRenameOperations", NULL, NULL, NULL, &dataLength ))
goto end;
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, dataLength ))) goto end;
if (RegQueryValueExW( hSession, L"PendingFileRenameOperations", NULL, NULL,
(LPBYTE)buffer, &dataLength ))
goto end;
/* Make sure that the data is long enough and ends with two NULLs. This
* simplifies the code later on.
*/
if( dataLength<2*sizeof(buffer[0]) ||
buffer[dataLength/sizeof(buffer[0])-1]!='\0' ||
buffer[dataLength/sizeof(buffer[0])-2]!='\0' )
goto end;
for( src=buffer; (src-buffer)*sizeof(src[0])<dataLength && *src!='\0';
src=dst+lstrlenW(dst)+1 )
{
DWORD dwFlags=0;
dst=src+lstrlenW(src)+1;
/* We need to skip the \??\ header */
if( src[0]=='\\' && src[1]=='?' && src[2]=='?' && src[3]=='\\' )
src+=4;
if( dst[0]=='!' )
{
dwFlags|=MOVEFILE_REPLACE_EXISTING;
dst++;
}
if( dst[0]=='\\' && dst[1]=='?' && dst[2]=='?' && dst[3]=='\\' )
dst+=4;
if( *dst!='\0' )
{
/* Rename the file */
MoveFileExW( src, dst, dwFlags );
} else
{
/* Delete the file or directory */
if (!RemoveDirectoryW( src ) && GetLastError() == ERROR_DIRECTORY) DeleteFileW( src );
}
}
RegDeleteValueW(hSession, L"PendingFileRenameOperations");
end:
HeapFree(GetProcessHeap(), 0, buffer);
RegCloseKey( hSession );
}
#define INVALID_RUNCMD_RETURN -1
/*
* This function runs the specified command in the specified dir.
* [in,out] cmdline - the command line to run. The function may change the passed buffer.
* [in] dir - the dir to run the command in. If it is NULL, then the current dir is used.
* [in] wait - whether to wait for the run program to finish before returning.
* [in] minimized - Whether to ask the program to run minimized.
*
* Returns:
* If running the process failed, returns INVALID_RUNCMD_RETURN. Use GetLastError to get the error code.
* If wait is FALSE - returns 0 if successful.
* If wait is TRUE - returns the program's return value.
*/
static DWORD runCmd(LPWSTR cmdline, LPCWSTR dir, BOOL wait, BOOL minimized)
{
STARTUPINFOW si;
PROCESS_INFORMATION info;
DWORD exit_code=0;
memset(&si, 0, sizeof(si));
si.cb=sizeof(si);
if( minimized )
{
si.dwFlags=STARTF_USESHOWWINDOW;
si.wShowWindow=SW_MINIMIZE;
}
memset(&info, 0, sizeof(info));
if( !CreateProcessW(NULL, cmdline, NULL, NULL, FALSE, 0, NULL, dir, &si, &info) )
{
WINE_WARN("Failed to run command %s (%ld)\n", wine_dbgstr_w(cmdline), GetLastError() );
return INVALID_RUNCMD_RETURN;
}
WINE_TRACE("Successfully ran command %s - Created process handle %p\n",
wine_dbgstr_w(cmdline), info.hProcess );
if(wait)
{ /* wait for the process to exit */
WaitForSingleObject(info.hProcess, INFINITE);
GetExitCodeProcess(info.hProcess, &exit_code);
}
CloseHandle( info.hThread );
CloseHandle( info.hProcess );
return exit_code;
}
static void process_run_key( HKEY key, const WCHAR *keyname, BOOL delete, BOOL synchronous )
{
HKEY runkey;
LONG res;
DWORD disp, i, max_cmdline = 0, max_value = 0;
WCHAR *cmdline = NULL, *value = NULL;
if (RegCreateKeyExW( key, keyname, 0, NULL, 0, delete ? KEY_ALL_ACCESS : KEY_READ, NULL, &runkey, &disp ))
return;
if (disp == REG_CREATED_NEW_KEY)
goto end;
if (RegQueryInfoKeyW( runkey, NULL, NULL, NULL, NULL, NULL, NULL, &i, &max_value, &max_cmdline, NULL, NULL ))
goto end;
if (!i)
{
WINE_TRACE( "No commands to execute.\n" );
goto end;
}
if (!(cmdline = HeapAlloc( GetProcessHeap(), 0, max_cmdline )))
{
WINE_ERR( "Couldn't allocate memory for the commands to be executed.\n" );
goto end;
}
if (!(value = HeapAlloc( GetProcessHeap(), 0, ++max_value * sizeof(*value) )))
{
WINE_ERR( "Couldn't allocate memory for the value names.\n" );
goto end;
}
while (i)
{
DWORD len = max_value, len_data = max_cmdline, type;
if ((res = RegEnumValueW( runkey, --i, value, &len, 0, &type, (BYTE *)cmdline, &len_data )))
{
WINE_ERR( "Couldn't read value %lu (%ld).\n", i, res );
continue;
}
if (delete && (res = RegDeleteValueW( runkey, value )))
{
WINE_ERR( "Couldn't delete value %lu (%ld). Running command anyways.\n", i, res );
}
if (type != REG_SZ)
{
WINE_ERR( "Incorrect type of value %lu (%lu).\n", i, type );
continue;
}
if (runCmd( cmdline, NULL, synchronous, FALSE ) == INVALID_RUNCMD_RETURN)
{
WINE_ERR( "Error running cmd %s (%lu).\n", wine_dbgstr_w(cmdline), GetLastError() );
}
WINE_TRACE( "Done processing cmd %lu.\n", i );
}
end:
HeapFree( GetProcessHeap(), 0, value );
HeapFree( GetProcessHeap(), 0, cmdline );
RegCloseKey( runkey );
WINE_TRACE( "Done.\n" );
}
/*
* Process a "Run" type registry key.
* hkRoot is the HKEY from which "Software\Microsoft\Windows\CurrentVersion" is
* opened.
* szKeyName is the key holding the actual entries.
* bDelete tells whether we should delete each value right before executing it.
* bSynchronous tells whether we should wait for the prog to complete before
* going on to the next prog.
*/
static void ProcessRunKeys( HKEY root, const WCHAR *keyname, BOOL delete, BOOL synchronous )
{
HKEY key;
if (root == HKEY_LOCAL_MACHINE)
{
WINE_TRACE( "Processing %s entries under HKLM.\n", wine_dbgstr_w(keyname) );
if (!RegCreateKeyExW( root, L"Software\\Microsoft\\Windows\\CurrentVersion",
0, NULL, 0, KEY_READ, NULL, &key, NULL ))
{
process_run_key( key, keyname, delete, synchronous );
RegCloseKey( key );
}
if (is_64bit && !RegCreateKeyExW( root, L"Software\\Microsoft\\Windows\\CurrentVersion",
0, NULL, 0, KEY_READ|KEY_WOW64_32KEY, NULL, &key, NULL ))
{
process_run_key( key, keyname, delete, synchronous );
RegCloseKey( key );
}
}
else
{
WINE_TRACE( "Processing %s entries under HKCU.\n", wine_dbgstr_w(keyname) );
if (!RegCreateKeyExW( root, L"Software\\Microsoft\\Windows\\CurrentVersion",
0, NULL, 0, KEY_READ, NULL, &key, NULL ))
{
process_run_key( key, keyname, delete, synchronous );
RegCloseKey( key );
}
}
}
/*
* WFP is Windows File Protection, in NT5 and Windows 2000 it maintains a cache
* of known good dlls and scans through and replaces corrupted DLLs with these
* known good versions. The only programs that should install into this dll
* cache are Windows Updates and IE (which is treated like a Windows Update)
*
* Implementing this allows installing ie in win2k mode to actually install the
* system dlls that we expect and need
*/
static int ProcessWindowsFileProtection(void)
{
WIN32_FIND_DATAW finddata;
HANDLE find_handle;
BOOL find_rc;
DWORD rc;
HKEY hkey;
LPWSTR dllcache = NULL;
if (!RegOpenKeyW( HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", &hkey ))
{
DWORD sz = 0;
if (!RegQueryValueExW( hkey, L"SFCDllCacheDir", 0, NULL, NULL, &sz))
{
sz += sizeof(WCHAR);
dllcache = HeapAlloc(GetProcessHeap(),0,sz + sizeof(L"\\*"));
RegQueryValueExW( hkey, L"SFCDllCacheDir", 0, NULL, (LPBYTE)dllcache, &sz);
lstrcatW( dllcache, L"\\*" );
}
}
RegCloseKey(hkey);
if (!dllcache)
{
DWORD sz = GetSystemDirectoryW( NULL, 0 );
dllcache = HeapAlloc( GetProcessHeap(), 0, sz * sizeof(WCHAR) + sizeof(L"\\dllcache\\*"));
GetSystemDirectoryW( dllcache, sz );
lstrcatW( dllcache, L"\\dllcache\\*" );
}
find_handle = FindFirstFileW(dllcache,&finddata);
dllcache[ lstrlenW(dllcache) - 2] = 0; /* strip off wildcard */
find_rc = find_handle != INVALID_HANDLE_VALUE;
while (find_rc)
{
WCHAR targetpath[MAX_PATH];
WCHAR currentpath[MAX_PATH];
UINT sz;
UINT sz2;
WCHAR tempfile[MAX_PATH];
if (wcscmp(finddata.cFileName,L".") == 0 || wcscmp(finddata.cFileName,L"..") == 0)
{
find_rc = FindNextFileW(find_handle,&finddata);
continue;
}
sz = MAX_PATH;
sz2 = MAX_PATH;
VerFindFileW(VFFF_ISSHAREDFILE, finddata.cFileName, windowsdir,
windowsdir, currentpath, &sz, targetpath, &sz2);
sz = MAX_PATH;
rc = VerInstallFileW(0, finddata.cFileName, finddata.cFileName,
dllcache, targetpath, currentpath, tempfile, &sz);
if (rc != ERROR_SUCCESS)
{
WINE_WARN("WFP: %s error 0x%lx\n",wine_dbgstr_w(finddata.cFileName),rc);
DeleteFileW(tempfile);
}
/* now delete the source file so that we don't try to install it over and over again */
lstrcpynW( targetpath, dllcache, MAX_PATH - 1 );
sz = lstrlenW( targetpath );
targetpath[sz++] = '\\';
lstrcpynW( targetpath + sz, finddata.cFileName, MAX_PATH - sz );
if (!DeleteFileW( targetpath ))
WINE_WARN( "failed to delete %s: error %lu\n", wine_dbgstr_w(targetpath), GetLastError() );
find_rc = FindNextFileW(find_handle,&finddata);
}
FindClose(find_handle);
HeapFree(GetProcessHeap(),0,dllcache);
return 1;
}
static BOOL start_services_process(void)
{
static const WCHAR svcctl_started_event[] = SVCCTL_STARTED_EVENT;
PROCESS_INFORMATION pi;
STARTUPINFOW si = { sizeof(si) };
HANDLE wait_handles[2];
if (!CreateProcessW(L"C:\\windows\\system32\\services.exe", NULL,
NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
{
WINE_ERR("Couldn't start services.exe: error %lu\n", GetLastError());
return FALSE;
}
CloseHandle(pi.hThread);
wait_handles[0] = CreateEventW(NULL, TRUE, FALSE, svcctl_started_event);
wait_handles[1] = pi.hProcess;
/* wait for the event to become available or the process to exit */
if ((WaitForMultipleObjects(2, wait_handles, FALSE, INFINITE)) == WAIT_OBJECT_0 + 1)
{
DWORD exit_code;
GetExitCodeProcess(pi.hProcess, &exit_code);
WINE_ERR("Unexpected termination of services.exe - exit code %ld\n", exit_code);
CloseHandle(pi.hProcess);
CloseHandle(wait_handles[0]);
return FALSE;
}
CloseHandle(pi.hProcess);
CloseHandle(wait_handles[0]);
return TRUE;
}
static INT_PTR CALLBACK wait_dlgproc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
{
switch (msg)
{
case WM_INITDIALOG:
{
DWORD len;
WCHAR *buffer, text[1024];
const WCHAR *name = (WCHAR *)lp;
HICON icon = LoadImageW( 0, (LPCWSTR)IDI_WINLOGO, IMAGE_ICON, 48, 48, LR_SHARED );
SendDlgItemMessageW( hwnd, IDC_WAITICON, STM_SETICON, (WPARAM)icon, 0 );
SendDlgItemMessageW( hwnd, IDC_WAITTEXT, WM_GETTEXT, 1024, (LPARAM)text );
len = lstrlenW(text) + lstrlenW(name) + 1;
buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
swprintf( buffer, len, text, name );
SendDlgItemMessageW( hwnd, IDC_WAITTEXT, WM_SETTEXT, 0, (LPARAM)buffer );
HeapFree( GetProcessHeap(), 0, buffer );
}
break;
}
return 0;
}
static HWND show_wait_window(void)
{
HWND hwnd = CreateDialogParamW( GetModuleHandleW(0), MAKEINTRESOURCEW(IDD_WAITDLG), 0,
wait_dlgproc, (LPARAM)prettyprint_configdir() );
ShowWindow( hwnd, SW_SHOWNORMAL );
return hwnd;
}
static HANDLE start_rundll32( const WCHAR *inf_path, const WCHAR *install, WORD machine )
{
WCHAR app[MAX_PATH + ARRAY_SIZE(L"\\rundll32.exe" )];
STARTUPINFOW si;
PROCESS_INFORMATION pi;
WCHAR *buffer;
DWORD len;
memset( &si, 0, sizeof(si) );
si.cb = sizeof(si);
if (!GetSystemWow64Directory2W( app, MAX_PATH, machine )) return 0;
lstrcatW( app, L"\\rundll32.exe" );
TRACE( "machine %x starting %s\n", machine, debugstr_w(app) );
len = lstrlenW(app) + ARRAY_SIZE(L" setupapi,InstallHinfSection DefaultInstall 128 ") + lstrlenW(inf_path);
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return 0;
swprintf( buffer, len, L"%s setupapi,InstallHinfSection %s 128 %s", app, install, inf_path );
if (CreateProcessW( app, buffer, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
CloseHandle( pi.hThread );
else
pi.hProcess = 0;
HeapFree( GetProcessHeap(), 0, buffer );
return pi.hProcess;
}
static void install_root_pnp_devices(void)
{
static const struct
{
const char *name;
const char *hardware_id;
const char *infpath;
}
root_devices[] =
{
{"root\\wine\\winebus", "root\\winebus\0", "C:\\windows\\inf\\winebus.inf"},
{"root\\wine\\wineusb", "root\\wineusb\0", "C:\\windows\\inf\\wineusb.inf"},
};
SP_DEVINFO_DATA device = {sizeof(device)};
unsigned int i;
HDEVINFO set;
if ((set = SetupDiCreateDeviceInfoList( NULL, NULL )) == INVALID_HANDLE_VALUE)
{
WINE_ERR("Failed to create device info list, error %#lx.\n", GetLastError());
return;
}
for (i = 0; i < ARRAY_SIZE(root_devices); ++i)
{
if (!SetupDiCreateDeviceInfoA( set, root_devices[i].name, &GUID_NULL, NULL, NULL, 0, &device))
{
if (GetLastError() != ERROR_DEVINST_ALREADY_EXISTS)
WINE_ERR("Failed to create device %s, error %#lx.\n", debugstr_a(root_devices[i].name), GetLastError());
continue;
}
if (!SetupDiSetDeviceRegistryPropertyA(set, &device, SPDRP_HARDWAREID,
(const BYTE *)root_devices[i].hardware_id, (strlen(root_devices[i].hardware_id) + 2) * sizeof(WCHAR)))
{
WINE_ERR("Failed to set hardware id for %s, error %#lx.\n", debugstr_a(root_devices[i].name), GetLastError());
continue;
}
if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, set, &device))
{
WINE_ERR("Failed to register device %s, error %#lx.\n", debugstr_a(root_devices[i].name), GetLastError());
continue;
}
if (!UpdateDriverForPlugAndPlayDevicesA(NULL, root_devices[i].hardware_id, root_devices[i].infpath, 0, NULL))
WINE_ERR("Failed to install drivers for %s, error %#lx.\n", debugstr_a(root_devices[i].name), GetLastError());
}
SetupDiDestroyDeviceInfoList(set);
}
static void update_user_profile(void)
{
char token_buf[sizeof(TOKEN_USER) + sizeof(SID) + sizeof(DWORD) * SID_MAX_SUB_AUTHORITIES];
HANDLE token;
WCHAR profile[MAX_PATH], *sid;
DWORD size;
HKEY hkey, profile_hkey;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &token))
return;
size = sizeof(token_buf);
GetTokenInformation(token, TokenUser, token_buf, size, &size);
CloseHandle(token);
ConvertSidToStringSidW(((TOKEN_USER *)token_buf)->User.Sid, &sid);
if (!RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList",
0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL))
{
if (!RegCreateKeyExW(hkey, sid, 0, NULL, 0,
KEY_ALL_ACCESS, NULL, &profile_hkey, NULL))
{
DWORD flags = 0;
if (SHGetSpecialFolderPathW(NULL, profile, CSIDL_PROFILE, TRUE))
set_reg_value(profile_hkey, L"ProfileImagePath", profile);
RegSetValueExW( profile_hkey, L"Flags", 0, REG_DWORD, (const BYTE *)&flags, sizeof(flags) );
RegCloseKey(profile_hkey);
}
RegCloseKey(hkey);
}
LocalFree(sid);
}
/* execute rundll32 on the wine.inf file if necessary */
static void update_wineprefix( BOOL force )
{
const WCHAR *config_dir = _wgetenv( L"WINECONFIGDIR" );
WCHAR *inf_path = get_wine_inf_path();
int fd;
struct stat st;
if (!inf_path)
{
WINE_MESSAGE( "wine: failed to update %s, wine.inf not found\n", debugstr_w( config_dir ));
return;
}
if ((fd = _wopen( inf_path, O_RDONLY )) == -1)
{
WINE_MESSAGE( "wine: failed to update %s with %s: %s\n",
debugstr_w(config_dir), debugstr_w(inf_path), strerror(errno) );
goto done;
}
fstat( fd, &st );
close( fd );
if (update_timestamp( config_dir, st.st_mtime ) || force)
{
ULONG machines[8];
HANDLE process = 0;
DWORD count = 0;
if (NtQuerySystemInformationEx( SystemSupportedProcessorArchitectures, &process, sizeof(process),
machines, sizeof(machines), NULL )) machines[0] = 0;
if ((process = start_rundll32( inf_path, L"PreInstall", IMAGE_FILE_MACHINE_TARGET_HOST )))
{
HWND hwnd = show_wait_window();
for (;;)
{
MSG msg;
DWORD res = MsgWaitForMultipleObjects( 1, &process, FALSE, INFINITE, QS_ALLINPUT );
if (res == WAIT_OBJECT_0)
{
CloseHandle( process );
if (!machines[count]) break;
if (HIWORD(machines[count]) & 4 /* native machine */)
process = start_rundll32( inf_path, L"DefaultInstall", IMAGE_FILE_MACHINE_TARGET_HOST );
else
process = start_rundll32( inf_path, L"Wow64Install", LOWORD(machines[count]) );
count++;
if (!process) break;
}
else while (PeekMessageW( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageW( &msg );
}
DestroyWindow( hwnd );
}
install_root_pnp_devices();
update_user_profile();
WINE_MESSAGE( "wine: configuration in %s has been updated.\n", debugstr_w(prettyprint_configdir()) );
}
done:
HeapFree( GetProcessHeap(), 0, inf_path );
}
/* Process items in the StartUp group of the user's Programs under the Start Menu. Some installers put
* shell links here to restart themselves after boot. */
static BOOL ProcessStartupItems(void)
{
BOOL ret = FALSE;
HRESULT hr;
IShellFolder *psfDesktop = NULL, *psfStartup = NULL;
LPITEMIDLIST pidlStartup = NULL, pidlItem;
ULONG NumPIDLs;
IEnumIDList *iEnumList = NULL;
STRRET strret;
WCHAR wszCommand[MAX_PATH];
WINE_TRACE("Processing items in the StartUp folder.\n");
hr = SHGetDesktopFolder(&psfDesktop);
if (FAILED(hr))
{
WINE_ERR("Couldn't get desktop folder.\n");
goto done;
}
hr = SHGetSpecialFolderLocation(NULL, CSIDL_STARTUP, &pidlStartup);
if (FAILED(hr))
{
WINE_TRACE("Couldn't get StartUp folder location.\n");
goto done;
}
hr = IShellFolder_BindToObject(psfDesktop, pidlStartup, NULL, &IID_IShellFolder, (LPVOID*)&psfStartup);
if (FAILED(hr))
{
WINE_TRACE("Couldn't bind IShellFolder to StartUp folder.\n");
goto done;
}
hr = IShellFolder_EnumObjects(psfStartup, NULL, SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN, &iEnumList);
if (FAILED(hr))
{
WINE_TRACE("Unable to enumerate StartUp objects.\n");
goto done;
}
while (IEnumIDList_Next(iEnumList, 1, &pidlItem, &NumPIDLs) == S_OK &&
(NumPIDLs) == 1)
{
hr = IShellFolder_GetDisplayNameOf(psfStartup, pidlItem, SHGDN_FORPARSING, &strret);
if (FAILED(hr))
WINE_TRACE("Unable to get display name of enumeration item.\n");
else
{
hr = StrRetToBufW(&strret, pidlItem, wszCommand, MAX_PATH);
if (FAILED(hr))
WINE_TRACE("Unable to parse display name.\n");
else
{
HINSTANCE hinst;
hinst = ShellExecuteW(NULL, NULL, wszCommand, NULL, NULL, SW_SHOWNORMAL);
if (PtrToUlong(hinst) <= 32)
WINE_WARN("Error %p executing command %s.\n", hinst, wine_dbgstr_w(wszCommand));
}
}
ILFree(pidlItem);
}
/* Return success */
ret = TRUE;
done:
if (iEnumList) IEnumIDList_Release(iEnumList);
if (psfStartup) IShellFolder_Release(psfStartup);
if (pidlStartup) ILFree(pidlStartup);
return ret;
}
static void usage( int status )
{
WINE_MESSAGE( "Usage: wineboot [options]\n" );
WINE_MESSAGE( "Options;\n" );
WINE_MESSAGE( " -h,--help Display this help message\n" );
WINE_MESSAGE( " -e,--end-session End the current session cleanly\n" );
WINE_MESSAGE( " -f,--force Force exit for processes that don't exit cleanly\n" );
WINE_MESSAGE( " -i,--init Perform initialization for first Wine instance\n" );
WINE_MESSAGE( " -k,--kill Kill running processes without any cleanup\n" );
WINE_MESSAGE( " -r,--restart Restart only, don't do normal startup operations\n" );
WINE_MESSAGE( " -s,--shutdown Shutdown only, don't reboot\n" );
WINE_MESSAGE( " -u,--update Update the wineprefix directory\n" );
exit( status );
}
int __cdecl main( int argc, char *argv[] )
{
/* First, set the current directory to SystemRoot */
int i, j;
BOOL end_session, force, init, kill, restart, shutdown, update;
HANDLE event;
OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW;
BOOL is_wow64;
end_session = force = init = kill = restart = shutdown = update = FALSE;
GetWindowsDirectoryW( windowsdir, MAX_PATH );
if( !SetCurrentDirectoryW( windowsdir ) )
WINE_ERR("Cannot set the dir to %s (%ld)\n", wine_dbgstr_w(windowsdir), GetLastError() );
if (IsWow64Process( GetCurrentProcess(), &is_wow64 ) && is_wow64)
{
STARTUPINFOW si;
PROCESS_INFORMATION pi;
WCHAR filename[MAX_PATH];
void *redir;
DWORD exit_code;
memset( &si, 0, sizeof(si) );
si.cb = sizeof(si);
GetSystemDirectoryW( filename, MAX_PATH );
wcscat( filename, L"\\wineboot.exe" );
Wow64DisableWow64FsRedirection( &redir );
if (CreateProcessW( filename, GetCommandLineW(), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ))
{
WINE_TRACE( "restarting %s\n", wine_dbgstr_w(filename) );
WaitForSingleObject( pi.hProcess, INFINITE );
GetExitCodeProcess( pi.hProcess, &exit_code );
ExitProcess( exit_code );
}
else WINE_ERR( "failed to restart 64-bit %s, err %ld\n", wine_dbgstr_w(filename), GetLastError() );
Wow64RevertWow64FsRedirection( redir );
}
for (i = 1; i < argc; i++)
{
if (argv[i][0] != '-') continue;
if (argv[i][1] == '-')
{
if (!strcmp( argv[i], "--help" )) usage( 0 );
else if (!strcmp( argv[i], "--end-session" )) end_session = TRUE;
else if (!strcmp( argv[i], "--force" )) force = TRUE;
else if (!strcmp( argv[i], "--init" )) init = TRUE;
else if (!strcmp( argv[i], "--kill" )) kill = TRUE;
else if (!strcmp( argv[i], "--restart" )) restart = TRUE;
else if (!strcmp( argv[i], "--shutdown" )) shutdown = TRUE;
else if (!strcmp( argv[i], "--update" )) update = TRUE;
else usage( 1 );
continue;
}
for (j = 1; argv[i][j]; j++)
{
switch (argv[i][j])
{
case 'e': end_session = TRUE; break;
case 'f': force = TRUE; break;
case 'i': init = TRUE; break;
case 'k': kill = TRUE; break;
case 'r': restart = TRUE; break;
case 's': shutdown = TRUE; break;
case 'u': update = TRUE; break;
case 'h': usage(0); break;
default: usage(1); break;
}
}
}
if (end_session)
{
if (kill)
{
if (!shutdown_all_desktops( force )) return 1;
}
else if (!shutdown_close_windows( force )) return 1;
}
if (kill) kill_processes( shutdown );
if (shutdown) return 0;
/* create event to be inherited by services.exe */
InitializeObjectAttributes( &attr, &nameW, OBJ_OPENIF | OBJ_INHERIT, 0, NULL );
RtlInitUnicodeString( &nameW, L"\\KernelObjects\\__wineboot_event" );
NtCreateEvent( &event, EVENT_ALL_ACCESS, &attr, NotificationEvent, 0 );
ResetEvent( event ); /* in case this is a restart */
create_user_shared_data();
create_hardware_registry_keys();
create_dynamic_registry_keys();
create_environment_registry_keys();
create_computer_name_keys();
wininit();
pendingRename();
ProcessWindowsFileProtection();
ProcessRunKeys( HKEY_LOCAL_MACHINE, L"RunServicesOnce", TRUE, FALSE );
if (init || (kill && !restart))
{
ProcessRunKeys( HKEY_LOCAL_MACHINE, L"RunServices", FALSE, FALSE );
start_services_process();
}
if (init || update) update_wineprefix( update );
create_volatile_environment_registry_key();
ProcessRunKeys( HKEY_LOCAL_MACHINE, L"RunOnce", TRUE, TRUE );
if (!init && !restart)
{
ProcessRunKeys( HKEY_LOCAL_MACHINE, L"Run", FALSE, FALSE );
ProcessRunKeys( HKEY_CURRENT_USER, L"Run", FALSE, FALSE );
ProcessStartupItems();
}
WINE_TRACE("Operation done\n");
SetEvent( event );
return 0;
}
|