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.

172 lines
4.4 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "nt.h"
  4. #include "ntrtl.h"
  5. #include "nturtl.h"
  6. #include "windows.h"
  7. HANDLE rpipe, wpipe;
  8. ULONG buf[1];
  9. IO_STATUS_BLOCK iosb;
  10. VOID
  11. Save (
  12. ULONG Count)
  13. {
  14. DWORD i;
  15. NTSTATUS status;
  16. DWORD retlen;
  17. for (i = 0; i < Count; i++) {
  18. status = NtFsControlFile (wpipe,
  19. NULL,
  20. NULL,
  21. NULL,
  22. &iosb,
  23. FSCTL_PIPE_INTERNAL_WRITE,
  24. buf, sizeof (buf),
  25. NULL, 0);
  26. if (!NT_SUCCESS (status)) {
  27. printf ("NtFsControlFile failed %X\n", status);
  28. ExitProcess (1);
  29. }
  30. }
  31. }
  32. VOID
  33. Restore (
  34. ULONG Count)
  35. {
  36. IO_STATUS_BLOCK iosb;
  37. DWORD i;
  38. NTSTATUS status;
  39. DWORD retlen;
  40. for (i = 0; i < Count; i++) {
  41. if (!ReadFile (rpipe, buf, sizeof (buf), &retlen, NULL)) {
  42. printf ("ReadFileEx failed %d\n", GetLastError ());
  43. ExitProcess (1);
  44. }
  45. }
  46. }
  47. VOID
  48. Invert (
  49. ULONG Count)
  50. {
  51. Save (Count);
  52. Restore (Count);
  53. }
  54. DWORD
  55. WINAPI
  56. Thrash (LPVOID arg)
  57. {
  58. IO_STATUS_BLOCK iosb;
  59. ULONG i;
  60. HANDLE Handle1, Handle2, Handle3;
  61. if (!arg) {
  62. SetThreadAffinityMask (GetCurrentThread (), 1);
  63. while (1) {
  64. NtQueryEaFile (NULL,
  65. &iosb,
  66. NULL,
  67. 0,
  68. FALSE,
  69. &buf,
  70. sizeof (buf),
  71. NULL,
  72. FALSE);
  73. }
  74. } else {
  75. while (1) {
  76. SetThreadAffinityMask (GetCurrentThread (), 1);
  77. Save (1);
  78. Sleep (0);
  79. SetThreadAffinityMask (GetCurrentThread (), 2);
  80. NtSuspendThread ((HANDLE) arg, NULL);
  81. SetThreadAffinityMask (GetCurrentThread (), 1);
  82. Invert (2);
  83. for (i = 0; i < 256-2; i++) {
  84. NtQueryEaFile (NULL,
  85. &iosb,
  86. NULL,
  87. 0,
  88. FALSE,
  89. &buf,
  90. sizeof (buf),
  91. NULL,
  92. FALSE);
  93. }
  94. NtResumeThread ((HANDLE) arg, NULL);
  95. Sleep (0);
  96. Restore (1);
  97. SetThreadAffinityMask (GetCurrentThread (), 2);
  98. }
  99. }
  100. return 0;
  101. }
  102. int __cdecl main ()
  103. {
  104. ULONG i;
  105. HANDLE thread1;
  106. DWORD id;
  107. DWORD mode;
  108. OVERLAPPED ovl={0};
  109. wpipe = CreateNamedPipe ("\\\\.\\pipe\\testpipe",
  110. PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,
  111. PIPE_TYPE_MESSAGE|PIPE_READMODE_MESSAGE|PIPE_WAIT,
  112. 1,
  113. 100,
  114. 100,
  115. 100000,
  116. NULL);
  117. if (wpipe == INVALID_HANDLE_VALUE) {
  118. printf ("CreateNamedPipe failed %d\n", GetLastError ());
  119. ExitProcess (1);
  120. }
  121. if (!ConnectNamedPipe (wpipe, &ovl)) {
  122. if (GetLastError () != ERROR_IO_PENDING) {
  123. printf ("ConnectNamedPipe failed %d\n", GetLastError ());
  124. ExitProcess (1);
  125. }
  126. }
  127. rpipe = CreateFile ("\\\\.\\pipe\\testpipe",
  128. GENERIC_READ|GENERIC_WRITE,
  129. FILE_SHARE_READ|FILE_SHARE_WRITE,
  130. NULL,
  131. OPEN_EXISTING,
  132. FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED,
  133. NULL);
  134. if (rpipe == INVALID_HANDLE_VALUE) {
  135. printf ("CreateFile failed %d\n", GetLastError ());
  136. ExitProcess (1);
  137. }
  138. mode = PIPE_READMODE_MESSAGE|PIPE_WAIT;
  139. if (!SetNamedPipeHandleState (rpipe, &mode, NULL, NULL)) {
  140. printf ("SetNamedPipeHandleState failed %d\n", GetLastError ());
  141. ExitProcess (1);
  142. }
  143. thread1 = CreateThread (NULL, 0, Thrash, NULL, 0, &id);
  144. if (!thread1) {
  145. printf ("CreateThread failed %d\n", GetLastError ());
  146. exit (EXIT_FAILURE);
  147. }
  148. Thrash (thread1);
  149. return EXIT_SUCCESS;
  150. }