Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

uclient.c File Reference

#include "ulpc.h"

Go to the source code of this file.

Defines

#define MAX_CLIENT_PROCESSES   9
#define MAX_CLIENT_THREADS   9

Functions

DWORD ClientThread (LPVOID Context)
VOID Usage (VOID)
int _cdecl main (int argc, char *argv[])

Variables

CHAR ProcessName [32]
HANDLE PortHandle = NULL
HANDLE ClientThreadHandles [MAX_CLIENT_THREADS] = {NULL}
DWORD ClientThreadClientIds [MAX_CLIENT_THREADS]


Define Documentation

#define MAX_CLIENT_PROCESSES   9
 

Definition at line 23 of file uclient.c.

Referenced by main().

#define MAX_CLIENT_THREADS   9
 

Definition at line 24 of file uclient.c.

Referenced by main().


Function Documentation

DWORD ClientThread LPVOID  Context  ) 
 

Definition at line 33 of file uclient.c.

References CHAR, EnterThread(), FALSE, NT_SUCCESS, NTSTATUS(), NULL, PortHandle, RtlIntegerToChar(), RtlNtStatusToDosError(), SendRequest(), Status, strlen(), and TLPC_MAX_MSG_DATA_LENGTH.

Referenced by LpcpCopyRequestData(), LpcpDeletePort(), LpcpPrepareToWakeClient(), main(), NtAcceptConnectPort(), NtCompleteConnectPort(), NtImpersonateClientOfPort(), NtImpersonateThread(), NtOpenChannel(), NtReplyWaitSendChannel(), NtSendWaitReplyChannel(), and SeCreateClientSecurity().

00036 { 00037 CHAR ThreadName[ 64 ]; 00038 NTSTATUS Status = STATUS_SUCCESS; 00039 ULONG MsgLength; 00040 PTEB Teb = NtCurrentTeb(); 00041 00042 Teb->ActiveRpcHandle = NULL; 00043 00044 strcpy( ThreadName, "Client Thread Id: " ); 00045 RtlIntegerToChar( (ULONG)Teb->ClientId.UniqueProcess, 16, 9, 00046 ThreadName + strlen( ThreadName ) 00047 ); 00048 strcat( ThreadName, "." ); 00049 RtlIntegerToChar( (ULONG)Teb->ClientId.UniqueThread, 16, 9, 00050 ThreadName + strlen( ThreadName ) 00051 ); 00052 00053 EnterThread( ThreadName, (ULONG)Context ); 00054 00055 MsgLength = 0; 00056 while (NT_SUCCESS( Status )) { 00057 Status = SendRequest( 1, 00058 ThreadName, 00059 PortHandle, 00060 Context, 00061 MsgLength, 00062 NULL, 00063 FALSE 00064 ); 00065 MsgLength += sizeof( ULONG ); 00066 if (MsgLength >= (TLPC_MAX_MSG_DATA_LENGTH * sizeof( ULONG ))) { 00067 break; 00068 } 00069 } 00070 00071 if (PortHandle != NULL) { 00072 if (!CloseHandle( PortHandle )) { 00073 fprintf( stderr, "CloseHandle( 0x%lx ) failed - %u\n", PortHandle, GetLastError() ); 00074 } 00075 else { 00076 PortHandle = NULL; 00077 } 00078 } 00079 00080 fprintf( stderr, "%s %s\n", 00081 NT_SUCCESS( Status ) ? "Exiting" : "ABORTING", 00082 ThreadName 00083 ); 00084 00085 return RtlNtStatusToDosError( Status ); 00086 }

int _cdecl main int  argc,
char *  argv[]
 

Definition at line 99 of file uclient.c.

References ClientMemoryBase, ClientMemorySize, ClientThread(), ClientThreadClientIds, ClientThreadHandles, DWORD, DynamicQos, LPVOID, MAX_CLIENT_PROCESSES, MAX_CLIENT_THREADS, NtConnectPort(), NtCreateSection(), NTSTATUS(), NULL, PORT_NAME, PortHandle, PortName, ProcessName, RtlInitUnicodeString(), RtlNtStatusToDosError(), ServerMemoryBase, ServerMemoryDelta, ShowHandleOrStatus(), sprintf(), Status, strlen(), and Usage().

00103 { 00104 NTSTATUS Status; 00105 DWORD rc; 00106 PORT_VIEW ClientView; 00107 REMOTE_PORT_VIEW ServerView; 00108 ULONG ClientNumber; 00109 ULONG NumberOfThreads; 00110 ULONG MaxMessageLength; 00111 ULONG ConnectionInformationLength; 00112 UCHAR ConnectionInformation[ 64 ]; 00113 ULONG i; 00114 PULONG p; 00115 PTEB Teb = NtCurrentTeb(); 00116 LARGE_INTEGER MaximumSize; 00117 00118 Status = STATUS_SUCCESS; 00119 00120 fprintf( stderr, "Entering UCLIENT User Mode LPC Test Program\n" ); 00121 00122 if (argc < 2) { 00123 Usage(); 00124 } 00125 00126 ClientNumber = atoi( argv[ 1 ] ); 00127 if (argc < 3) { 00128 NumberOfThreads = 1; 00129 } 00130 else { 00131 NumberOfThreads = atoi( argv[ 2 ] ); 00132 } 00133 00134 if (ClientNumber > MAX_CLIENT_PROCESSES || 00135 NumberOfThreads > MAX_CLIENT_THREADS 00136 ) { 00137 Usage(); 00138 } 00139 00140 sprintf( ProcessName, "Client Process %08x", Teb->ClientId.UniqueProcess ); 00141 strcpy( ConnectionInformation, ProcessName ); 00142 ConnectionInformationLength = strlen( ProcessName ) + 1; 00143 00144 RtlInitUnicodeString( &PortName, PORT_NAME ); 00145 fprintf( stderr, "Creating Port Memory Section" ); 00146 00147 MaximumSize.QuadPart = 0x4000 * NumberOfThreads; 00148 Status = NtCreateSection( &ClientView.SectionHandle, 00149 SECTION_MAP_READ | SECTION_MAP_WRITE, 00150 NULL, 00151 &MaximumSize, 00152 PAGE_READWRITE, 00153 SEC_COMMIT, 00154 NULL 00155 ); 00156 00157 if (ShowHandleOrStatus( Status, ClientView.SectionHandle )) { 00158 ClientView.Length = sizeof( ClientView ); 00159 ClientView.SectionOffset = 0; 00160 ClientView.ViewSize = 0x2000; 00161 ClientView.ViewBase = 0; 00162 ClientView.ViewRemoteBase = 0; 00163 ServerView.Length = sizeof( ServerView ); 00164 ServerView.ViewSize = 0; 00165 ServerView.ViewBase = 0; 00166 00167 fprintf( stderr, "%s calling NtConnectPort( %wZ )\n", ProcessName, &PortName ); 00168 Status = NtConnectPort( &PortHandle, 00169 &PortName, 00170 &DynamicQos, 00171 &ClientView, 00172 &ServerView, 00173 (PULONG)&MaxMessageLength, 00174 (PVOID)ConnectionInformation, 00175 (PULONG)&ConnectionInformationLength 00176 ); 00177 00178 00179 00180 if (ShowHandleOrStatus( Status, PortHandle )) { 00181 fprintf( stderr, " MaxMessageLength: %ld\n", MaxMessageLength ); 00182 fprintf( stderr, " ConnectionInfo: (%ld) '%.*s'\n", 00183 ConnectionInformationLength, 00184 ConnectionInformationLength, 00185 (PSZ)&ConnectionInformation[0] 00186 ); 00187 fprintf( stderr, " ClientView: Base=%lx, Size=%lx, RemoteBase: %lx\n", 00188 ClientView.ViewBase, 00189 ClientView.ViewSize, 00190 ClientView.ViewRemoteBase 00191 ); 00192 fprintf( stderr, " ServerView: Base=%lx, Size=%lx\n", 00193 ServerView.ViewBase, 00194 ServerView.ViewSize 00195 ); 00196 ClientMemoryBase = ClientView.ViewBase; 00197 ClientMemorySize = ClientView.ViewSize; 00198 ServerMemoryBase = ClientView.ViewRemoteBase; 00199 ServerMemoryDelta = (ULONG)ServerMemoryBase - 00200 (ULONG)ClientMemoryBase; 00201 00202 p = (PULONG)ClientMemoryBase; 00203 i = ClientMemorySize; 00204 while (i) { 00205 fprintf( stderr, "ClientView[%lx] == %lx (%lx)\n", 00206 p, 00207 *p, 00208 *p - ServerMemoryDelta 00209 ); 00210 p += (0x1000/sizeof( ULONG )); 00211 i -= 0x1000; 00212 } 00213 p = (PULONG)ServerView.ViewBase; 00214 i = ServerView.ViewSize; 00215 while (i) { 00216 fprintf( stderr, "ServerView[%lx] == %lx\n", p, *p ); 00217 p += (0x1000/sizeof( ULONG )); 00218 i -= 0x1000; 00219 } 00220 } 00221 } 00222 00223 rc = RtlNtStatusToDosError( Status ); 00224 if (rc == NO_ERROR) { 00225 ClientThreadHandles[ 0 ] = GetCurrentThread(); 00226 ClientThreadClientIds[ 0 ] = GetCurrentThreadId(); 00227 for (i=1; i< NumberOfThreads; i++) { 00228 fprintf( stderr, "Creating %s, Thread %ld\n", ProcessName, i+1 ); 00229 rc = NO_ERROR; 00230 ClientThreadHandles[ i ] = CreateThread( NULL, 00231 0, 00232 (LPTHREAD_START_ROUTINE)ClientThread, 00233 (LPVOID)((ClientNumber << 4) | (i+1)), 00234 CREATE_SUSPENDED, 00235 &ClientThreadClientIds[ i ] 00236 ); 00237 if (ClientThreadHandles[ i ] == NULL) { 00238 rc = GetLastError(); 00239 break; 00240 } 00241 } 00242 00243 if (rc == NO_ERROR) { 00244 for (i=1; i<NumberOfThreads; i++) { 00245 ResumeThread( ClientThreadHandles[ i ] ); 00246 } 00247 00248 ClientThread( (LPVOID)((ClientNumber << 4) | 1) ); 00249 } 00250 } 00251 00252 if (rc == NO_ERROR) { 00253 } 00254 else { 00255 fprintf( stderr, "UCLIENT: Initialization Failed - %u\n", rc ); 00256 ExitProcess( rc ); 00257 } 00258 00259 return( rc ); 00260 }

VOID Usage VOID   ) 
 

Definition at line 90 of file uclient.c.

00091 { 00092 fprintf( stderr, "usage: UCLIENT ClientNumber [#threads]\n" ); 00093 ExitProcess( 1 ); 00094 }


Variable Documentation

DWORD ClientThreadClientIds[MAX_CLIENT_THREADS]
 

Definition at line 30 of file uclient.c.

Referenced by main().

HANDLE ClientThreadHandles[MAX_CLIENT_THREADS] = {NULL}
 

Definition at line 29 of file uclient.c.

Referenced by main().

HANDLE PortHandle = NULL
 

Definition at line 27 of file uclient.c.

Referenced by ClientThread(), LpcpCopyRequestData(), LpcpCreatePort(), main(), NtAcceptConnectPort(), NtCompleteConnectPort(), NtConnectPort(), NtCreatePort(), NtCreateWaitablePort(), NtImpersonateClientOfPort(), NtListenPort(), NtQueryInformationPort(), NtReadRequestData(), NtRegisterThreadTerminatePort(), NtReplyPort(), NtReplyWaitReceivePort(), NtReplyWaitReceivePortEx(), NtReplyWaitReplyPort(), NtRequestPort(), NtRequestWaitReplyPort(), NtSecureConnectPort(), NtWriteRequestData(), ReplyMessageToTerminalServer(), and SendRequest().

CHAR ProcessName[32]
 

Definition at line 26 of file uclient.c.

Referenced by HorPtoP(), and main().


Generated on Sat May 15 19:45:50 2004 for test by doxygen 1.3.7