- Make the NDK compatible with the MSDDK again.
[reactos.git] / reactos / ntoskrnl / lpc / create.c
1 /* $Id$
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 *
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 * NAME
19 * LpcpVerifyCreateParameters/5
20 *
21 * DESCRIPTION
22 * Verify user parameters in NtCreatePort and in
23 * NtCreateWaitablePort.
24 *
25 * ARGUMENTS
26 *
27 * RETURN VALUE
28 */
29 STATIC NTSTATUS STDCALL
30 LpcpVerifyCreateParameters (IN PHANDLE PortHandle,
31 IN POBJECT_ATTRIBUTES ObjectAttributes,
32 IN ULONG MaxConnectInfoLength,
33 IN ULONG MaxDataLength,
34 IN ULONG MaxPoolUsage)
35 {
36 if (NULL == PortHandle)
37 {
38 return (STATUS_INVALID_PARAMETER_1);
39 }
40 if (NULL == ObjectAttributes)
41 {
42 return (STATUS_INVALID_PARAMETER_2);
43 }
44 if ((ObjectAttributes->Attributes & OBJ_OPENLINK)
45 || (ObjectAttributes->Attributes & OBJ_OPENIF)
46 || (ObjectAttributes->Attributes & OBJ_EXCLUSIVE)
47 || (ObjectAttributes->Attributes & OBJ_PERMANENT)
48 || (ObjectAttributes->Attributes & OBJ_INHERIT))
49 {
50 return (STATUS_INVALID_PORT_ATTRIBUTES);
51 }
52 if (MaxConnectInfoLength > LPC_MAX_DATA_LENGTH)
53 {
54 return (STATUS_INVALID_PARAMETER_3);
55 }
56 if (MaxDataLength > LPC_MAX_MESSAGE_LENGTH)
57 {
58 return (STATUS_INVALID_PARAMETER_4);
59 }
60 /* TODO: some checking is done also on MaxPoolUsage
61 * to avoid choking the executive */
62 return (STATUS_SUCCESS);
63 }
64
65 /**********************************************************************
66 * NAME EXPORTED
67 * NtCreatePort/5
68 *
69 * DESCRIPTION
70 *
71 * ARGUMENTS
72 * PortHandle,
73 * ObjectAttributes,
74 * MaxConnectInfoLength,
75 * MaxDataLength,
76 * MaxPoolUsage: size of NP zone the NP part of msgs is kept in
77 *
78 * RETURN VALUE
79 */
80 /*EXPORTED*/ NTSTATUS STDCALL
81 NtCreatePort (PHANDLE PortHandle,
82 POBJECT_ATTRIBUTES ObjectAttributes,
83 ULONG MaxConnectInfoLength,
84 ULONG MaxDataLength,
85 ULONG MaxPoolUsage)
86 {
87 PEPORT Port;
88 NTSTATUS Status;
89
90 DPRINT("NtCreatePort() Name %x\n", ObjectAttributes->ObjectName->Buffer);
91
92 /* Verify parameters */
93 Status = LpcpVerifyCreateParameters (PortHandle,
94 ObjectAttributes,
95 MaxConnectInfoLength,
96 MaxDataLength,
97 MaxPoolUsage);
98 if (STATUS_SUCCESS != Status)
99 {
100 return (Status);
101 }
102
103 /* Ask Ob to create the object */
104 Status = ObCreateObject (ExGetPreviousMode(),
105 LpcPortObjectType,
106 ObjectAttributes,
107 ExGetPreviousMode(),
108 NULL,
109 sizeof(EPORT),
110 0,
111 0,
112 (PVOID*)&Port);
113 if (!NT_SUCCESS(Status))
114 {
115 return (Status);
116 }
117
118 Status = ObInsertObject ((PVOID)Port,
119 NULL,
120 PORT_ALL_ACCESS,
121 0,
122 NULL,
123 PortHandle);
124 if (!NT_SUCCESS(Status))
125 {
126 ObDereferenceObject (Port);
127 return (Status);
128 }
129
130 Status = LpcpInitializePort (Port, EPORT_TYPE_SERVER_RQST_PORT, NULL);
131 Port->MaxConnectInfoLength = LPC_MAX_DATA_LENGTH;
132 Port->MaxDataLength = LPC_MAX_MESSAGE_LENGTH;
133 Port->MaxPoolUsage = MaxPoolUsage;
134
135 ObDereferenceObject (Port);
136
137 return (Status);
138 }
139
140 /**********************************************************************
141 * NAME EXPORTED
142 * NtCreateWaitablePort/5
143 *
144 * DESCRIPTION
145 * Waitable ports can be connected to with NtSecureConnectPort.
146 * No port interface can be used with waitable ports but
147 * NtReplyWaitReceivePort and NtReplyWaitReceivePortEx.
148 * Present only in w2k+.
149 *
150 * ARGUMENTS
151 * PortHandle,
152 * ObjectAttributes,
153 * MaxConnectInfoLength,
154 * MaxDataLength,
155 * MaxPoolUsage
156 *
157 * RETURN VALUE
158 */
159 /*EXPORTED*/ NTSTATUS STDCALL
160 NtCreateWaitablePort (OUT PHANDLE PortHandle,
161 IN POBJECT_ATTRIBUTES ObjectAttributes,
162 IN ULONG MaxConnectInfoLength,
163 IN ULONG MaxDataLength,
164 IN ULONG MaxPoolUsage)
165 {
166 NTSTATUS Status;
167
168 /* Verify parameters */
169 Status = LpcpVerifyCreateParameters (PortHandle,
170 ObjectAttributes,
171 MaxConnectInfoLength,
172 MaxDataLength,
173 MaxPoolUsage);
174 if (STATUS_SUCCESS != Status)
175 {
176 return (Status);
177 }
178 /* TODO */
179 return (STATUS_NOT_IMPLEMENTED);
180 }
181
182 /* EOF */