VirtualBox

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

Last change on this file since 10301 was 10265, checked in by vboxsync, 17 years ago

Some more IDC code.

  • 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 10265 2008-07-05 00:47:50Z vboxsync $ */
2/** @file
3 * VirtualBox Support Driver - Windows NT specific parts.
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
33/*******************************************************************************
34* Header Files *
35*******************************************************************************/
36#include "../SUPDrvInternal.h"
37#include <excpt.h>
38#include <iprt/assert.h>
39#include <iprt/process.h>
40#include <iprt/initterm.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 int rc = supdrvCreateSession(pDevExt, &pSession);
235 if (!rc)
236 {
237 pSession->Uid = NIL_RTUID;
238 pSession->Gid = NIL_RTGID;
239 pSession->Process = RTProcSelf();
240 pSession->R0Process = RTR0ProcHandleSelf();
241 pFileObj->FsContext = pSession;
242 }
243
244 NTSTATUS rcNt = pIrp->IoStatus.Status = VBoxDrvNtErr2NtStatus(rc);
245 pIrp->IoStatus.Information = 0;
246 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
247
248 return rcNt;
249}
250
251
252/**
253 * Close file entry point.
254 *
255 * @param pDevObj Device object.
256 * @param pIrp Request packet.
257 */
258NTSTATUS _stdcall VBoxDrvNtClose(PDEVICE_OBJECT pDevObj, PIRP pIrp)
259{
260 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
261 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
262 PFILE_OBJECT pFileObj = pStack->FileObject;
263 dprintf(("VBoxDrvNtClose: pDevExt=%p pFileObj=%p pSession=%p\n",
264 pDevExt, pFileObj, pFileObj->FsContext));
265 supdrvCloseSession(pDevExt, (PSUPDRVSESSION)pFileObj->FsContext);
266 pFileObj->FsContext = NULL;
267 pIrp->IoStatus.Information = 0;
268 pIrp->IoStatus.Status = STATUS_SUCCESS;
269 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
270
271 return STATUS_SUCCESS;
272}
273
274
275/**
276 * Device I/O Control entry point.
277 *
278 * @param pDevObj Device object.
279 * @param pIrp Request packet.
280 */
281NTSTATUS _stdcall VBoxDrvNtDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
282{
283 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
284 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
285 PSUPDRVSESSION pSession = (PSUPDRVSESSION)pStack->FileObject->FsContext;
286
287 /*
288 * Deal with the two high-speed IOCtl that takes it's arguments from
289 * the session and iCmd, and only returns a VBox status code.
290 */
291 ULONG ulCmd = pStack->Parameters.DeviceIoControl.IoControlCode;
292 if ( ulCmd == SUP_IOCTL_FAST_DO_RAW_RUN
293 || ulCmd == SUP_IOCTL_FAST_DO_HWACC_RUN
294 || ulCmd == SUP_IOCTL_FAST_DO_NOP)
295 {
296 KIRQL oldIrql;
297 int rc;
298
299 /* Raise the IRQL to DISPATCH_LEVEl to prevent Windows from rescheduling us to another CPU/core. */
300 Assert(KeGetCurrentIrql() <= DISPATCH_LEVEL);
301 KeRaiseIrql(DISPATCH_LEVEL, &oldIrql);
302 rc = supdrvIOCtlFast(ulCmd, pDevExt, pSession);
303 KeLowerIrql(oldIrql);
304
305 /* Complete the I/O request. */
306 NTSTATUS rcNt = pIrp->IoStatus.Status = STATUS_SUCCESS;
307 pIrp->IoStatus.Information = sizeof(rc);
308 __try
309 {
310 *(int *)pIrp->UserBuffer = rc;
311 }
312 __except(EXCEPTION_EXECUTE_HANDLER)
313 {
314 rcNt = pIrp->IoStatus.Status = GetExceptionCode();
315 dprintf(("VBoxSupDrvDeviceContorl: Exception Code %#x\n", rcNt));
316 }
317 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
318 return rcNt;
319 }
320
321 return VBoxDrvNtDeviceControlSlow(pDevExt, pSession, pIrp, pStack);
322}
323
324
325/**
326 * Worker for VBoxDrvNtDeviceControl that takes the slow IOCtl functions.
327 *
328 * @returns NT status code.
329 *
330 * @param pDevObj Device object.
331 * @param pSession The session.
332 * @param pIrp Request packet.
333 * @param pStack The stack location containing the DeviceControl parameters.
334 */
335static int VBoxDrvNtDeviceControlSlow(PSUPDRVDEVEXT pDevExt, PSUPDRVSESSION pSession, PIRP pIrp, PIO_STACK_LOCATION pStack)
336{
337 NTSTATUS rcNt;
338 unsigned cbOut = 0;
339 int rc = 0;
340 dprintf2(("VBoxDrvNtDeviceControlSlow(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
341 pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
342 pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
343 pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
344
345#ifdef RT_ARCH_AMD64
346 /* Don't allow 32-bit processes to do any I/O controls. */
347 if (!IoIs32bitProcess(pIrp))
348#endif
349 {
350 /* Verify that it's a buffered CTL. */
351 if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
352 {
353 /* Verify that the sizes in the request header are correct. */
354 PSUPREQHDR pHdr = (PSUPREQHDR)pIrp->AssociatedIrp.SystemBuffer;
355 if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
356 && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cbIn
357 && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cbOut)
358 {
359 /*
360 * Do the job.
361 */
362 rc = supdrvIOCtl(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
363 if (!rc)
364 {
365 rcNt = STATUS_SUCCESS;
366 cbOut = pHdr->cbOut;
367 if (cbOut > pStack->Parameters.DeviceIoControl.OutputBufferLength)
368 {
369 cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength;
370 OSDBGPRINT(("VBoxDrvLinuxIOCtl: too much output! %#x > %#x; uCmd=%#x!\n",
371 pHdr->cbOut, cbOut, pStack->Parameters.DeviceIoControl.IoControlCode));
372 }
373 }
374 else
375 rcNt = STATUS_INVALID_PARAMETER;
376 dprintf2(("VBoxDrvNtDeviceControlSlow: returns %#x cbOut=%d rc=%#x\n", rcNt, cbOut, rc));
377 }
378 else
379 {
380 dprintf(("VBoxDrvNtDeviceControlSlow: Mismatching sizes (%#x) - Hdr=%#lx/%#lx Irp=%#lx/%#lx!\n",
381 pStack->Parameters.DeviceIoControl.IoControlCode,
382 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbIn : 0,
383 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cbOut : 0,
384 pStack->Parameters.DeviceIoControl.InputBufferLength,
385 pStack->Parameters.DeviceIoControl.OutputBufferLength));
386 rcNt = STATUS_INVALID_PARAMETER;
387 }
388 }
389 else
390 {
391 dprintf(("VBoxDrvNtDeviceControlSlow: not buffered request (%#x) - not supported\n",
392 pStack->Parameters.DeviceIoControl.IoControlCode));
393 rcNt = STATUS_NOT_SUPPORTED;
394 }
395 }
396#ifdef RT_ARCH_AMD64
397 else
398 {
399 dprintf(("VBoxDrvNtDeviceControlSlow: WOW64 req - not supported\n"));
400 rcNt = STATUS_NOT_SUPPORTED;
401 }
402#endif
403
404 /* complete the request. */
405 pIrp->IoStatus.Status = rcNt;
406 pIrp->IoStatus.Information = cbOut;
407 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
408 return rcNt;
409}
410
411
412/**
413 * Internal Device I/O Control entry point, used for IDC.
414 *
415 * @param pDevObj Device object.
416 * @param pIrp Request packet.
417 */
418NTSTATUS _stdcall VBoxDrvNtInternalDeviceControl(PDEVICE_OBJECT pDevObj, PIRP pIrp)
419{
420 PSUPDRVDEVEXT pDevExt = (PSUPDRVDEVEXT)pDevObj->DeviceExtension;
421 PIO_STACK_LOCATION pStack = IoGetCurrentIrpStackLocation(pIrp);
422 PFILE_OBJECT pFileObj = pStack ? pStack->FileObject : NULL;
423 PSUPDRVSESSION pSession = pFileObj ? (PSUPDRVSESSION)pFileObj->FsContext : NULL;
424 NTSTATUS rcNt;
425 unsigned cbOut = 0;
426 int rc = 0;
427 dprintf2(("VBoxDrvNtInternalDeviceControl(%p,%p): ioctl=%#x pBuf=%p cbIn=%#x cbOut=%#x pSession=%p\n",
428 pDevExt, pIrp, pStack->Parameters.DeviceIoControl.IoControlCode,
429 pIrp->AssociatedIrp.SystemBuffer, pStack->Parameters.DeviceIoControl.InputBufferLength,
430 pStack->Parameters.DeviceIoControl.OutputBufferLength, pSession));
431
432/** @todo IDC on NT: figure when to create the session and that stuff... */
433
434 /* Verify that it's a buffered CTL. */
435 if ((pStack->Parameters.DeviceIoControl.IoControlCode & 0x3) == METHOD_BUFFERED)
436 {
437 /* Verify the pDevExt in the session. */
438 if ( ( !pSession
439 && pStack->Parameters.DeviceIoControl.IoControlCode == SUPDRV_IDC_REQ_CONNECT)
440 || ( VALID_PTR(pSession)
441 && pSession->pDevExt == pDevExt))
442 {
443 /* Verify that the size in the request header is correct. */
444 PSUPDRVIDCREQHDR pHdr = (PSUPDRVIDCREQHDR)pIrp->AssociatedIrp.SystemBuffer;
445 if ( pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr)
446 && pStack->Parameters.DeviceIoControl.InputBufferLength == pHdr->cb
447 && pStack->Parameters.DeviceIoControl.OutputBufferLength == pHdr->cb)
448 {
449 /*
450 * Do the job.
451 */
452 rc = supdrvIDC(pStack->Parameters.DeviceIoControl.IoControlCode, pDevExt, pSession, pHdr);
453 if (!rc)
454 {
455 rcNt = STATUS_SUCCESS;
456 cbOut = pHdr->cb;
457 }
458 else
459 rcNt = STATUS_INVALID_PARAMETER;
460 dprintf2(("VBoxDrvNtInternalDeviceControl: returns %#x/rc=%#x\n", rcNt, rc));
461 }
462 else
463 {
464 dprintf(("VBoxDrvNtInternalDeviceControl: Mismatching sizes (%#x) - Hdr=%#lx Irp=%#lx/%#lx!\n",
465 pStack->Parameters.DeviceIoControl.IoControlCode,
466 pStack->Parameters.DeviceIoControl.InputBufferLength >= sizeof(*pHdr) ? pHdr->cb : 0,
467 pStack->Parameters.DeviceIoControl.InputBufferLength,
468 pStack->Parameters.DeviceIoControl.OutputBufferLength));
469 rcNt = STATUS_INVALID_PARAMETER;
470 }
471 }
472 else
473 rcNt = STATUS_NOT_SUPPORTED;
474 }
475 else
476 {
477 dprintf(("VBoxDrvNtInternalDeviceControl: not buffered request (%#x) - not supported\n",
478 pStack->Parameters.DeviceIoControl.IoControlCode));
479 rcNt = STATUS_NOT_SUPPORTED;
480 }
481
482 /* complete the request. */
483 pIrp->IoStatus.Status = rcNt;
484 pIrp->IoStatus.Information = cbOut;
485 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
486 return rcNt;
487}
488
489
490/**
491 * Stub function for functions we don't implemented.
492 *
493 * @returns STATUS_NOT_SUPPORTED
494 * @param pDevObj Device object.
495 * @param pIrp IRP.
496 */
497NTSTATUS _stdcall VBoxDrvNtNotSupportedStub(PDEVICE_OBJECT pDevObj, PIRP pIrp)
498{
499 dprintf(("VBoxDrvNtNotSupportedStub\n"));
500 pDevObj = pDevObj;
501
502 pIrp->IoStatus.Information = 0;
503 pIrp->IoStatus.Status = STATUS_NOT_SUPPORTED;
504 IoCompleteRequest(pIrp, IO_NO_INCREMENT);
505
506 return STATUS_NOT_SUPPORTED;
507}
508
509
510/**
511 * Initializes any OS specific object creator fields.
512 */
513void VBOXCALL supdrvOSObjInitCreator(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession)
514{
515 NOREF(pObj);
516 NOREF(pSession);
517}
518
519
520/**
521 * Checks if the session can access the object.
522 *
523 * @returns true if a decision has been made.
524 * @returns false if the default access policy should be applied.
525 *
526 * @param pObj The object in question.
527 * @param pSession The session wanting to access the object.
528 * @param pszObjName The object name, can be NULL.
529 * @param prc Where to store the result when returning true.
530 */
531bool VBOXCALL supdrvOSObjCanAccess(PSUPDRVOBJ pObj, PSUPDRVSESSION pSession, const char *pszObjName, int *prc)
532{
533 NOREF(pObj);
534 NOREF(pSession);
535 NOREF(pszObjName);
536 NOREF(prc);
537 return false;
538}
539
540
541/**
542 * Force async tsc mode (stub).
543 */
544bool VBOXCALL supdrvOSGetForcedAsyncTscMode(PSUPDRVDEVEXT pDevExt)
545{
546 return false;
547}
548
549
550/**
551 * Converts a supdrv error code to an nt status code.
552 *
553 * @returns corresponding nt status code.
554 * @param rc supdrv error code (SUPDRV_ERR_* defines).
555 */
556static NTSTATUS VBoxDrvNtErr2NtStatus(int rc)
557{
558 switch (rc)
559 {
560 case 0: return STATUS_SUCCESS;
561 case SUPDRV_ERR_GENERAL_FAILURE: return STATUS_NOT_SUPPORTED;
562 case SUPDRV_ERR_INVALID_PARAM: return STATUS_INVALID_PARAMETER;
563 case SUPDRV_ERR_INVALID_MAGIC: return STATUS_UNKNOWN_REVISION;
564 case SUPDRV_ERR_INVALID_HANDLE: return STATUS_INVALID_HANDLE;
565 case SUPDRV_ERR_INVALID_POINTER: return STATUS_INVALID_ADDRESS;
566 case SUPDRV_ERR_LOCK_FAILED: return STATUS_NOT_LOCKED;
567 case SUPDRV_ERR_ALREADY_LOADED: return STATUS_IMAGE_ALREADY_LOADED;
568 case SUPDRV_ERR_PERMISSION_DENIED: return STATUS_ACCESS_DENIED;
569 case SUPDRV_ERR_VERSION_MISMATCH: return STATUS_REVISION_MISMATCH;
570 }
571
572 return STATUS_UNSUCCESSFUL;
573}
574
575
576
577/** @todo move this to IPRT */
578RTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
579{
580 DbgPrint("\n!!Assertion Failed!!\n"
581 "Expression: %s\n"
582 "Location : %s(%d) %s\n",
583 pszExpr, pszFile, uLine, pszFunction);
584}
585
586/** @todo use the nocrt stuff? */
587int VBOXCALL mymemcmp(const void *pv1, const void *pv2, size_t cb)
588{
589 const uint8_t *pb1 = (const uint8_t *)pv1;
590 const uint8_t *pb2 = (const uint8_t *)pv2;
591 for (; cb > 0; cb--, pb1++, pb2++)
592 if (*pb1 != *pb2)
593 return *pb1 - *pb2;
594 return 0;
595}
596
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