1 | /** @file
|
---|
2 | * IPRT - Kernel module.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2017-2022 Oracle Corporation
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef IPRT_INCLUDED_krnlmod_h
|
---|
27 | #define IPRT_INCLUDED_krnlmod_h
|
---|
28 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
29 | # pragma once
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include <iprt/cdefs.h>
|
---|
33 | #include <iprt/types.h>
|
---|
34 |
|
---|
35 |
|
---|
36 | RT_C_DECLS_BEGIN
|
---|
37 |
|
---|
38 | /** @defgroup grp_rt_kmod RTKrnlMod - Kernel module/driver userspace side API.
|
---|
39 | * @ingroup grp_rt
|
---|
40 | * @{
|
---|
41 | */
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Checks whether the given kernel module was loaded.
|
---|
45 | *
|
---|
46 | * @returns IPRT status code.
|
---|
47 | * @param pszName The driver name to check.
|
---|
48 | * @param pfLoaded Where to store the flag whether the module is loaded on success.
|
---|
49 | */
|
---|
50 | RTDECL(int) RTKrnlModQueryLoaded(const char *pszName, bool *pfLoaded);
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * Returns the kernel module information handle for the given loaded kernel module.
|
---|
54 | *
|
---|
55 | * @returns IPRT status code.
|
---|
56 | * @retval VERR_NOT_FOUND if the kernel driver is not loaded.
|
---|
57 | * @param pszName The driver name.
|
---|
58 | * @param phKrnlModInfo Where to store the handle to the kernel module information record.
|
---|
59 | */
|
---|
60 | RTDECL(int) RTKrnlModLoadedQueryInfo(const char *pszName, PRTKRNLMODINFO phKrnlModInfo);
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Returns the number of kernel modules loaded on the host system.
|
---|
64 | *
|
---|
65 | * @returns Number of kernel modules loaded.
|
---|
66 | */
|
---|
67 | RTDECL(uint32_t) RTKrnlModLoadedGetCount(void);
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Returns all loaded kernel modules on the host.
|
---|
71 | *
|
---|
72 | * @returns IPRT status code.
|
---|
73 | * @retval VERR_BUFFER_OVERFLOW if there are not enough entries in the passed handle array.
|
---|
74 | * The required number of entries will be returned in pcEntries.
|
---|
75 | * @param pahKrnlModInfo Where to store the handles to the kernel module information records
|
---|
76 | * on success.
|
---|
77 | * @param cEntriesMax Maximum number of entries fitting in the given array.
|
---|
78 | * @param pcEntries Where to store the number of entries used/required.
|
---|
79 | */
|
---|
80 | RTDECL(int) RTKrnlModLoadedQueryInfoAll(PRTKRNLMODINFO pahKrnlModInfo, uint32_t cEntriesMax,
|
---|
81 | uint32_t *pcEntries);
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Retains the given kernel module information record handle.
|
---|
85 | *
|
---|
86 | * @returns New reference count.
|
---|
87 | * @param hKrnlModInfo The kernel module information record handle.
|
---|
88 | */
|
---|
89 | RTDECL(uint32_t) RTKrnlModInfoRetain(RTKRNLMODINFO hKrnlModInfo);
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Releases the given kernel module information record handle.
|
---|
93 | *
|
---|
94 | * @returns New reference count, on 0 the handle is destroyed.
|
---|
95 | * @param hKrnlModInfo The kernel module information record handle.
|
---|
96 | */
|
---|
97 | RTDECL(uint32_t) RTKrnlModInfoRelease(RTKRNLMODINFO hKrnlModInfo);
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Returns the number of references held onto the kernel module by other
|
---|
101 | * drivers or userspace clients.
|
---|
102 | *
|
---|
103 | * @returns Number of references held on the kernel module.
|
---|
104 | * @param hKrnlModInfo The kernel module information record handle.
|
---|
105 | */
|
---|
106 | RTDECL(uint32_t) RTKrnlModInfoGetRefCnt(RTKRNLMODINFO hKrnlModInfo);
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Returns the name of the kernel module.
|
---|
110 | *
|
---|
111 | * @returns Pointer to the kernel module name.
|
---|
112 | * @param hKrnlModInfo The kernel module information record handle.
|
---|
113 | */
|
---|
114 | RTDECL(const char *) RTKrnlModInfoGetName(RTKRNLMODINFO hKrnlModInfo);
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Returns the filepath of the kernel module.
|
---|
118 | *
|
---|
119 | * @returns Pointer to the kernel module path.
|
---|
120 | * @param hKrnlModInfo The kernel module information record handle.
|
---|
121 | */
|
---|
122 | RTDECL(const char *) RTKrnlModInfoGetFilePath(RTKRNLMODINFO hKrnlModInfo);
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Returns the size of the kernel module.
|
---|
126 | *
|
---|
127 | * @returns Size of the kernel module in bytes.
|
---|
128 | * @param hKrnlModInfo The kernel module information record handle.
|
---|
129 | */
|
---|
130 | RTDECL(size_t) RTKrnlModInfoGetSize(RTKRNLMODINFO hKrnlModInfo);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Returns the load address of the kernel module.
|
---|
134 | *
|
---|
135 | * @returns Load address of the kernel module.
|
---|
136 | * @param hKrnlModInfo The kernel module information record handle.
|
---|
137 | */
|
---|
138 | RTDECL(RTR0UINTPTR) RTKrnlModInfoGetLoadAddr(RTKRNLMODINFO hKrnlModInfo);
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Query the kernel information record for a referencing kernel module of the
|
---|
142 | * given record.
|
---|
143 | *
|
---|
144 | * @returns IPRT status code.
|
---|
145 | * @param hKrnlModInfo The kernel module information record handle.
|
---|
146 | * @param idx Referencing kernel module index (< reference count
|
---|
147 | * as retrieved by RTKrnlModInfoGetRefCnt() ).
|
---|
148 | * @param phKrnlModInfoRef Where to store the handle to the referencing kernel module
|
---|
149 | * information record.
|
---|
150 | */
|
---|
151 | RTDECL(int) RTKrnlModInfoQueryRefModInfo(RTKRNLMODINFO hKrnlModInfo, uint32_t idx,
|
---|
152 | PRTKRNLMODINFO phKrnlModInfoRef);
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * Tries to load a kernel module by the given name.
|
---|
156 | *
|
---|
157 | * @returns IPRT status code.
|
---|
158 | * @retval VERR_NOT_SUPPORTED if not supported by or implemented for the platform.
|
---|
159 | * @param pszName The name of the kernel module. This is highly platform
|
---|
160 | * dependent.
|
---|
161 | *
|
---|
162 | * @note On macOS for example the name is the bundle ID.
|
---|
163 | */
|
---|
164 | RTDECL(int) RTKrnlModLoadByName(const char *pszName);
|
---|
165 |
|
---|
166 | /**
|
---|
167 | * Tries to load a kernel module by the given file path.
|
---|
168 | *
|
---|
169 | * @returns IPRT status code.
|
---|
170 | * @retval VERR_NOT_SUPPORTED if not supported by or implemented for the platform.
|
---|
171 | * @param pszPath The path of the kernel module.
|
---|
172 | */
|
---|
173 | RTDECL(int) RTKrnlModLoadByPath(const char *pszPath);
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * Tries to unload a kernel module by the given name.
|
---|
177 | *
|
---|
178 | * @returns IPRT status code.
|
---|
179 | * @param pszName The name of the kernel module. This is highly platform
|
---|
180 | * dependent and should be queried with RTKrnlModInfoGetName()
|
---|
181 | * when checking whether the module was actually loaded.
|
---|
182 | *
|
---|
183 | * @note On macOS for example the name is the bundle ID.
|
---|
184 | */
|
---|
185 | RTDECL(int) RTKrnlModUnloadByName(const char *pszName);
|
---|
186 |
|
---|
187 | /** @} */
|
---|
188 |
|
---|
189 | RT_C_DECLS_END
|
---|
190 |
|
---|
191 | #endif /* !IPRT_INCLUDED_krnlmod_h */
|
---|
192 |
|
---|