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.

260 lines
7.6 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. uclient.c
  5. Abstract:
  6. User Mode Client Test program for the LPC subcomponent of the NTOS project
  7. Author:
  8. Steve Wood (stevewo) 28-Aug-1989
  9. Revision History:
  10. --*/
  11. #include "ulpc.h"
  12. #define MAX_CLIENT_PROCESSES 9
  13. #define MAX_CLIENT_THREADS 9
  14. CHAR ProcessName[ 32 ];
  15. HANDLE PortHandle = NULL;
  16. HANDLE ClientThreadHandles[ MAX_CLIENT_THREADS ] = {NULL};
  17. DWORD ClientThreadClientIds[ MAX_CLIENT_THREADS ];
  18. DWORD
  19. ClientThread(
  20. LPVOID Context
  21. )
  22. {
  23. CHAR ThreadName[ 64 ];
  24. NTSTATUS Status = STATUS_SUCCESS;
  25. ULONG MsgLength;
  26. PTEB Teb = NtCurrentTeb();
  27. Teb->ActiveRpcHandle = NULL;
  28. strcpy( ThreadName, "Client Thread Id: " );
  29. RtlIntegerToChar( (ULONG)Teb->ClientId.UniqueProcess, 16, 9,
  30. ThreadName + strlen( ThreadName )
  31. );
  32. strcat( ThreadName, "." );
  33. RtlIntegerToChar( (ULONG)Teb->ClientId.UniqueThread, 16, 9,
  34. ThreadName + strlen( ThreadName )
  35. );
  36. EnterThread( ThreadName, (ULONG)Context );
  37. MsgLength = 0;
  38. while (NT_SUCCESS( Status )) {
  39. Status = SendRequest( 1,
  40. ThreadName,
  41. PortHandle,
  42. Context,
  43. MsgLength,
  44. NULL,
  45. FALSE
  46. );
  47. MsgLength += sizeof( ULONG );
  48. if (MsgLength >= (TLPC_MAX_MSG_DATA_LENGTH * sizeof( ULONG ))) {
  49. break;
  50. }
  51. }
  52. if (PortHandle != NULL) {
  53. if (!CloseHandle( PortHandle )) {
  54. fprintf( stderr, "CloseHandle( 0x%lx ) failed - %u\n", PortHandle, GetLastError() );
  55. }
  56. else {
  57. PortHandle = NULL;
  58. }
  59. }
  60. fprintf( stderr, "%s %s\n",
  61. NT_SUCCESS( Status ) ? "Exiting" : "ABORTING",
  62. ThreadName
  63. );
  64. return RtlNtStatusToDosError( Status );
  65. }
  66. VOID
  67. Usage( VOID )
  68. {
  69. fprintf( stderr, "usage: UCLIENT ClientNumber [#threads]\n" );
  70. ExitProcess( 1 );
  71. }
  72. int
  73. _cdecl
  74. main(
  75. int argc,
  76. char *argv[]
  77. )
  78. {
  79. NTSTATUS Status;
  80. DWORD rc;
  81. PORT_VIEW ClientView;
  82. REMOTE_PORT_VIEW ServerView;
  83. ULONG ClientNumber;
  84. ULONG NumberOfThreads;
  85. ULONG MaxMessageLength;
  86. ULONG ConnectionInformationLength;
  87. UCHAR ConnectionInformation[ 64 ];
  88. ULONG i;
  89. PULONG p;
  90. PTEB Teb = NtCurrentTeb();
  91. LARGE_INTEGER MaximumSize;
  92. Status = STATUS_SUCCESS;
  93. fprintf( stderr, "Entering UCLIENT User Mode LPC Test Program\n" );
  94. if (argc < 2) {
  95. Usage();
  96. }
  97. ClientNumber = atoi( argv[ 1 ] );
  98. if (argc < 3) {
  99. NumberOfThreads = 1;
  100. }
  101. else {
  102. NumberOfThreads = atoi( argv[ 2 ] );
  103. }
  104. if (ClientNumber > MAX_CLIENT_PROCESSES ||
  105. NumberOfThreads > MAX_CLIENT_THREADS
  106. ) {
  107. Usage();
  108. }
  109. sprintf( ProcessName, "Client Process %08x", Teb->ClientId.UniqueProcess );
  110. strcpy( ConnectionInformation, ProcessName );
  111. ConnectionInformationLength = strlen( ProcessName ) + 1;
  112. RtlInitUnicodeString( &PortName, PORT_NAME );
  113. fprintf( stderr, "Creating Port Memory Section" );
  114. MaximumSize.QuadPart = 0x4000 * NumberOfThreads;
  115. Status = NtCreateSection( &ClientView.SectionHandle,
  116. SECTION_MAP_READ | SECTION_MAP_WRITE,
  117. NULL,
  118. &MaximumSize,
  119. PAGE_READWRITE,
  120. SEC_COMMIT,
  121. NULL
  122. );
  123. if (ShowHandleOrStatus( Status, ClientView.SectionHandle )) {
  124. ClientView.Length = sizeof( ClientView );
  125. ClientView.SectionOffset = 0;
  126. ClientView.ViewSize = 0x2000;
  127. ClientView.ViewBase = 0;
  128. ClientView.ViewRemoteBase = 0;
  129. ServerView.Length = sizeof( ServerView );
  130. ServerView.ViewSize = 0;
  131. ServerView.ViewBase = 0;
  132. fprintf( stderr, "%s calling NtConnectPort( %wZ )\n", ProcessName, &PortName );
  133. Status = NtConnectPort( &PortHandle,
  134. &PortName,
  135. &DynamicQos,
  136. &ClientView,
  137. &ServerView,
  138. (PULONG)&MaxMessageLength,
  139. (PVOID)ConnectionInformation,
  140. (PULONG)&ConnectionInformationLength
  141. );
  142. if (ShowHandleOrStatus( Status, PortHandle )) {
  143. fprintf( stderr, " MaxMessageLength: %ld\n", MaxMessageLength );
  144. fprintf( stderr, " ConnectionInfo: (%ld) '%.*s'\n",
  145. ConnectionInformationLength,
  146. ConnectionInformationLength,
  147. (PSZ)&ConnectionInformation[0]
  148. );
  149. fprintf( stderr, " ClientView: Base=%lx, Size=%lx, RemoteBase: %lx\n",
  150. ClientView.ViewBase,
  151. ClientView.ViewSize,
  152. ClientView.ViewRemoteBase
  153. );
  154. fprintf( stderr, " ServerView: Base=%lx, Size=%lx\n",
  155. ServerView.ViewBase,
  156. ServerView.ViewSize
  157. );
  158. ClientMemoryBase = ClientView.ViewBase;
  159. ClientMemorySize = ClientView.ViewSize;
  160. ServerMemoryBase = ClientView.ViewRemoteBase;
  161. ServerMemoryDelta = (ULONG)ServerMemoryBase -
  162. (ULONG)ClientMemoryBase;
  163. p = (PULONG)ClientMemoryBase;
  164. i = ClientMemorySize;
  165. while (i) {
  166. fprintf( stderr, "ClientView[%lx] == %lx (%lx)\n",
  167. p,
  168. *p,
  169. *p - ServerMemoryDelta
  170. );
  171. p += (0x1000/sizeof( ULONG ));
  172. i -= 0x1000;
  173. }
  174. p = (PULONG)ServerView.ViewBase;
  175. i = ServerView.ViewSize;
  176. while (i) {
  177. fprintf( stderr, "ServerView[%lx] == %lx\n", p, *p );
  178. p += (0x1000/sizeof( ULONG ));
  179. i -= 0x1000;
  180. }
  181. }
  182. }
  183. rc = RtlNtStatusToDosError( Status );
  184. if (rc == NO_ERROR) {
  185. ClientThreadHandles[ 0 ] = GetCurrentThread();
  186. ClientThreadClientIds[ 0 ] = GetCurrentThreadId();
  187. for (i=1; i< NumberOfThreads; i++) {
  188. fprintf( stderr, "Creating %s, Thread %ld\n", ProcessName, i+1 );
  189. rc = NO_ERROR;
  190. ClientThreadHandles[ i ] = CreateThread( NULL,
  191. 0,
  192. (LPTHREAD_START_ROUTINE)ClientThread,
  193. (LPVOID)((ClientNumber << 4) | (i+1)),
  194. CREATE_SUSPENDED,
  195. &ClientThreadClientIds[ i ]
  196. );
  197. if (ClientThreadHandles[ i ] == NULL) {
  198. rc = GetLastError();
  199. break;
  200. }
  201. }
  202. if (rc == NO_ERROR) {
  203. for (i=1; i<NumberOfThreads; i++) {
  204. ResumeThread( ClientThreadHandles[ i ] );
  205. }
  206. ClientThread( (LPVOID)((ClientNumber << 4) | 1) );
  207. }
  208. }
  209. if (rc == NO_ERROR) {
  210. }
  211. else {
  212. fprintf( stderr, "UCLIENT: Initialization Failed - %u\n", rc );
  213. ExitProcess( rc );
  214. }
  215. return( rc );
  216. }