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