:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / 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 <ntdll/dbg.h>
17 #include <napi/lpc.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 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 NTSTATUS STDCALL
66 DbgSsHandleKmApiMsg(ULONG Unknown1,
67                     HANDLE EventHandle)
68 {
69   return STATUS_NOT_IMPLEMENTED;
70 }
71
72
73 NTSTATUS STDCALL
74 DbgSsInitialize(HANDLE ReplyPort,
75                 ULONG Unknown1,
76                 ULONG Unknown2,
77                 ULONG Unknown3)
78 {
79         SECURITY_QUALITY_OF_SERVICE Qos;
80         UNICODE_STRING PortName = UNICODE_STRING_INITIALIZER(L"\\DbgSsApiPort");
81         NTSTATUS Status;
82
83         Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
84         Qos.ImpersonationLevel = SecurityIdentification;
85         Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
86         Qos.EffectiveOnly = TRUE;
87
88         Status = NtConnectPort (&DbgSsApiPort,
89                                 &PortName,
90                                 &Qos,
91                                 NULL,
92                                 NULL,
93                                 NULL,
94                                 NULL,
95                                 NULL);
96         if (!NT_SUCCESS(Status))
97                 return Status;
98
99         DbgSsReplyPort = ReplyPort;
100 //      UnknownData1 = Unknown1;
101 //      UnknownData2 = Unknown2;
102 //      UnknownData3 = Unknown3;
103
104         Status = RtlCreateUserThread (NtCurrentProcess (),
105                                       NULL,
106                                       FALSE,
107                                       0,
108                                       NULL,
109                                       NULL,
110                                       (PTHREAD_START_ROUTINE)DbgSsServerThread,
111                                       NULL,
112                                       NULL,
113                                       NULL);
114
115         return Status;
116 }
117
118
119 NTSTATUS STDCALL
120 DbgUiConnectToDbg(VOID)
121 {
122         SECURITY_QUALITY_OF_SERVICE Qos;
123         UNICODE_STRING PortName = UNICODE_STRING_INITIALIZER(L"\\DbgUiApiPort");
124         NTSTATUS Status;
125         PTEB Teb;
126         ULONG InfoSize;
127
128         Teb = NtCurrentTeb ();
129
130         Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
131         Qos.ImpersonationLevel = SecurityIdentification;
132         Qos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
133         Qos.EffectiveOnly = TRUE;
134
135         InfoSize = sizeof(ULONG);
136
137         Status = NtConnectPort (&Teb->DbgSsReserved[1],
138                                 &PortName,
139                                 &Qos,
140                                 NULL,
141                                 NULL,
142                                 NULL,
143                                 &Teb->DbgSsReserved[0],
144                                 &InfoSize);
145         if (!NT_SUCCESS(Status))
146         {
147                 Teb->DbgSsReserved[1] = NULL;
148                 return Status;
149         }
150
151         NtRegisterThreadTerminatePort(Teb->DbgSsReserved[1]);
152
153         return Status;
154 }
155
156
157 NTSTATUS STDCALL
158 DbgUiContinue(PCLIENT_ID ClientId,
159               ULONG ContinueStatus)
160 {
161   return STATUS_NOT_IMPLEMENTED;
162 }
163
164
165 NTSTATUS STDCALL
166 DbgUiWaitStateChange(ULONG Unknown1,
167                      ULONG Unknown2)
168 {
169   return STATUS_NOT_IMPLEMENTED;
170 }
171
172 /* EOF */