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.

322 lines
7.1 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. vrfsdk.c
  5. Abstract:
  6. This module implements verifier SDK exports that other verifiers
  7. can use.
  8. Author:
  9. Silviu Calinoiu (SilviuC) 13-Feb-2002
  10. Revision History:
  11. --*/
  12. #include "pch.h"
  13. #include "verifier.h"
  14. #include "support.h"
  15. /////////////////////////////////////////////////////////////////////
  16. /////////////////////////////////////////////////// Run-time settings
  17. /////////////////////////////////////////////////////////////////////
  18. NTSTATUS
  19. VerifierSetRuntimeFlags (
  20. IN ULONG VerifierFlags
  21. )
  22. /*++
  23. Routine Description:
  24. This routine enables at runtime application verifier flags.
  25. Note that not all flags can be set or reset after process initialization.
  26. Arguments:
  27. VerifierFlags - verifier flags to be set. This is a set of RTL_VRF_FLG_XXX bits.
  28. Return Value:
  29. STATUS_SUCCESS if all flags requested have been enabled.
  30. STATUS_INVALID_PARAMETER if a flag was not set according to the mask or
  31. if application verifier is not enabled for the process.
  32. --*/
  33. {
  34. NTSTATUS Status;
  35. if ((NtCurrentPeb()->NtGlobalFlag & FLG_APPLICATION_VERIFIER)) {
  36. if ((VerifierFlags & RTL_VRF_FLG_RPC_CHECKS)) {
  37. AVrfpProvider.VerifierFlags |= RTL_VRF_FLG_RPC_CHECKS;
  38. }
  39. else {
  40. AVrfpProvider.VerifierFlags &= ~RTL_VRF_FLG_RPC_CHECKS;
  41. }
  42. Status = STATUS_SUCCESS;
  43. }
  44. else {
  45. Status = STATUS_INVALID_PARAMETER;
  46. }
  47. return Status;
  48. }
  49. NTSTATUS
  50. VerifierQueryRuntimeFlags (
  51. OUT PLOGICAL VerifierEnabled,
  52. OUT PULONG VerifierFlags
  53. )
  54. /*++
  55. Routine Description:
  56. This routine queries at runtime application verifier flags.
  57. Arguments:
  58. VerifierEnabled - variable to pass true or false if verifier is enabled.
  59. VerifierFlags - variable to pass verifier flags. This is a set of RTL_VRF_FLG_XXX bits.
  60. Return Value:
  61. STATUS_SUCCESS if the flags were successfully written.
  62. STATUS_INVALID_PARAMETER or exception code if the flags could not be
  63. written.
  64. --*/
  65. {
  66. NTSTATUS Status;
  67. try {
  68. if ((NtCurrentPeb()->NtGlobalFlag & FLG_APPLICATION_VERIFIER)) {
  69. if (VerifierEnabled != NULL && VerifierFlags != NULL) {
  70. *VerifierEnabled = TRUE;
  71. *VerifierFlags = AVrfpProvider.VerifierFlags;
  72. Status = STATUS_SUCCESS;
  73. }
  74. else {
  75. Status = STATUS_INVALID_PARAMETER;
  76. }
  77. }
  78. else {
  79. if (VerifierEnabled != NULL && VerifierFlags != NULL) {
  80. *VerifierEnabled = FALSE;
  81. *VerifierFlags = 0;
  82. Status = STATUS_SUCCESS;
  83. }
  84. else {
  85. Status = STATUS_INVALID_PARAMETER;
  86. }
  87. }
  88. }
  89. except (EXCEPTION_EXECUTE_HANDLER) {
  90. Status = _exception_code();
  91. }
  92. return Status;
  93. }
  94. /////////////////////////////////////////////////////////////////////
  95. //////////////////////////////////////// RPC read-only page heap APIs
  96. /////////////////////////////////////////////////////////////////////
  97. PVOID
  98. VerifierCreateRpcPageHeap (
  99. IN ULONG Flags,
  100. IN PVOID HeapBase OPTIONAL,
  101. IN SIZE_T ReserveSize OPTIONAL,
  102. IN SIZE_T CommitSize OPTIONAL,
  103. IN PVOID Lock OPTIONAL,
  104. IN PRTL_HEAP_PARAMETERS Parameters OPTIONAL
  105. )
  106. {
  107. UNREFERENCED_PARAMETER(Parameters);
  108. //
  109. // If application verifier is not enabled or RPC verifier is not enabled
  110. // the function will fail. This APIs are exclusively for RPC verifier.
  111. //
  112. if ((NtCurrentPeb()->NtGlobalFlag & FLG_APPLICATION_VERIFIER) == 0) {
  113. return NULL;
  114. }
  115. if ((AVrfpProvider.VerifierFlags & RTL_VRF_FLG_RPC_CHECKS) == 0) {
  116. return NULL;
  117. }
  118. //
  119. // Now call the page heap create API.
  120. //
  121. return AVrfpRtlpDebugPageHeapCreate (Flags,
  122. HeapBase,
  123. ReserveSize,
  124. CommitSize,
  125. Lock,
  126. (PVOID)-2);
  127. }
  128. PVOID
  129. VerifierDestroyRpcPageHeap (
  130. IN PVOID HeapHandle
  131. )
  132. {
  133. //
  134. // If application verifier is not enabled or RPC verifier is not enabled
  135. // the function will fail. This APIs are exclusively for RPC verifier.
  136. //
  137. if ((NtCurrentPeb()->NtGlobalFlag & FLG_APPLICATION_VERIFIER) == 0) {
  138. return NULL;
  139. }
  140. if ((AVrfpProvider.VerifierFlags & RTL_VRF_FLG_RPC_CHECKS) == 0) {
  141. return NULL;
  142. }
  143. //
  144. // Now call the page heap destroy API.
  145. //
  146. return AVrfpRtlpDebugPageHeapDestroy (HeapHandle);
  147. }
  148. /////////////////////////////////////////////////////////////////////
  149. ///////////////////////////////////////////// DLL related information
  150. /////////////////////////////////////////////////////////////////////
  151. LOGICAL
  152. VerifierIsDllEntryActive (
  153. OUT PVOID * Reserved
  154. )
  155. {
  156. PAVRF_TLS_STRUCT TlsStruct;
  157. UNREFERENCED_PARAMETER (Reserved);
  158. //
  159. // If application verifier is not enabled the function will return
  160. // false.
  161. //
  162. if ((NtCurrentPeb()->NtGlobalFlag & FLG_APPLICATION_VERIFIER) == 0) {
  163. return FALSE;
  164. }
  165. TlsStruct = AVrfpGetVerifierTlsValue();
  166. if (TlsStruct != NULL &&
  167. (TlsStruct->Flags & VRFP_THREAD_FLAGS_LOADER_LOCK_OWNER)) {
  168. return TRUE;
  169. }
  170. else {
  171. return FALSE;
  172. }
  173. }
  174. LOGICAL
  175. VerifierIsCurrentThreadHoldingLocks (
  176. VOID
  177. )
  178. {
  179. PAVRF_TLS_STRUCT TlsStruct;
  180. //
  181. // If application verifier is not enabled the function will return
  182. // false.
  183. //
  184. if ((NtCurrentPeb()->NtGlobalFlag & FLG_APPLICATION_VERIFIER) == 0) {
  185. return FALSE;
  186. }
  187. TlsStruct = AVrfpGetVerifierTlsValue();
  188. if (TlsStruct != NULL &&
  189. TlsStruct->CountOfOwnedCriticalSections > 0) {
  190. return TRUE;
  191. }
  192. else {
  193. return FALSE;
  194. }
  195. }
  196. /////////////////////////////////////////////////////////////////////
  197. /////////////////////////////////////////////// Free memory callbacks
  198. /////////////////////////////////////////////////////////////////////
  199. NTSTATUS
  200. VerifierAddFreeMemoryCallback (
  201. VERIFIER_FREE_MEMORY_CALLBACK Callback
  202. )
  203. {
  204. NTSTATUS Status;
  205. if ((NtCurrentPeb()->NtGlobalFlag & FLG_APPLICATION_VERIFIER) == 0) {
  206. Status = STATUS_INVALID_PARAMETER;
  207. }
  208. else {
  209. Status = AVrfpAddFreeMemoryCallback (Callback);
  210. }
  211. return Status;
  212. }
  213. NTSTATUS
  214. VerifierDeleteFreeMemoryCallback (
  215. VERIFIER_FREE_MEMORY_CALLBACK Callback
  216. )
  217. {
  218. NTSTATUS Status;
  219. if ((NtCurrentPeb()->NtGlobalFlag & FLG_APPLICATION_VERIFIER) == 0) {
  220. Status = STATUS_INVALID_PARAMETER;
  221. }
  222. else {
  223. Status = AVrfpDeleteFreeMemoryCallback (Callback);
  224. }
  225. return Status;
  226. }