merge ROS Shell without integrated explorer part into trunk
[reactos.git] / reactos / ntoskrnl / lpc / port.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/lpc/port.c
6 * PURPOSE: Communication mechanism
7 *
8 * PROGRAMMERS: David Welch (welch@cwcom.net)
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ntoskrnl.h>
14 #define NDEBUG
15 #include <internal/debug.h>
16
17
18 /* GLOBALS *******************************************************************/
19
20 POBJECT_TYPE LpcPortObjectType = 0;
21 ULONG LpcpNextMessageId = 0; /* 0 is not a valid ID */
22 FAST_MUTEX LpcpLock; /* global internal sync in LPC facility */
23
24 static GENERIC_MAPPING ExpPortMapping = {
25 STANDARD_RIGHTS_READ,
26 STANDARD_RIGHTS_WRITE,
27 0,
28 PORT_ALL_ACCESS};
29
30 /* FUNCTIONS *****************************************************************/
31
32
33 NTSTATUS INIT_FUNCTION
34 LpcpInitSystem (VOID)
35 {
36 /* Allocate Memory for the LPC Object */
37 LpcPortObjectType = ExAllocatePool(NonPagedPool, sizeof(OBJECT_TYPE));
38 RtlZeroMemory (LpcPortObjectType, sizeof (OBJECT_TYPE));
39
40 RtlInitUnicodeString(&LpcPortObjectType->TypeName,L"Port");
41
42 LpcPortObjectType->Tag = TAG('L', 'P', 'R', 'T');
43 LpcPortObjectType->PeakObjects = 0;
44 LpcPortObjectType->PeakHandles = 0;
45 LpcPortObjectType->TotalObjects = 0;
46 LpcPortObjectType->TotalHandles = 0;
47 LpcPortObjectType->PagedPoolCharge = 0;
48 LpcPortObjectType->NonpagedPoolCharge = sizeof(EPORT);
49 LpcPortObjectType->Mapping = &ExpPortMapping;
50 LpcPortObjectType->Dump = NULL;
51 LpcPortObjectType->Open = NULL;
52 LpcPortObjectType->Close = NiClosePort;
53 LpcPortObjectType->Delete = NiDeletePort;
54 LpcPortObjectType->Parse = NULL;
55 LpcPortObjectType->Security = NULL;
56 LpcPortObjectType->QueryName = NULL;
57 LpcPortObjectType->OkayToClose = NULL;
58 LpcPortObjectType->Create = NiCreatePort;
59 LpcPortObjectType->DuplicationNotify = NULL;
60
61 ObpCreateTypeObject(LpcPortObjectType);
62
63 LpcpNextMessageId = 0;
64
65 ExInitializeFastMutex (& LpcpLock);
66
67 return(STATUS_SUCCESS);
68 }
69
70
71 /**********************************************************************
72 * NAME INTERNAL
73 * NiInitializePort/3
74 *
75 * DESCRIPTION
76 * Initialize the EPORT object attributes. The Port
77 * object enters the inactive state.
78 *
79 * ARGUMENTS
80 * Port Pointer to an EPORT object to initialize.
81 * Type connect (RQST), or communication port (COMM)
82 * Parent OPTIONAL connect port a communication port
83 * is created from
84 *
85 * RETURN VALUE
86 * STATUS_SUCCESS if initialization succedeed. An error code
87 * otherwise.
88 */
89 NTSTATUS STDCALL
90 LpcpInitializePort (IN OUT PEPORT Port,
91 IN USHORT Type,
92 IN PEPORT Parent OPTIONAL)
93 {
94 if ((Type != EPORT_TYPE_SERVER_RQST_PORT) &&
95 (Type != EPORT_TYPE_SERVER_COMM_PORT) &&
96 (Type != EPORT_TYPE_CLIENT_COMM_PORT))
97 {
98 return STATUS_INVALID_PARAMETER_2;
99 }
100 memset (Port, 0, sizeof(EPORT));
101 KeInitializeSpinLock (& Port->Lock);
102 KeInitializeSemaphore( &Port->Semaphore, 0, LONG_MAX );
103 Port->RequestPort = Parent;
104 Port->OtherPort = NULL;
105 Port->QueueLength = 0;
106 Port->ConnectQueueLength = 0;
107 Port->Type = Type;
108 Port->State = EPORT_INACTIVE;
109 InitializeListHead (& Port->QueueListHead);
110 InitializeListHead (& Port->ConnectQueueListHead);
111
112 return (STATUS_SUCCESS);
113 }
114
115
116 /* MISCELLANEA SYSTEM SERVICES */
117
118
119 /**********************************************************************
120 * NAME SYSTEM
121 * NtImpersonateClientOfPort/2
122 *
123 * DESCRIPTION
124 *
125 * ARGUMENTS
126 * PortHandle,
127 * ClientMessage
128 *
129 * RETURN VALUE
130 */
131 NTSTATUS STDCALL
132 NtImpersonateClientOfPort (HANDLE PortHandle,
133 PLPC_MESSAGE ClientMessage)
134 {
135 UNIMPLEMENTED;
136 return(STATUS_NOT_IMPLEMENTED);
137 }
138
139 /* EOF */