diff --git a/reactos/apps/tests/lpc/conport.c b/reactos/apps/tests/lpc/conport.c index 7794225985f..e7d80f47511 100644 --- a/reactos/apps/tests/lpc/conport.c +++ b/reactos/apps/tests/lpc/conport.c @@ -1,4 +1,4 @@ -/* $Id: conport.c,v 1.1 1999/06/24 22:54:27 ea Exp $ +/* $Id: conport.c,v 1.2 1999/06/27 07:11:25 ea Exp $ * * reactos/apps/lpc/conport.c * @@ -24,34 +24,47 @@ #define LPC_CONNECT_FLAG4 0x00001000 #define LPC_CONNECT_FLAG5 0x00010000 +#define QUERY_OBJECT_LPC_PORT_BASIC_INFORMATION_SIZE 55 + NTSTATUS (STDCALL * ConnectPort)( - PHANDLE, - PUNICODE_STRING, - DWORD, - DWORD, - DWORD, - DWORD, - DWORD, - DWORD + OUT PHANDLE PortHandle, + IN PUNICODE_STRING PortName, + IN POBJECT_ATTRIBUTES ObjectAttributes, + IN DWORD Unknown3, + IN DWORD Unknown4, + IN DWORD Unknown5, + IN DWORD Unknown6, + IN ULONG Flags ); +NTSTATUS +(STDCALL * QueryObject)( + IN HANDLE ObjectHandle, + IN CINT ObjectInformationClass, + OUT PVOID ObjectInformation, + IN ULONG Length, + OUT PULONG ResultLength + ); + NTSTATUS (STDCALL * YieldExecution)(VOID); -#define BUF_SIZE 256 +#define BUF_SIZE 1024 +#define MAXARG 1000000 VOID DumpBuffer( char *Name, - BYTE *buffer + BYTE *buffer, + ULONG size ) { - register int i = 0; + register ULONG i = 0; - printf("%s = ",Name); + printf("%s [%d] = ",size,Name); for ( i = 0; - i < BUF_SIZE; + i != size; ++i ) { @@ -60,19 +73,150 @@ DumpBuffer( printf("\n"); } -#define MAXARG 1000000 + +VOID +DumpInfo ( + LPCSTR Name, + NTSTATUS Status, + HANDLE Port + ) +{ + int i; + BYTE ObjectInformation [BUF_SIZE] = {0}; + ULONG ResultLength; + + printf("Port \"%s\" connected:\n",Name); + + printf("Status = %08X\n",Status); + printf("Port = %08X\n\n",Port); + /* + * Query object information. + */ + printf("Basic Information:\n"); + Status = -1; + for ( i=1024000; i && Status != STATUS_SUCCESS; --i) + Status = QueryObject( + Port, + ObjectBasicInformation, + ObjectInformation, + QUERY_OBJECT_LPC_PORT_BASIC_INFORMATION_SIZE, + & ResultLength + ); + if (Status == STATUS_SUCCESS) + { + DumpBuffer( + "RAW", + ObjectInformation, + ResultLength + ); + } + else + { + printf("\tStatus = %08X\n",Status); + } + printf("Type Information:\n"); + Status = QueryObject( + Port, + ObjectTypeInformation, + ObjectInformation, + sizeof ObjectInformation, + & ResultLength + ); + if (Status == STATUS_SUCCESS) + { + OBJECT_TYPE_INFORMATION * i; + + i = (OBJECT_TYPE_INFORMATION *) ObjectInformation; + + wprintf( + L"\tName: \"%s\"\n", + (i->Name.Length ? i->Name.Buffer : L"") + ); +/* +FIXME: why this always raise an access violation exception? + wprintf( + L"\tType: \"%s\"\n", + (i->Type.Length ? i->Type.Buffer : L"") + ); +*/ + printf( + "\tTotal Handles: %d\n", + i->TotalHandles + ); + printf( + "\tReference Count: %d\n", + i->ReferenceCount + ); + } + else + { + printf("\tStatus = %08X\n",Status); + } + printf("Name Information:\n"); + Status = QueryObject( + Port, + ObjectNameInformation, + ObjectInformation, + sizeof ObjectInformation, + & ResultLength + ); + if (Status == STATUS_SUCCESS) + { + OBJECT_NAME_INFORMATION * i; + + i = (OBJECT_NAME_INFORMATION *) ObjectInformation; + wprintf( + L"\tName: \"%s\"\n", + (i->Name.Length ? i->Name.Buffer : L"") + ); + } + else + { + printf("\tStatus = %08X\n",Status); + } + printf("Data Information:\n"); + Status = QueryObject( + Port, + ObjectDataInformation, + ObjectInformation, + sizeof ObjectInformation, + & ResultLength + ); + if (Status == STATUS_SUCCESS) + { + OBJECT_DATA_INFORMATION * i; + + i = (OBJECT_DATA_INFORMATION *) ObjectInformation; + printf( + "\tInherit Handle: %s\n", + (i->bInheritHandle ? "TRUE" : "FALSE") + ); + printf( + "\tProtect from Close: %s\n", + (i->bProtectFromClose ? "TRUE" : "FALSE") + ); + } + else + { + printf("\tStatus = %08X\n",Status); + } +} + VOID TryConnectPort(char *port_name) { - DWORD Status = 0; - HANDLE Port = 0; - int i; - UNICODE_STRING PortName; - WORD Name [BUF_SIZE] = {0}; - int dwx = 0; - BYTE bb [BUF_SIZE] = {0}; + DWORD Status = 0; + HANDLE Port = 0; + int i; + UNICODE_STRING PortName; + OBJECT_ATTRIBUTES ObjectAttributes; + WORD Name [BUF_SIZE] = {0}; + int dwx = 0; + /* + * Convert the port's name to Unicode. + */ for ( PortName.Length = 0; ( *port_name @@ -87,28 +231,56 @@ TryConnectPort(char *port_name) PortName.Length = PortName.Length * sizeof (WORD); PortName.MaximumLength = PortName.Length + sizeof (WORD); PortName.Buffer = (PWSTR) Name; - + /* + * Prepare the port object attributes. + */ + ObjectAttributes.Length = + sizeof (OBJECT_ATTRIBUTES); + ObjectAttributes.RootDirectory = + NULL; + ObjectAttributes.ObjectName = + NULL /*& PortName */; + ObjectAttributes.Attributes = + OBJ_CASE_INSENSITIVE; + ObjectAttributes.SecurityDescriptor = + NULL; + ObjectAttributes.SecurityQualityOfService = + NULL; + /* + * Try to issue a connection request. + */ Port = 0; Status = ConnectPort( & Port, & PortName, - bb, + & ObjectAttributes, 0, 0, 0, 0, LPC_CONNECT_FLAG5 ); - if (Port) + if (Status == STATUS_SUCCESS) { - printf("Status = %08X\n",Status); - printf("Port = %08X\n\n",Port); + DumpInfo(port_name,Status,Port); + /* Hot waiting */ for (dwx=0; dwx