info.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*++
  2. Copyright (c) 2014 Minoca Corp. All Rights Reserved
  3. Module Name:
  4. info.c
  5. Abstract:
  6. This module implements support for handling process subsystem information
  7. requests.
  8. Author:
  9. Chris Stevens 13-Aug-2014
  10. Environment:
  11. Kernel
  12. --*/
  13. //
  14. // ------------------------------------------------------------------- Includes
  15. //
  16. #include <minoca/kernel/kernel.h>
  17. #include "psp.h"
  18. //
  19. // ---------------------------------------------------------------- Definitions
  20. //
  21. //
  22. // ------------------------------------------------------ Data Type Definitions
  23. //
  24. //
  25. // ----------------------------------------------- Internal Function Prototypes
  26. //
  27. KSTATUS
  28. PspGetSetProcessInformation (
  29. PVOID Data,
  30. PUINTN DataSize,
  31. BOOL Set
  32. );
  33. KSTATUS
  34. PspGetProcessIdListInformation (
  35. PVOID Data,
  36. PUINTN DataSize,
  37. BOOL Set
  38. );
  39. //
  40. // -------------------------------------------------------------------- Globals
  41. //
  42. //
  43. // ------------------------------------------------------------------ Functions
  44. //
  45. KSTATUS
  46. PsGetSetSystemInformation (
  47. BOOL FromKernelMode,
  48. PS_INFORMATION_TYPE InformationType,
  49. PVOID Data,
  50. PUINTN DataSize,
  51. BOOL Set
  52. )
  53. /*++
  54. Routine Description:
  55. This routine gets or sets system information.
  56. Arguments:
  57. FromKernelMode - Supplies a boolean indicating whether or not this request
  58. (and the buffer associated with it) originates from user mode (FALSE)
  59. or kernel mode (TRUE).
  60. InformationType - Supplies the information type.
  61. Data - Supplies a pointer to the data buffer where the data is either
  62. returned for a get operation or given for a set operation.
  63. DataSize - Supplies a pointer that on input contains the size of the
  64. data buffer. On output, contains the required size of the data buffer.
  65. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  66. a set operation (TRUE).
  67. Return Value:
  68. Status code.
  69. --*/
  70. {
  71. KSTATUS Status;
  72. switch (InformationType) {
  73. case PsInformationProcess:
  74. Status = PspGetSetProcessInformation(Data, DataSize, Set);
  75. break;
  76. case PsInformationProcessIdList:
  77. Status = PspGetProcessIdListInformation(Data, DataSize, Set);
  78. break;
  79. default:
  80. Status = STATUS_INVALID_PARAMETER;
  81. *DataSize = 0;
  82. break;
  83. }
  84. return Status;
  85. }
  86. //
  87. // --------------------------------------------------------- Internal Functions
  88. //
  89. KSTATUS
  90. PspGetSetProcessInformation (
  91. PVOID Data,
  92. PUINTN DataSize,
  93. BOOL Set
  94. )
  95. /*++
  96. Routine Description:
  97. This routine gets or sets process informaiton.
  98. Arguments:
  99. Data - Supplies a pointer to the data buffer where the data is either
  100. returned for a get operation or given for a set operation.
  101. DataSize - Supplies a pointer that on input contains the size of the
  102. data buffer. On output, contains the required size of the data buffer.
  103. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  104. a set operation (TRUE).
  105. Return Value:
  106. Status code.
  107. --*/
  108. {
  109. PKPROCESS Process;
  110. PROCESS_ID ProcessId;
  111. PPROCESS_INFORMATION ProcessInformation;
  112. KSTATUS Status;
  113. if (Set != FALSE) {
  114. *DataSize = 0;
  115. return STATUS_ACCESS_DENIED;
  116. }
  117. if (Data == NULL) {
  118. return STATUS_INVALID_PARAMETER;
  119. }
  120. //
  121. // Check the version and size of the supplied data structure.
  122. //
  123. if (*DataSize < sizeof(ULONG)) {
  124. *DataSize = sizeof(PROCESS_INFORMATION);
  125. return STATUS_BUFFER_TOO_SMALL;
  126. }
  127. ProcessInformation = Data;
  128. if (ProcessInformation->Version < PROCESS_INFORMATION_VERSION) {
  129. return STATUS_VERSION_MISMATCH;
  130. }
  131. if (*DataSize < sizeof(PROCESS_INFORMATION)) {
  132. *DataSize = sizeof(PROCESS_INFORMATION);
  133. return STATUS_BUFFER_TOO_SMALL;
  134. }
  135. //
  136. // Get the process ID of the process whose information is to be retrieved.
  137. //
  138. ProcessId = ProcessInformation->ProcessId;
  139. if (ProcessId == -1ULL) {
  140. Process = PsGetCurrentProcess();
  141. ProcessId = Process->Identifiers.ProcessId;
  142. }
  143. //
  144. // TODO: Make sure the caller has access to this process's information.
  145. //
  146. //
  147. // Get the process information, or at least the necessary size of the
  148. // process information.
  149. //
  150. Status = PsGetProcessInformation(ProcessId, Data, DataSize);
  151. return Status;
  152. }
  153. KSTATUS
  154. PspGetProcessIdListInformation (
  155. PVOID Data,
  156. PUINTN DataSize,
  157. BOOL Set
  158. )
  159. /*++
  160. Routine Description:
  161. This routine gets the list of process identifiers for processes currently
  162. running on the system.
  163. Arguments:
  164. Data - Supplies a pointer to the data buffer where the data is either
  165. returned for a get operation or given for a set operation.
  166. DataSize - Supplies a pointer that on input contains the size of the
  167. data buffer. On output, contains the required size of the data buffer.
  168. Set - Supplies a boolean indicating if this is a get operation (FALSE) or
  169. a set operation (TRUE).
  170. Return Value:
  171. Status code.
  172. --*/
  173. {
  174. KSTATUS Status;
  175. if (Set != FALSE) {
  176. *DataSize = 0;
  177. return STATUS_ACCESS_DENIED;
  178. }
  179. //
  180. // Attempt to get the full list of IDs for the currently running processes.
  181. //
  182. Status = PspGetProcessIdList(Data, DataSize);
  183. if (!KSUCCESS(Status)) {
  184. goto GetProcessIdListInformationEnd;
  185. }
  186. Status = STATUS_SUCCESS;
  187. GetProcessIdListInformationEnd:
  188. return Status;
  189. }