Source code of Windows XP (NT5)
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.

430 lines
9.4 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. wow64csr.c
  5. Abstract:
  6. This module contains the WOW64 versions of the code for the Windows Client.
  7. See csr* files in ntos\dll for more function comments.
  8. Author:
  9. Michael Zoran (mzoran) 2-JUN-1998
  10. Environment:
  11. User Mode only
  12. Revision History:
  13. --*/
  14. #include "csrdll.h"
  15. #include "ldrp.h"
  16. #include "ntwow64.h"
  17. NTSTATUS
  18. CsrClientConnectToServer(
  19. IN PWSTR ObjectDirectory,
  20. IN ULONG ServerDllIndex,
  21. IN PVOID ConnectionInformation,
  22. IN OUT PULONG ConnectionInformationLength OPTIONAL,
  23. OUT PBOOLEAN CalledFromServer OPTIONAL
  24. )
  25. {
  26. return NtWow64CsrClientConnectToServer(ObjectDirectory,
  27. ServerDllIndex,
  28. ConnectionInformation,
  29. ConnectionInformationLength,
  30. CalledFromServer);
  31. }
  32. NTSTATUS
  33. CsrNewThread(
  34. VOID
  35. )
  36. {
  37. return NtWow64CsrNewThread();
  38. }
  39. NTSTATUS
  40. CsrIdentifyAlertableThread( VOID )
  41. {
  42. return NtWow64CsrIdentifyAlertableThread();
  43. }
  44. NTSTATUS
  45. CsrSetPriorityClass(
  46. IN HANDLE ProcessHandle,
  47. IN OUT PULONG PriorityClass
  48. )
  49. {
  50. return NtWow64CsrSetPriorityClass(ProcessHandle, PriorityClass);
  51. }
  52. NTSTATUS
  53. CsrClientCallServer(
  54. IN OUT PCSR_API_MSG m,
  55. IN OUT PCSR_CAPTURE_HEADER CaptureBuffer OPTIONAL,
  56. IN CSR_API_NUMBER ApiNumber,
  57. IN ULONG ArgLength
  58. )
  59. {
  60. return NtWow64CsrClientCallServer(m,CaptureBuffer,ApiNumber,ArgLength);
  61. }
  62. PCSR_CAPTURE_HEADER
  63. CsrAllocateCaptureBuffer(
  64. IN ULONG CountMessagePointers,
  65. IN ULONG Sizecd
  66. )
  67. {
  68. return NtWow64CsrAllocateCaptureBuffer(CountMessagePointers, Sizecd);
  69. }
  70. VOID
  71. CsrFreeCaptureBuffer(
  72. IN PCSR_CAPTURE_HEADER CaptureBuffer
  73. )
  74. {
  75. NtWow64CsrFreeCaptureBuffer(CaptureBuffer);
  76. }
  77. ULONG
  78. CsrAllocateMessagePointer(
  79. IN OUT PCSR_CAPTURE_HEADER CaptureBuffer,
  80. IN ULONG Length,
  81. OUT PVOID *Pointer
  82. )
  83. {
  84. return NtWow64CsrAllocateMessagePointer(CaptureBuffer, Length, Pointer);
  85. }
  86. VOID
  87. CsrCaptureMessageBuffer(
  88. IN OUT PCSR_CAPTURE_HEADER CaptureBuffer,
  89. IN PVOID Buffer OPTIONAL,
  90. IN ULONG Length,
  91. OUT PVOID *CapturedBuffer
  92. )
  93. {
  94. NtWow64CsrCaptureMessageBuffer(CaptureBuffer,Buffer,Length,CapturedBuffer);
  95. }
  96. VOID
  97. CsrCaptureMessageString(
  98. IN OUT PCSR_CAPTURE_HEADER CaptureBuffer,
  99. IN PCSTR String OPTIONAL,
  100. IN ULONG Length,
  101. IN ULONG MaximumLength,
  102. OUT PSTRING CapturedString
  103. )
  104. {
  105. NtWow64CsrCaptureMessageString(CaptureBuffer, String, Length, MaximumLength, CapturedString);
  106. }
  107. PLARGE_INTEGER
  108. CsrCaptureTimeout(
  109. IN ULONG MilliSeconds,
  110. OUT PLARGE_INTEGER Timeout
  111. )
  112. {
  113. if (MilliSeconds == -1) {
  114. return( NULL );
  115. }
  116. else {
  117. Timeout->QuadPart = Int32x32To64( MilliSeconds, -10000 );
  118. return( (PLARGE_INTEGER)Timeout );
  119. }
  120. }
  121. VOID
  122. CsrProbeForWrite(
  123. IN PVOID Address,
  124. IN ULONG Length,
  125. IN ULONG Alignment
  126. )
  127. /*++
  128. Routine Description:
  129. This function probes a structure for read accessibility.
  130. If the structure is not accessible, then an exception is raised.
  131. Arguments:
  132. Address - Supplies a pointer to the structure to be probed.
  133. Length - Supplies the length of the structure.
  134. Alignment - Supplies the required alignment of the structure expressed
  135. as the number of bytes in the primitive datatype (e.g., 1 for char,
  136. 2 for short, 4 for long, and 8 for quad).
  137. Return Value:
  138. None.
  139. --*/
  140. {
  141. volatile CHAR *StartAddress;
  142. volatile CHAR *EndAddress;
  143. CHAR Temp;
  144. //
  145. // If the structure has zero length, then do not probe the structure for
  146. // write accessibility or alignment.
  147. //
  148. if (Length != 0) {
  149. //
  150. // If the structure is not properly aligned, then raise a data
  151. // misalignment exception.
  152. //
  153. ASSERT((Alignment == 1) || (Alignment == 2) ||
  154. (Alignment == 4) || (Alignment == 8));
  155. StartAddress = (volatile CHAR *)Address;
  156. if (((ULONG_PTR)StartAddress & (Alignment - 1)) != 0) {
  157. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  158. } else {
  159. //
  160. // BUG, BUG - this should not be necessary once the 386 kernel
  161. // makes system space inaccessable to user mode.
  162. //
  163. if ((ULONG_PTR)StartAddress > CsrNtSysInfo.MaximumUserModeAddress) {
  164. RtlRaiseStatus(STATUS_ACCESS_VIOLATION);
  165. }
  166. Temp = *StartAddress;
  167. *StartAddress = Temp;
  168. EndAddress = StartAddress + Length - 1;
  169. Temp = *EndAddress;
  170. *EndAddress = Temp;
  171. }
  172. }
  173. }
  174. VOID
  175. CsrProbeForRead(
  176. IN PVOID Address,
  177. IN ULONG Length,
  178. IN ULONG Alignment
  179. )
  180. /*++
  181. Routine Description:
  182. This function probes a structure for read accessibility.
  183. If the structure is not accessible, then an exception is raised.
  184. Arguments:
  185. Address - Supplies a pointer to the structure to be probed.
  186. Length - Supplies the length of the structure.
  187. Alignment - Supplies the required alignment of the structure expressed
  188. as the number of bytes in the primitive datatype (e.g., 1 for char,
  189. 2 for short, 4 for long, and 8 for quad).
  190. Return Value:
  191. None.
  192. --*/
  193. {
  194. volatile CHAR *StartAddress;
  195. volatile CHAR *EndAddress;
  196. CHAR Temp;
  197. //
  198. // If the structure has zero length, then do not probe the structure for
  199. // read accessibility or alignment.
  200. //
  201. if (Length != 0) {
  202. //
  203. // If the structure is not properly aligned, then raise a data
  204. // misalignment exception.
  205. //
  206. ASSERT((Alignment == 1) || (Alignment == 2) ||
  207. (Alignment == 4) || (Alignment == 8));
  208. StartAddress = (volatile CHAR *)Address;
  209. if (((ULONG_PTR)StartAddress & (Alignment - 1)) != 0) {
  210. RtlRaiseStatus(STATUS_DATATYPE_MISALIGNMENT);
  211. } else {
  212. Temp = *StartAddress;
  213. EndAddress = StartAddress + Length - 1;
  214. Temp = *EndAddress;
  215. }
  216. }
  217. }
  218. HANDLE
  219. CsrGetProcessId(
  220. VOID
  221. )
  222. {
  223. return NtWow64CsrGetProcessId ();
  224. }
  225. VOID
  226. CsrCaptureMessageUnicodeStringInPlace(
  227. IN OUT PCSR_CAPTURE_HEADER CaptureBuffer,
  228. IN OUT PUNICODE_STRING String
  229. )
  230. /*++
  231. Routine Description:
  232. This function captures an ASCII string into a counted string data
  233. structure located in an API request message.
  234. Arguments:
  235. CaptureBuffer - Pointer to a capture buffer allocated by
  236. CsrAllocateCaptureBuffer.
  237. String - Optional pointer to the Unicode string. If this parameter is
  238. not present, then the counted string data structure is set to
  239. the null string.
  240. Length - Length of the Unicode string in bytes, ignored if String is NULL.
  241. MaximumLength - Maximum length of the string. Different for null
  242. terminated strings, where Length does not include the null and
  243. MaximumLength does. This is always how much space is allocated
  244. from the capture buffer.
  245. CaptureString - Pointer to the counted string data structure that will
  246. be filled in to point to the captured Unicode string.
  247. Return Value:
  248. None, but if you don't trust the String parameter, use a __try block.
  249. --*/
  250. {
  251. ASSERT(String != NULL);
  252. CsrCaptureMessageString(
  253. CaptureBuffer,
  254. (PCSTR)String->Buffer,
  255. String->Length,
  256. String->MaximumLength,
  257. (PSTRING)String
  258. );
  259. // test > before substraction due to unsignedness
  260. if (String->MaximumLength > String->Length) {
  261. if ((String->MaximumLength - String->Length) >= sizeof(WCHAR)) {
  262. String->Buffer[ String->Length / sizeof(WCHAR) ] = 0;
  263. }
  264. }
  265. }
  266. NTSTATUS
  267. CsrCaptureMessageMultiUnicodeStringsInPlace(
  268. IN OUT PCSR_CAPTURE_HEADER* InOutCaptureBuffer,
  269. IN ULONG NumberOfStringsToCapture,
  270. IN const PUNICODE_STRING* StringsToCapture
  271. )
  272. /*++
  273. Routine Description:
  274. Capture multiple unicode strings.
  275. If the CaptureBuffer hasn't been allocated yet (passed as NULL), first
  276. allocate it.
  277. Arguments:
  278. CaptureBuffer - Pointer to a capture buffer allocated by
  279. CsrAllocateCaptureBuffer, or NULL, in which case we call CsrAllocateCaptureBuffer
  280. for you; this is the case if you are only capturing these strings
  281. and nothing else.
  282. NumberOfStringsToCapture -
  283. StringsToCapture -
  284. Return Value:
  285. NTSTATUS
  286. --*/
  287. {
  288. NTSTATUS Status = STATUS_SUCCESS;
  289. ULONG Length = 0;
  290. ULONG i = 0;
  291. PCSR_CAPTURE_HEADER CaptureBuffer = NULL;
  292. if (InOutCaptureBuffer == NULL) {
  293. Status = STATUS_INVALID_PARAMETER;
  294. goto Exit;
  295. }
  296. CaptureBuffer = *InOutCaptureBuffer;
  297. if (CaptureBuffer == NULL) {
  298. Length = 0;
  299. for (i = 0 ; i != NumberOfStringsToCapture ; ++i) {
  300. if (StringsToCapture[i] != NULL) {
  301. Length += StringsToCapture[i]->MaximumLength;
  302. }
  303. }
  304. CaptureBuffer = CsrAllocateCaptureBuffer(NumberOfStringsToCapture, Length);
  305. if (CaptureBuffer == NULL) {
  306. Status = STATUS_NO_MEMORY;
  307. goto Exit;
  308. }
  309. *InOutCaptureBuffer = CaptureBuffer;
  310. }
  311. for (i = 0 ; i != NumberOfStringsToCapture ; ++i) {
  312. if (StringsToCapture[i] != NULL) {
  313. CsrCaptureMessageUnicodeStringInPlace(
  314. CaptureBuffer,
  315. StringsToCapture[i]
  316. );
  317. } else {
  318. }
  319. }
  320. Status = STATUS_SUCCESS;
  321. Exit:
  322. return Status;
  323. }