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