VirtualBox

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

最後變更 在這個檔案從23891是 23430,由 vboxsync 提交於 16 年 前

Experiment with KeSetSystemAffinityThread instead of raising the IRQL to DISPATCH_LEVEL when running guest code. (potential problem case -> take note!)

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 24.3 KB
 
1/* $Id: SUPDrv-win.cpp 23430 2009-09-30 09:53:51Z 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.alldomusa.eu.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*******************************************************************************/
93RT_C_DECLS_BEGIN
94ULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath);
95RT_C_DECLS_END
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#ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
325 int rc = supdrvIOCtlFast(ulCmd, (unsigned)(uintptr_t)pIrp->UserBuffer /* VMCPU id */, pDevExt, pSession);
326#else
327# if 1 /* experiment */
328 /* Prevent Windows from rescheduling us to another CPU/core. */
329 KeSetSystemAffinityThread((KAFFINITY)1 << KeGetCurrentProcessorNumber());
330 int rc = supdrvIOCtlFast(ulCmd, (unsigned)(uintptr_t)pIrp->UserBuffer /* VMCPU id */, pDevExt, pSession);
331 KeSetSystmeAffinityThread(KeQueryActiveProcessors());
332# else /* old code */
333 /* Raise the IRQL to DISPATCH_LEVEL to prevent Windows from rescheduling us to another CPU/core. */
334 Assert(KeGetCurrentIrql() <= DISPATCH_LEVEL);
335 KIRQL oldIrql;
336 KeRaiseIrql(DISPATCH_LEVEL, &oldIrql);
337 int rc = supdrvIOCtlFast(ulCmd, (unsigned)(uintptr_t)pIrp->UserBuffer /* VMCPU id */, pDevExt, pSession);
338 KeLowerIrql(oldIrql);
339# endif
340#endif
341
342 /* Complete the I/O request. */
343 NTSTATUS rcNt = pIrp->IoStatus.Status = RT_SUCCESS(rc) ? STATUS_SUCCESS : STATUS_INVALID_PARAMETER;
344 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
345 return rcNt;
346 }
347
348 return VBoxDrvNtDeviceControlSlow(pDevExt, pSession, pIrp, pStack);
349}
350
351
352/**
353 * Worker for VBoxDrvNtDeviceControl that takes the slow IOCtl functions.
354 *
355 * @returns NT status code.
356 *
357 * @param pDevObj Device object.
358 * @param pSession The session.
359 * @param pIrp Request packet.
360 * @param pStack The stack location containing the DeviceControl parameters.
361 */
362static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack)
363{
364 NTSTATUS rcNt;
365 unsigned cbOut = 0;
366 int rc = 0;
367 dprintf2(("VBoxDrvNtDeviceControlSlow(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
368 pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
369 pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
370 pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
371
372#ifdef RT_ARCH_AMD64
373 /* Don't allow 32-bit processes to do any I/O controls. */
374 if (!IoIs32bitProcess(pIrp))
375#endif
376 {
377 /* Verify that it's a buffered CTL. */
378 if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
379 {
380 /* Verify that the sizes in the request header are correct. */
381 PSUPREQHDR pHdr = (PSUPREQHDR)pIrp->AssociatedIrp.SystemBuffer;
382 if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
383 && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cbIn
384 && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cbOut)
385 {
386 /*
387 * Do the job.
388 */
389 rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
390 if (!rc)
391 {
392 rcNt = STATUS_SUCCESS;
393 cbOut = pHdr->cbOut;
394 if (cbOut > pStack->Parameters.DeviceIoControl.OutputBufferLength)
395 {
396 cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength;
397 OSDBGPRINT(("VBoxDrvLinuxIOCtl: too much output! %#x > %#x; uCmd=%#x!\n",
398 pHdr->cbOut, cbOut, pStack->Parameters.DeviceIoControl.IoControlCode));
399 }
400 }
401 else
402 rcNt = STATUS_INVALID_PARAMETER;
403 dprintf2(("VBoxDrvNtDeviceControlSlow: returns %#x cbOut=%d rc=%#x\n", rcNt, cbOut, rc));
404 }
405 else
406 {
407 dprintf(("VBoxDrvNtDeviceControlSlow: Mismatching sizes (%#x) - Hdr=%#lx/%#lx Irp=%#lx/%#lx!\n",
408 pStack->Parameters.DeviceIoControl.IoControlCode,
409 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbIn : 0,
410 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbOut : 0,
411 pStack->Parameters.DeviceIoControl.InputBufferLength,
412 pStack->Parameters.DeviceIoControl.OutputBufferLength));
413 rcNt = STATUS_INVALID_PARAMETER;
414 }
415 }
416 else
417 {
418 dprintf(("VBoxDrvNtDeviceControlSlow: not buffered request (%#x) - not supported\n",
419 pStack->Parameters.DeviceIoControl.IoControlCode));
420 rcNt = STATUS_NOT_SUPPORTED;
421 }
422 }
423#ifdef RT_ARCH_AMD64
424 else
425 {
426 dprintf(("VBoxDrvNtDeviceControlSlow: WOW64 req - not supported\n"));
427 rcNt = STATUS_NOT_SUPPORTED;
428 }
429#endif
430
431 /* complete the request. */
432 pIrp->IoStatus.Status = rcNt;
433 pIrp->IoStatus.Information = cbOut;
434 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
435 return rcNt;
436}
437
438
439/**
440 * Internal Device I/O Control entry point, used for IDC.
441 *
442 * @param pDevObj Device object.
443 * @param pIrp Request packet.
444 */
445NTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
446{
447 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
448 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
449 PFILE_OBJECT pFileObj = pStack ? pStack->FileObject : NULL;
450 PSUPDRVSESSION pSession = pFileObj ? (PSUPDRVSESSION)pFileObj->FsContext : NULL;
451 NTSTATUS rcNt;
452 unsigned cbOut = 0;
453 int rc = 0;
454 dprintf2(("VBoxDrvNtInternalDeviceControl(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
455 pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
456 pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
457 pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
458
459/** @todo IDC on NT: figure when to create the session and that stuff... */
460
461 /* Verify that it's a buffered CTL. */
462 if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
463 {
464 /* Verify the pDevExt in the session. */
465 if ( ( !pSession
466 && pStack->Parameters.DeviceIoControl.IoControlCode == SUPDRV_IDC_REQ_CONNECT)
467 || ( VALID_PTR(pSession)
468 && pSession->pDevExt == pDevExt))
469 {
470 /* Verify that the size in the request header is correct. */
471 PSUPDRVIDCREQHDR pHdr = (PSUPDRVIDCREQHDR)pIrp->AssociatedIrp.SystemBuffer;
472 if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
473 && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cb
474 && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cb)
475 {
476 /*
477 * Do the job.
478 */
479 rc = supdrvIDC(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
480 if (!rc)
481 {
482 rcNt = STATUS_SUCCESS;
483 cbOut = pHdr->cb;
484 }
485 else
486 rcNt = STATUS_INVALID_PARAMETER;
487 dprintf2(("VBoxDrvNtInternalDeviceControl: returns %#x/rc=%#x\n", rcNt, rc));
488 }
489 else
490 {
491 dprintf(("VBoxDrvNtInternalDeviceControl: Mismatching sizes (%#x) - Hdr=%#lx Irp=%#lx/%#lx!\n",
492 pStack->Parameters.DeviceIoControl.IoControlCode,
493 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cb : 0,
494 pStack->Parameters.DeviceIoControl.InputBufferLength,
495 pStack->Parameters.DeviceIoControl.OutputBufferLength));
496 rcNt = STATUS_INVALID_PARAMETER;
497 }
498 }
499 else
500 rcNt = STATUS_NOT_SUPPORTED;
501 }
502 else
503 {
504 dprintf(("VBoxDrvNtInternalDeviceControl: not buffered request (%#x) - not supported\n",
505 pStack->Parameters.DeviceIoControl.IoControlCode));
506 rcNt = STATUS_NOT_SUPPORTED;
507 }
508
509 /* complete the request. */
510 pIrp->IoStatus.Status = rcNt;
511 pIrp->IoStatus.Information = cbOut;
512 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
513 return rcNt;
514}
515
516
517/**
518 * Stub function for functions we don't implemented.
519 *
520 * @returns STATUS_NOT_SUPPORTED
521 * @param pDevObj Device object.
522 * @param pIrp IRP.
523 */
524NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp)
525{
526 dprintf(("VBoxDrvNtNotSupportedStub\n"));
527 pDevObj = pDevObj;
528
529 pIrp->IoStatus.Information = 0;
530 pIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
531 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
532
533 return STATUS_NOT_SUPPORTED;
534}
535
536
537/**
538 * ExRegisterCallback handler for power events
539 *
540 * @param pCallbackContext User supplied parameter (pDevObj)
541 * @param pArgument1 First argument
542 * @param pArgument2 Second argument
543 */
544VOID _stdcall VBoxPowerDispatchCallback(PVOID pCallbackContext, PVOID pArgument1, PVOID pArgument2)
545{
546 PDEVICE_OBJECT pDevObj = (PDEVICE_OBJECT)pCallbackContext;
547
548 dprintf(("VBoxPowerDispatchCallback: %x %x\n", pArgument1, pArgument2));
549
550 /* Power change imminent? */
551 if ((unsigned)pArgument1 == PO_CB_SYSTEM_STATE_LOCK)
552 {
553 if ((unsigned)pArgument2 == 0)
554 dprintf(("VBoxPowerDispatchCallback: about to go into suspend mode!\n"));
555 else
556 dprintf(("VBoxPowerDispatchCallback: resumed!\n"));
557
558 /* Inform any clients that have registered themselves with IPRT. */
559 UNWIND_WRAP(RTPowerSignalEvent)(((unsigned)pArgument2 == 0) ? RTPOWEREVENT_SUSPEND : RTPOWEREVENT_RESUME);
560 }
561}
562
563
564/**
565 * Initializes any OS specific object creator fields.
566 */
567void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
568{
569 NOREF(pObj);
570 NOREF(pSession);
571}
572
573
574/**
575 * Checks if the session can access the object.
576 *
577 * @returns true if a decision has been made.
578 * @returns false if the default access policy should be applied.
579 *
580 * @param pObj The object in question.
581 * @param pSession The session wanting to access the object.
582 * @param pszObjName The object name, can be NULL.
583 * @param prc Where to store the result when returning true.
584 */
585bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
586{
587 NOREF(pObj);
588 NOREF(pSession);
589 NOREF(pszObjName);
590 NOREF(prc);
591 return false;
592}
593
594
595/**
596 * Force async tsc mode (stub).
597 */
598bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
599{
600 return false;
601}
602
603
604/**
605 * Converts a supdrv error code to an nt status code.
606 *
607 * @returns corresponding nt status code.
608 * @param rc supdrv error code (SUPDRV_ERR_* defines).
609 */
610static NTSTATUS VBoxDrvNtErr2NtStatus(int rc)
611{
612 switch (rc)
613 {
614 case 0: return STATUS_SUCCESS;
615 case SUPDRV_ERR_GENERAL_FAILURE: return STATUS_NOT_SUPPORTED;
616 case SUPDRV_ERR_INVALID_PARAM: return STATUS_INVALID_PARAMETER;
617 case SUPDRV_ERR_INVALID_MAGIC: return STATUS_UNKNOWN_REVISION;
618 case SUPDRV_ERR_INVALID_HANDLE: return STATUS_INVALID_HANDLE;
619 case SUPDRV_ERR_INVALID_POINTER: return STATUS_INVALID_ADDRESS;
620 case SUPDRV_ERR_LOCK_FAILED: return STATUS_NOT_LOCKED;
621 case SUPDRV_ERR_ALREADY_LOADED: return STATUS_IMAGE_ALREADY_LOADED;
622 case SUPDRV_ERR_PERMISSION_DENIED: return STATUS_ACCESS_DENIED;
623 case SUPDRV_ERR_VERSION_MISMATCH: return STATUS_REVISION_MISMATCH;
624 }
625
626 return STATUS_UNSUCCESSFUL;
627}
628
629
630
631/** @todo use the nocrt stuff? */
632int VBOXCALL mymemcmp(const void *pv1, const void *pv2, size_t cb)
633{
634 const uint8_t *pb1 = (const uint8_t *)pv1;
635 const uint8_t *pb2 = (const uint8_t *)pv2;
636 for (; cb > 0; cb--, pb1++, pb2++)
637 if (*pb1 != *pb2)
638 return *pb1 - *pb2;
639 return 0;
640}
641
642
643#if 0 /* See alternative in SUPDrvA-win.asm */
644/**
645 * Alternative version of SUPR0Printf for Windows.
646 *
647 * @returns 0.
648 * @param pszFormat The format string.
649 */
650SUPR0DECL(int) SUPR0Printf(const char *pszFormat, ...)
651{
652 va_list va;
653 char szMsg[512];
654
655 va_start(va, pszFormat);
656 size_t cch = RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
657 szMsg[sizeof(szMsg) - 1] = '\0';
658 va_end(va);
659
660 RTLogWriteDebugger(szMsg, cch);
661 return 0;
662}
663#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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