LPC: initial work on NT/ROS compatibility.
[reactos.git] / reactos / ntoskrnl / lpc / create.c
1 /* $Id: create.c,v 1.16 2004/02/02 23:48:42 ea Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/lpc/create.c
6 * PURPOSE: Communication mechanism
7 * PROGRAMMER: David Welch (welch@cwcom.net)
8 * UPDATE HISTORY:
9 * Created 22/05/98
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #define NTOS_MODE_KERNEL
15 #include <ntos.h>
16 #include <internal/port.h>
17 #include <internal/dbg.h>
18
19 #define NDEBUG
20 #include <internal/debug.h>
21
22 /**********************************************************************
23 * NAME
24 * LpcpVerifyCreateParameters/5
25 *
26 * DESCRIPTION
27 * Verify user parameters in NtCreatePort and in
28 * NtCreateWaitablePort.
29 *
30 * ARGUMENTS
31 *
32 * RETURN VALUE
33 */
34 STATIC NTSTATUS STDCALL
35 LpcpVerifyCreateParameters (IN PHANDLE PortHandle,
36 IN POBJECT_ATTRIBUTES ObjectAttributes,
37 IN ULONG MaxConnectInfoLength,
38 IN ULONG MaxDataLength,
39 IN ULONG Reserved)
40 {
41 if (NULL == PortHandle)
42 {
43 return (STATUS_INVALID_PARAMETER_1);
44 }
45 if (NULL == ObjectAttributes)
46 {
47 return (STATUS_INVALID_PARAMETER_2);
48 }
49 if ((ObjectAttributes->Attributes & OBJ_OPENLINK)
50 || (ObjectAttributes->Attributes & OBJ_OPENIF)
51 || (ObjectAttributes->Attributes & OBJ_EXCLUSIVE)
52 || (ObjectAttributes->Attributes & OBJ_PERMANENT)
53 || (ObjectAttributes->Attributes & OBJ_INHERIT))
54 {
55 return (STATUS_INVALID_PORT_ATTRIBUTES);
56 }
57 if (MaxConnectInfoLength > PORT_MAX_DATA_LENGTH)
58 {
59 return (STATUS_INVALID_PARAMETER_3);
60 }
61 if (MaxDataLength > PORT_MAX_MESSAGE_LENGTH)
62 {
63 return (STATUS_INVALID_PARAMETER_4);
64 }
65 /* FIXME: some checking is done also on Reserved, but
66 * not in public (free/checked) versions. */
67 return (STATUS_SUCCESS);
68 }
69
70
71 /**********************************************************************
72 * NAME
73 * NiCreatePort/4
74 *
75 * DESCRIPTION
76 *
77 * ARGUMENTS
78 *
79 * RETURN VALUE
80 */
81 NTSTATUS STDCALL
82 NiCreatePort (PVOID ObjectBody,
83 PVOID Parent,
84 PWSTR RemainingPath,
85 POBJECT_ATTRIBUTES ObjectAttributes)
86 {
87 if (RemainingPath == NULL)
88 {
89 return (STATUS_SUCCESS);
90 }
91
92 if (wcschr(RemainingPath+1, '\\') != NULL)
93 {
94 return (STATUS_UNSUCCESSFUL);
95 }
96
97 return (STATUS_SUCCESS);
98 }
99
100
101 /**********************************************************************
102 * NAME EXPORTED
103 * NtCreatePort/5
104 *
105 * DESCRIPTION
106 *
107 * ARGUMENTS
108 * PortHandle,
109 * ObjectAttributes,
110 * MaxConnectInfoLength,
111 * MaxDataLength,
112 * Reserved
113 *
114 * RETURN VALUE
115 */
116 /*EXPORTED*/ NTSTATUS STDCALL
117 NtCreatePort (PHANDLE PortHandle,
118 POBJECT_ATTRIBUTES ObjectAttributes,
119 ULONG MaxConnectInfoLength,
120 ULONG MaxDataLength,
121 ULONG Reserved)
122 {
123 PEPORT Port;
124 NTSTATUS Status;
125
126 DPRINT("NtCreatePort() Name %x\n", ObjectAttributes->ObjectName->Buffer);
127
128 /* Verify parameters */
129 Status = LpcpVerifyCreateParameters (PortHandle,
130 ObjectAttributes,
131 MaxConnectInfoLength,
132 MaxDataLength,
133 Reserved);
134 if (STATUS_SUCCESS != Status)
135 {
136 return (Status);
137 }
138
139 /* Ask Ob to create the object */
140 Status = ObCreateObject (ExGetPreviousMode(),
141 ExPortType,
142 ObjectAttributes,
143 ExGetPreviousMode(),
144 NULL,
145 sizeof(EPORT),
146 0,
147 0,
148 (PVOID*)&Port);
149 if (!NT_SUCCESS(Status))
150 {
151 return (Status);
152 }
153
154 Status = ObInsertObject ((PVOID)Port,
155 NULL,
156 PORT_ALL_ACCESS,
157 0,
158 NULL,
159 PortHandle);
160 if (!NT_SUCCESS(Status))
161 {
162 ObDereferenceObject (Port);
163 return (Status);
164 }
165
166 Status = NiInitializePort (Port, EPORT_TYPE_SERVER_RQST_PORT, NULL);
167 Port->MaxConnectInfoLength = PORT_MAX_DATA_LENGTH;
168 Port->MaxDataLength = PORT_MAX_MESSAGE_LENGTH;
169
170 ObDereferenceObject (Port);
171
172 return (Status);
173 }
174
175 /**********************************************************************
176 * NAME EXPORTED
177 * NtCreateWaitablePort/5
178 *
179 * DESCRIPTION
180 * Waitable ports can be connected to with NtSecureConnectPort.
181 * No port interface can be used with waitable ports but
182 * NtReplyWaitReceivePort and NtReplyWaitReceivePortEx.
183 * Present only in w2k+.
184 *
185 * ARGUMENTS
186 * PortHandle,
187 * ObjectAttributes,
188 * MaxConnectInfoLength,
189 * MaxDataLength,
190 * Reserved
191 *
192 * RETURN VALUE
193 */
194 /*EXPORTED*/ NTSTATUS STDCALL
195 NtCreateWaitablePort (OUT PHANDLE PortHandle,
196 IN POBJECT_ATTRIBUTES ObjectAttributes,
197 IN ULONG MaxConnectInfoLength,
198 IN ULONG MaxDataLength,
199 IN ULONG Reserved)
200 {
201 NTSTATUS Status;
202
203 /* Verify parameters */
204 Status = LpcpVerifyCreateParameters (PortHandle,
205 ObjectAttributes,
206 MaxConnectInfoLength,
207 MaxDataLength,
208 Reserved);
209 if (STATUS_SUCCESS != Status)
210 {
211 return (Status);
212 }
213 /* TODO */
214 return (STATUS_NOT_IMPLEMENTED);
215 }
216
217 /* EOF */