ReactOS  0.4.14-dev-49-gfb4591c
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 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225

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
VOID NTAPI ObReleaseObjectSecurity(IN PSECURITY_DESCRIPTOR SecurityDescriptor, IN BOOLEAN MemoryAllocated)
Definition: obsecure.c:709
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
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
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SacFreePool(Pointer)
Definition: sacdrv.h:26
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1553
#define SAC_DBG_INIT
Definition: sacdrv.h:34
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define SAC_DBG_ENTRY_EXIT
Definition: sacdrv.h:32
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NT_ASSERT
Definition: rtlfuncs.h:3312

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 */
156  if ((GlobalDataInitialized) && (DeviceExtension->Initialized))
157  {
158  /* Attempt to rundown while holding the lock */
159  KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql);
160  while (DeviceExtension->RundownInProgress)
161  {
162  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeDeviceData: Waiting....\n");
163 
164  /* Initiate and wait for rundown */
165  KeInitializeEvent(&DeviceExtension->RundownEvent, SynchronizationEvent, 0);
166  KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql);
167  Status = KeWaitForSingleObject(&DeviceExtension->RundownEvent,
168  Executive,
169  KernelMode,
170  FALSE,
171  NULL);
173 
174  /* Re-acquire the lock and check if rundown is done */
175  KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql);
176  }
177  }
178 
179  /* Now set the rundown flag while we cancel the timer */
180  DeviceExtension->RundownInProgress = TRUE;
181  KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql);
182 
183  /* Cancel it */
184  KeCancelTimer(&DeviceExtension->Timer);
185 
186  /* Reacquire the lock*/
187  KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql);
188  DeviceExtension->RundownInProgress = FALSE;
189 
190  /* Now do the last rundown attempt, we should be the only ones here */
191  KeInitializeEvent(&DeviceExtension->RundownEvent, SynchronizationEvent, 0);
192  KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql);
193  KeSetEvent(&DeviceExtension->Event, DeviceExtension->PriorityBoost, 0);
194  Status = KeWaitForSingleObject(&DeviceExtension->RundownEvent,
195  Executive,
196  KernelMode,
197  FALSE,
198  NULL);
200 
201  /* We no longer care about shutdown */
203 
204  /* We are now fully uninitialized */
205  KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql);
206  DeviceExtension->Initialized = FALSE;
207  KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql);
208  SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeDeviceData: Exiting.\n");
209 }
#define TRUE
Definition: types.h:120
struct _SAC_DEVICE_EXTENSION * PSAC_DEVICE_EXTENSION
LONG NTSTATUS
Definition: precomp.h:26
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
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
KPRIORITY PriorityBoost
Definition: sacdrv.h:512
BOOLEAN NTAPI KeCancelTimer(IN OUT PKTIMER Timer)
Definition: timerobj.c:206
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
KSPIN_LOCK Lock
Definition: sacdrv.h:514
VOID NTAPI IoUnregisterShutdownNotification(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1725
BOOLEAN Initialized
Definition: sacdrv.h:508
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:803
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
Status
Definition: gdiplustypes.h:24
BOOLEAN RundownInProgress
Definition: sacdrv.h:511
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
BOOLEAN GlobalDataInitialized
Definition: data.c:17
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define SAC_DBG_ENTRY_EXIT
Definition: sacdrv.h:32
return STATUS_SUCCESS
Definition: btrfs.c:2966

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:1153
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
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS NTAPI TearDownGlobalMessageTable(VOID)
Definition: util.c:379
VOID NTAPI FreeMemoryManagement(VOID)
Definition: memory.c:62
#define SacFreePool(Pointer)
Definition: sacdrv.h:26
static const WCHAR L[]
Definition: oid.c:1250
#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
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 213 of file data.c.

214 {
216  BOOLEAN EnableData;
217  ULONG PriorityValue;
220  PWCHAR Message;
221  PAGED_CODE();
222  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Entering.\n");
223 
224  /* If we already did this, bail out */
225  if (DeviceExtension->Initialized) goto SuccessExit;
226 
227  /* Setup the DO flags */
229  DeviceObject->StackSize = 16;
230 
231  /* Setup the device extension */
232  DeviceExtension->DeviceObject = DeviceObject;
233  DeviceExtension->PriorityBoost = IO_SERIAL_INCREMENT;
234  DeviceExtension->PriorityFail = 0;
235  DeviceExtension->RundownInProgress = 0;
236 
237  /* Initialize locks, events, timers, DPCs, etc... */
238  KeInitializeTimer(&DeviceExtension->Timer);
239  KeInitializeDpc(&DeviceExtension->Dpc, TimerDpcRoutine, DeviceExtension);
240  KeInitializeSpinLock(&DeviceExtension->Lock);
241  KeInitializeEvent(&DeviceExtension->Event, SynchronizationEvent, FALSE);
242  InitializeListHead(&DeviceExtension->List);
243 
244  /* Attempt to enable HDL support */
245  EnableData = TRUE;
247  &EnableData,
248  sizeof(EnableData),
249  NULL,
250  0);
251  if (!NT_SUCCESS(Status))
252  {
253  /* Bail out if we couldn't even get this far */
254  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting (1) with status FALSE\n");
255  return FALSE;
256  }
257 
258  /* Remember which process we started in */
259  DeviceExtension->Process = IoGetCurrentProcess();
260 
261  /* Protect the device against non-admins */
263  if (!NT_SUCCESS(Status))
264  {
265  /* Write down why we failed */
266  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting (2) with status FALSE\n");
267 
268  /* Disable the HDL terminal on failure */
269  EnableData = FALSE;
271  &EnableData,
272  sizeof(EnableData),
273  NULL,
274  NULL);
275  if (!NT_SUCCESS(Status)) SAC_DBG(SAC_DBG_INIT, "Failed dispatch\n");
276 
277  /* Bail out */
278  return FALSE;
279  }
280 
281  /* Create the worker thread */
282  Status = PsCreateSystemThread(&DeviceExtension->WorkerThreadHandle,
284  NULL,
285  NULL,
286  NULL,
288  DeviceExtension);
289  if (!NT_SUCCESS(Status))
290  {
291  /* Write down why we failed */
292  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting (3) with status FALSE\n");
293 
294  /* Disable the HDL terminal on failure */
295  EnableData = FALSE;
297  &EnableData,
298  sizeof(EnableData),
299  NULL,
300  NULL);
301  if (!NT_SUCCESS(Status)) SAC_DBG(SAC_DBG_INIT, "Failed dispatch\n");
302 
303  /* Bail out */
304  return FALSE;
305  }
306 
307  /* Set the priority of our thread to highest */
308  PriorityValue = HIGH_PRIORITY;
311  &PriorityValue,
312  sizeof(PriorityValue));
313  if (!NT_SUCCESS(Status))
314  {
315  /* For debugging, write down why we failed */
316  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting (6) with status FALSE\n");
317  DeviceExtension->PriorityFail = TRUE;
318 
319  /* Initialize rundown and wait for the thread to do it */
321  KeSetEvent(&DeviceExtension->Event, DeviceExtension->PriorityBoost, FALSE);
322  Status = KeWaitForSingleObject(&DeviceExtension->RundownEvent,
323  Executive,
324  KernelMode,
325  FALSE,
326  NULL);
328 
329  /* Disable the HDL terminal on failure */
330  EnableData = FALSE;
332  &EnableData,
333  sizeof(EnableData),
334  NULL,
335  0);
336  if (!NT_SUCCESS(Status)) SAC_DBG(SAC_DBG_INIT, "Failed dispatch\n");
337 
338  /* Bail out */
339  return FALSE;
340  }
341 
342  /* The first "packet" is the machine information in XML... */
344  if (NT_SUCCESS(Status))
345  {
346  /* Go ahead and send it */
347  UTF8EncodeAndSend(L"<?xml version=\"1.0\"?>\r\n");
349 
350  /* Free the temporary buffer */
352  }
353 
354  /* Finally, initialize the I/O Manager */
356  if (!NT_SUCCESS(Status)) return FALSE;
357 
358  /* Set the timer. Once this is done, the device is initialized */
359  DueTime.QuadPart = -4000;
360  KeSetTimerEx(&DeviceExtension->Timer, DueTime, 4, &DeviceExtension->Dpc);
361  DeviceExtension->Initialized = TRUE;
362 
363 SuccessExit:
364  /* Success path -- everything worked */
365  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting with status TRUE\n");
366  return TRUE;
367 }
NTSTATUS NTAPI UTF8EncodeAndSend(IN PWCHAR String)
Definition: util.c:165
NTSTATUS NTAPI TranslateMachineInformationXML(IN PWCHAR *Buffer, IN PWCHAR ExtraData)
Definition: util.c:538
BOOLEAN PriorityFail
Definition: sacdrv.h:510
#define THREAD_ALL_ACCESS
Definition: nt_native.h:1339
#define TRUE
Definition: types.h:120
PDEVICE_OBJECT DeviceObject
Definition: sacdrv.h:507
_In_ LARGE_INTEGER DueTime
Definition: kefuncs.h:524
#define IO_SERIAL_INCREMENT
Definition: iotypes.h:575
NTSTATUS NTAPI ConMgrInitialize(VOID)
Definition: conmgr.c:163
LONG NTSTATUS
Definition: precomp.h:26
PEPROCESS Process
Definition: sacdrv.h:513
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:54
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 PAGED_CODE()
Definition: video.h:57
#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
VOID NTAPI WorkerThreadStartUp(IN PVOID Context)
Definition: data.c:36
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
PVOID DeviceExtension
Definition: env_spec_w32.h:418
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
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:2014
#define HIGH_PRIORITY
KPRIORITY PriorityBoost
Definition: sacdrv.h:512
PEPROCESS NTAPI IoGetCurrentProcess(VOID)
Definition: util.c:139
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
KSPIN_LOCK Lock
Definition: sacdrv.h:514
#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:508
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
CHAR Message[80]
Definition: alive.c:5
static const WCHAR L[]
Definition: oid.c:1250
#define SAC_DBG_INIT
Definition: sacdrv.h:34
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
LIST_ENTRY List
Definition: sacdrv.h:521
HANDLE WorkerThreadHandle
Definition: sacdrv.h:517
Status
Definition: gdiplustypes.h:24
BOOLEAN RundownInProgress
Definition: sacdrv.h:511
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#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
unsigned int ULONG
Definition: retypes.h:1
#define SAC_DBG_ENTRY_EXIT
Definition: sacdrv.h:32
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:711
return STATUS_SUCCESS
Definition: btrfs.c:2966
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by DriverEntry().

◆ InitializeGlobalData()

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

Definition at line 371 of file data.c.

373 {
375  UNICODE_STRING LinkName;
377  UNICODE_STRING EventName;
378  PAGED_CODE();
379  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Entering.\n");
380 
381  /* If we already did this, bail out */
382  if (GlobalDataInitialized) goto SuccessExit;
383 
384  /* Setup the symbolic link for Win32 support */
385  RtlInitUnicodeString(&LinkName, L"\\DosDevices\\SAC");
386  RtlInitUnicodeString(&DeviceName, L"\\Device\\SAC");
387  Status = IoCreateSymbolicLink(&LinkName, &DeviceName);
388  if (!NT_SUCCESS(Status)) return FALSE;
389 
390  /* Initialize the internal heap manager */
392  {
393  IoDeleteSymbolicLink(&LinkName);
394  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting with status FALSE\n");
395  return FALSE;
396  }
397 
398  /* Preload the messages in memory */
400  if (!NT_SUCCESS(Status))
401  {
402  IoDeleteSymbolicLink(&LinkName);
403  SAC_DBG(SAC_DBG_INIT, "unable to pre-load message table: %X\n", Status);
404  return FALSE;
405  }
406 
407  /* Check if the administrator enabled this */
409  if (!NT_SUCCESS(Status))
410  {
411  /* Is it enabled? */
413  {
414  /* Set the service start type to the correct value */
416  if (!NT_SUCCESS(Status))
417  {
418  SAC_DBG(SAC_DBG_INIT, "failed ImposeSacCmdServiceStartTypePolicy: %X\n", Status);
419  }
420  }
421 
422  /* We're going to keep going with the default */
423  SAC_DBG(SAC_DBG_INIT, "failed GetCommandConsoleLaunchingPermission: %X\n", Status);
424  }
425 
426  /* Allocate the UTF-8 Conversion Buffer */
429  {
430  /* Handle failure case */
432  IoDeleteSymbolicLink(&LinkName);
433  SAC_DBG(SAC_DBG_INIT, "unable to allocate memory for UTF8 translation\n");
434  return FALSE;
435  }
436 
437  /* Initialize the channel manager */
439  if (!NT_SUCCESS(Status))
440  {
441  /* Handle failure case */
444  IoDeleteSymbolicLink(&LinkName);
445  SAC_DBG(SAC_DBG_INIT, "Failed to create SAC Channel\n");
446  return FALSE;
447  }
448 
449  /* Allocate the serial port buffer */
451  if (!SerialPortBuffer)
452  {
453  /* Handle failure case */
456  IoDeleteSymbolicLink(&LinkName);
457  SAC_DBG(SAC_DBG_INIT, "Failed to allocate Serial Port Buffer\n");
458  return FALSE;
459  }
460 
461  /* Zero it out */
463 
464  /* Initialize command events. After this, driver data is good to go */
468  ProcessingType = 0;
469  IoctlSubmitted = 0;
470 
471  /* Create the SAC event */
472  RtlInitUnicodeString(&EventName, L"\\SACEvent");
474  if (!SACEvent)
475  {
476  /* Handle failure case */
479  IoDeleteSymbolicLink(&LinkName);
480  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting with event NULL\n");
481  return FALSE;
482  }
483 
484  /* Cache machine information */
486 
487  /* Register it */
489  if (!NT_SUCCESS(Status))
490  {
491  /* Handle failure case */
494  IoDeleteSymbolicLink(&LinkName);
495  SAC_DBG(SAC_DBG_INIT, "Failed to register blue screen machine info\n");
496  return FALSE;
497  }
498 
499 SuccessExit:
500  /* Success path -- everything worked */
501  SAC_DBG(SAC_DBG_ENTRY_EXIT, "Exiting with status TRUE\n");
502  return TRUE;
503 }
PCHAR Utf8ConversionBuffer
Definition: util.c:17
ULONG ProcessingType
Definition: data.c:20
#define TRUE
Definition: types.h:120
ULONG Utf8ConversionBufferSize
Definition: util.c:18
PCHAR SerialPortBuffer
Definition: util.c:35
LONG NTSTATUS
Definition: precomp.h:26
PVOID DriverStart
Definition: iotypes.h:2171
BOOLEAN IoctlSubmitted
Definition: data.c:19
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS NTAPI PreloadGlobalMessageTable(IN PVOID ImageBase)
Definition: util.c:280
#define GLOBAL_BLOCK_TAG
Definition: sacdrv.h:141
BOOLEAN CommandConsoleLaunchingEnabled
Definition: data.c:16
NTSTATUS NTAPI GetCommandConsoleLaunchingPermission(OUT PBOOLEAN Permission)
Definition: util.c:978
VOID NTAPI InitializeCmdEventInfo(VOID)
Definition: util.c:1059
BOOLEAN NTAPI InitializeMemoryManagement(VOID)
Definition: memory.c:23
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define SacAllocatePool(Length, Tag)
Definition: sacdrv.h:24
NTSTATUS NTAPI TearDownGlobalMessageTable(VOID)
Definition: util.c:379
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI InitializeMachineInformation(VOID)
Definition: util.c:689
#define SacFreePool(Pointer)
Definition: sacdrv.h:26
VOID NTAPI KeInitializeMutex(IN PKMUTEX Mutex, IN ULONG Level)
Definition: mutex.c:67
static const WCHAR L[]
Definition: oid.c:1250
#define SAC_DBG_INIT
Definition: sacdrv.h:34
#define SAC_DBG(x,...)
Definition: sacdrv.h:37
NTSTATUS NTAPI RegisterBlueScreenMachineInformation(VOID)
Definition: util.c:1101
NTSTATUS NTAPI ImposeSacCmdServiceStartTypePolicy(VOID)
Definition: util.c:1005
Status
Definition: gdiplustypes.h:24
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:154
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:261
KMUTEX SACCMDEventInfoMutex
Definition: data.c:18
NTSTATUS NTAPI ChanMgrInitialize(VOID)
Definition: chanmgr.c:118

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().