info.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*++
  2. Copyright (c) 2015 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. info.c
  9. Abstract:
  10. This module handles getting and setting system information calls.
  11. Author:
  12. Chris Stevens 18-Jan-2015
  13. Environment:
  14. Kernel
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include <minoca/kernel/kernel.h>
  20. #include "spp.h"
  21. //
  22. // ---------------------------------------------------------------- Definitions
  23. //
  24. //
  25. // ------------------------------------------------------ Data Type Definitions
  26. //
  27. //
  28. // ----------------------------------------------- Internal Function Prototypes
  29. //
  30. KSTATUS
  31. SppGetSetState (
  32. PVOID Data,
  33. PUINTN DataSize,
  34. BOOL Set
  35. );
  36. //
  37. // -------------------------------------------------------------------- Globals
  38. //
  39. //
  40. // ------------------------------------------------------------------ Functions
  41. //
  42. KSTATUS
  43. SpGetSetSystemInformation (
  44. BOOL FromKernelMode,
  45. SP_INFORMATION_TYPE InformationType,
  46. PVOID Data,
  47. PUINTN DataSize,
  48. BOOL Set
  49. )
  50. /*++
  51. Routine Description:
  52. This routine gets or sets system information.
  53. Arguments:
  54. FromKernelMode - Supplies a boolean indicating whether or not this request
  55. (and the buffer associated with it) originates from user mode (FALSE)
  56. or kernel mode (TRUE).
  57. InformationType - Supplies the information type.
  58. Data - Supplies a pointer to the data buffer where the data is either
  59. returned for a get operation or given for a set operation.
  60. DataSize - Supplies a pointer that on input contains the size of the
  61. data buffer. On output, contains the required size of the data buffer.
  62. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  63. a set operation (TRUE).
  64. Return Value:
  65. Status code.
  66. --*/
  67. {
  68. KSTATUS Status;
  69. switch (InformationType) {
  70. case SpInformationGetSetState:
  71. Status = SppGetSetState(Data, DataSize, Set);
  72. break;
  73. default:
  74. Status = STATUS_INVALID_PARAMETER;
  75. *DataSize = 0;
  76. break;
  77. }
  78. return Status;
  79. }
  80. //
  81. // --------------------------------------------------------- Internal Functions
  82. //
  83. KSTATUS
  84. SppGetSetState (
  85. PVOID Data,
  86. PUINTN DataSize,
  87. BOOL Set
  88. )
  89. /*++
  90. Routine Description:
  91. This routine gets or sets the system profiler state.
  92. Arguments:
  93. Data - Supplies a pointer to the data buffer where the data is either
  94. returned for a get operation or given for a set operation.
  95. DataSize - Supplies a pointer that on input contains the size of the
  96. data buffer. On output, contains the required size of the data buffer.
  97. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  98. a set operation (TRUE).
  99. Return Value:
  100. Status code.
  101. --*/
  102. {
  103. ULONG ChangedFlags;
  104. ULONG DisableFlags;
  105. ULONG EnableFlags;
  106. PSP_GET_SET_STATE_INFORMATION Information;
  107. BOOL LockHeld;
  108. KSTATUS Status;
  109. Status = PsCheckPermission(PERMISSION_SYSTEM_ADMINISTRATOR);
  110. if (!KSUCCESS(Status)) {
  111. return Status;
  112. }
  113. Information = Data;
  114. if (*DataSize < sizeof(SP_GET_SET_STATE_INFORMATION)) {
  115. *DataSize = sizeof(SP_GET_SET_STATE_INFORMATION);
  116. return STATUS_DATA_LENGTH_MISMATCH;
  117. }
  118. //
  119. // Return the current set of enabled flags on a get request.
  120. //
  121. Information = (PSP_GET_SET_STATE_INFORMATION)Data;
  122. LockHeld = FALSE;
  123. if (Set == FALSE) {
  124. Information->Operation = SpGetSetStateOperationNone;
  125. Information->ProfilerTypeFlags = SpEnabledFlags;
  126. } else if (Information->Operation != SpGetSetStateOperationNone) {
  127. DisableFlags = 0;
  128. EnableFlags = 0;
  129. KeAcquireQueuedLock(SpProfilingQueuedLock);
  130. LockHeld = TRUE;
  131. switch (Information->Operation) {
  132. case SpGetSetStateOperationOverwrite:
  133. ChangedFlags = SpEnabledFlags ^ Information->ProfilerTypeFlags;
  134. EnableFlags = ChangedFlags & ~SpEnabledFlags;
  135. DisableFlags = ChangedFlags & SpEnabledFlags;
  136. break;
  137. case SpGetSetStateOperationEnable:
  138. EnableFlags = Information->ProfilerTypeFlags & ~SpEnabledFlags;
  139. break;
  140. case SpGetSetStateOperationDisable:
  141. DisableFlags = Information->ProfilerTypeFlags & SpEnabledFlags;
  142. break;
  143. default:
  144. break;
  145. }
  146. if (DisableFlags != 0) {
  147. Status = SppStopSystemProfiler(DisableFlags);
  148. if (!KSUCCESS(Status)) {
  149. goto GetSetStateEnd;
  150. }
  151. }
  152. if (EnableFlags != 0) {
  153. Status = SppStartSystemProfiler(EnableFlags);
  154. if (!KSUCCESS(Status)) {
  155. goto GetSetStateEnd;
  156. }
  157. }
  158. KeReleaseQueuedLock(SpProfilingQueuedLock);
  159. LockHeld = FALSE;
  160. }
  161. Status = STATUS_SUCCESS;
  162. GetSetStateEnd:
  163. if (LockHeld != FALSE) {
  164. KeReleaseQueuedLock(SpProfilingQueuedLock);
  165. }
  166. return Status;
  167. }