VirtualBox

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

Last change on this file since 12000 was 11814, checked in by vboxsync, 16 years ago

Initial commit of the NetFlt driver for Windows

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.4 KB
Line 
1/* $Id: SUPDrv-win.cpp 11814 2008-08-29 12:47:44Z 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 <VBox/log.h>
41
42
43/*******************************************************************************
44* Defined Constants And Macros *
45*******************************************************************************/
46/** The support service name. */
47#define SERVICE_NAME "VBoxDrv"
48/** Win32 Device name. */
49#define DEVICE_NAME "\\\\.\\VBoxDrv"
50/** NT Device name. */
51#define DEVICE_NAME_NT L"\\Device\\VBoxDrv"
52/** Win Symlink name. */
53#define DEVICE_NAME_DOS L"\\DosDevices\\VBoxDrv"
54/** The Pool tag (VBox). */
55#define SUPDRV_NT_POOL_TAG 'xoBV'
56
57
58/*******************************************************************************
59* Structures and Typedefs *
60*******************************************************************************/
61#if 0 //def RT_ARCH_AMD64
62typedef struct SUPDRVEXECMEM
63{
64 PMDL pMdl;
65 void *pvMapping;
66 void *pvAllocation;
67} SUPDRVEXECMEM, *PSUPDRVEXECMEM;
68#endif
69
70
71/*******************************************************************************
72* Internal Functions *
73*******************************************************************************/
74static void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj);
75static NTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp);
76static NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp);
77static NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
78static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack);
79static NTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp);
80static NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp);
81static NTSTATUS VBoxDrvNtErr2NtStatus(int rc);
82
83
84/*******************************************************************************
85* Exported Functions *
86*******************************************************************************/
87__BEGIN_DECLS
88ULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath);
89__END_DECLS
90
91
92/**
93 * Driver entry point.
94 *
95 * @returns appropriate status code.
96 * @param pDrvObj Pointer to driver object.
97 * @param pRegPath Registry base path.
98 */
99ULONG _stdcall DriverEntry(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath)
100{
101 NTSTATUS rc;
102 dprintf(("VBoxDrv::DriverEntry\n"));
103
104 /*
105 * Create device.
106 * (That means creating a device object and a symbolic link so the DOS
107 * subsystems (OS/2, win32, ++) can access the device.)
108 */
109 UNICODE_STRING DevName;
110 RtlInitUnicodeString(&DevName, DEVICE_NAME_NT);
111 PDEVICE_OBJECT pDevObj;
112 rc = IoCreateDevice(pDrvObj, sizeof(SUPDRVDEVEXT), &DevName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDevObj);
113 if (NT_SUCCESS(rc))
114 {
115 UNICODE_STRING DosName;
116 RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS);
117 rc = IoCreateSymbolicLink(&DosName, &DevName);
118 if (NT_SUCCESS(rc))
119 {
120 int vrc = RTR0Init(0);
121 if (RT_SUCCESS(rc))
122 {
123 /*
124 * Initialize the device extension.
125 */
126 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
127 memset(pDevExt, 0, sizeof(*pDevExt));
128
129 vrc = supdrvInitDevExt(pDevExt);
130 if (!vrc)
131 {
132 /*
133 * Setup the driver entry points in pDrvObj.
134 */
135 pDrvObj->DriverUnload = VBoxDrvNtUnload;
136 pDrvObj->MajorFunction[IRP_MJ_CREATE] = VBoxDrvNtCreate;
137 pDrvObj->MajorFunction[IRP_MJ_CLOSE] = VBoxDrvNtClose;
138 pDrvObj->MajorFunction[IRP_MJ_DEVICE_CONTROL] = VBoxDrvNtDeviceControl;
139//#if 0 /** @todo test IDC on windows. */
140 pDrvObj->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = VBoxDrvNtInternalDeviceControl;
141//#endif
142 pDrvObj->MajorFunction[IRP_MJ_READ] = VBoxDrvNtNotSupportedStub;
143 pDrvObj->MajorFunction[IRP_MJ_WRITE] = VBoxDrvNtNotSupportedStub;
144 /* more? */
145 dprintf(("VBoxDrv::DriverEntry returning STATUS_SUCCESS\n"));
146 return STATUS_SUCCESS;
147 }
148
149 dprintf(("supdrvInitDevExit failed with vrc=%d!\n", vrc));
150 rc = VBoxDrvNtErr2NtStatus(vrc);
151
152 IoDeleteSymbolicLink(&DosName);
153 RTR0Term();
154 }
155 else
156 {
157 dprintf(("RTR0Init failed with vrc=%d!\n", vrc));
158 rc = VBoxDrvNtErr2NtStatus(vrc);
159 }
160 }
161 else
162 dprintf(("IoCreateSymbolicLink failed with rc=%#x!\n", rc));
163
164 IoDeleteDevice(pDevObj);
165 }
166 else
167 dprintf(("IoCreateDevice failed with rc=%#x!\n", rc));
168
169 if (NT_SUCCESS(rc))
170 rc = STATUS_INVALID_PARAMETER;
171 dprintf(("VBoxDrv::DriverEntry returning %#x\n", rc));
172 return rc;
173}
174
175
176/**
177 * Unload the driver.
178 *
179 * @param pDrvObj Driver object.
180 */
181void _stdcall VBoxDrvNtUnload(PDRIVER_OBJECT pDrvObj)
182{
183 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDrvObj->DeviceObject->DeviceExtension;
184
185 dprintf(("VBoxDrvNtUnload at irql %d\n", KeGetCurrentIrql()));
186
187 /*
188 * We ASSUME that it's not possible to unload a driver with open handles.
189 * Start by deleting the symbolic link
190 */
191 UNICODE_STRING DosName;
192 RtlInitUnicodeString(&DosName, DEVICE_NAME_DOS);
193 NTSTATUS rc = IoDeleteSymbolicLink(&DosName);
194
195 /*
196 * Terminate the GIP page and delete the device extension.
197 */
198 supdrvDeleteDevExt(pDevExt);
199 RTR0Term();
200 IoDeleteDevice(pDrvObj->DeviceObject);
201}
202
203
204/**
205 * Create (i.e. Open) file entry point.
206 *
207 * @param pDevObj Device object.
208 * @param pIrp Request packet.
209 */
210NTSTATUS _stdcall VBoxDrvNtCreate(PDEVICE_OBJECT pDevObj, PIRP pIrp)
211{
212 dprintf(("VBoxDrvNtCreate\n"));
213 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
214 PFILE_OBJECT pFileObj = pStack->FileObject;
215 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
216
217 /*
218 * We are not remotely similar to a directory...
219 * (But this is possible.)
220 */
221 if (pStack->Parameters.Create.Options & FILE_DIRECTORY_FILE)
222 {
223 pIrp->IoStatus.Status = STATUS_NOT_A_DIRECTORY;
224 pIrp->IoStatus.Information = 0;
225 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
226 return STATUS_NOT_A_DIRECTORY;
227 }
228
229 /*
230 * Call common code for the rest.
231 */
232 pFileObj->FsContext = NULL;
233 PSUPDRVSESSION pSession;
234//#if 0 /** @todo check if this works, consider OBJ_KERNEL_HANDLE too. */
235 bool fUser = pIrp->RequestorMode != KernelMode;
236//#else
237 // bool fUser = true;
238//#endif
239 int rc = supdrvCreateSession(pDevExt, fUser, &pSession);
240 if (!rc)
241 pFileObj->FsContext = pSession;
242
243 NTSTATUS rcNt = pIrp->IoStatus.Status = VBoxDrvNtErr2NtStatus(rc);
244 pIrp->IoStatus.Information = 0;
245 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
246
247 return rcNt;
248}
249
250
251/**
252 * Close file entry point.
253 *
254 * @param pDevObj Device object.
255 * @param pIrp Request packet.
256 */
257NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp)
258{
259 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
260 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
261 PFILE_OBJECT pFileObj = pStack->FileObject;
262 dprintf(("VBoxDrvNtClose: pDevExt=%p pFileObj=%p pSession=%p\n",
263 pDevExt, pFileObj, pFileObj->FsContext));
264 supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext);
265 pFileObj->FsContext = NULL;
266 pIrp->IoStatus.Information = 0;
267 pIrp->IoStatus.Status = STATUS_SUCCESS;
268 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
269
270 return STATUS_SUCCESS;
271}
272
273
274/**
275 * Device I/O Control entry point.
276 *
277 * @param pDevObj Device object.
278 * @param pIrp Request packet.
279 */
280NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
281{
282 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
283 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
284 PSUPDRVSESSION pSession = (PSUPDRVSESSION)pStack->FileObject->FsContext;
285
286 /*
287 * Deal with the two high-speed IOCtl that takes it's arguments from
288 * the session and iCmd, and only returns a VBox status code.
289 *
290 * Note: The previous method of returning the rc prior to IOC version
291 * 7.4 has been abandond, we're no longer compatible with that
292 * interface.
293 */
294 ULONG ulCmd = pStack->Parameters.DeviceIoControl.IoControlCode;
295 if ( ulCmd == SUP_IOCTL_FAST_DO_RAW_RUN
296 || ulCmd == SUP_IOCTL_FAST_DO_HWACC_RUN
297 || ulCmd == SUP_IOCTL_FAST_DO_NOP)
298 {
299 /* Raise the IRQL to DISPATCH_LEVEl to prevent Windows from rescheduling us to another CPU/core. */
300 Assert(KeGetCurrentIrql() <= DISPATCH_LEVEL);
301 KIRQL oldIrql;
302 KeRaiseIrql(DISPATCH_LEVEL, &oldIrql);
303 int rc = supdrvIOCtlFast(ulCmd, pDevExt, pSession);
304 KeLowerIrql(oldIrql);
305
306 /* Complete the I/O request. */
307 NTSTATUS rcNt = pIrp->IoStatus.Status = RT_SUCCESS(rc) ? STATUS_SUCCESS : STATUS_INVALID_PARAMETER;
308 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
309 return rcNt;
310 }
311
312 return VBoxDrvNtDeviceControlSlow(pDevExt, pSession, pIrp, pStack);
313}
314
315
316/**
317 * Worker for VBoxDrvNtDeviceControl that takes the slow IOCtl functions.
318 *
319 * @returns NT status code.
320 *
321 * @param pDevObj Device object.
322 * @param pSession The session.
323 * @param pIrp Request packet.
324 * @param pStack The stack location containing the DeviceControl parameters.
325 */
326static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack)
327{
328 NTSTATUS rcNt;
329 unsigned cbOut = 0;
330 int rc = 0;
331 dprintf2(("VBoxDrvNtDeviceControlSlow(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
332 pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
333 pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
334 pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
335
336#ifdef RT_ARCH_AMD64
337 /* Don't allow 32-bit processes to do any I/O controls. */
338 if (!IoIs32bitProcess(pIrp))
339#endif
340 {
341 /* Verify that it's a buffered CTL. */
342 if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
343 {
344 /* Verify that the sizes in the request header are correct. */
345 PSUPREQHDR pHdr = (PSUPREQHDR)pIrp->AssociatedIrp.SystemBuffer;
346 if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
347 && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cbIn
348 && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cbOut)
349 {
350 /*
351 * Do the job.
352 */
353 rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
354 if (!rc)
355 {
356 rcNt = STATUS_SUCCESS;
357 cbOut = pHdr->cbOut;
358 if (cbOut > pStack->Parameters.DeviceIoControl.OutputBufferLength)
359 {
360 cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength;
361 OSDBGPRINT(("VBoxDrvLinuxIOCtl: too much output! %#x > %#x; uCmd=%#x!\n",
362 pHdr->cbOut, cbOut, pStack->Parameters.DeviceIoControl.IoControlCode));
363 }
364 }
365 else
366 rcNt = STATUS_INVALID_PARAMETER;
367 dprintf2(("VBoxDrvNtDeviceControlSlow: returns %#x cbOut=%d rc=%#x\n", rcNt, cbOut, rc));
368 }
369 else
370 {
371 dprintf(("VBoxDrvNtDeviceControlSlow: Mismatching sizes (%#x) - Hdr=%#lx/%#lx Irp=%#lx/%#lx!\n",
372 pStack->Parameters.DeviceIoControl.IoControlCode,
373 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbIn : 0,
374 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbOut : 0,
375 pStack->Parameters.DeviceIoControl.InputBufferLength,
376 pStack->Parameters.DeviceIoControl.OutputBufferLength));
377 rcNt = STATUS_INVALID_PARAMETER;
378 }
379 }
380 else
381 {
382 dprintf(("VBoxDrvNtDeviceControlSlow: not buffered request (%#x) - not supported\n",
383 pStack->Parameters.DeviceIoControl.IoControlCode));
384 rcNt = STATUS_NOT_SUPPORTED;
385 }
386 }
387#ifdef RT_ARCH_AMD64
388 else
389 {
390 dprintf(("VBoxDrvNtDeviceControlSlow: WOW64 req - not supported\n"));
391 rcNt = STATUS_NOT_SUPPORTED;
392 }
393#endif
394
395 /* complete the request. */
396 pIrp->IoStatus.Status = rcNt;
397 pIrp->IoStatus.Information = cbOut;
398 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
399 return rcNt;
400}
401
402
403/**
404 * Internal Device I/O Control entry point, used for IDC.
405 *
406 * @param pDevObj Device object.
407 * @param pIrp Request packet.
408 */
409NTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
410{
411 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
412 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
413 PFILE_OBJECT pFileObj = pStack ? pStack->FileObject : NULL;
414 PSUPDRVSESSION pSession = pFileObj ? (PSUPDRVSESSION)pFileObj->FsContext : NULL;
415 NTSTATUS rcNt;
416 unsigned cbOut = 0;
417 int rc = 0;
418 dprintf2(("VBoxDrvNtInternalDeviceControl(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
419 pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
420 pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
421 pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
422
423/** @todo IDC on NT: figure when to create the session and that stuff... */
424
425 /* Verify that it's a buffered CTL. */
426 if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
427 {
428 /* Verify the pDevExt in the session. */
429 if ( ( !pSession
430 && pStack->Parameters.DeviceIoControl.IoControlCode == SUPDRV_IDC_REQ_CONNECT)
431 || ( VALID_PTR(pSession)
432 && pSession->pDevExt == pDevExt))
433 {
434 /* Verify that the size in the request header is correct. */
435 PSUPDRVIDCREQHDR pHdr = (PSUPDRVIDCREQHDR)pIrp->AssociatedIrp.SystemBuffer;
436 if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
437 && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cb
438 && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cb)
439 {
440 /*
441 * Do the job.
442 */
443 rc = supdrvIDC(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
444 if (!rc)
445 {
446 rcNt = STATUS_SUCCESS;
447 cbOut = pHdr->cb;
448 }
449 else
450 rcNt = STATUS_INVALID_PARAMETER;
451 dprintf2(("VBoxDrvNtInternalDeviceControl: returns %#x/rc=%#x\n", rcNt, rc));
452 }
453 else
454 {
455 dprintf(("VBoxDrvNtInternalDeviceControl: Mismatching sizes (%#x) - Hdr=%#lx Irp=%#lx/%#lx!\n",
456 pStack->Parameters.DeviceIoControl.IoControlCode,
457 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cb : 0,
458 pStack->Parameters.DeviceIoControl.InputBufferLength,
459 pStack->Parameters.DeviceIoControl.OutputBufferLength));
460 rcNt = STATUS_INVALID_PARAMETER;
461 }
462 }
463 else
464 rcNt = STATUS_NOT_SUPPORTED;
465 }
466 else
467 {
468 dprintf(("VBoxDrvNtInternalDeviceControl: not buffered request (%#x) - not supported\n",
469 pStack->Parameters.DeviceIoControl.IoControlCode));
470 rcNt = STATUS_NOT_SUPPORTED;
471 }
472
473 /* complete the request. */
474 pIrp->IoStatus.Status = rcNt;
475 pIrp->IoStatus.Information = cbOut;
476 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
477 return rcNt;
478}
479
480
481/**
482 * Stub function for functions we don't implemented.
483 *
484 * @returns STATUS_NOT_SUPPORTED
485 * @param pDevObj Device object.
486 * @param pIrp IRP.
487 */
488NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp)
489{
490 dprintf(("VBoxDrvNtNotSupportedStub\n"));
491 pDevObj = pDevObj;
492
493 pIrp->IoStatus.Information = 0;
494 pIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
495 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
496
497 return STATUS_NOT_SUPPORTED;
498}
499
500
501/**
502 * Initializes any OS specific object creator fields.
503 */
504void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
505{
506 NOREF(pObj);
507 NOREF(pSession);
508}
509
510
511/**
512 * Checks if the session can access the object.
513 *
514 * @returns true if a decision has been made.
515 * @returns false if the default access policy should be applied.
516 *
517 * @param pObj The object in question.
518 * @param pSession The session wanting to access the object.
519 * @param pszObjName The object name, can be NULL.
520 * @param prc Where to store the result when returning true.
521 */
522bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
523{
524 NOREF(pObj);
525 NOREF(pSession);
526 NOREF(pszObjName);
527 NOREF(prc);
528 return false;
529}
530
531
532/**
533 * Force async tsc mode (stub).
534 */
535bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
536{
537 return false;
538}
539
540
541/**
542 * Converts a supdrv error code to an nt status code.
543 *
544 * @returns corresponding nt status code.
545 * @param rc supdrv error code (SUPDRV_ERR_* defines).
546 */
547static NTSTATUS VBoxDrvNtErr2NtStatus(int rc)
548{
549 switch (rc)
550 {
551 case 0: return STATUS_SUCCESS;
552 case SUPDRV_ERR_GENERAL_FAILURE: return STATUS_NOT_SUPPORTED;
553 case SUPDRV_ERR_INVALID_PARAM: return STATUS_INVALID_PARAMETER;
554 case SUPDRV_ERR_INVALID_MAGIC: return STATUS_UNKNOWN_REVISION;
555 case SUPDRV_ERR_INVALID_HANDLE: return STATUS_INVALID_HANDLE;
556 case SUPDRV_ERR_INVALID_POINTER: return STATUS_INVALID_ADDRESS;
557 case SUPDRV_ERR_LOCK_FAILED: return STATUS_NOT_LOCKED;
558 case SUPDRV_ERR_ALREADY_LOADED: return STATUS_IMAGE_ALREADY_LOADED;
559 case SUPDRV_ERR_PERMISSION_DENIED: return STATUS_ACCESS_DENIED;
560 case SUPDRV_ERR_VERSION_MISMATCH: return STATUS_REVISION_MISMATCH;
561 }
562
563 return STATUS_UNSUCCESSFUL;
564}
565
566
567
568/** @todo move this to IPRT */
569RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
570{
571 DbgPrint("\n!!Assertion Failed!!\n"
572 "Expression: %s\n"
573 "Location : %s(%d) %s\n",
574 pszExpr, pszFile, uLine, pszFunction);
575}
576
577/** @todo use the nocrt stuff? */
578int VBOXCALL mymemcmp(const void *pv1, const void *pv2, size_t cb)
579{
580 const uint8_t *pb1 = (const uint8_t *)pv1;
581 const uint8_t *pb2 = (const uint8_t *)pv2;
582 for (; cb > 0; cb--, pb1++, pb2++)
583 if (*pb1 != *pb2)
584 return *pb1 - *pb2;
585 return 0;
586}
587
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