prevent buffer overflow, LoadString accepts the size of the buffer in TCHARs, not...
[reactos.git] / reactos / drivers / dd / green / misc.c
1 /* $Id:
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS VT100 emulator
5 * FILE: drivers/dd/green/misc.c
6 * PURPOSE: Misceallenous operations
7 *
8 * PROGRAMMERS: Hervé Poussineau (hpoussin@reactos.com)
9 */
10
11 //#define NDEBUG
12 #include "green.h"
13
14 NTSTATUS
15 GreenDeviceIoControl(
16 IN PDEVICE_OBJECT DeviceObject,
17 IN ULONG CtlCode,
18 IN PVOID InputBuffer OPTIONAL,
19 IN ULONG InputBufferSize,
20 IN OUT PVOID OutputBuffer OPTIONAL,
21 IN OUT PULONG OutputBufferSize)
22 {
23 KEVENT Event;
24 PIRP Irp;
25 IO_STATUS_BLOCK IoStatus;
26 NTSTATUS Status;
27
28 KeInitializeEvent (&Event, NotificationEvent, FALSE);
29
30 Irp = IoBuildDeviceIoControlRequest(CtlCode,
31 DeviceObject,
32 InputBuffer,
33 InputBufferSize,
34 OutputBuffer,
35 (OutputBufferSize) ? *OutputBufferSize : 0,
36 FALSE,
37 &Event,
38 &IoStatus);
39 if (Irp == NULL)
40 {
41 DPRINT("Green: IoBuildDeviceIoControlRequest() failed\n");
42 return STATUS_INSUFFICIENT_RESOURCES;
43 }
44
45 Status = IoCallDriver(DeviceObject, Irp);
46
47 if (Status == STATUS_PENDING)
48 {
49 DPRINT("Green: Operation pending\n");
50 KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
51 Status = IoStatus.Status;
52 }
53
54 if (OutputBufferSize)
55 {
56 *OutputBufferSize = IoStatus.Information;
57 }
58
59 return Status;
60 }