Partial patch of larger rosrtl removal patch. This one merely is a structure fix...
[reactos.git] / reactos / lib / ntdll / dbg / debug.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: lib/ntdll/dbg/debug.c
6 * PURPOSE: User mode debugger support functions
7 * PROGRAMMER: Eric Kohl
8 * UPDATE HISTORY:
9 * 14/04/2000 Created
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ntdll.h>
15 #define NDEBUG
16 #include <debug.h>
17
18 /* FUNCTIONS *****************************************************************/
19
20 static HANDLE DbgSsApiPort = NULL;
21 static HANDLE DbgSsReplyPort = NULL;
22
23
24 typedef struct _LPC_DBGSS_MESSAGE
25 {
26 LPC_MESSAGE Header;
27 ULONG Unknown1;
28 ULONG Unknown2;
29 ULONG Unknown3;
30 ULONG Unknown4;
31 } LPC_DBGSS_MESSAGE, *PLPC_DBGSS_MESSAGE;
32
33
34 /* FUNCTIONS *****************************************************************/
35
36 VOID STDCALL
37 DbgSsServerThread(PVOID Unused)
38 {
39 LPC_DBGSS_MESSAGE Message;
40 NTSTATUS Status;
41
42 for (;;)
43 {
44 Status = NtReplyWaitReceivePort (DbgSsApiPort,
45 NULL,
46 NULL,
47 (PLPC_MESSAGE)&Message);
48 if (!NT_SUCCESS(Status))
49 {
50 DbgPrint ("DbgSs: NtReplyWaitReceivePort failed - Status == %lx\n",
51 Status);
52
53 DbgBreakPoint ();
54 }
55 else
56 {
57 /* FIXME: missing code!! */
58
59 }
60 }
61 }
62
63
64 /*
65 * @unimplemented
66 */
67 NTSTATUS STDCALL
68 DbgSsHandleKmApiMsg(ULONG Unknown1,
69 HANDLE EventHandle)
70 {
71 return STATUS_NOT_IMPLEMENTED;
72 }
73
74
75 /*
76 * @implemented
77 */
78 NTSTATUS STDCALL
79 DbgSsInitialize(HANDLE ReplyPort,
80 ULONG Unknown1,
81 ULONG Unknown2,
82 ULONG Unknown3)
83 {
84 SECURITY_QUALITY_OF_SERVICE Qos;
85 UNICODE_STRING PortName = RTL_CONSTANT_STRING(L"\\DbgSsApiPort");
86 NTSTATUS Status;
87
88 Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
89 Qos.ImpersonationLevel = SecurityIdentification;
90 Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
91 Qos.EffectiveOnly = TRUE;
92
93 Status = NtConnectPort (&DbgSsApiPort,
94 &PortName,
95 &Qos,
96 NULL,
97 NULL,
98 NULL,
99 NULL,
100 NULL);
101 if (!NT_SUCCESS(Status))
102 return Status;
103
104 DbgSsReplyPort = ReplyPort;
105 // UnknownData1 = Unknown1;
106 // UnknownData2 = Unknown2;
107 // UnknownData3 = Unknown3;
108
109 Status = RtlCreateUserThread (NtCurrentProcess (),
110 NULL,
111 FALSE,
112 0,
113 0,
114 0,
115 (PTHREAD_START_ROUTINE)DbgSsServerThread,
116 NULL,
117 NULL,
118 NULL);
119
120 return Status;
121 }
122
123
124 /*
125 * @implemented
126 */
127 NTSTATUS STDCALL
128 DbgUiConnectToDbg(VOID)
129 {
130 SECURITY_QUALITY_OF_SERVICE Qos;
131 UNICODE_STRING PortName = RTL_CONSTANT_STRING(L"\\DbgUiApiPort");
132 NTSTATUS Status;
133 PTEB Teb;
134 ULONG InfoSize;
135
136 Teb = NtCurrentTeb ();
137
138 Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
139 Qos.ImpersonationLevel = SecurityIdentification;
140 Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
141 Qos.EffectiveOnly = TRUE;
142
143 InfoSize = sizeof(ULONG);
144
145 Status = NtConnectPort (&Teb->DbgSsReserved[1],
146 &PortName,
147 &Qos,
148 NULL,
149 NULL,
150 NULL,
151 &Teb->DbgSsReserved[0],
152 &InfoSize);
153 if (!NT_SUCCESS(Status))
154 {
155 Teb->DbgSsReserved[1] = NULL;
156 return Status;
157 }
158
159 NtRegisterThreadTerminatePort(Teb->DbgSsReserved[1]);
160
161 return Status;
162 }
163
164
165 /*
166 * @unimplemented
167 */
168 NTSTATUS STDCALL
169 DbgUiContinue(PCLIENT_ID ClientId,
170 ULONG ContinueStatus)
171 {
172 return STATUS_NOT_IMPLEMENTED;
173 }
174
175
176 /*
177 * @unimplemented
178 */
179 NTSTATUS STDCALL
180 DbgUiWaitStateChange(ULONG Unknown1,
181 ULONG Unknown2)
182 {
183 return STATUS_NOT_IMPLEMENTED;
184 }
185
186 VOID STDCALL DbgUiRemoteBreakin(VOID)
187 {
188 DbgBreakPoint();
189
190 RtlExitUserThread(STATUS_SUCCESS);
191 }
192
193 NTSTATUS STDCALL DbgUiIssueRemoteBreakin(HANDLE Process)
194 {
195 HANDLE hThread;
196 CLIENT_ID cidClientId;
197 NTSTATUS nErrCode;
198 ULONG nStackSize = PAGE_SIZE;
199
200 nErrCode = RtlCreateUserThread
201 (
202 Process,
203 NULL,
204 FALSE,
205 0,
206 nStackSize,
207 nStackSize,
208 (PTHREAD_START_ROUTINE)DbgUiRemoteBreakin,
209 NULL,
210 &hThread,
211 &cidClientId
212 );
213
214 if(!NT_SUCCESS(nErrCode)) return nErrCode;
215
216 NtClose(hThread);
217
218 return STATUS_SUCCESS;
219 }
220
221 /* EOF */