62619f3d730d6775a9e1e848728b5ee8f89ff2e2
[reactos.git] / reactos / subsys / smss / debug.c
1 /* $Id$
2 *
3 * debug.c - Session Manager debug messages switch and router
4 *
5 * ReactOS Operating System
6 *
7 * --------------------------------------------------------------------
8 *
9 * This software is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This software is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this software; see the file COPYING.LIB. If not, write
21 * to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
22 * MA 02139, USA.
23 *
24 * --------------------------------------------------------------------
25 */
26 #include "smss.h"
27
28 #define NDEBUG
29 #include <debug.h>
30
31
32 /* GLOBALS ***********************************************************/
33
34 HANDLE DbgSsApiPort = (HANDLE) 0;
35 HANDLE DbgUiApiPort = (HANDLE) 0;
36
37 /* FUNCTIONS *********************************************************/
38
39 static VOID STDCALL
40 DbgSsApiPortThread (PVOID dummy)
41 {
42 NTSTATUS Status = STATUS_SUCCESS;
43 PORT_MESSAGE Request ;
44
45 RtlZeroMemory(&Request, sizeof(PORT_MESSAGE));
46 while (TRUE)
47 {
48 Status = NtListenPort (DbgSsApiPort, & Request);
49 if (!NT_SUCCESS(Status))
50 {
51 DPRINT1("SM: %s: NtListenPort() failed! (Status==x%08lx)\n", __FUNCTION__, Status);
52 break;
53 }
54 /* TODO */
55 }
56 NtTerminateThread(NtCurrentThread(),Status);
57 }
58
59 static VOID STDCALL
60 DbgUiApiPortThread (PVOID dummy)
61 {
62 NTSTATUS Status = STATUS_SUCCESS;
63 PORT_MESSAGE Request;
64
65 RtlZeroMemory(&Request, sizeof(PORT_MESSAGE));
66 while (TRUE)
67 {
68 Status = NtListenPort (DbgUiApiPort, & Request);
69 if (!NT_SUCCESS(Status))
70 {
71 DPRINT1("SM: %s: NtListenPort() failed! (Status==x%08lx)\n", __FUNCTION__, Status);
72 break;
73 }
74 /* TODO */
75 }
76 NtTerminateThread(NtCurrentThread(),Status);
77 }
78
79 static NTSTATUS STDCALL
80 SmpCreatePT (IN OUT PHANDLE hPort,
81 IN LPWSTR wcPortName,
82 IN ULONG ulMaxDataSize,
83 IN ULONG ulMaxMessageSize,
84 IN ULONG ulPoolCharge OPTIONAL,
85 IN VOID (STDCALL * procServingThread)(PVOID) OPTIONAL,
86 IN OUT PHANDLE phServingThread OPTIONAL)
87 {
88 NTSTATUS Status = STATUS_SUCCESS;
89 UNICODE_STRING PortName = {0};
90 OBJECT_ATTRIBUTES ObjectAttributes;
91 HANDLE Thread = (HANDLE) 0;
92 CLIENT_ID Cid = {0, 0};
93
94 RtlInitUnicodeString (& PortName, wcPortName);
95 InitializeObjectAttributes (& ObjectAttributes,
96 & PortName,
97 0,
98 NULL,
99 NULL);
100 Status = NtCreatePort (hPort,
101 & ObjectAttributes,
102 ulMaxDataSize,
103 ulMaxMessageSize,
104 ulPoolCharge);
105 if(STATUS_SUCCESS != Status)
106 {
107 return Status;
108 }
109 /* Create thread for DbgSsApiPort */
110 RtlCreateUserThread(NtCurrentProcess(),
111 NULL,
112 FALSE,
113 0,
114 0,
115 0,
116 (PTHREAD_START_ROUTINE) procServingThread,
117 hPort,
118 & Thread,
119 & Cid);
120 if((HANDLE) 0 == Thread)
121 {
122 NtClose(*hPort);
123 Status = STATUS_UNSUCCESSFUL;
124 }
125 if(NULL != phServingThread)
126 {
127 *phServingThread = Thread;
128 }
129 return Status;
130 }
131
132 NTSTATUS
133 SmInitializeDbgSs (VOID)
134 {
135 NTSTATUS Status = STATUS_SUCCESS;
136 HANDLE hDbgSsApiPortThread = (HANDLE) 0;
137
138 DPRINT("SM: %s called\n", __FUNCTION__);
139
140 /* Create the \DbgSsApiPort object (LPC) */
141 Status = SmpCreatePT(& DbgSsApiPort,
142 SM_DBGSS_PORT_NAME,
143 0, /* MaxDataSize */
144 0, /* MaxMessageSize */
145 0, /* PoolCharge */
146 DbgSsApiPortThread,
147 & hDbgSsApiPortThread);
148 if(!NT_SUCCESS(Status))
149 {
150 DPRINT("SM: %s: DBGSS port not created\n",__FUNCTION__);
151 return Status;
152 }
153 /* Create the \DbgUiApiPort object (LPC) */
154 Status = SmpCreatePT(& DbgUiApiPort,
155 SM_DBGUI_PORT_NAME,
156 0, /* MaxDataSize */
157 0, /* MaxMessageSize */
158 0, /* PoolCharge */
159 DbgUiApiPortThread,
160 NULL);
161 if(!NT_SUCCESS(Status))
162 {
163 DPRINT("SM: %s: DBGUI port not created\n",__FUNCTION__);
164 NtClose (hDbgSsApiPortThread);
165 NtClose (DbgSsApiPort);
166 return Status;
167 }
168 return STATUS_SUCCESS;
169 }
170
171 /* EOF */
172