diff --git a/reactos/apps/tests/lpc/conport.c b/reactos/apps/tests/lpc/conport.c index 5f43ce96b7c..4f0b16355bd 100644 --- a/reactos/apps/tests/lpc/conport.c +++ b/reactos/apps/tests/lpc/conport.c @@ -1,4 +1,4 @@ -/* $Id: conport.c,v 1.3 1999/06/27 07:15:16 ea Exp $ +/* $Id: conport.c,v 1.4 1999/07/04 22:04:31 ea Exp $ * * reactos/apps/lpc/conport.c * @@ -11,12 +11,18 @@ * conport.exe owns two unnamed LPC ports: * the one created by kernel32.dll connecting * to csrss.exe, and one connected to here. + * + * 19990627 (Emanuele Aliberti) + * Initial implementation. + * 19990704 (EA) + * Dump object's attributes moved in dumpinfo.c. */ #include #include #include #define PROTO_LPC #include +#include "dumpinfo.h" #define LPC_CONNECT_FLAG1 0x00000001 #define LPC_CONNECT_FLAG2 0x00000010 @@ -24,8 +30,6 @@ #define LPC_CONNECT_FLAG4 0x00001000 #define LPC_CONNECT_FLAG5 0x00010000 -#define QUERY_OBJECT_LPC_PORT_BASIC_INFORMATION_SIZE 55 - NTSTATUS (STDCALL * ConnectPort)( OUT PHANDLE PortHandle, @@ -53,152 +57,6 @@ NTSTATUS #define BUF_SIZE 1024 #define MAXARG 1000000 -VOID -DumpBuffer( - char *Name, - BYTE *buffer, - ULONG size - ) -{ - register ULONG i = 0; - - printf("%s [%d] = ",size,Name); - for ( i = 0; - i != size; - ++i - ) - { - printf("%02X",buffer[i]); - } - printf("\n"); -} - - -VOID -DumpInfo ( - LPCSTR Name, - NTSTATUS Status, - HANDLE Port - ) -{ - 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 = 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) @@ -210,6 +68,7 @@ TryConnectPort(char *port_name) OBJECT_ATTRIBUTES ObjectAttributes; WORD Name [BUF_SIZE] = {0}; int dwx = 0; + char * port_name_save = port_name; /* * Convert the port's name to Unicode. @@ -259,7 +118,12 @@ TryConnectPort(char *port_name) ); if (Status == STATUS_SUCCESS) { - DumpInfo(port_name,Status,Port); + DumpInfo( + port_name_save, + Status, + "connected", + Port + ); /* Hot waiting */ for (dwx=0; dwx +#include +#include +#define PROTO_LPC +#include +#include "dumpinfo.h" + +#define LPC_CONNECT_FLAG1 0x00000001 +#define LPC_CONNECT_FLAG2 0x00000010 +#define LPC_CONNECT_FLAG3 0x00000100 +#define LPC_CONNECT_FLAG4 0x00001000 +#define LPC_CONNECT_FLAG5 0x00010000 + +NTSTATUS +(STDCALL * CreatePort)( + /*OUT PHANDLE PortHandle,*/ + PVOID Buffer, + IN POBJECT_ATTRIBUTES PortAttributes OPTIONAL, + IN ACCESS_MASK DesiredAccess, + IN DWORD Unknown3, + 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 1024 +#define MAXARG 5000000 + + +VOID +TryCreatePort(char *port_name) +{ + DWORD Status = 0; + HANDLE Port = 0; + int i; + UNICODE_STRING PortName; + OBJECT_ATTRIBUTES ObjectAttributes; + WORD Name [BUF_SIZE] = {0}; + int dwx = 0; + char * port_name_save = port_name; + + /* + * Convert the port's name to Unicode. + */ + for ( + PortName.Length = 0; + ( *port_name + && (PortName.Length < BUF_SIZE) + ); + ) + { + Name[PortName.Length++] = (WORD) *port_name++; + } + Name[PortName.Length] = 0; + + 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 = + & PortName; + ObjectAttributes.Attributes = + 0; //OBJ_CASE_INSENSITIVE --> STATUS_INVALID_PARAMETER ==> case sensitive!; + ObjectAttributes.SecurityDescriptor = + NULL; + ObjectAttributes.SecurityQualityOfService = + NULL; + /* + * Try to issue a connection request. + */ + Port = 0; + Status = CreatePort( + & Port, + & ObjectAttributes, + 0, /* ACCESS_MASK? */ + 0, /* Unknown3 */ + LPC_CONNECT_FLAG5 + ); + if (Status == STATUS_SUCCESS) + { + DumpInfo( + port_name_save, + Status, + "created", + Port + ); + /* Hot waiting */ + for (dwx=0; dwx +#include +#include +#include + +#define BUF_SIZE 1024 +#define MAX_BASIC_INFO_SIZE 512 + + +extern +NTSTATUS +(STDCALL * QueryObject)( + IN HANDLE ObjectHandle, + IN CINT ObjectInformationClass, + OUT PVOID ObjectInformation, + IN ULONG Length, + OUT PULONG ResultLength + ); + +/* +static +VOID +DumpBuffer( + char *Name, + BYTE *buffer, + ULONG size + ) +{ + register ULONG i = 0; + + printf("%s [%d] = ",Name,size); + for ( i = 0; + i != size; + ++i + ) + { + printf("%02X",buffer[i]); + } + printf("\n"); +} +*/ + +VOID +DumpInfo ( + LPCSTR Name, + NTSTATUS Status, + LPCSTR Comment, + HANDLE Port + ) +{ + BYTE ObjectInformation [BUF_SIZE] = {0}; + ULONG ResultLength; + + printf("Port \"%s\" %s:\n",Name,Comment); + + printf("\tStatus = %08X\n",Status); + printf("\tPort = %08X\n\n",Port); + /* + * Query object information. + */ + printf("Basic Information:\n"); + Status = QueryObject( + Port, + ObjectBasicInformation, + ObjectInformation, + sizeof (LPC_PORT_BASIC_INFORMATION), + & ResultLength + ); + if (Status == STATUS_SUCCESS) + { + PLPC_PORT_BASIC_INFORMATION i; + + i = (PLPC_PORT_BASIC_INFORMATION) ObjectInformation; + + printf( "\tUnknown01 = 0x%08X\n", i->Unknown0 ); + printf( "\tUnknown02 = 0x%08X\n", i->Unknown1 ); + printf( "\tUnknown03 = 0x%08X\n", i->Unknown2 ); + printf( "\tUnknown04 = 0x%08X\n", i->Unknown3 ); + printf( "\tUnknown05 = 0x%08X\n", i->Unknown4 ); + printf( "\tUnknown06 = 0x%08X\n", i->Unknown5 ); + printf( "\tUnknown07 = 0x%08X\n", i->Unknown6 ); + printf( "\tUnknown08 = 0x%08X\n", i->Unknown7 ); + printf( "\tUnknown09 = 0x%08X\n", i->Unknown8 ); + printf( "\tUnknown10 = 0x%08X\n", i->Unknown9 ); + printf( "\tUnknown11 = 0x%08X\n", i->Unknown10 ); + printf( "\tUnknown12 = 0x%08X\n", i->Unknown11 ); + printf( "\tUnknown13 = 0x%08X\n", i->Unknown12 ); + printf( "\tUnknown14 = 0x%08X\n", i->Unknown13 ); + } + 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); + } +} + + +/* EOF */ diff --git a/reactos/apps/tests/lpc/dumpinfo.h b/reactos/apps/tests/lpc/dumpinfo.h new file mode 100644 index 00000000000..7a62ccc0a70 --- /dev/null +++ b/reactos/apps/tests/lpc/dumpinfo.h @@ -0,0 +1,8 @@ +VOID +DumpInfo ( + LPCSTR Name, + NTSTATUS Status, + LPCSTR Comment, + HANDLE Port + ); + diff --git a/reactos/apps/tests/lpc/makefile b/reactos/apps/tests/lpc/makefile index 26820bdffb3..ff510b50002 100644 --- a/reactos/apps/tests/lpc/makefile +++ b/reactos/apps/tests/lpc/makefile @@ -1,6 +1,21 @@ +# $Id: makefile,v 1.2 1999/07/04 22:04:31 ea Exp $ +# ReactOS Operating System +# LPC test CC=gcc -TARGET=conport +LD=ld CFLAGS=-I../../include -$(TARGET).exe: $(TARGET).c - $(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c + +all: conport.exe creport.exe + +conport.exe: conport.o dumpinfo.o + $(CC) -o conport conport.o dumpinfo.o + +creport.exe: creport.o dumpinfo.o. + $(CC) -o creport creport.o dumpinfo.o + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + + +#EOF