- Support INIT section pragmas for msvc. Patch by Brezenbak.
[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 #if defined (ALLOC_PRAGMA)
18 #pragma alloc_text(INIT, LpcpInitSystem)
19 #endif
20
21
22 /* GLOBALS *******************************************************************/
23
24 POBJECT_TYPE LpcPortObjectType = 0;
25 ULONG LpcpNextMessageId = 0; /* 0 is not a valid ID */
26 FAST_MUTEX LpcpLock; /* global internal sync in LPC facility */
27
28 static GENERIC_MAPPING LpcpPortMapping =
29 {
30 STANDARD_RIGHTS_READ,
31 STANDARD_RIGHTS_WRITE,
32 0,
33 PORT_ALL_ACCESS
34 };
35
36 /* FUNCTIONS *****************************************************************/
37
38
39 NTSTATUS
40 INIT_FUNCTION
41 NTAPI
42 LpcpInitSystem (VOID)
43 {
44 OBJECT_TYPE_INITIALIZER ObjectTypeInitializer;
45 UNICODE_STRING Name;
46
47 DPRINT("Creating Port Object Type\n");
48
49 /* Create the Port Object Type */
50 RtlZeroMemory(&ObjectTypeInitializer, sizeof(ObjectTypeInitializer));
51 RtlInitUnicodeString(&Name, L"Port");
52 ObjectTypeInitializer.Length = sizeof(ObjectTypeInitializer);
53 ObjectTypeInitializer.DefaultNonPagedPoolCharge = sizeof(EPORT);
54 ObjectTypeInitializer.GenericMapping = LpcpPortMapping;
55 ObjectTypeInitializer.PoolType = NonPagedPool;
56 ObjectTypeInitializer.UseDefaultObject = TRUE;
57 ObjectTypeInitializer.CloseProcedure = LpcpClosePort;
58 ObjectTypeInitializer.DeleteProcedure = LpcpDeletePort;
59 ObpCreateTypeObject(&ObjectTypeInitializer, &Name, &LpcPortObjectType);
60
61 LpcpNextMessageId = 0;
62 ExInitializeFastMutex (& LpcpLock);
63
64 return(STATUS_SUCCESS);
65 }
66
67
68 /**********************************************************************
69 * NAME INTERNAL
70 * NiInitializePort/3
71 *
72 * DESCRIPTION
73 * Initialize the EPORT object attributes. The Port
74 * object enters the inactive state.
75 *
76 * ARGUMENTS
77 * Port Pointer to an EPORT object to initialize.
78 * Type connect (RQST), or communication port (COMM)
79 * Parent OPTIONAL connect port a communication port
80 * is created from
81 *
82 * RETURN VALUE
83 * STATUS_SUCCESS if initialization succedeed. An error code
84 * otherwise.
85 */
86 NTSTATUS STDCALL
87 LpcpInitializePort (IN OUT PEPORT Port,
88 IN USHORT Type,
89 IN PEPORT Parent OPTIONAL)
90 {
91 if ((Type != EPORT_TYPE_SERVER_RQST_PORT) &&
92 (Type != EPORT_TYPE_SERVER_COMM_PORT) &&
93 (Type != EPORT_TYPE_CLIENT_COMM_PORT))
94 {
95 return STATUS_INVALID_PARAMETER_2;
96 }
97 memset (Port, 0, sizeof(EPORT));
98 KeInitializeSpinLock (& Port->Lock);
99 KeInitializeSemaphore( &Port->Semaphore, 0, MAXLONG );
100 Port->RequestPort = Parent;
101 Port->OtherPort = NULL;
102 Port->QueueLength = 0;
103 Port->ConnectQueueLength = 0;
104 Port->Type = Type;
105 Port->State = EPORT_INACTIVE;
106 InitializeListHead (& Port->QueueListHead);
107 InitializeListHead (& Port->ConnectQueueListHead);
108
109 return (STATUS_SUCCESS);
110 }
111
112
113 /* MISCELLANEA SYSTEM SERVICES */
114
115
116 /**********************************************************************
117 * NAME SYSTEM
118 * NtImpersonateClientOfPort/2
119 *
120 * DESCRIPTION
121 *
122 * ARGUMENTS
123 * PortHandle,
124 * ClientMessage
125 *
126 * RETURN VALUE
127 */
128 NTSTATUS STDCALL
129 NtImpersonateClientOfPort (HANDLE PortHandle,
130 PPORT_MESSAGE ClientMessage)
131 {
132 UNIMPLEMENTED;
133 return(STATUS_NOT_IMPLEMENTED);
134 }
135
136 /* EOF */