ReactOS  0.4.14-dev-614-gbfd8a84
kmtest_drv.c File Reference
#include <ntddk.h>
#include <ntifs.h>
#include <ndk/ketypes.h>
#include <ntstrsafe.h>
#include <limits.h>
#include <pseh/pseh2.h>
#include <debug.h>
#include <kmt_public.h>
#include <kmt_test.h>
Include dependency graph for kmtest_drv.c:

Go to the source code of this file.

Classes

struct  _KMT_USER_WORK_ENTRY
 
struct  _KMT_USER_WORK_LIST
 

Macros

#define NDEBUG
 
#define KMT_DEFINE_TEST_FUNCTIONS
 

Typedefs

typedef struct _KMT_USER_WORK_ENTRY KMT_USER_WORK_ENTRY
 
typedef struct _KMT_USER_WORK_ENTRYPKMT_USER_WORK_ENTRY
 
typedef struct _KMT_USER_WORK_LIST KMT_USER_WORK_LIST
 
typedef struct _KMT_USER_WORK_LISTPKMT_USER_WORK_LIST
 

Functions

DriverUnload

Driver cleanup funtion.

Parameters
DriverObjectDriver Object
static VOID NTAPI DriverUnload (IN PDRIVER_OBJECT DriverObject)
 
DriverCreate

Driver Dispatch function for IRP_MJ_CREATE

Parameters
DeviceObjectDevice Object
IrpI/O request packet
Returns
Status
static NTSTATUS NTAPI DriverCreate (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
DriverCleanup

Driver Dispatch function for IRP_MJ_CLEANUP

Parameters
DeviceObjectDevice Object
IrpI/O request packet
Returns
Status
static NTSTATUS NTAPI DriverCleanup (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
DriverClose

Driver Dispatch function for IRP_MJ_CLOSE

Parameters
DeviceObjectDevice Object
IrpI/O request packet
Returns
Status
static NTSTATUS NTAPI DriverClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
DriverIoControl

Driver Dispatch function for IRP_MJ_DEVICE_CONTROL

Parameters
DeviceObjectDevice Object
IrpI/O request packet
Returns
Status
static NTSTATUS NTAPI DriverIoControl (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
KmtUserModeCallback

Enqueue a request to the usermode callback queue and blocks until the work is finished.

Parameters
OperationTODO
ParametersTODO TODO: why is this PVOID?
Returns
Response from user mode
PKMT_RESPONSE KmtUserModeCallback (IN KMT_CALLBACK_INFORMATION_CLASS Operation, IN PVOID Parameters)
 
KmtFreeCallbackResponse

TODO

Parameters
ResponseTODO
VOID KmtFreeCallbackResponse (PKMT_RESPONSE Response)
 
KmtCleanUsermodeCallbacks

TODO

static VOID KmtCleanUsermodeCallbacks (VOID)
 

Variables

DRIVER_INITIALIZE DriverEntry
 
static DRIVER_UNLOAD DriverUnload
 

Macro Definition Documentation

◆ KMT_DEFINE_TEST_FUNCTIONS

#define KMT_DEFINE_TEST_FUNCTIONS

Definition at line 20 of file kmtest_drv.c.

◆ NDEBUG

#define NDEBUG

Definition at line 16 of file kmtest_drv.c.

Typedef Documentation

◆ KMT_USER_WORK_ENTRY

◆ KMT_USER_WORK_LIST

◆ PKMT_USER_WORK_ENTRY

◆ PKMT_USER_WORK_LIST

Function Documentation

◆ DriverCleanup()

static NTSTATUS NTAPI DriverCleanup ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 217 of file kmtest_drv.c.

220 {
222  PIO_STACK_LOCATION IoStackLocation;
223  PKMT_DEVICE_EXTENSION DeviceExtension;
224 
225  PAGED_CODE();
226 
227  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
228 
229  DPRINT("DriverCleanup. DeviceObject=%p, RequestorMode=%d, FileObject=%p, FsContext=%p, FsContext2=%p\n",
230  DeviceObject, Irp->RequestorMode, IoStackLocation->FileObject,
231  IoStackLocation->FileObject->FsContext, IoStackLocation->FileObject->FsContext2);
232 
233  ASSERT(IoStackLocation->FileObject->FsContext2 == NULL);
234  DeviceExtension = DeviceObject->DeviceExtension;
235  if (DeviceExtension->Mdl && IoStackLocation->FileObject->FsContext == DeviceExtension->Mdl)
236  {
237  MmUnlockPages(DeviceExtension->Mdl);
238  IoFreeMdl(DeviceExtension->Mdl);
239  DeviceExtension->Mdl = NULL;
240  ResultBuffer = DeviceExtension->ResultBuffer = NULL;
241  }
242  else
243  {
244  ASSERT(IoStackLocation->FileObject->FsContext == NULL);
245  }
246 
247  Irp->IoStatus.Status = Status;
248  Irp->IoStatus.Information = 0;
249 
251 
252  return Status;
253 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
#define PAGED_CODE()
Definition: video.h:57
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938
PKMT_RESULTBUFFER ResultBuffer

◆ DriverClose()

static NTSTATUS NTAPI DriverClose ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 270 of file kmtest_drv.c.

273 {
275 
276  PAGED_CODE();
277 
278  DPRINT("DriverClose. DeviceObject=%p, RequestorMode=%d\n",
279  DeviceObject, Irp->RequestorMode);
280 
281  Irp->IoStatus.Status = Status;
282  Irp->IoStatus.Information = 0;
283 
285 
286  return Status;
287 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ DriverCreate()

static NTSTATUS NTAPI DriverCreate ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 179 of file kmtest_drv.c.

182 {
184  PIO_STACK_LOCATION IoStackLocation;
185 
186  PAGED_CODE();
187 
188  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
189 
190  DPRINT("DriverCreate. DeviceObject=%p, RequestorMode=%d, FileObject=%p, FsContext=%p, FsContext2=%p\n",
191  DeviceObject, Irp->RequestorMode, IoStackLocation->FileObject,
192  IoStackLocation->FileObject->FsContext, IoStackLocation->FileObject->FsContext2);
193 
194  Irp->IoStatus.Status = Status;
195  Irp->IoStatus.Information = 0;
196 
198 
199  return Status;
200 }
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
#define PAGED_CODE()
Definition: video.h:57
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define IO_NO_INCREMENT
Definition: iotypes.h:566
return STATUS_SUCCESS
Definition: btrfs.c:2938

◆ DriverIoControl()

static NTSTATUS NTAPI DriverIoControl ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)
static

Definition at line 304 of file kmtest_drv.c.

307 {
309  PIO_STACK_LOCATION IoStackLocation;
310  SIZE_T Length = 0;
311 
312  PAGED_CODE();
313 
314  IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
315 
316  DPRINT("DriverIoControl. Code=0x%08X, DeviceObject=%p, FileObject=%p, FsContext=%p, FsContext2=%p\n",
317  IoStackLocation->Parameters.DeviceIoControl.IoControlCode,
318  DeviceObject, IoStackLocation->FileObject,
319  IoStackLocation->FileObject->FsContext, IoStackLocation->FileObject->FsContext2);
320 
321  switch (IoStackLocation->Parameters.DeviceIoControl.IoControlCode)
322  {
324  {
326  LPSTR OutputBuffer = Irp->AssociatedIrp.SystemBuffer;
327  size_t Remaining = IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength;
328 
329  DPRINT("DriverIoControl. IOCTL_KMTEST_GET_TESTS, outlen=%lu\n",
330  IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength);
331 
332  for (TestEntry = TestList; TestEntry->TestName; ++TestEntry)
333  {
334  RtlStringCbCopyExA(OutputBuffer, Remaining, TestEntry->TestName, &OutputBuffer, &Remaining, 0);
335  if (Remaining)
336  {
337  *OutputBuffer++ = '\0';
338  --Remaining;
339  }
340  }
341  if (Remaining)
342  {
343  *OutputBuffer++ = '\0';
344  --Remaining;
345  }
346  Length = IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength - Remaining;
347  break;
348  }
350  {
351  ANSI_STRING TestName;
353 
354  DPRINT("DriverIoControl. IOCTL_KMTEST_RUN_TEST, inlen=%lu, outlen=%lu\n",
355  IoStackLocation->Parameters.DeviceIoControl.InputBufferLength,
356  IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength);
357  TestName.Length = TestName.MaximumLength = (USHORT)min(IoStackLocation->Parameters.DeviceIoControl.InputBufferLength, USHRT_MAX);
358  TestName.Buffer = Irp->AssociatedIrp.SystemBuffer;
359  DPRINT("DriverIoControl. Run test: %Z\n", &TestName);
360 
361  for (TestEntry = TestList; TestEntry->TestName; ++TestEntry)
362  {
363  ANSI_STRING EntryName;
364  if (TestEntry->TestName[0] == '-')
365  RtlInitAnsiString(&EntryName, TestEntry->TestName + 1);
366  else
367  RtlInitAnsiString(&EntryName, TestEntry->TestName);
368 
369  if (!RtlCompareString(&TestName, &EntryName, FALSE))
370  {
371  DPRINT1("DriverIoControl. Starting test %Z\n", &EntryName);
372  TestEntry->TestFunction();
373  DPRINT1("DriverIoControl. Finished test %Z\n", &EntryName);
374  break;
375  }
376  }
377 
378  if (!TestEntry->TestName)
380 
381  break;
382  }
384  {
385  PKMT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
386 
387  DPRINT("DriverIoControl. IOCTL_KMTEST_SET_RESULTBUFFER, buffer=%p, inlen=%lu, outlen=%lu\n",
388  IoStackLocation->Parameters.DeviceIoControl.Type3InputBuffer,
389  IoStackLocation->Parameters.DeviceIoControl.InputBufferLength,
390  IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength);
391 
392  if (DeviceExtension->Mdl)
393  {
394  if (IoStackLocation->FileObject->FsContext != DeviceExtension->Mdl)
395  {
397  break;
398  }
399  MmUnlockPages(DeviceExtension->Mdl);
400  IoFreeMdl(DeviceExtension->Mdl);
401  IoStackLocation->FileObject->FsContext = NULL;
402  ResultBuffer = DeviceExtension->ResultBuffer = NULL;
403  }
404 
405  DeviceExtension->Mdl = IoAllocateMdl(IoStackLocation->Parameters.DeviceIoControl.Type3InputBuffer,
406  IoStackLocation->Parameters.DeviceIoControl.InputBufferLength,
407  FALSE, FALSE, NULL);
408  if (!DeviceExtension->Mdl)
409  {
411  break;
412  }
413 
414  _SEH2_TRY
415  {
416  MmProbeAndLockPages(DeviceExtension->Mdl, UserMode, IoModifyAccess);
417  }
419  {
421  IoFreeMdl(DeviceExtension->Mdl);
422  DeviceExtension->Mdl = NULL;
423  break;
424  } _SEH2_END;
425 
426  ResultBuffer = DeviceExtension->ResultBuffer = MmGetSystemAddressForMdlSafe(DeviceExtension->Mdl, NormalPagePriority);
427  IoStackLocation->FileObject->FsContext = DeviceExtension->Mdl;
428 
429  DPRINT("DriverIoControl. ResultBuffer: %ld %ld %ld %ld\n",
432  break;
433  }
435  {
437  PKMT_USER_WORK_ENTRY WorkItem;
438 
439  DPRINT("DriverIoControl. IOCTL_KMTEST_USERMODE_AWAIT_REQ, len=%lu\n",
440  IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength);
441 
442  /* TODO: prevent multiple concurrent invocations */
443  Status = KeWaitForSingleObject(&WorkList.NewWorkEvent, UserRequest, UserMode, FALSE, NULL);
445  break;
446 
447  if (IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength < sizeof(KMT_CALLBACK_REQUEST_PACKET))
448  {
450  break;
451  }
452 
453  ASSERT(!IsListEmpty(&WorkList.ListHead));
454 
455  Entry = WorkList.ListHead.Flink;
456  WorkItem = CONTAINING_RECORD(Entry, KMT_USER_WORK_ENTRY, ListEntry);
457 
458  Length = sizeof(WorkItem->Request);
459  RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, &WorkItem->Request, Length);
461 
462  KeClearEvent(&WorkList.NewWorkEvent);
463  break;
464 
465  }
467  {
469  PKMT_USER_WORK_ENTRY WorkEntry;
470  PVOID Response;
471  ULONG ResponseSize = IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength;
472 
473  DPRINT("DriverIoControl. IOCTL_KMTEST_USERMODE_SEND_RESPONSE, inlen=%lu, outlen=%lu\n",
474  IoStackLocation->Parameters.DeviceIoControl.InputBufferLength,
475  IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength);
476 
477  if (IoStackLocation->Parameters.DeviceIoControl.InputBufferLength != sizeof(ULONG) || ResponseSize != sizeof(KMT_RESPONSE))
478  {
480  break;
481  }
482 
483  /* FIXME: don't misuse the output buffer as an input! */
485  if (Response == NULL)
486  {
488  break;
489  }
490 
491  ExAcquireFastMutex(&WorkList.Lock);
492 
494 
495  Entry = WorkList.ListHead.Flink;
496  while (Entry != &WorkList.ListHead)
497  {
498  WorkEntry = CONTAINING_RECORD(Entry, KMT_USER_WORK_ENTRY, ListEntry);
499  if (WorkEntry->Request.RequestId == *(PULONG)Irp->AssociatedIrp.SystemBuffer)
500  {
501  WorkEntry->Response = ExAllocatePoolWithTag(PagedPool, sizeof(KMT_RESPONSE), 'pseR');
502  if (WorkEntry->Response == NULL)
503  {
505  break;
506  }
507 
508  RtlCopyMemory(WorkEntry->Response, Response, ResponseSize);
511  break;
512  }
513 
514  Entry = Entry->Flink;
515  }
516 
517  ExReleaseFastMutex(&WorkList.Lock);
518 
519  break;
520  }
521  default:
522  DPRINT1("DriverIoControl. Invalid IoCtl code 0x%08X\n",
523  IoStackLocation->Parameters.DeviceIoControl.IoControlCode);
525  break;
526  }
527 
528  Irp->IoStatus.Status = Status;
529  Irp->IoStatus.Information = Length;
530 
532 
533  return Status;
534 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
NTSYSAPI LONG NTAPI RtlCompareString(PSTRING String1, PSTRING String2, BOOLEAN CaseInSensitive)
#define STATUS_OBJECTID_NOT_FOUND
Definition: ntstatus.h:846
struct _Entry Entry
Definition: kefuncs.h:640
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
NTSTRSAFEAPI RtlStringCbCopyExA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ NTSTRSAFE_PCSTR pszSrc, _Outptr_opt_result_bytebuffer_(*pcbRemaining) STRSAFE_LPSTR *ppszDestEnd, _Out_opt_ size_t *pcbRemaining, _In_ STRSAFE_DWORD dwFlags)
Definition: ntstrsafe.h:270
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
VOID NTAPI MmUnlockPages(IN PMDL Mdl)
Definition: mdlsup.c:1439
char * LPSTR
Definition: xmlstorage.h:182
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
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
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define PAGED_CODE()
Definition: video.h:57
_SEH2_TRY
Definition: create.c:4250
NTSYSAPI VOID NTAPI RtlInitAnsiString(PANSI_STRING DestinationString, PCSZ SourceString)
#define USHRT_MAX
Definition: limits.h:38
static void TestEntry(const ENTRY *pEntry)
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
#define STATUS_KERNEL_APC
Definition: ntstatus.h:79
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
EH_STD::__list__< TestClass, eh_allocator(TestClass) > TestList
Definition: test_list.cpp:31
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:636
#define IOCTL_KMTEST_USERMODE_SEND_RESPONSE
Definition: kmt_public.h:22
USHORT MaximumLength
Definition: env_spec_w32.h:377
LONG LogBufferMaxLength
Definition: kmt_test.h:40
KEVENT WorkDoneEvent
Definition: kmtest_drv.c:27
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
Definition: ncftp.h:89
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Definition: typedefs.h:117
volatile LONG Failures
Definition: kmt_test.h:37
Status
Definition: gdiplustypes.h:24
Definition: kmtest_drv.c:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define STATUS_USER_APC
Definition: ntstatus.h:78
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define IOCTL_KMTEST_GET_TESTS
Definition: kmt_public.h:13
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
ULONG_PTR SIZE_T
Definition: typedefs.h:78
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
unsigned short USHORT
Definition: pedump.c:61
#define IOCTL_KMTEST_SET_RESULTBUFFER
Definition: kmt_public.h:19
#define STATUS_OBJECT_NAME_INVALID
Definition: udferr_usr.h:148
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
volatile LONG Successes
Definition: kmt_test.h:36
volatile LONG LogBufferLength
Definition: kmt_test.h:39
PKMT_RESPONSE Response
Definition: kmtest_drv.c:29
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
struct Response Response
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
KMT_CALLBACK_REQUEST_PACKET Request
Definition: kmtest_drv.c:28
#define IOCTL_KMTEST_RUN_TEST
Definition: kmt_public.h:16
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
return STATUS_SUCCESS
Definition: btrfs.c:2938
PKMT_RESULTBUFFER ResultBuffer
base of all file and directory entries
Definition: entries.h:82
#define IOCTL_KMTEST_USERMODE_AWAIT_REQ
Definition: kmt_public.h:25

◆ DriverUnload()

static VOID NTAPI DriverUnload ( IN PDRIVER_OBJECT  DriverObject)
static

Definition at line 141 of file kmtest_drv.c.

143 {
144  PAGED_CODE();
145 
147 
148  DPRINT("DriverUnload\n");
149 
151 
152  if (MainDeviceObject)
153  {
154 #if DBG
155  PKMT_DEVICE_EXTENSION DeviceExtension = MainDeviceObject->DeviceExtension;
156  ASSERT(!DeviceExtension->Mdl);
157  ASSERT(!DeviceExtension->ResultBuffer);
158 #endif
161  }
162 }
static VOID KmtCleanUsermodeCallbacks(VOID)
Definition: kmtest_drv.c:621
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define PAGED_CODE()
Definition: video.h:57
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
void DPRINT(...)
Definition: polytest.cpp:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
static PDEVICE_OBJECT MainDeviceObject
PKMT_RESULTBUFFER ResultBuffer

◆ KmtCleanUsermodeCallbacks()

static VOID KmtCleanUsermodeCallbacks ( VOID  )
static

Definition at line 621 of file kmtest_drv.c.

622 {
624 
625  PAGED_CODE();
626 
627  ExAcquireFastMutex(&WorkList.Lock);
628 
629  Entry = WorkList.ListHead.Flink;
630  while (Entry != &WorkList.ListHead)
631  {
633  if (WorkEntry->Response != NULL)
634  {
635  KmtFreeCallbackResponse(WorkEntry->Response);
636  }
637 
638  Entry = Entry->Flink;
639 
640  ExFreePoolWithTag(WorkEntry, 'ekrW');
641  }
642 
643  ExReleaseFastMutex(&WorkList.Lock);
644 }
struct _Entry Entry
Definition: kefuncs.h:640
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define PAGED_CODE()
Definition: video.h:57
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
VOID KmtFreeCallbackResponse(PKMT_RESPONSE Response)
Definition: kmtest_drv.c:606
Definition: typedefs.h:117
Definition: kmtest_drv.c:24
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
PKMT_RESPONSE Response
Definition: kmtest_drv.c:29
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
base of all file and directory entries
Definition: entries.h:82

Referenced by DriverUnload().

◆ KmtFreeCallbackResponse()

VOID KmtFreeCallbackResponse ( PKMT_RESPONSE  Response)

Definition at line 606 of file kmtest_drv.c.

608 {
609  PAGED_CODE();
610 
611  ExFreePoolWithTag(Response, 'pseR');
612 }
#define PAGED_CODE()
Definition: video.h:57
Definition: ncftp.h:89
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by KmtCleanUsermodeCallbacks().

◆ KmtUserModeCallback()

PKMT_RESPONSE KmtUserModeCallback ( IN KMT_CALLBACK_INFORMATION_CLASS  Operation,
IN PVOID  Parameters 
)

Definition at line 551 of file kmtest_drv.c.

554 {
557  PKMT_USER_WORK_ENTRY WorkEntry;
559 
560  PAGED_CODE();
561 
562  WorkEntry = ExAllocatePoolWithTag(PagedPool, sizeof(KMT_USER_WORK_ENTRY), 'ekrW');
563  if (WorkEntry == NULL)
564  return NULL;
565 
567  WorkEntry->Request.RequestId = RequestId++;
568  WorkEntry->Request.OperationClass = Operation;
569  WorkEntry->Request.Parameters = Parameters;
570  WorkEntry->Response = NULL;
571 
572  ExAcquireFastMutex(&WorkList.Lock);
573  InsertTailList(&WorkList.ListHead, &WorkEntry->ListEntry);
574  ExReleaseFastMutex(&WorkList.Lock);
575 
576  KeSetEvent(&WorkList.NewWorkEvent, IO_NO_INCREMENT, FALSE);
577 
578  Timeout.QuadPart = -10 * 1000 * 1000 * 10; //wait for 10 seconds
580 
582  {
583  DPRINT1("Unexpected callback abortion! Reason: %lx\n", Status);
584  }
585 
586  ExAcquireFastMutex(&WorkList.Lock);
587  RemoveEntryList(&WorkEntry->ListEntry);
588  ExReleaseFastMutex(&WorkList.Lock);
589 
590  Result = WorkEntry->Response;
591 
592  ExFreePoolWithTag(WorkEntry, 'ekrW');
593 
594  return Result;
595 }
KMT_CALLBACK_INFORMATION_CLASS OperationClass
Definition: kmt_test.h:64
LONG NTSTATUS
Definition: precomp.h:26
#define InsertTailList(ListHead, Entry)
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
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31
#define PAGED_CODE()
Definition: video.h:57
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define STATUS_KERNEL_APC
Definition: ntstatus.h:79
KEVENT WorkDoneEvent
Definition: kmtest_drv.c:27
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
LIST_ENTRY ListEntry
Definition: kmtest_drv.c:26
Status
Definition: gdiplustypes.h:24
Definition: kmtest_drv.c:24
#define STATUS_USER_APC
Definition: ntstatus.h:78
static ULONG Timeout
Definition: ping.c:61
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23
PKMT_RESPONSE Response
Definition: kmtest_drv.c:29
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:566
_In_ FLT_SET_CONTEXT_OPERATION Operation
Definition: fltkernel.h:1468
KMT_CALLBACK_REQUEST_PACKET Request
Definition: kmtest_drv.c:28
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Variable Documentation

◆ DriverEntry

DRIVER_INITIALIZE DriverEntry

Definition at line 40 of file kmtest_drv.c.

◆ DriverUnload

DRIVER_UNLOAD DriverUnload
static

Definition at line 41 of file kmtest_drv.c.