1 | /* $Id: VBoxDrvTool.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Windows Driver R0 Tooling.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef VBOX_INCLUDED_SRC_VBoxUSB_win_cmn_VBoxDrvTool_h
|
---|
38 | #define VBOX_INCLUDED_SRC_VBoxUSB_win_cmn_VBoxDrvTool_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <VBox/cdefs.h>
|
---|
44 | #include <iprt/stdint.h>
|
---|
45 | #include <iprt/assert.h>
|
---|
46 | #include <iprt/asm.h>
|
---|
47 | #include <iprt/nt/wdm.h>
|
---|
48 |
|
---|
49 |
|
---|
50 | RT_C_DECLS_BEGIN
|
---|
51 |
|
---|
52 | #if 0
|
---|
53 | /* enable this in case we include this in a dll*/
|
---|
54 | # ifdef IN_VBOXDRVTOOL
|
---|
55 | # define VBOXDRVTOOL_DECL(a_Type) DECLEXPORT(a_Type)
|
---|
56 | # else
|
---|
57 | # define VBOXDRVTOOL_DECL(a_Type) DECLIMPORT(a_Type)
|
---|
58 | # endif
|
---|
59 | #else
|
---|
60 | /*enable this in case we include this in a static lib*/
|
---|
61 | # define VBOXDRVTOOL_DECL(a_Type) a_Type VBOXCALL
|
---|
62 | #endif
|
---|
63 |
|
---|
64 | VBOXDRVTOOL_DECL(NTSTATUS) VBoxDrvToolRegOpenKeyU(OUT PHANDLE phKey, IN PUNICODE_STRING pName, IN ACCESS_MASK fAccess);
|
---|
65 | VBOXDRVTOOL_DECL(NTSTATUS) VBoxDrvToolRegOpenKey(OUT PHANDLE phKey, IN PWCHAR pName, IN ACCESS_MASK fAccess);
|
---|
66 | VBOXDRVTOOL_DECL(NTSTATUS) VBoxDrvToolRegCloseKey(IN HANDLE hKey);
|
---|
67 | VBOXDRVTOOL_DECL(NTSTATUS) VBoxDrvToolRegQueryValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT PULONG pDword);
|
---|
68 | VBOXDRVTOOL_DECL(NTSTATUS) VBoxDrvToolRegSetValueDword(IN HANDLE hKey, IN PWCHAR pName, OUT ULONG val);
|
---|
69 |
|
---|
70 | VBOXDRVTOOL_DECL(NTSTATUS) VBoxDrvToolIoPostAsync(PDEVICE_OBJECT pDevObj, PIRP pIrp, PKEVENT pEvent);
|
---|
71 | VBOXDRVTOOL_DECL(NTSTATUS) VBoxDrvToolIoPostSync(PDEVICE_OBJECT pDevObj, PIRP pIrp);
|
---|
72 | VBOXDRVTOOL_DECL(NTSTATUS) VBoxDrvToolIoPostSyncWithTimeout(PDEVICE_OBJECT pDevObj, PIRP pIrp, ULONG dwTimeoutMs);
|
---|
73 | DECLINLINE(NTSTATUS) VBoxDrvToolIoComplete(PIRP pIrp, NTSTATUS Status, ULONG ulInfo)
|
---|
74 | {
|
---|
75 | pIrp->IoStatus.Status = Status;
|
---|
76 | pIrp->IoStatus.Information = ulInfo;
|
---|
77 | IoCompleteRequest(pIrp, IO_NO_INCREMENT);
|
---|
78 | return Status;
|
---|
79 | }
|
---|
80 |
|
---|
81 | typedef struct VBOXDRVTOOL_REF
|
---|
82 | {
|
---|
83 | volatile uint32_t cRefs;
|
---|
84 | } VBOXDRVTOOL_REF, *PVBOXDRVTOOL_REF;
|
---|
85 |
|
---|
86 | DECLINLINE(void) VBoxDrvToolRefInit(PVBOXDRVTOOL_REF pRef)
|
---|
87 | {
|
---|
88 | pRef->cRefs = 1;
|
---|
89 | }
|
---|
90 |
|
---|
91 | DECLINLINE(uint32_t) VBoxDrvToolRefRetain(PVBOXDRVTOOL_REF pRef)
|
---|
92 | {
|
---|
93 | Assert(pRef->cRefs);
|
---|
94 | Assert(pRef->cRefs < UINT32_MAX / 2);
|
---|
95 | return ASMAtomicIncU32(&pRef->cRefs);
|
---|
96 | }
|
---|
97 |
|
---|
98 | DECLINLINE(uint32_t) VBoxDrvToolRefRelease(PVBOXDRVTOOL_REF pRef)
|
---|
99 | {
|
---|
100 | uint32_t cRefs = ASMAtomicDecU32(&pRef->cRefs);
|
---|
101 | Assert(cRefs < UINT32_MAX/2);
|
---|
102 | return cRefs;
|
---|
103 | }
|
---|
104 |
|
---|
105 | VBOXDRVTOOL_DECL(VOID) VBoxDrvToolRefWaitEqual(PVBOXDRVTOOL_REF pRef, uint32_t u32Val);
|
---|
106 |
|
---|
107 | VBOXDRVTOOL_DECL(NTSTATUS) VBoxDrvToolStrCopy(PUNICODE_STRING pDst, CONST PUNICODE_STRING pSrc);
|
---|
108 | VBOXDRVTOOL_DECL(VOID) VBoxDrvToolStrFree(PUNICODE_STRING pStr);
|
---|
109 |
|
---|
110 | RT_C_DECLS_END
|
---|
111 |
|
---|
112 | #endif /* !VBOX_INCLUDED_SRC_VBoxUSB_win_cmn_VBoxDrvTool_h */
|
---|
113 |
|
---|