Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

533 lines
12 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. kerntwk.c
  5. Abstract:
  6. Kernel Tweaker program for setting various kernel parameters
  7. Author:
  8. John Vert (jvert) 20-Feb-1995
  9. Revision History:
  10. --*/
  11. #include "nt.h"
  12. #include "ntrtl.h"
  13. #include "nturtl.h"
  14. #include <windows.h>
  15. #include <commctrl.h>
  16. #include "dialogs.h"
  17. #include "stdio.h"
  18. #include "twkeng.h"
  19. //
  20. // Local function prototypes
  21. //
  22. BOOL
  23. SaveToRegistry(
  24. VOID
  25. );
  26. VOID
  27. UpdateFromRegistry(
  28. VOID
  29. );
  30. BOOL
  31. ApplyDpcChanges(
  32. BOOL fInit,
  33. HWND hDlg
  34. );
  35. BOOL
  36. ApplyGlobalFlagChanges(
  37. BOOL fInit,
  38. HWND hDlg
  39. );
  40. //
  41. // Knobs
  42. //
  43. KNOB MaximumDpcQueueDepth =
  44. {
  45. HKEY_LOCAL_MACHINE,
  46. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Kernel"),
  47. TEXT("MaximumDpcQueueDepth"),
  48. DPC_MAX_QUEUE_DEPTH,
  49. 0,
  50. 4,
  51. 0
  52. };
  53. KNOB MinimumDpcRate =
  54. {
  55. HKEY_LOCAL_MACHINE,
  56. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Kernel"),
  57. TEXT("MinimumDpcRate"),
  58. DPC_MIN_RATE,
  59. 0,
  60. 3,
  61. 0
  62. };
  63. KNOB AdjustDpcThreshold =
  64. {
  65. HKEY_LOCAL_MACHINE,
  66. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Kernel"),
  67. TEXT("AdjustDpcThreshold"),
  68. DPC_ADJUST_THRESHOLD,
  69. 0,
  70. 50,
  71. 0
  72. };
  73. KNOB IdealDpcRate =
  74. {
  75. HKEY_LOCAL_MACHINE,
  76. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Kernel"),
  77. TEXT("IdealDpcRate"),
  78. DPC_IDEAL_RATE,
  79. 0,
  80. 50,
  81. 0
  82. };
  83. KNOB DpcUpdateRegistry =
  84. {
  85. NULL,
  86. NULL,
  87. NULL,
  88. DPC_UPDATE_REGISTRY,
  89. 0,
  90. 0,
  91. 0
  92. };
  93. KNOB GlobalFlagUpdateRegistry =
  94. {
  95. NULL,
  96. NULL,
  97. NULL,
  98. GLOBAL_FLAG_UPDATE_REGISTRY,
  99. 0,
  100. 0,
  101. 0
  102. };
  103. KNOB PagedPoolQuota =
  104. {
  105. HKEY_LOCAL_MACHINE,
  106. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"),
  107. TEXT("PagedPoolQuota"),
  108. MM_PAGED_QUOTA,
  109. 0,
  110. 0,
  111. 0
  112. };
  113. KNOB NonPagedPoolQuota =
  114. {
  115. HKEY_LOCAL_MACHINE,
  116. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"),
  117. TEXT("NonPagedPoolQuota"),
  118. MM_NONPAGED_QUOTA,
  119. 0,
  120. 0,
  121. 0
  122. };
  123. KNOB PagingFileQuota =
  124. {
  125. HKEY_LOCAL_MACHINE,
  126. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"),
  127. TEXT("PagingFileQuota"),
  128. MM_PAGING_FILE_QUOTA,
  129. 0,
  130. 0,
  131. 0
  132. };
  133. KNOB PagedPoolSize =
  134. {
  135. HKEY_LOCAL_MACHINE,
  136. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"),
  137. TEXT("PagedPoolSize"),
  138. MM_PAGED_SIZE,
  139. 0,
  140. 0,
  141. 0
  142. };
  143. KNOB NonPagedPoolSize =
  144. {
  145. HKEY_LOCAL_MACHINE,
  146. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"),
  147. TEXT("NonPagedPoolSize"),
  148. MM_NONPAGED_SIZE,
  149. 0,
  150. 0,
  151. 0
  152. };
  153. KNOB SystemPages =
  154. {
  155. HKEY_LOCAL_MACHINE,
  156. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"),
  157. TEXT("SystemPages"),
  158. MM_SYSTEM_PAGES,
  159. 0,
  160. 0,
  161. 0
  162. };
  163. KNOB SecondLevelDataCache =
  164. {
  165. HKEY_LOCAL_MACHINE,
  166. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"),
  167. TEXT("SecondLevelDataCache"),
  168. MM_L2_CACHE_SIZE,
  169. 0,
  170. 0,
  171. 0
  172. };
  173. KNOB LargeSystemCache =
  174. {
  175. HKEY_LOCAL_MACHINE,
  176. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Memory Management"),
  177. TEXT("LargeSystemCache"),
  178. MM_LARGE_CACHE,
  179. 0,
  180. 0,
  181. 0
  182. };
  183. KNOB NtfsDisable8dot3 =
  184. {
  185. HKEY_LOCAL_MACHINE,
  186. TEXT("System\\CurrentControlSet\\Control\\FileSystem"),
  187. TEXT("NtfsDisable8dot3NameCreation"),
  188. FS_NTFS_DISABLE_SHORTNAME,
  189. 0,
  190. 0,
  191. 0
  192. };
  193. KNOB FatWin31Compatible =
  194. {
  195. HKEY_LOCAL_MACHINE,
  196. TEXT("System\\CurrentControlSet\\Control\\FileSystem"),
  197. TEXT("Win31FileSystem"),
  198. FS_FAT_WIN_31,
  199. 0,
  200. 0,
  201. 0
  202. };
  203. KNOB Win95Extensions =
  204. {
  205. HKEY_LOCAL_MACHINE,
  206. TEXT("System\\CurrentControlSet\\Control\\FileSystem"),
  207. TEXT("Win95TruncatedExtensions"),
  208. FS_WIN95_EXTENSIONS,
  209. 0,
  210. 0,
  211. 0
  212. };
  213. KNOB AdditionalCriticalWorkerThreads =
  214. {
  215. HKEY_LOCAL_MACHINE,
  216. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Executive"),
  217. TEXT("AdditionalCriticalWorkerThreads"),
  218. FS_CRITICAL_WORKERS,
  219. 0,
  220. 0,
  221. 0
  222. };
  223. KNOB AdditionalDelayedWorkerThreads =
  224. {
  225. HKEY_LOCAL_MACHINE,
  226. TEXT("System\\CurrentControlSet\\Control\\Session Manager\\Executive"),
  227. TEXT("AdditionalDelayedWorkerThreads"),
  228. FS_DELAYED_WORKERS,
  229. 0,
  230. 0,
  231. 0
  232. };
  233. #include "sockpage.h"
  234. #include "tcppage.h"
  235. //
  236. // Pages
  237. //
  238. TWEAK_PAGE DpcPage =
  239. {
  240. MAKEINTRESOURCE(DPC_BEHAVIOR_DLG),
  241. ApplyDpcChanges,
  242. {
  243. &MaximumDpcQueueDepth,
  244. &MinimumDpcRate,
  245. &AdjustDpcThreshold,
  246. &IdealDpcRate,
  247. &DpcUpdateRegistry,
  248. NULL
  249. }
  250. };
  251. TWEAK_PAGE MmPage =
  252. {
  253. MAKEINTRESOURCE(MM_DLG),
  254. NULL,
  255. {
  256. &PagedPoolQuota,
  257. &NonPagedPoolQuota,
  258. &PagingFileQuota,
  259. &PagedPoolSize,
  260. &NonPagedPoolSize,
  261. &SystemPages,
  262. &SecondLevelDataCache,
  263. &LargeSystemCache,
  264. NULL
  265. }
  266. };
  267. TWEAK_PAGE GlobalFlagPage =
  268. {
  269. MAKEINTRESOURCE(GLOBAL_FLAG_DLG),
  270. ApplyGlobalFlagChanges,
  271. {
  272. &GlobalFlagUpdateRegistry,
  273. NULL
  274. }
  275. };
  276. TWEAK_PAGE FilesystemPage =
  277. {
  278. MAKEINTRESOURCE(FILESYSTEM_DLG),
  279. NULL,
  280. {
  281. &NtfsDisable8dot3,
  282. &FatWin31Compatible,
  283. &AdditionalCriticalWorkerThreads,
  284. &AdditionalDelayedWorkerThreads,
  285. NULL
  286. }
  287. };
  288. int
  289. WINAPI
  290. WinMain(
  291. HINSTANCE hInstance, // handle of current instance
  292. HINSTANCE hPrevInstance, // handle of previous instance
  293. LPSTR lpszCmdLine, // address of command line
  294. int nCmdShow // show state of window
  295. )
  296. {
  297. PTWEAK_PAGE TweakPages[] = {
  298. &DpcPage,
  299. &MmPage,
  300. &GlobalFlagPage,
  301. &FilesystemPage,
  302. &WinsockPage,
  303. &TcpPage
  304. };
  305. return(TweakSheet(sizeof(TweakPages)/sizeof(PTWEAK_PAGE),TweakPages));
  306. }
  307. BOOL
  308. ApplyDpcChanges(
  309. BOOL fInit,
  310. HWND hDlg
  311. )
  312. {
  313. SYSTEM_DPC_BEHAVIOR_INFORMATION DpcBehavior;
  314. BOOLEAN Enabled;
  315. NTSTATUS Status;
  316. if (fInit) {
  317. Status = NtQuerySystemInformation(SystemDpcBehaviorInformation,
  318. &DpcBehavior,
  319. sizeof(DpcBehavior),
  320. NULL);
  321. if (!NT_SUCCESS(Status)) {
  322. CHAR Buffer[128];
  323. sprintf(Buffer,
  324. "NtQuerySystemInformation failed (%08lx)\n"
  325. "You probably need a newer build.\n"
  326. "Use information from the registry?",
  327. Status);
  328. if (MessageBox(NULL,Buffer,TEXT("Horrible Disaster"),MB_YESNO) == IDYES) {
  329. return(FALSE);
  330. } else {
  331. ExitProcess(0);
  332. }
  333. } else {
  334. MaximumDpcQueueDepth.CurrentValue = DpcBehavior.DpcQueueDepth;
  335. MinimumDpcRate.CurrentValue = DpcBehavior.MinimumDpcRate;
  336. AdjustDpcThreshold.CurrentValue = DpcBehavior.AdjustDpcThreshold;
  337. IdealDpcRate.CurrentValue = DpcBehavior.IdealDpcRate;
  338. }
  339. } else {
  340. DpcBehavior.DpcQueueDepth = MaximumDpcQueueDepth.NewValue;
  341. DpcBehavior.MinimumDpcRate = MinimumDpcRate.NewValue;
  342. DpcBehavior.AdjustDpcThreshold = AdjustDpcThreshold.NewValue;
  343. DpcBehavior.IdealDpcRate = IdealDpcRate.NewValue;
  344. //
  345. // Attempt to enable the load driver privilege to
  346. // allow setting the DPC behavior.
  347. //
  348. RtlAdjustPrivilege(SE_LOAD_DRIVER_PRIVILEGE,
  349. TRUE,
  350. FALSE,
  351. &Enabled);
  352. Status = NtSetSystemInformation(SystemDpcBehaviorInformation,
  353. &DpcBehavior,
  354. sizeof(DpcBehavior));
  355. RtlAdjustPrivilege(SE_LOAD_DRIVER_PRIVILEGE,
  356. Enabled,
  357. FALSE,
  358. &Enabled);
  359. if (!NT_SUCCESS(Status)) {
  360. CHAR Buffer[128];
  361. sprintf(Buffer,
  362. "NtSetSystemInformation failed, status %08lx",
  363. Status);
  364. MessageBox(NULL,Buffer,TEXT("Oops"),MB_OK);
  365. return(FALSE);
  366. }
  367. if (DpcUpdateRegistry.NewValue) {
  368. //
  369. // Let the common routine update the values in the registry
  370. //
  371. return(FALSE);
  372. }
  373. }
  374. return(TRUE);
  375. }
  376. BOOL
  377. ApplyGlobalFlagChanges(
  378. BOOL fInit,
  379. HWND hDlg
  380. )
  381. {
  382. BOOLEAN Enabled;
  383. NTSTATUS Status;
  384. SYSTEM_FLAGS_INFORMATION SystemInformation;
  385. int iBit;
  386. if (fInit) {
  387. Status = NtQuerySystemInformation(SystemFlagsInformation,
  388. &SystemInformation,
  389. sizeof(SystemInformation),
  390. NULL);
  391. if (!NT_SUCCESS(Status)) {
  392. CHAR Buffer[128];
  393. sprintf(Buffer,
  394. "NtQuerySystemInformation failed (%08lx)\n",
  395. Status);
  396. MessageBox(NULL,Buffer,TEXT("Horrible Disaster"),MB_OK);
  397. ExitProcess(0);
  398. } else {
  399. for (iBit = 0; iBit < 32; iBit++) {
  400. CheckDlgButton(hDlg,
  401. GLOBAL_FLAG_ID + iBit,
  402. (SystemInformation.Flags & (1 << iBit)));
  403. }
  404. }
  405. } else {
  406. SystemInformation.Flags = 0;
  407. for (iBit = 0; iBit < 32; iBit++) {
  408. if (IsDlgButtonChecked(hDlg, GLOBAL_FLAG_ID + iBit)) {
  409. SystemInformation.Flags |= (1 << iBit);
  410. }
  411. }
  412. //
  413. // Attempt to enable the load driver privilege to
  414. // allow setting the DPC behavior.
  415. //
  416. RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE,
  417. TRUE,
  418. FALSE,
  419. &Enabled);
  420. Status = NtSetSystemInformation(SystemFlagsInformation,
  421. &SystemInformation,
  422. sizeof(SystemInformation));
  423. RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE,
  424. Enabled,
  425. FALSE,
  426. &Enabled);
  427. if (!NT_SUCCESS(Status)) {
  428. CHAR Buffer[128];
  429. sprintf(Buffer,
  430. "SetSystemInformationFailed (%08lx)\nYou probably do not have debug privileges",
  431. Status);
  432. MessageBox(NULL,Buffer,TEXT("Oops"),MB_OK);
  433. }
  434. if (GlobalFlagUpdateRegistry.NewValue) {
  435. HKEY Key;
  436. LONG Result;
  437. DWORD Disposition;
  438. //
  439. // Update the Value in the registry
  440. //
  441. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  442. TEXT("SYSTEM\\CurrentControlSet\\Control\\Session Manager"),
  443. 0L,
  444. NULL,
  445. 0L,
  446. KEY_SET_VALUE,
  447. NULL,
  448. &Key,
  449. &Disposition) != ERROR_SUCCESS) {
  450. CHAR Buffer[128];
  451. sprintf(Buffer,
  452. "RegCreateKey for NtGlobalFlag failed (%d)\nYou probably are Not Authorized.",
  453. GetLastError());
  454. MessageBox(NULL,Buffer,TEXT("Oops"),MB_OK);
  455. return(TRUE);
  456. }
  457. RegSetValueEx(Key,
  458. "GlobalFlag",
  459. 0,
  460. REG_DWORD,
  461. (LPBYTE)&SystemInformation.Flags,
  462. sizeof(SystemInformation.Flags));
  463. SendMessage(GetParent(hDlg),
  464. PSM_REBOOTSYSTEM,
  465. 0,
  466. 0);
  467. }
  468. }
  469. return(TRUE);
  470. }