ReactOS  0.4.15-dev-4574-g434cf85
data.c File Reference
#include "sacdrv.h"
Include dependency graph for data.c:

Go to the source code of this file.

Functions

VOID NTAPI WorkerProcessEvents (IN PSAC_DEVICE_EXTENSION DeviceExtension)
 
VOID NTAPI WorkerThreadStartUp (IN PVOID Context)
 
NTSTATUS NTAPI BuildDeviceAcl (OUT PACL *Dacl)
 
NTSTATUS NTAPI CreateDeviceSecurityDescriptor (IN PDEVICE_OBJECT *DeviceObject)
 
VOID NTAPI FreeGlobalData (VOID)
 
VOID NTAPI FreeDeviceData (IN PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI InitializeDeviceData (IN PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI InitializeGlobalData (IN PUNICODE_STRING RegistryPath, IN PDRIVER_OBJECT DriverObject)
 

Variables

ULONG SACDebug = 0
 
BOOLEAN CommandConsoleLaunchingEnabled
 
BOOLEAN GlobalDataInitialized
 
KMUTEX SACCMDEventInfoMutex
 
BOOLEAN IoctlSubmitted
 
ULONG ProcessingType
 
PKEVENT SACEvent
 
HANDLE SACEventHandle
 

Function Documentation

◆ BuildDeviceAcl()

NTSTATUS NTAPI BuildDeviceAcl ( OUT PACL Dacl)

Definition at line 44 of file data.c.

45 {
46  /* TODO */
48 }
return STATUS_NOT_IMPLEMENTED

Referenced by CreateDeviceSecurityDescriptor().

◆ CreateDeviceSecurityDescriptor()

NTSTATUS NTAPI CreateDeviceSecurityDescriptor ( IN PDEVICE_OBJECT DeviceObject)

Definition at line 52 of file data.c.

53 {
57  PACL Dacl = NULL;
58  PVOID ObjectSecurityDescriptor = NULL;
59  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC CreateDeviceSecurityDescriptor: Entering.\n");
60 
61  /* Get the current SD of the device object */
63  if (!NT_SUCCESS(Status))
64  {
65  SAC_DBG(SAC_DBG_INIT, "SAC: Unable to get security descriptor, error: %x\n", Status);
67  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC CreateDeviceSecurityDescriptor: Exiting with status 0x%x\n", Status);
68  return Status;
69  }
70 
71  /* Build a DACL for it */
73  if (Status >= 0)
74  {
75  ASSERT(FALSE);
76  }
77  else
78  {
79  SAC_DBG(SAC_DBG_INIT, "SAC CreateDeviceSecurityDescriptor : Unable to create Raw ACL, error : %x\n", Status);
80  /* FIXME: Temporary hack */
82  goto CleanupPath;
83  }
84 
85 CleanupPath:
86  /* Release the SD we queried */
88 
89  /* Free anything else we may have allocated */
90  if (ObjectSecurityDescriptor) ExFreePool(ObjectSecurityDescriptor);
91  if (Dacl) SacFreePool(Dacl);
92 
93  /* All done */
94  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC CreateDeviceSecurityDescriptor: Exiting with status 0x%x\n", Status);
95  return Status;
96 }
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
_Out_ PSECURITY_DESCRIPTOR _Out_ PBOOLEAN MemoryAllocated
Definition: obfuncs.h:23
LONG NTSTATUS
Definition: precomp.h:26
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
VOID NTAPI ObReleaseObjectSecurity(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN BOOLEAN MemoryAllocated)
Definition: obsecure.c:709
unsigned char BOOLEAN
NTSTATUS NTAPI BuildDeviceAcl(OUT PACL *Dacl)
Definition: data.c:44
NTSTATUS NTAPI ObGetObjectSecurity(IN PVOID Object, OUT PSECURITY_DESCRIPTOR *SecurityDescriptor, OUT PBOOLEAN MemoryAllocated)
Definition: obsecure.c:611
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SacFreePool(Pointer)
Definition: sacdrv.h:26
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1552
#define SAC_DBG_INIT
Definition: sacdrv.h:34
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
#define NULL
Definition: types.h:112
#define SAC_DBG_ENTRY_EXIT
Definition: sacdrv.h:32
#define STATUS_SUCCESS
Definition: shellext.h:65
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NT_ASSERT
Definition: rtlfuncs.h:3310

Referenced by InitializeDeviceData().

◆ FreeDeviceData()

VOID NTAPI FreeDeviceData ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 147 of file data.c.

148 {
149  PSAC_DEVICE_EXTENSION DeviceExtension;
151  KIRQL OldIrql;
152  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeDeviceData: Entering.\n");
153 
154  /* Get the device extension and see how far we had gotten */
155  DeviceExtension = (PSAC_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
156  if (!(GlobalDataInitialized) || !(DeviceExtension->Initialized))
157  {
158  goto Exit;
159  }
160 
161  /* Attempt to rundown while holding the lock */
162  KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql);
163  while (DeviceExtension->RundownInProgress)
164  {
165  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeDeviceData: Waiting....\n");
166 
167  /* Initiate and wait for rundown */
168  KeInitializeEvent(&DeviceExtension->RundownEvent, SynchronizationEvent, 0);
169  KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql);
170  Status = KeWaitForSingleObject(&DeviceExtension->RundownEvent,
171  Executive,
172  KernelMode,
173  FALSE,
174  NULL);
176 
177  /* Re-acquire the lock and check if rundown is done */
178  KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql);
179  }
180 
181  /* Now set the rundown flag while we cancel the timer */
182  DeviceExtension->RundownInProgress = TRUE;
183  KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql);
184 
185  /* Cancel it */
186  KeCancelTimer(&DeviceExtension->Timer);
187 
188  /* Reacquire the lock*/
189  KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql);
190  DeviceExtension->RundownInProgress = FALSE;
191 
192  /* Now do the last rundown attempt, we should be the only ones here */
193  KeInitializeEvent(&DeviceExtension->RundownEvent, SynchronizationEvent, 0);
194  KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql);
195  KeSetEvent(&DeviceExtension->Event, DeviceExtension->PriorityBoost, 0);
196  Status = KeWaitForSingleObject(&DeviceExtension->RundownEvent,
197  Executive,
198  KernelMode,
199  FALSE,
200  NULL);
202 
203  /* We no longer care about shutdown */
205 
206  /* We are now fully uninitialized */
207  KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql);
208  DeviceExtension->Initialized = FALSE;
209  KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql);
210 Exit:
211  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeDeviceData: Exiting.\n");
212 }
#define TRUE
Definition: types.h:120
struct _SAC_DEVICE_EXTENSION * PSAC_DEVICE_EXTENSION
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
if(dx==0 &&dy==0)
Definition: linetemp.h:174
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define FALSE
Definition: types.h:117
Status
Definition: gdiplustypes.h:24
KPRIORITY PriorityBoost
Definition: sacdrv.h:513
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
#define ASSERT(a)
Definition: mode.c:44
static void Exit(void)
Definition: sock.c:1331
KSPIN_LOCK Lock
Definition: sacdrv.h:515
VOID NTAPI IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1725
BOOLEAN Initialized
Definition: sacdrv.h:509
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:792
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
BOOLEAN RundownInProgress
Definition: sacdrv.h:512
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
BOOLEAN GlobalDataInitialized
Definition: data.c:17
#define NULL
Definition: types.h:112
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define SAC_DBG_ENTRY_EXIT
Definition: sacdrv.h:32
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by UnloadHandler().

◆ FreeGlobalData()

VOID NTAPI FreeGlobalData ( VOID  )

Definition at line 100 of file data.c.

101 {
103  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeGlobalData: Entering.\n");
104 
105  /* Only free if we allocated */
107  {
108  /* Close the SAC event if we had created one */
109  if (SACEvent)
110  {
112  SACEvent = NULL;
113  }
114 
115  /* Destroy the cached messages */
117 
118  /* Delete the Win32 symbolic link */
119  RtlInitUnicodeString(&SymbolicLink, L"\\DosDevices\\SAC");
121 
122  /* Tear down connections */
123  ConMgrShutdown();
124 
125  /* Tear down channels */
126  ChanMgrShutdown();
127 
128  /* Free the serial port buffer */
130 
131  /* Free cached machine information */
133 
134  /* Cleanup the custom heap allocator */
136 
137  /* We're back to a virgin state */
139  }
140 
141  /* All done */
142  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeGlobalData: Exiting.\n");
143 }
VOID NTAPI FreeMachineInformation(VOID)
Definition: util.c:1156
PCHAR SerialPortBuffer
Definition: util.c:35
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSTATUS NTAPI ConMgrShutdown(VOID)
Definition: conmgr.c:372
NTSTATUS NTAPI ChanMgrShutdown(VOID)
Definition: chanmgr.c:144
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI TearDownGlobalMessageTable(VOID)
Definition: util.c:379
VOID NTAPI FreeMemoryManagement(VOID)
Definition: memory.c:62
#define SacFreePool(Pointer)
Definition: sacdrv.h:26
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
BOOLEAN GlobalDataInitialized
Definition: data.c:17
PKEVENT SACEvent
Definition: data.c:21
HANDLE SACEventHandle
Definition: data.c:22
#define NULL
Definition: types.h:112
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define SAC_DBG_ENTRY_EXIT
Definition: sacdrv.h:32
static const WCHAR SymbolicLink[]
Definition: interface.c:31

Referenced by DriverEntry(), and UnloadHandler().

◆ InitializeDeviceData()

BOOLEAN NTAPI InitializeDeviceData ( IN PDEVICE_OBJECT  DeviceObject)

Definition at line 216 of file data.c.

217 {
218  PSAC_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
219  BOOLEAN EnableData;
220  ULONG PriorityValue;
223  PWCHAR Message;
224  PAGED_CODE();
225  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Entering.\n");
226 
227  /* If we already did this, bail out */
228  if (DeviceExtension->Initialized) goto SuccessExit;
229 
230  /* Setup the DO flags */
231  DeviceObject->Flags |= DO_DIRECT_IO;
232  DeviceObject->StackSize = 16;
233 
234  /* Setup the device extension */
235  DeviceExtension->DeviceObject = DeviceObject;
236  DeviceExtension->PriorityBoost = IO_SERIAL_INCREMENT;
237  DeviceExtension->PriorityFail = 0;
238  DeviceExtension->RundownInProgress = 0;
239 
240  /* Initialize locks, events, timers, DPCs, etc... */
241  KeInitializeTimer(&DeviceExtension->Timer);
242  KeInitializeDpc(&DeviceExtension->Dpc, TimerDpcRoutine, DeviceExtension);
243  KeInitializeSpinLock(&DeviceExtension->Lock);
244  KeInitializeEvent(&DeviceExtension->Event, SynchronizationEvent, FALSE);
245  InitializeListHead(&DeviceExtension->List);
246 
247  /* Attempt to enable HDL support */
248  EnableData = TRUE;
250  &EnableData,
251  sizeof(EnableData),
252  NULL,
253  NULL);
254  if (!NT_SUCCESS(Status))
255  {
256  /* Bail out if we couldn't even get this far */
257  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting (1) with status FALSE\n");
258  return FALSE;
259  }
260 
261  /* Remember which process we started in */
262  DeviceExtension->Process = IoGetCurrentProcess();
263 
264  /* Protect the device against non-admins */
266  if (!NT_SUCCESS(Status))
267  {
268  /* Write down why we failed */
269  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting (2) with status FALSE\n");
270 
271  /* Disable the HDL terminal on failure */
272  EnableData = FALSE;
274  &EnableData,
275  sizeof(EnableData),
276  NULL,
277  NULL);
278  if (!NT_SUCCESS(Status)) SAC_DBG(SAC_DBG_INIT, "Failed dispatch\n");
279 
280  /* Bail out */
281  return FALSE;
282  }
283 
284  /* Create the worker thread */
285  Status = PsCreateSystemThread(&DeviceExtension->WorkerThreadHandle,
287  NULL,
288  NULL,
289  NULL,
291  DeviceExtension);
292  if (!NT_SUCCESS(Status))
293  {
294  /* Write down why we failed */
295  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting (3) with status FALSE\n");
296 
297  /* Disable the HDL terminal on failure */
298  EnableData = FALSE;
300  &EnableData,
301  sizeof(EnableData),
302  NULL,
303  NULL);
304  if (!NT_SUCCESS(Status)) SAC_DBG(SAC_DBG_INIT, "Failed dispatch\n");
305 
306  /* Bail out */
307  return FALSE;
308  }
309 
310  /* Set the priority of our thread to highest */
311  PriorityValue = HIGH_PRIORITY;
314  &PriorityValue,
315  sizeof(PriorityValue));
316  if (!NT_SUCCESS(Status))
317  {
318  /* For debugging, write down why we failed */
319  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting (6) with status FALSE\n");
320  DeviceExtension->PriorityFail = TRUE;
321 
322  /* Initialize rundown and wait for the thread to do it */
324  KeSetEvent(&DeviceExtension->Event, DeviceExtension->PriorityBoost, FALSE);
325  Status = KeWaitForSingleObject(&DeviceExtension->RundownEvent,
326  Executive,
327  KernelMode,
328  FALSE,
329  NULL);
331 
332  /* Disable the HDL terminal on failure */
333  EnableData = FALSE;
335  &EnableData,
336  sizeof(EnableData),
337  NULL,
338  NULL);
339  if (!NT_SUCCESS(Status)) SAC_DBG(SAC_DBG_INIT, "Failed dispatch\n");
340 
341  /* Bail out */
342  return FALSE;
343  }
344 
345  /* The first "packet" is the machine information in XML... */
347  if (NT_SUCCESS(Status))
348  {
349  /* Go ahead and send it */
350  UTF8EncodeAndSend(L"<?xml version=\"1.0\"?>\r\n");
352 
353  /* Free the temporary buffer */
355  }
356 
357  /* Finally, initialize the I/O Manager */
359  if (!NT_SUCCESS(Status)) return FALSE;
360 
361  /* Set the timer. Once this is done, the device is initialized */
362  DueTime.QuadPart = -4000;
363  KeSetTimerEx(&DeviceExtension->Timer, DueTime, 4, &DeviceExtension->Dpc);
364  DeviceExtension->Initialized = TRUE;
365 
366 SuccessExit:
367  /* Success path -- everything worked */
368  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting with status TRUE\n");
369  return TRUE;
370 }
NTSTATUS NTAPI UTF8EncodeAndSend(IN PWCHAR String)
Definition: util.c:165
NTSTATUS NTAPI TranslateMachineInformationXML(IN PWCHAR *Buffer, IN PWCHAR ExtraData)
Definition: util.c:541
BOOLEAN PriorityFail
Definition: sacdrv.h:511
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
PDEVICE_OBJECT DeviceObject
Definition: sacdrv.h:508
#define TRUE
Definition: types.h:120
#define IO_SERIAL_INCREMENT
Definition: iotypes.h:607
NTSTATUS NTAPI ConMgrInitialize(VOID)
Definition: conmgr.c:163
LONG NTSTATUS
Definition: precomp.h:26
PEPROCESS Process
Definition: sacdrv.h:514
BOOLEAN NTAPI KeSetTimerEx(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN LONG Period, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:294
uint16_t * PWCHAR
Definition: typedefs.h:56
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
NTSTATUS NTAPI CreateDeviceSecurityDescriptor(IN PDEVICE_OBJECT *DeviceObject)
Definition: data.c:52
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
NTSTATUS NTAPI HeadlessDispatch(IN HEADLESS_CMD Command, IN PVOID InputBuffer, IN SIZE_T InputBufferSize, OUT PVOID OutputBuffer, OUT PSIZE_T OutputBufferSize)
Definition: hdlsterm.c:570
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
#define L(x)
Definition: ntvdm.h:50
#define FALSE
Definition: types.h:117
VOID NTAPI WorkerThreadStartUp(IN PVOID Context)
Definition: data.c:36
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:240
unsigned char BOOLEAN
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
NTSTATUS NTAPI NtSetInformationThread(IN HANDLE ThreadHandle, IN THREADINFOCLASS ThreadInformationClass, IN PVOID ThreadInformation, IN ULONG ThreadInformationLength)
Definition: query.c:2018
#define HIGH_PRIORITY
Status
Definition: gdiplustypes.h:24
KPRIORITY PriorityBoost
Definition: sacdrv.h:513
PEPROCESS NTAPI IoGetCurrentProcess(VOID)
Definition: util.c:139
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
KSPIN_LOCK Lock
Definition: sacdrv.h:515
#define SacFreePool(Pointer)
Definition: sacdrv.h:26
VOID NTAPI TimerDpcRoutine(IN PKDPC Dpc, IN PVOID DeferredContext, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dispatch.c:61
BOOLEAN Initialized
Definition: sacdrv.h:509
CHAR Message[80]
Definition: alive.c:5
#define SAC_DBG_INIT
Definition: sacdrv.h:34
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
LIST_ENTRY List
Definition: sacdrv.h:522
HANDLE WorkerThreadHandle
Definition: sacdrv.h:518
BOOLEAN RundownInProgress
Definition: sacdrv.h:512
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NTSTATUS NTAPI PsCreateSystemThread(OUT PHANDLE ThreadHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN HANDLE ProcessHandle, IN PCLIENT_ID ClientId, IN PKSTART_ROUTINE StartRoutine, IN PVOID StartContext)
Definition: thread.c:602
#define NULL
Definition: types.h:112
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:187
unsigned int ULONG
Definition: retypes.h:1
#define SAC_DBG_ENTRY_EXIT
Definition: sacdrv.h:32
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define PAGED_CODE()

Referenced by DriverEntry().

◆ InitializeGlobalData()

BOOLEAN NTAPI InitializeGlobalData ( IN PUNICODE_STRING  RegistryPath,
IN PDRIVER_OBJECT  DriverObject 
)

Definition at line 374 of file data.c.

376 {
378  UNICODE_STRING LinkName;
380  UNICODE_STRING EventName;
381  PAGED_CODE();
382  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Entering.\n");
383 
384  /* If we already did this, bail out */
385  if (GlobalDataInitialized) goto SuccessExit;
386 
387  /* Setup the symbolic link for Win32 support */
388  RtlInitUnicodeString(&LinkName, L"\\DosDevices\\SAC");
389  RtlInitUnicodeString(&DeviceName, L"\\Device\\SAC");
390  Status = IoCreateSymbolicLink(&LinkName, &DeviceName);
391  if (!NT_SUCCESS(Status)) return FALSE;
392 
393  /* Initialize the internal heap manager */
395  {
396  IoDeleteSymbolicLink(&LinkName);
397  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting with status FALSE\n");
398  return FALSE;
399  }
400 
401  /* Preload the messages in memory */
403  if (!NT_SUCCESS(Status))
404  {
405  IoDeleteSymbolicLink(&LinkName);
406  SAC_DBG(SAC_DBG_INIT, "unable to pre-load message table: %X\n", Status);
407  return FALSE;
408  }
409 
410  /* Check if the administrator enabled this */
412  if (!NT_SUCCESS(Status))
413  {
414  /* Is it enabled? */
416  {
417  /* Set the service start type to the correct value */
419  if (!NT_SUCCESS(Status))
420  {
421  SAC_DBG(SAC_DBG_INIT, "failed ImposeSacCmdServiceStartTypePolicy: %X\n", Status);
422  }
423  }
424 
425  /* We're going to keep going with the default */
426  SAC_DBG(SAC_DBG_INIT, "failed GetCommandConsoleLaunchingPermission: %X\n", Status);
427  }
428 
429  /* Allocate the UTF-8 Conversion Buffer */
432  {
433  /* Handle failure case */
435  IoDeleteSymbolicLink(&LinkName);
436  SAC_DBG(SAC_DBG_INIT, "unable to allocate memory for UTF8 translation\n");
437  return FALSE;
438  }
439 
440  /* Initialize the channel manager */
442  if (!NT_SUCCESS(Status))
443  {
444  /* Handle failure case */
447  IoDeleteSymbolicLink(&LinkName);
448  SAC_DBG(SAC_DBG_INIT, "Failed to create SAC Channel\n");
449  return FALSE;
450  }
451 
452  /* Allocate the serial port buffer */
454  if (!SerialPortBuffer)
455  {
456  /* Handle failure case */
459  IoDeleteSymbolicLink(&LinkName);
460  SAC_DBG(SAC_DBG_INIT, "Failed to allocate Serial Port Buffer\n");
461  return FALSE;
462  }
463 
464  /* Zero it out */
466 
467  /* Initialize command events. After this, driver data is good to go */
471  ProcessingType = 0;
472  IoctlSubmitted = 0;
473 
474  /* Create the SAC event */
475  RtlInitUnicodeString(&EventName, L"\\SACEvent");
477  if (!SACEvent)
478  {
479  /* Handle failure case */
482  IoDeleteSymbolicLink(&LinkName);
483  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting with event NULL\n");
484  return FALSE;
485  }
486 
487  /* Cache machine information */
489 
490  /* Register it */
492  if (!NT_SUCCESS(Status))
493  {
494  /* Handle failure case */
497  IoDeleteSymbolicLink(&LinkName);
498  SAC_DBG(SAC_DBG_INIT, "Failed to register blue screen machine info\n");
499  return FALSE;
500  }
501 
502 SuccessExit:
503  /* Success path -- everything worked */
504  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting with status TRUE\n");
505  return TRUE;
506 }
PCHAR Utf8ConversionBuffer
Definition: util.c:17
ULONG ProcessingType
Definition: data.c:20
ULONG Utf8ConversionBufferSize
Definition: util.c:18
PCHAR SerialPortBuffer
Definition: util.c:35
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN IoctlSubmitted
Definition: data.c:19
NTSTATUS NTAPI PreloadGlobalMessageTable(IN PVOID ImageBase)
Definition: util.c:280
#define GLOBAL_BLOCK_TAG
Definition: sacdrv.h:142
BOOLEAN CommandConsoleLaunchingEnabled
Definition: data.c:16
#define L(x)
Definition: ntvdm.h:50
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3272
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI GetCommandConsoleLaunchingPermission(OUT PBOOLEAN Permission)
Definition: util.c:981
VOID NTAPI InitializeCmdEventInfo(VOID)
Definition: util.c:1062
BOOLEAN NTAPI InitializeMemoryManagement(VOID)
Definition: memory.c:23
#define SacAllocatePool(Length, Tag)
Definition: sacdrv.h:24
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
NTSTATUS NTAPI TearDownGlobalMessageTable(VOID)
Definition: util.c:379
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI InitializeMachineInformation(VOID)
Definition: util.c:692
#define SacFreePool(Pointer)
Definition: sacdrv.h:26
VOID NTAPI KeInitializeMutex(IN PKMUTEX Mutex, IN ULONG Level)
Definition: mutex.c:67
#define SAC_DBG_INIT
Definition: sacdrv.h:34
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
NTSTATUS NTAPI RegisterBlueScreenMachineInformation(VOID)
Definition: util.c:1104
NTSTATUS NTAPI ImposeSacCmdServiceStartTypePolicy(VOID)
Definition: util.c:1008
BOOLEAN GlobalDataInitialized
Definition: data.c:17
PKEVENT SACEvent
Definition: data.c:21
HANDLE SACEventHandle
Definition: data.c:22
PKEVENT NTAPI IoCreateSynchronizationEvent(IN PUNICODE_STRING EventName, IN PHANDLE EventHandle)
Definition: ioevent.c:82
#define SAC_SERIAL_PORT_BUFFER_SIZE
Definition: sacdrv.h:155
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define SAC_DBG_ENTRY_EXIT
Definition: sacdrv.h:32
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
KMUTEX SACCMDEventInfoMutex
Definition: data.c:18
NTSTATUS NTAPI ChanMgrInitialize(VOID)
Definition: chanmgr.c:118
#define PAGED_CODE()

Referenced by DriverEntry().

◆ WorkerProcessEvents()

VOID NTAPI WorkerProcessEvents ( IN PSAC_DEVICE_EXTENSION  DeviceExtension)

Definition at line 28 of file data.c.

29 {
30  /* Call the worker function */
31  ConMgrWorkerProcessEvents(DeviceExtension);
32 }
VOID NTAPI ConMgrWorkerProcessEvents(IN PSAC_DEVICE_EXTENSION DeviceExtension)
Definition: conmgr.c:835

Referenced by WorkerThreadStartUp().

◆ WorkerThreadStartUp()

VOID NTAPI WorkerThreadStartUp ( IN PVOID  Context)

Definition at line 36 of file data.c.

37 {
38  /* Call the worker function */
40 }
VOID NTAPI WorkerProcessEvents(IN PSAC_DEVICE_EXTENSION DeviceExtension)
Definition: data.c:28

Referenced by InitializeDeviceData().

Variable Documentation

◆ CommandConsoleLaunchingEnabled

BOOLEAN CommandConsoleLaunchingEnabled

Definition at line 16 of file data.c.

Referenced by ConMgrProcessInputLine(), and InitializeGlobalData().

◆ GlobalDataInitialized

BOOLEAN GlobalDataInitialized

Definition at line 17 of file data.c.

Referenced by FreeDeviceData(), FreeGlobalData(), and InitializeGlobalData().

◆ IoctlSubmitted

BOOLEAN IoctlSubmitted

Definition at line 19 of file data.c.

Referenced by InitializeGlobalData().

◆ ProcessingType

ULONG ProcessingType

Definition at line 20 of file data.c.

Referenced by InitializeGlobalData().

◆ SACCMDEventInfoMutex

KMUTEX SACCMDEventInfoMutex

Definition at line 18 of file data.c.

Referenced by InitializeGlobalData().

◆ SACDebug

ULONG SACDebug = 0

Definition at line 15 of file data.c.

◆ SACEvent

PKEVENT SACEvent

Definition at line 21 of file data.c.

Referenced by FreeGlobalData(), and InitializeGlobalData().

◆ SACEventHandle

HANDLE SACEventHandle

Definition at line 22 of file data.c.

Referenced by FreeGlobalData(), and InitializeGlobalData().