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