VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/win/SUPDrv-win.cpp@ 19866

Last change on this file since 19866 was 18478, checked in by vboxsync, 16 years ago

SUPDrv-win.c: uintptr_t warning.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.8 KB
Line 
1/* $Id: SUPDrv-win.cpp 18478 2009-03-29 00:59:19Z vboxsync $ */
2/** @file
3 * VBoxDrv - The VirtualBox Support Driver - Windows NT specifics.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#define LOG_GROUP LOG_GROUP_SUP_DRV
35#include "../SUPDrvInternal.h"
36#include <excpt.h>
37#include <iprt/assert.h>
38#include <iprt/process.h>
39#include <iprt/initterm.h>
40#include <iprt/power.h>
41#include <VBox/log.h>
42
43
44/*******************************************************************************
45* Defined Constants And Macros *
46*******************************************************************************/
47/** The support service name. */
48#define SERVICE_NAME "VBoxDrv"
49/** Win32 Device name. */
50#define DEVICE_NAME "\\\\.\\VBoxDrv"
51/** NT Device name. */
52#define DEVICE_NAME_NT L"\\Device\\VBoxDrv"
53/** Win Symlink name. */
54#define DEVICE_NAME_DOS L"\\DosDevices\\VBoxDrv"
55/** The Pool tag (VBox). */
56#define SUPDRV_NT_POOL_TAG 'xoBV'
57
58
59/*******************************************************************************
60* Structures and Typedefs *
61*******************************************************************************/
62#if 0 //def RT_ARCH_AMD64
63typedef struct SUPDRVEXECMEM
64{
65 PMDL pMdl;
66 void *pvMapping;
67 void *pvAllocation;
68} SUPDRVEXECMEM, *PSUPDRVEXECMEM;
69#endif
70
71
72/*******************************************************************************
73* Internal Functions *
74*******************************************************************************/
75static void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj);
76static NTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp);
77static NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp);
78static NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
79static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack);
80static NTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
81static VOID _stdcall VBoxPowerDispatchCallback(PVOID pCallbackContext, PVOID pArgument1, PVOID pArgument2);
82static NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp);
83static NTSTATUS VBoxDrvNtErr2NtStatus(int rc);
84
85/*******************************************************************************
86* External Functions *
87*******************************************************************************/
88DECLASM(int) UNWIND_WRAP(RTPowerSignalEvent)(RTPOWEREVENT enmEvent);
89
90/*******************************************************************************
91* Exported Functions *
92*******************************************************************************/
93__BEGIN_DECLS
94ULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath);
95__END_DECLS
96
97
98/**
99 * Driver entry point.
100 *
101 * @returns appropriate status code.
102 * @param pDrvObj Pointer to driver object.
103 * @param pRegPath Registry base path.
104 */
105ULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath)
106{
107 NTSTATUS rc;
108 dprintf(("VBoxDrv::DriverEntry\n"));
109
110 /*
111 * Create device.
112 * (That means creating a device object and a symbolic link so the DOS
113 * subsystems (OS/2, win32, ++) can access the device.)
114 */
115 UNICODE_STRING DevName;
116 RtlInitUnicodeString(&DevName, DEVICE_NAME_NT);
117 PDEVICE_OBJECT pDevObj;
118 rc = IoCreateDevice(pDrvObj, sizeof(SUPDRVDEVEXT), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDevObj);
119 if (NT_SUCCESS(rc))
120 {
121 UNICODE_STRING DosName;
122 RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS);
123 rc = IoCreateSymbolicLink(&DosName, &DevName);
124 if (NT_SUCCESS(rc))
125 {
126 int vrc = RTR0Init(0);
127 if (RT_SUCCESS(rc))
128 {
129 /*
130 * Initialize the device extension.
131 */
132 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
133 memset(pDevExt, 0, sizeof(*pDevExt));
134
135 vrc = supdrvInitDevExt(pDevExt);
136 if (!vrc)
137 {
138 /*
139 * Setup the driver entry points in pDrvObj.
140 */
141 pDrvObj->DriverUnload = VBoxDrvNtUnload;
142 pDrvObj->MajorFunction[IRP_MJ_CREATE] = VBoxDrvNtCreate;
143 pDrvObj->MajorFunction[IRP_MJ_CLOSE] = VBoxDrvNtClose;
144 pDrvObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VBoxDrvNtDeviceControl;
145//#if 0 /** @todo test IDC on windows. */
146 pDrvObj->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = VBoxDrvNtInternalDeviceControl;
147//#endif
148 pDrvObj->MajorFunction[IRP_MJ_READ] = VBoxDrvNtNotSupportedStub;
149 pDrvObj->MajorFunction[IRP_MJ_WRITE] = VBoxDrvNtNotSupportedStub;
150
151 /* more? */
152
153 /* Register ourselves for power state changes. */
154 UNICODE_STRING CallbackName;
155 OBJECT_ATTRIBUTES Attr;
156
157 RtlInitUnicodeString(&CallbackName, L"\\Callback\\PowerState");
158 InitializeObjectAttributes(&Attr, &CallbackName, OBJ_CASE_INSENSITIVE, NULL, NULL);
159
160 rc = ExCreateCallback(&pDevExt->pObjPowerCallback, &Attr, TRUE, TRUE);
161 if (rc == STATUS_SUCCESS)
162 pDevExt->hPowerCallback = ExRegisterCallback(pDevExt->pObjPowerCallback, VBoxPowerDispatchCallback, pDevObj);
163
164 dprintf(("VBoxDrv::DriverEntry returning STATUS_SUCCESS\n"));
165 return STATUS_SUCCESS;
166 }
167
168 dprintf(("supdrvInitDevExit failed with vrc=%d!\n", vrc));
169 rc = VBoxDrvNtErr2NtStatus(vrc);
170
171 IoDeleteSymbolicLink(&DosName);
172 RTR0Term();
173 }
174 else
175 {
176 dprintf(("RTR0Init failed with vrc=%d!\n", vrc));
177 rc = VBoxDrvNtErr2NtStatus(vrc);
178 }
179 }
180 else
181 dprintf(("IoCreateSymbolicLink failed with rc=%#x!\n", rc));
182
183 IoDeleteDevice(pDevObj);
184 }
185 else
186 dprintf(("IoCreateDevice failed with rc=%#x!\n", rc));
187
188 if (NT_SUCCESS(rc))
189 rc = STATUS_INVALID_PARAMETER;
190 dprintf(("VBoxDrv::DriverEntry returning %#x\n", rc));
191 return rc;
192}
193
194
195/**
196 * Unload the driver.
197 *
198 * @param pDrvObj Driver object.
199 */
200void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj)
201{
202 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDrvObj->DeviceObject->DeviceExtension;
203
204 dprintf(("VBoxDrvNtUnload at irql %d\n", KeGetCurrentIrql()));
205
206 /* Clean up the power callback registration. */
207 if (pDevExt->hPowerCallback)
208 ExUnregisterCallback(pDevExt->hPowerCallback);
209 if (pDevExt->pObjPowerCallback)
210 ObDereferenceObject(pDevExt->pObjPowerCallback);
211
212 /*
213 * We ASSUME that it's not possible to unload a driver with open handles.
214 * Start by deleting the symbolic link
215 */
216 UNICODE_STRING DosName;
217 RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS);
218 NTSTATUS rc = IoDeleteSymbolicLink(&DosName);
219
220 /*
221 * Terminate the GIP page and delete the device extension.
222 */
223 supdrvDeleteDevExt(pDevExt);
224 RTR0Term();
225 IoDeleteDevice(pDrvObj->DeviceObject);
226}
227
228
229/**
230 * Create (i.e. Open) file entry point.
231 *
232 * @param pDevObj Device object.
233 * @param pIrp Request packet.
234 */
235NTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp)
236{
237 dprintf(("VBoxDrvNtCreate\n"));
238 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
239 PFILE_OBJECT pFileObj = pStack->FileObject;
240 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
241
242 /*
243 * We are not remotely similar to a directory...
244 * (But this is possible.)
245 */
246 if (pStack->Parameters.Create.Options & FILE_DIRECTORY_FILE)
247 {
248 pIrp->IoStatus.Status = STATUS_NOT_A_DIRECTORY;
249 pIrp->IoStatus.Information = 0;
250 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
251 return STATUS_NOT_A_DIRECTORY;
252 }
253
254 /*
255 * Call common code for the rest.
256 */
257 pFileObj->FsContext = NULL;
258 PSUPDRVSESSION pSession;
259//#if 0 /** @todo check if this works, consider OBJ_KERNEL_HANDLE too. */
260 bool fUser = pIrp->RequestorMode != KernelMode;
261//#else
262 // bool fUser = true;
263//#endif
264 int rc = supdrvCreateSession(pDevExt, fUser, &pSession);
265 if (!rc)
266 pFileObj->FsContext = pSession;
267
268 NTSTATUS rcNt = pIrp->IoStatus.Status = VBoxDrvNtErr2NtStatus(rc);
269 pIrp->IoStatus.Information = 0;
270 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
271
272 return rcNt;
273}
274
275
276/**
277 * Close file entry point.
278 *
279 * @param pDevObj Device object.
280 * @param pIrp Request packet.
281 */
282NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp)
283{
284 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
285 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
286 PFILE_OBJECT pFileObj = pStack->FileObject;
287 dprintf(("VBoxDrvNtClose: pDevExt=%p pFileObj=%p pSession=%p\n",
288 pDevExt, pFileObj, pFileObj->FsContext));
289 supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext);
290 pFileObj->FsContext = NULL;
291 pIrp->IoStatus.Information = 0;
292 pIrp->IoStatus.Status = STATUS_SUCCESS;
293 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
294
295 return STATUS_SUCCESS;
296}
297
298
299/**
300 * Device I/O Control entry point.
301 *
302 * @param pDevObj Device object.
303 * @param pIrp Request packet.
304 */
305NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
306{
307 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
308 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
309 PSUPDRVSESSION pSession = (PSUPDRVSESSION)pStack->FileObject->FsContext;
310
311 /*
312 * Deal with the two high-speed IOCtl that takes it's arguments from
313 * the session and iCmd, and only returns a VBox status code.
314 *
315 * Note: The previous method of returning the rc prior to IOC version
316 * 7.4 has been abandond, we're no longer compatible with that
317 * interface.
318 */
319 ULONG ulCmd = pStack->Parameters.DeviceIoControl.IoControlCode;
320 if ( ulCmd == SUP_IOCTL_FAST_DO_RAW_RUN
321 || ulCmd == SUP_IOCTL_FAST_DO_HWACC_RUN
322 || ulCmd == SUP_IOCTL_FAST_DO_NOP)
323 {
324 /* Raise the IRQL to DISPATCH_LEVEl to prevent Windows from rescheduling us to another CPU/core. */
325 Assert(KeGetCurrentIrql() <= DISPATCH_LEVEL);
326 KIRQL oldIrql;
327 KeRaiseIrql(DISPATCH_LEVEL, &oldIrql);
328 int rc = supdrvIOCtlFast(ulCmd, (unsigned)(uintptr_t)pIrp->UserBuffer /* VMCPU id */, pDevExt, pSession);
329 KeLowerIrql(oldIrql);
330
331 /* Complete the I/O request. */
332 NTSTATUS rcNt = pIrp->IoStatus.Status = RT_SUCCESS(rc) ? STATUS_SUCCESS : STATUS_INVALID_PARAMETER;
333 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
334 return rcNt;
335 }
336
337 return VBoxDrvNtDeviceControlSlow(pDevExt, pSession, pIrp, pStack);
338}
339
340
341/**
342 * Worker for VBoxDrvNtDeviceControl that takes the slow IOCtl functions.
343 *
344 * @returns NT status code.
345 *
346 * @param pDevObj Device object.
347 * @param pSession The session.
348 * @param pIrp Request packet.
349 * @param pStack The stack location containing the DeviceControl parameters.
350 */
351static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack)
352{
353 NTSTATUS rcNt;
354 unsigned cbOut = 0;
355 int rc = 0;
356 dprintf2(("VBoxDrvNtDeviceControlSlow(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
357 pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
358 pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
359 pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
360
361#ifdef RT_ARCH_AMD64
362 /* Don't allow 32-bit processes to do any I/O controls. */
363 if (!IoIs32bitProcess(pIrp))
364#endif
365 {
366 /* Verify that it's a buffered CTL. */
367 if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
368 {
369 /* Verify that the sizes in the request header are correct. */
370 PSUPREQHDR pHdr = (PSUPREQHDR)pIrp->AssociatedIrp.SystemBuffer;
371 if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
372 && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cbIn
373 && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cbOut)
374 {
375 /*
376 * Do the job.
377 */
378 rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
379 if (!rc)
380 {
381 rcNt = STATUS_SUCCESS;
382 cbOut = pHdr->cbOut;
383 if (cbOut > pStack->Parameters.DeviceIoControl.OutputBufferLength)
384 {
385 cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength;
386 OSDBGPRINT(("VBoxDrvLinuxIOCtl: too much output! %#x > %#x; uCmd=%#x!\n",
387 pHdr->cbOut, cbOut, pStack->Parameters.DeviceIoControl.IoControlCode));
388 }
389 }
390 else
391 rcNt = STATUS_INVALID_PARAMETER;
392 dprintf2(("VBoxDrvNtDeviceControlSlow: returns %#x cbOut=%d rc=%#x\n", rcNt, cbOut, rc));
393 }
394 else
395 {
396 dprintf(("VBoxDrvNtDeviceControlSlow: Mismatching sizes (%#x) - Hdr=%#lx/%#lx Irp=%#lx/%#lx!\n",
397 pStack->Parameters.DeviceIoControl.IoControlCode,
398 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbIn : 0,
399 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbOut : 0,
400 pStack->Parameters.DeviceIoControl.InputBufferLength,
401 pStack->Parameters.DeviceIoControl.OutputBufferLength));
402 rcNt = STATUS_INVALID_PARAMETER;
403 }
404 }
405 else
406 {
407 dprintf(("VBoxDrvNtDeviceControlSlow: not buffered request (%#x) - not supported\n",
408 pStack->Parameters.DeviceIoControl.IoControlCode));
409 rcNt = STATUS_NOT_SUPPORTED;
410 }
411 }
412#ifdef RT_ARCH_AMD64
413 else
414 {
415 dprintf(("VBoxDrvNtDeviceControlSlow: WOW64 req - not supported\n"));
416 rcNt = STATUS_NOT_SUPPORTED;
417 }
418#endif
419
420 /* complete the request. */
421 pIrp->IoStatus.Status = rcNt;
422 pIrp->IoStatus.Information = cbOut;
423 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
424 return rcNt;
425}
426
427
428/**
429 * Internal Device I/O Control entry point, used for IDC.
430 *
431 * @param pDevObj Device object.
432 * @param pIrp Request packet.
433 */
434NTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
435{
436 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
437 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
438 PFILE_OBJECT pFileObj = pStack ? pStack->FileObject : NULL;
439 PSUPDRVSESSION pSession = pFileObj ? (PSUPDRVSESSION)pFileObj->FsContext : NULL;
440 NTSTATUS rcNt;
441 unsigned cbOut = 0;
442 int rc = 0;
443 dprintf2(("VBoxDrvNtInternalDeviceControl(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
444 pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
445 pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
446 pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
447
448/** @todo IDC on NT: figure when to create the session and that stuff... */
449
450 /* Verify that it's a buffered CTL. */
451 if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
452 {
453 /* Verify the pDevExt in the session. */
454 if ( ( !pSession
455 && pStack->Parameters.DeviceIoControl.IoControlCode == SUPDRV_IDC_REQ_CONNECT)
456 || ( VALID_PTR(pSession)
457 && pSession->pDevExt == pDevExt))
458 {
459 /* Verify that the size in the request header is correct. */
460 PSUPDRVIDCREQHDR pHdr = (PSUPDRVIDCREQHDR)pIrp->AssociatedIrp.SystemBuffer;
461 if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
462 && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cb
463 && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cb)
464 {
465 /*
466 * Do the job.
467 */
468 rc = supdrvIDC(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
469 if (!rc)
470 {
471 rcNt = STATUS_SUCCESS;
472 cbOut = pHdr->cb;
473 }
474 else
475 rcNt = STATUS_INVALID_PARAMETER;
476 dprintf2(("VBoxDrvNtInternalDeviceControl: returns %#x/rc=%#x\n", rcNt, rc));
477 }
478 else
479 {
480 dprintf(("VBoxDrvNtInternalDeviceControl: Mismatching sizes (%#x) - Hdr=%#lx Irp=%#lx/%#lx!\n",
481 pStack->Parameters.DeviceIoControl.IoControlCode,
482 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cb : 0,
483 pStack->Parameters.DeviceIoControl.InputBufferLength,
484 pStack->Parameters.DeviceIoControl.OutputBufferLength));
485 rcNt = STATUS_INVALID_PARAMETER;
486 }
487 }
488 else
489 rcNt = STATUS_NOT_SUPPORTED;
490 }
491 else
492 {
493 dprintf(("VBoxDrvNtInternalDeviceControl: not buffered request (%#x) - not supported\n",
494 pStack->Parameters.DeviceIoControl.IoControlCode));
495 rcNt = STATUS_NOT_SUPPORTED;
496 }
497
498 /* complete the request. */
499 pIrp->IoStatus.Status = rcNt;
500 pIrp->IoStatus.Information = cbOut;
501 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
502 return rcNt;
503}
504
505
506/**
507 * Stub function for functions we don't implemented.
508 *
509 * @returns STATUS_NOT_SUPPORTED
510 * @param pDevObj Device object.
511 * @param pIrp IRP.
512 */
513NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp)
514{
515 dprintf(("VBoxDrvNtNotSupportedStub\n"));
516 pDevObj = pDevObj;
517
518 pIrp->IoStatus.Information = 0;
519 pIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
520 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
521
522 return STATUS_NOT_SUPPORTED;
523}
524
525
526/**
527 * ExRegisterCallback handler for power events
528 *
529 * @param pCallbackContext User supplied parameter (pDevObj)
530 * @param pArgument1 First argument
531 * @param pArgument2 Second argument
532 */
533VOID _stdcall VBoxPowerDispatchCallback(PVOID pCallbackContext, PVOID pArgument1, PVOID pArgument2)
534{
535 PDEVICE_OBJECT pDevObj = (PDEVICE_OBJECT)pCallbackContext;
536
537 dprintf(("VBoxPowerDispatchCallback: %x %x\n", pArgument1, pArgument2));
538
539 /* Power change imminent? */
540 if ((unsigned)pArgument1 == PO_CB_SYSTEM_STATE_LOCK)
541 {
542 if ((unsigned)pArgument2 == 0)
543 dprintf(("VBoxPowerDispatchCallback: about to go into suspend mode!\n"));
544 else
545 dprintf(("VBoxPowerDispatchCallback: resumed!\n"));
546
547 /* Inform any clients that have registered themselves with IPRT. */
548 UNWIND_WRAP(RTPowerSignalEvent)(((unsigned)pArgument2 == 0) ? RTPOWEREVENT_SUSPEND : RTPOWEREVENT_RESUME);
549 }
550}
551
552
553/**
554 * Initializes any OS specific object creator fields.
555 */
556void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
557{
558 NOREF(pObj);
559 NOREF(pSession);
560}
561
562
563/**
564 * Checks if the session can access the object.
565 *
566 * @returns true if a decision has been made.
567 * @returns false if the default access policy should be applied.
568 *
569 * @param pObj The object in question.
570 * @param pSession The session wanting to access the object.
571 * @param pszObjName The object name, can be NULL.
572 * @param prc Where to store the result when returning true.
573 */
574bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
575{
576 NOREF(pObj);
577 NOREF(pSession);
578 NOREF(pszObjName);
579 NOREF(prc);
580 return false;
581}
582
583
584/**
585 * Force async tsc mode (stub).
586 */
587bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
588{
589 return false;
590}
591
592
593/**
594 * Converts a supdrv error code to an nt status code.
595 *
596 * @returns corresponding nt status code.
597 * @param rc supdrv error code (SUPDRV_ERR_* defines).
598 */
599static NTSTATUS VBoxDrvNtErr2NtStatus(int rc)
600{
601 switch (rc)
602 {
603 case 0: return STATUS_SUCCESS;
604 case SUPDRV_ERR_GENERAL_FAILURE: return STATUS_NOT_SUPPORTED;
605 case SUPDRV_ERR_INVALID_PARAM: return STATUS_INVALID_PARAMETER;
606 case SUPDRV_ERR_INVALID_MAGIC: return STATUS_UNKNOWN_REVISION;
607 case SUPDRV_ERR_INVALID_HANDLE: return STATUS_INVALID_HANDLE;
608 case SUPDRV_ERR_INVALID_POINTER: return STATUS_INVALID_ADDRESS;
609 case SUPDRV_ERR_LOCK_FAILED: return STATUS_NOT_LOCKED;
610 case SUPDRV_ERR_ALREADY_LOADED: return STATUS_IMAGE_ALREADY_LOADED;
611 case SUPDRV_ERR_PERMISSION_DENIED: return STATUS_ACCESS_DENIED;
612 case SUPDRV_ERR_VERSION_MISMATCH: return STATUS_REVISION_MISMATCH;
613 }
614
615 return STATUS_UNSUCCESSFUL;
616}
617
618
619
620/** @todo use the nocrt stuff? */
621int VBOXCALL mymemcmp(const void *pv1, const void *pv2, size_t cb)
622{
623 const uint8_t *pb1 = (const uint8_t *)pv1;
624 const uint8_t *pb2 = (const uint8_t *)pv2;
625 for (; cb > 0; cb--, pb1++, pb2++)
626 if (*pb1 != *pb2)
627 return *pb1 - *pb2;
628 return 0;
629}
630
631
632#if 0 /* See alternative in SUPDrvA-win.asm */
633/**
634 * Alternative version of SUPR0Printf for Windows.
635 *
636 * @returns 0.
637 * @param pszFormat The format string.
638 */
639SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...)
640{
641 va_list va;
642 char szMsg[512];
643
644 va_start(va, pszFormat);
645 size_t cch = RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
646 szMsg[sizeof(szMsg) - 1] = '\0';
647 va_end(va);
648
649 RTLogWriteDebugger(szMsg, cch);
650 return 0;
651}
652#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette