ReactOS  0.4.14-dev-384-g5b37caa
controller.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Kernel
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: ntoskrnl/io/iomgr/controller.c
5  * PURPOSE: I/O Wrappers (called Controllers) for Kernel Device Queues
6  * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7  */
8 
9 /* INCLUDES *****************************************************************/
10 
11 #include <ntoskrnl.h>
12 #include <debug.h>
13 
14 /* GLOBALS *******************************************************************/
15 
17 
18 /* FUNCTIONS *****************************************************************/
19 
20 /*
21  * @implemented
22  */
23 VOID
24 NTAPI
29 {
32 
33  /* Initialize the Wait Context Block */
34  DeviceObject->Queue.Wcb.DeviceContext = Context;
35  DeviceObject->Queue.Wcb.DeviceRoutine = ExecutionRoutine;
36 
37  /* Insert the Device Queue */
38  if (!KeInsertDeviceQueue(&ControllerObject->DeviceWaitQueue,
39  &DeviceObject->Queue.Wcb.WaitQueueEntry))
40  {
41  /* Call the execution routine */
43  DeviceObject->CurrentIrp,
44  NULL,
45  Context);
46 
47  /* Free the controller if this was requested */
48  if (Result == DeallocateObject) IoFreeController(ControllerObject);
49  }
50 }
51 
52 /*
53  * @implemented
54  */
56 NTAPI
58 {
59  PCONTROLLER_OBJECT Controller;
61  HANDLE Handle;
63  PAGED_CODE();
64 
65  /* Initialize an empty OBA */
67  NULL,
69  NULL,
70  NULL);
71 
72  /* Create the Object */
76  KernelMode,
77  NULL,
78  sizeof(CONTROLLER_OBJECT) + Size,
79  0,
80  0,
81  (PVOID*)&Controller);
82  if (!NT_SUCCESS(Status)) return NULL;
83 
84  /* Insert it */
85  Status = ObInsertObject(Controller,
86  NULL,
88  1,
89  (PVOID*)&Controller,
90  &Handle);
91  if (!NT_SUCCESS(Status)) return NULL;
92 
93  /* Close the dummy handle */
95 
96  /* Zero the Object and set its data */
97  RtlZeroMemory(Controller, sizeof(CONTROLLER_OBJECT) + Size);
98  Controller->Type = IO_TYPE_CONTROLLER;
99  Controller->Size = sizeof(CONTROLLER_OBJECT) + (CSHORT)Size;
100  Controller->ControllerExtension = (Controller + 1);
101 
102  /* Initialize its Queue */
103  KeInitializeDeviceQueue(&Controller->DeviceWaitQueue);
104 
105  /* Return Controller */
106  return Controller;
107 }
108 
109 /*
110  * @implemented
111  */
112 VOID
113 NTAPI
115 {
116  /* Just Dereference it */
117  ObDereferenceObject(ControllerObject);
118 }
119 
120 /*
121  * @implemented
122  */
123 VOID
124 NTAPI
126 {
127  PKDEVICE_QUEUE_ENTRY QueueEntry;
130 
131  /* Remove the Queue */
132  QueueEntry = KeRemoveDeviceQueue(&ControllerObject->DeviceWaitQueue);
133  if (QueueEntry)
134  {
135  /* Get the Device Object */
136  DeviceObject = CONTAINING_RECORD(QueueEntry,
138  Queue.Wcb.WaitQueueEntry);
139 
140  /* Call the routine */
141  Result = DeviceObject->Queue.Wcb.DeviceRoutine(DeviceObject,
142  DeviceObject->CurrentIrp,
143  NULL,
144  DeviceObject->
145  Queue.Wcb.DeviceContext);
146  /* Free the controller if this was requested */
147  if (Result == DeallocateObject) IoFreeController(ControllerObject);
148  }
149 }
150 
151 /* EOF */
enum _IO_ALLOCATION_ACTION IO_ALLOCATION_ACTION
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
#define IN
Definition: typedefs.h:38
#define ASSERT_IRQL_EQUAL(x)
Definition: debug.h:43
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI KeInitializeDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
Definition: devqueue.c:22
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define PAGED_CODE()
Definition: video.h:57
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FILE_READ_DATA
Definition: nt_native.h:628
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI IoAllocateController(IN PCONTROLLER_OBJECT ControllerObject, IN PDEVICE_OBJECT DeviceObject, IN PDRIVER_CONTROL ExecutionRoutine, IN PVOID Context)
Definition: controller.c:25
_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
POBJECT_TYPE IoControllerObjectType
Definition: controller.c:16
#define FILE_WRITE_DATA
Definition: nt_native.h:631
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
NTSTATUS NTAPI ObCreateObject(IN KPROCESSOR_MODE ProbeMode OPTIONAL, IN POBJECT_TYPE Type, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN KPROCESSOR_MODE AccessMode, IN OUT PVOID ParseContext OPTIONAL, IN ULONG ObjectSize, IN ULONG PagedPoolCharge OPTIONAL, IN ULONG NonPagedPoolCharge OPTIONAL, OUT PVOID *Object)
Definition: oblife.c:952
_In_ HANDLE Handle
Definition: extypes.h:390
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IO_TYPE_CONTROLLER
struct _CONTROLLER_OBJECT CONTROLLER_OBJECT
BOOLEAN NTAPI KeInsertDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue, IN PKDEVICE_QUEUE_ENTRY DeviceQueueEntry)
Definition: devqueue.c:41
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3376
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
NTSTATUS NTAPI ObInsertObject(IN PVOID Object, IN PACCESS_STATE AccessState OPTIONAL, IN ACCESS_MASK DesiredAccess, IN ULONG ObjectPointerBias, OUT PVOID *NewObject OPTIONAL, OUT PHANDLE Handle)
Definition: obhandle.c:2932
PCONTROLLER_OBJECT NTAPI IoCreateController(IN ULONG Size)
Definition: controller.c:57
Definition: ketypes.h:566
PKDEVICE_QUEUE_ENTRY NTAPI KeRemoveDeviceQueue(IN PKDEVICE_QUEUE DeviceQueue)
Definition: devqueue.c:153
VOID NTAPI IoDeleteController(IN PCONTROLLER_OBJECT ControllerObject)
Definition: controller.c:114
VOID NTAPI IoFreeController(IN PCONTROLLER_OBJECT ControllerObject)
Definition: controller.c:125
_In_ PDEVICE_OBJECT _In_ ULONG _In_ PDRIVER_CONTROL ExecutionRoutine
Definition: iofuncs.h:1393
struct tagContext Context
Definition: acpixf.h:1030
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
DRIVER_CONTROL * PDRIVER_CONTROL
Definition: iotypes.h:192
short CSHORT
Definition: umtypes.h:127
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231