VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/win/SUPLib-win.cpp@ 51978

Last change on this file since 51978 was 51978, checked in by vboxsync, 10 years ago

Need to initialize the SUPR3HardenedVerify* bits in the extension pack manager too, so split it (the init code) out into a separate API.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 23.2 KB
Line 
1/* $Id: SUPLib-win.cpp 51978 2014-07-11 02:57:40Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Windows NT specific parts.
4 */
5
6/*
7 * Copyright (C) 2006-2013 Oracle Corporation
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
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#define LOG_GROUP LOG_GROUP_SUP
31#ifdef IN_SUP_HARDENED_R3
32# undef DEBUG /* Warning: disables RT_STRICT */
33# undef LOG_DISABLED
34# define LOG_DISABLED
35 /** @todo RTLOGREL_DISABLED */
36# include <iprt/log.h>
37# undef LogRelIt
38# define LogRelIt(pvInst, fFlags, iGroup, fmtargs) do { } while (0)
39#endif
40
41#define USE_NT_DEVICE_IO_CONTROL_FILE
42#include <iprt/nt/nt-and-windows.h>
43
44#include <VBox/sup.h>
45#include <VBox/types.h>
46#include <VBox/err.h>
47#include <VBox/param.h>
48#include <VBox/log.h>
49#include <iprt/assert.h>
50#include <iprt/path.h>
51#include <iprt/string.h>
52#include "../SUPLibInternal.h"
53#include "../SUPDrvIOC.h"
54#ifdef VBOX_WITH_HARDENING
55# include "win/SUPHardenedVerify-win.h"
56#endif
57
58
59/*******************************************************************************
60* Defined Constants And Macros *
61*******************************************************************************/
62/** The support service name. */
63#define SERVICE_NAME "VBoxDrv"
64
65
66/*******************************************************************************
67* Internal Functions *
68*******************************************************************************/
69#ifndef IN_SUP_HARDENED_R3
70static int suplibOsCreateService(void);
71//unused: static int suplibOsUpdateService(void);
72static int suplibOsDeleteService(void);
73static int suplibOsStartService(void);
74static int suplibOsStopService(void);
75#endif
76#ifdef USE_NT_DEVICE_IO_CONTROL_FILE
77static int suplibConvertNtStatus(NTSTATUS rcNt);
78#else
79static int suplibConvertWin32Err(int);
80#endif
81
82/*******************************************************************************
83* Global Variables *
84*******************************************************************************/
85static bool g_fHardenedVerifyInited = false;
86
87
88int suplibOsHardenedVerifyInit(void)
89{
90 if (!g_fHardenedVerifyInited)
91 {
92#if defined(VBOX_WITH_HARDENING) && !defined(IN_SUP_HARDENED_R3) && !defined(IN_SUP_R3_STATIC)
93 supR3HardenedWinInitVersion();
94 int rc = supHardenedWinInitImageVerifier(NULL);
95 if (RT_FAILURE(rc))
96 return rc;
97 supR3HardenedWinResolveVerifyTrustApiAndHookThreadCreation();
98#endif
99 g_fHardenedVerifyInited = true;
100 }
101 return VINF_SUCCESS;
102}
103
104
105int suplibOsHardenedVerifyTerm(void)
106{
107 /** @todo free resources... */
108 return VINF_SUCCESS;
109}
110
111
112int suplibOsInit(PSUPLIBDATA pThis, bool fPreInited, bool fUnrestricted)
113{
114 /*
115 * Make sure the image verifier is fully initialized.
116 */
117 int rc = suplibOsHardenedVerifyInit();
118 if (RT_FAILURE(rc))
119 return rc;
120
121 /*
122 * Done if of pre-inited.
123 */
124 if (fPreInited)
125 {
126#if defined(VBOX_WITH_HARDENING) && !defined(IN_SUP_HARDENED_R3)
127# ifdef IN_SUP_R3_STATIC
128 return VERR_NOT_SUPPORTED;
129# else
130 return VINF_SUCCESS;
131# endif
132#else
133 return VINF_SUCCESS;
134#endif
135 }
136
137 /*
138 * Try open the device.
139 */
140#ifndef IN_SUP_HARDENED_R3
141 uint32_t cTry = 0;
142#endif
143 HANDLE hDevice;
144 for (;;)
145 {
146 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
147
148 static const WCHAR s_wszName[] = L"\\Device\\VBoxDrvU";
149 UNICODE_STRING NtName;
150 NtName.Buffer = (PWSTR)s_wszName;
151 NtName.Length = sizeof(s_wszName) - sizeof(WCHAR) * (fUnrestricted ? 2 : 1);
152 NtName.MaximumLength = NtName.Length;
153
154 OBJECT_ATTRIBUTES ObjAttr;
155 InitializeObjectAttributes(&ObjAttr, &NtName, OBJ_CASE_INSENSITIVE, NULL /*hRootDir*/, NULL /*pSecDesc*/);
156
157 hDevice = RTNT_INVALID_HANDLE_VALUE;
158
159 NTSTATUS rcNt = NtCreateFile(&hDevice,
160 GENERIC_READ | GENERIC_WRITE,
161 &ObjAttr,
162 &Ios,
163 NULL /* Allocation Size*/,
164 FILE_ATTRIBUTE_NORMAL,
165 FILE_SHARE_READ | FILE_SHARE_WRITE,
166 FILE_OPEN,
167 FILE_NON_DIRECTORY_FILE,
168 NULL /*EaBuffer*/,
169 0 /*EaLength*/);
170 if (NT_SUCCESS(rcNt))
171 rcNt = Ios.Status;
172 if (!NT_SUCCESS(rcNt))
173 {
174#ifndef IN_SUP_HARDENED_R3
175 /*
176 * Failed to open, try starting the service and reopen the device
177 * exactly once.
178 */
179 if (cTry == 0 && !NT_SUCCESS(rcNt))
180 {
181 cTry++;
182 suplibOsStartService();
183 continue;
184 }
185#endif
186 switch (rcNt)
187 {
188 /** @todo someone must test what is actually returned. */
189 case STATUS_DEVICE_DOES_NOT_EXIST:
190 case STATUS_DEVICE_NOT_CONNECTED:
191 //case ERROR_BAD_DEVICE:
192 case STATUS_DEVICE_REMOVED:
193 //case ERROR_DEVICE_NOT_AVAILABLE:
194 return VERR_VM_DRIVER_LOAD_ERROR;
195 case STATUS_OBJECT_PATH_NOT_FOUND:
196 case STATUS_NO_SUCH_DEVICE:
197 case STATUS_NO_SUCH_FILE:
198 case STATUS_OBJECT_NAME_NOT_FOUND:
199 return VERR_VM_DRIVER_NOT_INSTALLED;
200 case STATUS_ACCESS_DENIED:
201 case STATUS_SHARING_VIOLATION:
202 return VERR_VM_DRIVER_NOT_ACCESSIBLE;
203 case STATUS_UNSUCCESSFUL:
204 return VERR_SUPLIB_NT_PROCESS_UNTRUSTED_0;
205 case STATUS_TRUST_FAILURE:
206 return VERR_SUPLIB_NT_PROCESS_UNTRUSTED_1;
207 case STATUS_TOO_LATE:
208 return VERR_SUPDRV_HARDENING_EVIL_HANDLE;
209 default:
210 if (SUP_NT_STATUS_IS_VBOX(rcNt)) /* See VBoxDrvNtErr2NtStatus. */
211 return SUP_NT_STATUS_TO_VBOX(rcNt);
212 return VERR_VM_DRIVER_OPEN_ERROR;
213 }
214 }
215 break;
216 }
217
218 /*
219 * We're done.
220 */
221 pThis->hDevice = hDevice;
222 pThis->fUnrestricted = fUnrestricted;
223 return VINF_SUCCESS;
224}
225
226
227#ifndef IN_SUP_HARDENED_R3
228
229int suplibOsInstall(void)
230{
231 return suplibOsCreateService();
232}
233
234
235int suplibOsUninstall(void)
236{
237 int rc = suplibOsStopService();
238 if (!rc)
239 rc = suplibOsDeleteService();
240 return rc;
241}
242
243
244/**
245 * Creates the service.
246 *
247 * @returns 0 on success.
248 * @returns -1 on failure.
249 */
250static int suplibOsCreateService(void)
251{
252 /*
253 * Assume it didn't exist, so we'll create the service.
254 */
255 SC_HANDLE hSMgrCreate = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG);
256 DWORD LastError = GetLastError(); NOREF(LastError);
257 AssertMsg(hSMgrCreate, ("OpenSCManager(,,create) failed rc=%d\n", LastError));
258 if (hSMgrCreate)
259 {
260 char szDriver[RTPATH_MAX];
261 int rc = RTPathExecDir(szDriver, sizeof(szDriver) - sizeof("\\VBoxDrv.sys"));
262 if (RT_SUCCESS(rc))
263 {
264 strcat(szDriver, "\\VBoxDrv.sys");
265 SC_HANDLE hService = CreateService(hSMgrCreate,
266 SERVICE_NAME,
267 "VBox Support Driver",
268 SERVICE_QUERY_STATUS,
269 SERVICE_KERNEL_DRIVER,
270 SERVICE_DEMAND_START,
271 SERVICE_ERROR_NORMAL,
272 szDriver,
273 NULL, NULL, NULL, NULL, NULL);
274 DWORD LastError = GetLastError(); NOREF(LastError);
275 AssertMsg(hService, ("CreateService failed! LastError=%Rwa szDriver=%s\n", LastError, szDriver));
276 CloseServiceHandle(hService);
277 CloseServiceHandle(hSMgrCreate);
278 return hService ? 0 : -1;
279 }
280 CloseServiceHandle(hSMgrCreate);
281 return rc;
282 }
283 return -1;
284}
285
286
287/**
288 * Stops a possibly running service.
289 *
290 * @returns 0 on success.
291 * @returns -1 on failure.
292 */
293static int suplibOsStopService(void)
294{
295 /*
296 * Assume it didn't exist, so we'll create the service.
297 */
298 int rc = -1;
299 SC_HANDLE hSMgr = OpenSCManager(NULL, NULL, SERVICE_STOP | SERVICE_QUERY_STATUS);
300 DWORD LastError = GetLastError(); NOREF(LastError);
301 AssertMsg(hSMgr, ("OpenSCManager(,,delete) failed rc=%d\n", LastError));
302 if (hSMgr)
303 {
304 SC_HANDLE hService = OpenService(hSMgr, SERVICE_NAME, SERVICE_STOP | SERVICE_QUERY_STATUS);
305 if (hService)
306 {
307 /*
308 * Stop the service.
309 */
310 SERVICE_STATUS Status;
311 QueryServiceStatus(hService, &Status);
312 if (Status.dwCurrentState == SERVICE_STOPPED)
313 rc = 0;
314 else if (ControlService(hService, SERVICE_CONTROL_STOP, &Status))
315 {
316 int iWait = 100;
317 while (Status.dwCurrentState == SERVICE_STOP_PENDING && iWait-- > 0)
318 {
319 Sleep(100);
320 QueryServiceStatus(hService, &Status);
321 }
322 if (Status.dwCurrentState == SERVICE_STOPPED)
323 rc = 0;
324 else
325 AssertMsgFailed(("Failed to stop service. status=%d\n", Status.dwCurrentState));
326 }
327 else
328 {
329 DWORD LastError = GetLastError(); NOREF(LastError);
330 AssertMsgFailed(("ControlService failed with LastError=%Rwa. status=%d\n", LastError, Status.dwCurrentState));
331 }
332 CloseServiceHandle(hService);
333 }
334 else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
335 rc = 0;
336 else
337 {
338 DWORD LastError = GetLastError(); NOREF(LastError);
339 AssertMsgFailed(("OpenService failed LastError=%Rwa\n", LastError));
340 }
341 CloseServiceHandle(hSMgr);
342 }
343 return rc;
344}
345
346
347/**
348 * Deletes the service.
349 *
350 * @returns 0 on success.
351 * @returns -1 on failure.
352 */
353int suplibOsDeleteService(void)
354{
355 /*
356 * Assume it didn't exist, so we'll create the service.
357 */
358 int rc = -1;
359 SC_HANDLE hSMgr = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG);
360 DWORD LastError = GetLastError(); NOREF(LastError);
361 AssertMsg(hSMgr, ("OpenSCManager(,,delete) failed rc=%d\n", LastError));
362 if (hSMgr)
363 {
364 SC_HANDLE hService = OpenService(hSMgr, SERVICE_NAME, DELETE);
365 if (hService)
366 {
367 /*
368 * Delete the service.
369 */
370 if (DeleteService(hService))
371 rc = 0;
372 else
373 {
374 DWORD LastError = GetLastError(); NOREF(LastError);
375 AssertMsgFailed(("DeleteService failed LastError=%Rwa\n", LastError));
376 }
377 CloseServiceHandle(hService);
378 }
379 else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
380 rc = 0;
381 else
382 {
383 DWORD LastError = GetLastError(); NOREF(LastError);
384 AssertMsgFailed(("OpenService failed LastError=%Rwa\n", LastError));
385 }
386 CloseServiceHandle(hSMgr);
387 }
388 return rc;
389}
390
391#if 0
392/**
393 * Creates the service.
394 *
395 * @returns 0 on success.
396 * @returns -1 on failure.
397 */
398static int suplibOsUpdateService(void)
399{
400 /*
401 * Assume it didn't exist, so we'll create the service.
402 */
403 SC_HANDLE hSMgr = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG);
404 DWORD LastError = GetLastError(); NOREF(LastError);
405 AssertMsg(hSMgr, ("OpenSCManager(,,delete) failed LastError=%Rwa\n", LastError));
406 if (hSMgr)
407 {
408 SC_HANDLE hService = OpenService(hSMgr, SERVICE_NAME, SERVICE_CHANGE_CONFIG);
409 if (hService)
410 {
411 char szDriver[RTPATH_MAX];
412 int rc = RTPathExecDir(szDriver, sizeof(szDriver) - sizeof("\\VBoxDrv.sys"));
413 if (RT_SUCCESS(rc))
414 {
415 strcat(szDriver, "\\VBoxDrv.sys");
416
417 SC_LOCK hLock = LockServiceDatabase(hSMgr);
418 if (ChangeServiceConfig(hService,
419 SERVICE_KERNEL_DRIVER,
420 SERVICE_DEMAND_START,
421 SERVICE_ERROR_NORMAL,
422 szDriver,
423 NULL, NULL, NULL, NULL, NULL, NULL))
424 {
425
426 UnlockServiceDatabase(hLock);
427 CloseServiceHandle(hService);
428 CloseServiceHandle(hSMgr);
429 return 0;
430 }
431 else
432 {
433 DWORD LastError = GetLastError(); NOREF(LastError);
434 AssertMsgFailed(("ChangeServiceConfig failed LastError=%Rwa\n", LastError));
435 }
436 }
437 UnlockServiceDatabase(hLock);
438 CloseServiceHandle(hService);
439 }
440 else
441 {
442 DWORD LastError = GetLastError(); NOREF(LastError);
443 AssertMsgFailed(("OpenService failed LastError=%Rwa\n", LastError));
444 }
445 CloseServiceHandle(hSMgr);
446 }
447 return -1;
448}
449#endif
450
451
452/**
453 * Attempts to start the service, creating it if necessary.
454 *
455 * @returns 0 on success.
456 * @returns -1 on failure.
457 * @param fRetry Indicates retry call.
458 */
459static int suplibOsStartService(void)
460{
461 /*
462 * Check if the driver service is there.
463 */
464 SC_HANDLE hSMgr = OpenSCManager(NULL, NULL, SERVICE_QUERY_STATUS | SERVICE_START);
465 if (hSMgr == NULL)
466 {
467 AssertMsgFailed(("couldn't open service manager in SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS mode!\n"));
468 return -1;
469 }
470
471 /*
472 * Try open our service to check it's status.
473 */
474 SC_HANDLE hService = OpenService(hSMgr, SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START);
475 if (!hService)
476 {
477 /*
478 * Create the service.
479 */
480 int rc = suplibOsCreateService();
481 if (rc)
482 return rc;
483
484 /*
485 * Try open the service.
486 */
487 hService = OpenService(hSMgr, SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START);
488 }
489
490 /*
491 * Check if open and on demand create succeeded.
492 */
493 int rc = -1;
494 if (hService)
495 {
496
497 /*
498 * Query service status to see if we need to start it or not.
499 */
500 SERVICE_STATUS Status;
501 BOOL fRc = QueryServiceStatus(hService, &Status);
502 Assert(fRc);
503 if ( Status.dwCurrentState != SERVICE_RUNNING
504 && Status.dwCurrentState != SERVICE_START_PENDING)
505 {
506 /*
507 * Start it.
508 */
509 fRc = StartService(hService, 0, NULL);
510 DWORD LastError = GetLastError(); NOREF(LastError);
511#ifndef DEBUG_bird
512 AssertMsg(fRc, ("StartService failed with LastError=%Rwa\n", LastError));
513#endif
514 }
515
516 /*
517 * Wait for the service to finish starting.
518 * We'll wait for 10 seconds then we'll give up.
519 */
520 QueryServiceStatus(hService, &Status);
521 if (Status.dwCurrentState == SERVICE_START_PENDING)
522 {
523 int iWait;
524 for (iWait = 100; iWait > 0 && Status.dwCurrentState == SERVICE_START_PENDING; iWait--)
525 {
526 Sleep(100);
527 QueryServiceStatus(hService, &Status);
528 }
529 DWORD LastError = GetLastError(); NOREF(LastError);
530 AssertMsg(Status.dwCurrentState != SERVICE_RUNNING,
531 ("Failed to start. LastError=%Rwa iWait=%d status=%d\n",
532 LastError, iWait, Status.dwCurrentState));
533 }
534
535 if (Status.dwCurrentState == SERVICE_RUNNING)
536 rc = 0;
537
538 /*
539 * Close open handles.
540 */
541 CloseServiceHandle(hService);
542 }
543 else
544 {
545 DWORD LastError = GetLastError(); NOREF(LastError);
546 AssertMsgFailed(("OpenService failed! LastError=%Rwa\n", LastError));
547 }
548 if (!CloseServiceHandle(hSMgr))
549 AssertFailed();
550
551 return rc;
552}
553
554
555int suplibOsTerm(PSUPLIBDATA pThis)
556{
557 /*
558 * Check if we're inited at all.
559 */
560 if (pThis->hDevice != NULL)
561 {
562 if (!CloseHandle((HANDLE)pThis->hDevice))
563 AssertFailed();
564 pThis->hDevice = NIL_RTFILE; /* yes, that's right */
565 }
566
567 return VINF_SUCCESS;
568}
569
570
571int suplibOsIOCtl(PSUPLIBDATA pThis, uintptr_t uFunction, void *pvReq, size_t cbReq)
572{
573 /*
574 * Issue the device I/O control.
575 */
576 PSUPREQHDR pHdr = (PSUPREQHDR)pvReq;
577 Assert(cbReq == RT_MAX(pHdr->cbIn, pHdr->cbOut));
578# ifdef USE_NT_DEVICE_IO_CONTROL_FILE
579 IO_STATUS_BLOCK Ios;
580 Ios.Status = -1;
581 Ios.Information = 0;
582 NTSTATUS rcNt = NtDeviceIoControlFile((HANDLE)pThis->hDevice, NULL /*hEvent*/, NULL /*pfnApc*/, NULL /*pvApcCtx*/, &Ios,
583 (ULONG)uFunction,
584 pvReq /*pvInput */, pHdr->cbIn /* cbInput */,
585 pvReq /*pvOutput*/, pHdr->cbOut /* cbOutput */);
586 if (NT_SUCCESS(rcNt))
587 {
588 if (NT_SUCCESS(Ios.Status))
589 return VINF_SUCCESS;
590 rcNt = Ios.Status;
591 }
592 return suplibConvertNtStatus(rcNt);
593
594# else
595 DWORD cbReturned = (ULONG)pHdr->cbOut;
596 if (DeviceIoControl((HANDLE)pThis->hDevice, uFunction, pvReq, pHdr->cbIn, pvReq, cbReturned, &cbReturned, NULL))
597 return 0;
598 return suplibConvertWin32Err(GetLastError());
599# endif
600}
601
602
603int suplibOsIOCtlFast(PSUPLIBDATA pThis, uintptr_t uFunction, uintptr_t idCpu)
604{
605 /*
606 * Issue device I/O control.
607 */
608# ifdef USE_NT_DEVICE_IO_CONTROL_FILE
609 IO_STATUS_BLOCK Ios;
610 Ios.Status = -1;
611 Ios.Information = 0;
612 NTSTATUS rcNt = NtDeviceIoControlFile((HANDLE)pThis->hDevice, NULL /*hEvent*/, NULL /*pfnApc*/, NULL /*pvApcCtx*/, &Ios,
613 (ULONG)uFunction,
614 NULL /*pvInput */, 0 /* cbInput */,
615 (PVOID)idCpu /*pvOutput*/, 0 /* cbOutput */);
616 if (NT_SUCCESS(rcNt))
617 {
618 if (NT_SUCCESS(Ios.Status))
619 return VINF_SUCCESS;
620 rcNt = Ios.Status;
621 }
622 return suplibConvertNtStatus(rcNt);
623# else
624 DWORD cbReturned = 0;
625 if (DeviceIoControl((HANDLE)pThis->hDevice, uFunction, NULL, 0, (LPVOID)idCpu, 0, &cbReturned, NULL))
626 return VINF_SUCCESS;
627 return suplibConvertWin32Err(GetLastError());
628# endif
629}
630
631
632int suplibOsPageAlloc(PSUPLIBDATA pThis, size_t cPages, void **ppvPages)
633{
634 NOREF(pThis);
635 *ppvPages = VirtualAlloc(NULL, (size_t)cPages << PAGE_SHIFT, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
636 if (*ppvPages)
637 return VINF_SUCCESS;
638 return RTErrConvertFromWin32(GetLastError());
639}
640
641
642int suplibOsPageFree(PSUPLIBDATA pThis, void *pvPages, size_t /* cPages */)
643{
644 NOREF(pThis);
645 if (VirtualFree(pvPages, 0, MEM_RELEASE))
646 return VINF_SUCCESS;
647 return RTErrConvertFromWin32(GetLastError());
648}
649
650
651# ifndef USE_NT_DEVICE_IO_CONTROL_FILE
652/**
653 * Converts a supdrv win32 error code to an IPRT status code.
654 *
655 * @returns corresponding IPRT error code.
656 * @param rc Win32 error code.
657 */
658static int suplibConvertWin32Err(int rc)
659{
660 /* Conversion program (link with ntdll.lib from ddk):
661 #define _WIN32_WINNT 0x0501
662 #include <windows.h>
663 #include <ntstatus.h>
664 #include <winternl.h>
665 #include <stdio.h>
666
667 int main()
668 {
669 #define CONVERT(a) printf(#a " %#x -> %d\n", a, RtlNtStatusToDosError((a)))
670 CONVERT(STATUS_SUCCESS);
671 CONVERT(STATUS_NOT_SUPPORTED);
672 CONVERT(STATUS_INVALID_PARAMETER);
673 CONVERT(STATUS_UNKNOWN_REVISION);
674 CONVERT(STATUS_INVALID_HANDLE);
675 CONVERT(STATUS_INVALID_ADDRESS);
676 CONVERT(STATUS_NOT_LOCKED);
677 CONVERT(STATUS_IMAGE_ALREADY_LOADED);
678 CONVERT(STATUS_ACCESS_DENIED);
679 CONVERT(STATUS_REVISION_MISMATCH);
680
681 return 0;
682 }
683 */
684
685 switch (rc)
686 {
687 //case 0: return STATUS_SUCCESS;
688 case 0: return VINF_SUCCESS;
689 case ERROR_NOT_SUPPORTED: return VERR_GENERAL_FAILURE;
690 case ERROR_INVALID_PARAMETER: return VERR_INVALID_PARAMETER;
691 case ERROR_UNKNOWN_REVISION: return VERR_INVALID_MAGIC;
692 case ERROR_INVALID_HANDLE: return VERR_INVALID_HANDLE;
693 case ERROR_UNEXP_NET_ERR: return VERR_INVALID_POINTER;
694 case ERROR_NOT_LOCKED: return VERR_LOCK_FAILED;
695 case ERROR_SERVICE_ALREADY_RUNNING: return VERR_ALREADY_LOADED;
696 case ERROR_ACCESS_DENIED: return VERR_PERMISSION_DENIED;
697 case ERROR_REVISION_MISMATCH: return VERR_VERSION_MISMATCH;
698 }
699
700 /* fall back on the default conversion. */
701 return RTErrConvertFromWin32(rc);
702}
703# else
704/**
705 * Reverse of VBoxDrvNtErr2NtStatus
706 * returns VBox status code.
707 * @param rcNt NT status code.
708 */
709static int suplibConvertNtStatus(NTSTATUS rcNt)
710{
711 switch (rcNt)
712 {
713 case STATUS_SUCCESS: return VINF_SUCCESS;
714 case STATUS_NOT_SUPPORTED: return VERR_GENERAL_FAILURE;
715 case STATUS_INVALID_PARAMETER: return VERR_INVALID_PARAMETER;
716 case STATUS_UNKNOWN_REVISION: return VERR_INVALID_MAGIC;
717 case STATUS_INVALID_HANDLE: return VERR_INVALID_HANDLE;
718 case STATUS_INVALID_ADDRESS: return VERR_INVALID_POINTER;
719 case STATUS_NOT_LOCKED: return VERR_LOCK_FAILED;
720 case STATUS_IMAGE_ALREADY_LOADED: return VERR_ALREADY_LOADED;
721 case STATUS_ACCESS_DENIED: return VERR_PERMISSION_DENIED;
722 case STATUS_REVISION_MISMATCH: return VERR_VERSION_MISMATCH;
723 }
724
725 /* See VBoxDrvNtErr2NtStatus. */
726 if (SUP_NT_STATUS_IS_VBOX(rcNt))
727 return SUP_NT_STATUS_TO_VBOX(rcNt);
728
729 /* Fall back on IPRT for the rest. */
730 return RTErrConvertFromNtStatus(rcNt);
731}
732# endif
733
734#endif /* !IN_SUP_HARDENED_R3 */
735
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