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.

263 lines
5.2 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #define BOOT_SECTOR_SIZE 512
  5. BOOLEAN
  6. WINAPI
  7. PassThruDllEntry(
  8. IN HINSTANCE DllHandle,
  9. IN DWORD Reason,
  10. IN LPVOID Reserved
  11. )
  12. /*++
  13. Routine Description:
  14. Main DLL entrypoint
  15. Arguments:
  16. DllHandle - Supplies the DLL handle.
  17. Reason - Supplies the call reason
  18. Return Value:
  19. TRUE if successful
  20. FALSE if unsuccessful
  21. --*/
  22. {
  23. switch ( Reason ) {
  24. case DLL_PROCESS_ATTACH:
  25. // DLL is attaching to the address
  26. // space of the current process.
  27. break;
  28. case DLL_THREAD_ATTACH:
  29. // A new thread is being created in the current process.
  30. break;
  31. case DLL_THREAD_DETACH:
  32. // A thread is exiting cleanly.
  33. break;
  34. case DLL_PROCESS_DETACH:
  35. // The calling process is detaching
  36. // the DLL from its address space.
  37. break;
  38. }
  39. return(TRUE);
  40. }
  41. DWORD
  42. WINAPI
  43. TestDllGetBootSector(
  44. IN LPSTR DeviceName,
  45. IN LPSTR ContextStr,
  46. OUT PVOID OutBuffer,
  47. IN DWORD OutBufferSize,
  48. OUT LPDWORD BytesReturned
  49. )
  50. {
  51. HANDLE hDisk = NULL;
  52. DWORD dwStatus = NO_ERROR;
  53. UNREFERENCED_PARAMETER( ContextStr );
  54. if ( !DeviceName || !OutBuffer || !BytesReturned ) {
  55. dwStatus = ERROR_INVALID_PARAMETER;
  56. goto FnExit;
  57. }
  58. if ( OutBufferSize < BOOT_SECTOR_SIZE ) {
  59. *BytesReturned = BOOT_SECTOR_SIZE;
  60. dwStatus = ERROR_MORE_DATA;
  61. goto FnExit;
  62. }
  63. //
  64. // Open a handle to the disk drive.
  65. //
  66. hDisk = CreateFile( DeviceName,
  67. GENERIC_READ | GENERIC_WRITE,
  68. FILE_SHARE_READ,
  69. 0, // No security attributes
  70. OPEN_EXISTING,
  71. FILE_FLAG_NO_BUFFERING,
  72. NULL // No template file
  73. );
  74. if ( INVALID_HANDLE_VALUE == hDisk ) {
  75. dwStatus = GetLastError();
  76. goto FnExit;
  77. }
  78. //
  79. // Clear out the array holding the boot sector.
  80. //
  81. ZeroMemory( OutBuffer, BOOT_SECTOR_SIZE );
  82. //
  83. // Read the boot sector.
  84. //
  85. if ( !ReadFile( hDisk,
  86. OutBuffer,
  87. BOOT_SECTOR_SIZE,
  88. BytesReturned,
  89. NULL
  90. ) ) {
  91. dwStatus = GetLastError();
  92. goto FnExit;
  93. }
  94. if ( *BytesReturned != BOOT_SECTOR_SIZE ) {
  95. dwStatus = ERROR_BAD_LENGTH;
  96. goto FnExit;
  97. }
  98. FnExit:
  99. if ( hDisk ) {
  100. CloseHandle( hDisk );
  101. }
  102. return dwStatus;
  103. } // TestDllGetBootSector
  104. DWORD
  105. WINAPI
  106. TestDllReturnContextAsError(
  107. IN LPSTR DeviceName,
  108. IN LPSTR ContextStr,
  109. OUT PVOID OutBuffer,
  110. IN DWORD OutBufferSize,
  111. OUT LPDWORD BytesReturned
  112. )
  113. {
  114. DWORD dwStatus = NO_ERROR;
  115. UNREFERENCED_PARAMETER( DeviceName );
  116. UNREFERENCED_PARAMETER( OutBuffer );
  117. UNREFERENCED_PARAMETER( OutBufferSize );
  118. if ( !BytesReturned ) {
  119. dwStatus = ERROR_INVALID_PARAMETER;
  120. goto FnExit;
  121. }
  122. *BytesReturned = 0;
  123. //
  124. // Convert context string to a DWORD value. Note that
  125. // strtol will return zero if it can't convert the string.
  126. // Zero happens to be NO_ERROR.
  127. //
  128. dwStatus = strtol( ContextStr, NULL, 10 );
  129. FnExit:
  130. return dwStatus;
  131. } // TestDllReturnContextAsError
  132. DWORD
  133. WINAPI
  134. TestDllNotEnoughParms(
  135. IN LPSTR DeviceName
  136. )
  137. {
  138. //
  139. // This routine _should_ fail and possibly cause a stack exception.
  140. //
  141. UNREFERENCED_PARAMETER( DeviceName );
  142. return NO_ERROR;
  143. } // TestDllNotEnoughParms
  144. DWORD
  145. WINAPI
  146. TestDllTooManyParms(
  147. IN LPSTR DeviceName,
  148. IN LPSTR ContextStr,
  149. OUT PVOID OutBuffer,
  150. IN DWORD OutBufferSize,
  151. OUT LPDWORD BytesReturned,
  152. IN PVOID Nada1,
  153. IN PVOID Nada2,
  154. IN PVOID Nada3
  155. )
  156. {
  157. //
  158. // This routine _should_ fail and possibly cause a stack exception.
  159. //
  160. UNREFERENCED_PARAMETER( DeviceName );
  161. UNREFERENCED_PARAMETER( ContextStr );
  162. UNREFERENCED_PARAMETER( OutBuffer );
  163. UNREFERENCED_PARAMETER( OutBufferSize );
  164. UNREFERENCED_PARAMETER( BytesReturned );
  165. UNREFERENCED_PARAMETER( Nada1 );
  166. UNREFERENCED_PARAMETER( Nada2 );
  167. UNREFERENCED_PARAMETER( Nada3 );
  168. return NO_ERROR;
  169. } // TestDllTooManyParms
  170. DWORD
  171. WINAPI
  172. TestDllCauseException(
  173. IN LPSTR DeviceName,
  174. IN LPSTR ContextStr,
  175. OUT PVOID OutBuffer,
  176. IN DWORD OutBufferSize,
  177. OUT LPDWORD BytesReturned
  178. )
  179. {
  180. DWORD x = 0;
  181. DWORD y;
  182. UNREFERENCED_PARAMETER( DeviceName );
  183. UNREFERENCED_PARAMETER( ContextStr );
  184. UNREFERENCED_PARAMETER( OutBuffer );
  185. UNREFERENCED_PARAMETER( OutBufferSize );
  186. UNREFERENCED_PARAMETER( BytesReturned );
  187. //
  188. // How about divide by zero?
  189. //
  190. y = 7 / x;
  191. return NO_ERROR;
  192. } // CauseException