VirtualBox

source: vbox/trunk/include/iprt/system.h@ 96507

Last change on this file since 96507 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.5 KB
Line 
1/** @file
2 * IPRT - System Information.
3 */
4
5/*
6 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_system_h
37#define IPRT_INCLUDED_system_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/cdefs.h>
43#include <iprt/types.h>
44
45
46RT_C_DECLS_BEGIN
47
48/** @defgroup grp_rt_system RTSystem - System Information
49 * @ingroup grp_rt
50 * @{
51 */
52
53/**
54 * Info level for RTSystemGetOSInfo().
55 */
56typedef enum RTSYSOSINFO
57{
58 RTSYSOSINFO_INVALID = 0, /**< The usual invalid entry. */
59 RTSYSOSINFO_PRODUCT, /**< OS product name. (uname -o) */
60 RTSYSOSINFO_RELEASE, /**< OS release. (uname -r) */
61 RTSYSOSINFO_VERSION, /**< OS version, optional. (uname -v) */
62 RTSYSOSINFO_SERVICE_PACK, /**< Service/fix pack level, optional. */
63 RTSYSOSINFO_END /**< End of the valid info levels. */
64} RTSYSOSINFO;
65
66
67/**
68 * Queries information about the OS.
69 *
70 * @returns IPRT status code.
71 * @retval VINF_SUCCESS on success.
72 * @retval VERR_INVALID_PARAMETER if enmInfo is invalid.
73 * @retval VERR_INVALID_POINTER if pszInfoStr is invalid.
74 * @retval VERR_BUFFER_OVERFLOW if the buffer is too small. The buffer will
75 * contain the chopped off result in this case, provided cchInfo isn't 0.
76 * @retval VERR_NOT_SUPPORTED if the info level isn't implemented. The buffer will
77 * contain an empty string.
78 *
79 * @param enmInfo The OS info level.
80 * @param pszInfo Where to store the result.
81 * @param cchInfo The size of the output buffer.
82 */
83RTDECL(int) RTSystemQueryOSInfo(RTSYSOSINFO enmInfo, char *pszInfo, size_t cchInfo);
84
85/**
86 * Queries the total amount of RAM in the system.
87 *
88 * This figure does not given any information about how much memory is
89 * currently available. Use RTSystemQueryAvailableRam instead.
90 *
91 * @returns IPRT status code.
92 * @retval VINF_SUCCESS and *pcb on sucess.
93 * @retval VERR_ACCESS_DENIED if the information isn't accessible to the
94 * caller.
95 *
96 * @param pcb Where to store the result (in bytes).
97 */
98RTDECL(int) RTSystemQueryTotalRam(uint64_t *pcb);
99
100/**
101 * Queries the total amount of RAM accessible to the system.
102 *
103 * This figure should not include memory that is installed but not used,
104 * nor memory that will be slow to bring online. The definition of 'slow'
105 * here is slower than swapping out a MB of pages to disk.
106 *
107 * @returns IPRT status code.
108 * @retval VINF_SUCCESS and *pcb on success.
109 * @retval VERR_ACCESS_DENIED if the information isn't accessible to the
110 * caller.
111 *
112 * @param pcb Where to store the result (in bytes).
113 */
114RTDECL(int) RTSystemQueryAvailableRam(uint64_t *pcb);
115
116/**
117 * Queries the amount of RAM that is currently locked down or in some other
118 * way made impossible to virtualize within reasonably short time.
119 *
120 * The purposes of this API is, when combined with RTSystemQueryTotalRam, to
121 * be able to determine an absolute max limit for how much fixed memory it is
122 * (theoretically) possible to allocate (or lock down).
123 *
124 * The kind memory covered by this function includes:
125 * - locked (wired) memory - like for instance RTR0MemObjLockUser
126 * and RTR0MemObjLockKernel makes,
127 * - kernel pools and heaps - like for instance the ring-0 variant
128 * of RTMemAlloc taps into,
129 * - fixed (not pageable) kernel allocations - like for instance
130 * all the RTR0MemObjAlloc* functions makes,
131 * - any similar memory that isn't easily swapped out, discarded,
132 * or flushed to disk.
133 *
134 * This works against the value returned by RTSystemQueryTotalRam, and
135 * the value reported by this function can never be larger than what a
136 * call to RTSystemQueryTotalRam returns.
137 *
138 * The short time term here is relative to swapping to disk like in
139 * RTSystemQueryTotalRam. This could mean that (part of) the dirty buffers
140 * in the dynamic I/O cache could be included in the total. If the dynamic
141 * I/O cache isn't likely to either flush buffers when the load increases
142 * and put them back into normal circulation, they should be included in
143 * the memory accounted for here.
144 *
145 * @retval VINF_SUCCESS and *pcb on success.
146 * @retval VERR_NOT_SUPPORTED if the information isn't available on the
147 * system in general. The caller must handle this scenario.
148 * @retval VERR_ACCESS_DENIED if the information isn't accessible to the
149 * caller.
150 *
151 * @param pcb Where to store the result (in bytes).
152 *
153 * @remarks This function could've been inverted and called
154 * RTSystemQueryAvailableRam, but that might give impression that
155 * it would be possible to allocate the amount of memory it
156 * indicates for a single purpose, something which would be very
157 * improbable on most systems.
158 *
159 * @remarks We might have to add another output parameter to this function
160 * that indicates if some of the memory kinds listed above cannot
161 * be accounted for on the system and therefore is not include in
162 * the returned amount.
163 */
164RTDECL(int) RTSystemQueryUnavailableRam(uint64_t *pcb);
165
166
167/**
168 * The DMI strings.
169 */
170typedef enum RTSYSDMISTR
171{
172 /** Invalid zero entry. */
173 RTSYSDMISTR_INVALID = 0,
174 /** The product name. */
175 RTSYSDMISTR_PRODUCT_NAME,
176 /** The product version. */
177 RTSYSDMISTR_PRODUCT_VERSION,
178 /** The product UUID. */
179 RTSYSDMISTR_PRODUCT_UUID,
180 /** The product serial. */
181 RTSYSDMISTR_PRODUCT_SERIAL,
182 /** The system manufacturer. */
183 RTSYSDMISTR_MANUFACTURER,
184 /** The end of the valid strings. */
185 RTSYSDMISTR_END,
186 /** The usual 32-bit hack. */
187 RTSYSDMISTR_32_BIT_HACK = 0x7fffffff
188} RTSYSDMISTR;
189
190/**
191 * Queries a DMI string.
192 *
193 * @returns IPRT status code.
194 * @retval VINF_SUCCESS on success.
195 * @retval VERR_BUFFER_OVERFLOW if the buffer is too small. The buffer will
196 * contain the chopped off result in this case, provided cbBuf isn't 0.
197 * @retval VERR_ACCESS_DENIED if the information isn't accessible to the
198 * caller.
199 * @retval VERR_NOT_SUPPORTED if the information isn't available on the system
200 * in general. The caller must expect this status code and deal with
201 * it.
202 *
203 * @param enmString Which string to query.
204 * @param pszBuf Where to store the string. This is always
205 * terminated, even on error.
206 * @param cbBuf The buffer size.
207 */
208RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf);
209
210/** @name Flags for RTSystemReboot and RTSystemShutdown.
211 * @{ */
212/** Reboot the system after shutdown. */
213#define RTSYSTEM_SHUTDOWN_REBOOT UINT32_C(0)
214/** Reboot the system after shutdown.
215 * The call may return VINF_SYS_MAY_POWER_OFF if the OS /
216 * hardware combination may power off instead of halting. */
217#define RTSYSTEM_SHUTDOWN_HALT UINT32_C(1)
218/** Power off the system after shutdown.
219 * This may be equvivalent to a RTSYSTEM_SHUTDOWN_HALT on systems where we
220 * cannot figure out whether the hardware/OS implements the actual powering
221 * off. If we can figure out that it's not supported, an
222 * VERR_SYS_CANNOT_POWER_OFF error is raised. */
223#define RTSYSTEM_SHUTDOWN_POWER_OFF UINT32_C(2)
224/** Power off the system after shutdown, or halt it if that's not possible. */
225#define RTSYSTEM_SHUTDOWN_POWER_OFF_HALT UINT32_C(3)
226/** The shutdown action mask. */
227#define RTSYSTEM_SHUTDOWN_ACTION_MASK UINT32_C(3)
228/** Unplanned shutdown/reboot. */
229#define RTSYSTEM_SHUTDOWN_UNPLANNED UINT32_C(0)
230/** Planned shutdown/reboot. */
231#define RTSYSTEM_SHUTDOWN_PLANNED RT_BIT_32(2)
232/** Force the system to shutdown/reboot regardless of objecting application
233 * or other stuff. This flag might not be realized on all systems. */
234#define RTSYSTEM_SHUTDOWN_FORCE RT_BIT_32(3)
235/** Parameter validation mask. */
236#define RTSYSTEM_SHUTDOWN_VALID_MASK UINT32_C(0x0000000f)
237/** @} */
238
239/**
240 * Shuts down the system.
241 *
242 * @returns IPRT status code on failure, on success it may or may not return
243 * depending on the OS.
244 * @retval VINF_SUCCESS
245 * @retval VINF_SYS_MAY_POWER_OFF
246 * @retval VERR_SYS_SHUTDOWN_FAILED
247 * @retval VERR_SYS_CANNOT_POWER_OFF
248 *
249 * @param cMsDelay The delay before the actual reboot. If this is
250 * not supported by the OS, an immediate reboot
251 * will be performed.
252 * @param fFlags Shutdown flags, see RTSYSTEM_SHUTDOWN_XXX.
253 * @param pszLogMsg Message for the log and users about why we're
254 * shutting down.
255 */
256RTDECL(int) RTSystemShutdown(RTMSINTERVAL cMsDelay, uint32_t fFlags, const char *pszLogMsg);
257
258/**
259 * Checks if we're executing inside a virtual machine (VM).
260 *
261 * The current implemention is very simplistic and won't try to detect the
262 * presence of a virtual machine monitor (VMM) unless it openly tells us it is
263 * there.
264 *
265 * @returns true if inside a VM, false if on real hardware.
266 *
267 * @todo If more information is needed, like which VMM it is and which
268 * version and such, add one or two new APIs.
269 */
270RTDECL(bool) RTSystemIsInsideVM(void);
271
272/**
273 * System firmware types.
274 */
275typedef enum RTSYSFWTYPE
276{
277 /** Invalid zero value. */
278 RTSYSFWTYPE_INVALID = 0,
279 /** Unknown firmware. */
280 RTSYSFWTYPE_UNKNOWN,
281 /** Firmware is BIOS. */
282 RTSYSFWTYPE_BIOS,
283 /** Firmware is UEFI. */
284 RTSYSFWTYPE_UEFI,
285 /** End valid firmware values (exclusive). */
286 RTSYSFWTYPE_END,
287 /** The usual 32-bit hack. */
288 RTSYSFWTYPE_32_BIT_HACK = 0x7fffffff
289} RTSYSFWTYPE;
290/** Pointer to a system firmware type. */
291typedef RTSYSFWTYPE *PRTSYSFWTYPE;
292
293/**
294 * Queries the system's firmware type.
295 *
296 * @returns IPRT status code.
297 * @retval VERR_NOT_SUPPORTED if not supported or implemented.
298 * @param penmType Where to return the firmware type on success.
299 */
300RTDECL(int) RTSystemQueryFirmwareType(PRTSYSFWTYPE penmType);
301
302/**
303 * Translates the @a enmType value to a string.
304 *
305 * @returns Read-only name.
306 * @param enmType The firmware type to convert to string.
307 */
308RTDECL(const char *) RTSystemFirmwareTypeName(RTSYSFWTYPE enmType);
309
310/**
311 * Boolean firmware values queriable via RTSystemQueryFirmwareBoolean().
312 */
313typedef enum RTSYSFWBOOL
314{
315 /** Invalid property, do not use. */
316 RTSYSFWBOOL_INVALID = 0,
317 /** Whether Secure Boot is enabled or not (type: boolean). */
318 RTSYSFWBOOL_SECURE_BOOT,
319 /** End of valid */
320 RTSYSFWBOOL_END,
321 /** The usual 32-bit hack. */
322 RTSYSFWBOOL_32_BIT_HACK = 0x7fffffff
323} RTSYSFWBOOL;
324
325/**
326 * Queries the value of a firmware property.
327 *
328 * @returns IPRT status code.
329 * @retval VERR_NOT_SUPPORTED if we cannot query firmware properties on the host.
330 * @retval VERR_SYS_UNSUPPORTED_FIRMWARE_PROPERTY if @a enmBoolean isn't
331 * supported.
332 * @param enmBoolean The value to query.
333 * @param pfValue Where to return the value.
334 */
335RTDECL(int) RTSystemQueryFirmwareBoolean(RTSYSFWBOOL enmBoolean, bool *pfValue);
336
337#ifdef RT_OS_WINDOWS
338
339/**
340 * Get the Windows NT build number.
341 *
342 * @returns NT build number.
343 *
344 * @remarks Windows NT only. Requires IPRT to be initialized.
345 */
346RTDECL(uint32_t) RTSystemGetNtBuildNo(void);
347
348/** Makes an NT version for comparison with RTSystemGetNtVersion(). */
349# define RTSYSTEM_MAKE_NT_VERSION(a_uMajor, a_uMinor, a_uBuild) \
350 ( ((uint64_t)(a_uMajor) << 52) | ((uint64_t)((a_uMinor) & 0xfffU) << 40) | ((uint32_t)(a_uBuild)) )
351/** Extracts the major version number from a RTSYSTEM_MAKE_NT_VERSION value. */
352# define RTSYSTEM_NT_VERSION_GET_MAJOR(a_uNtVersion) ((uint32_t)((a_uNtVersion) >> 52))
353/** Extracts the minor version number from a RTSYSTEM_MAKE_NT_VERSION value. */
354# define RTSYSTEM_NT_VERSION_GET_MINOR(a_uNtVersion) ((uint32_t)((a_uNtVersion) >> 40) & UINT32_C(0xfff))
355/** Extracts the build number from a RTSYSTEM_MAKE_NT_VERSION value. */
356# define RTSYSTEM_NT_VERSION_GET_BUILD(a_uNtVersion) ((uint32_t)(a_uNtVersion))
357
358/**
359 * Get the Windows NT version number.
360 *
361 * @returns Version formatted using RTSYSTEM_MAKE_NT_VERSION().
362 *
363 * @remarks Windows NT only. Requires IPRT to be initialized.
364 */
365RTDECL(uint64_t) RTSystemGetNtVersion(void);
366
367/**
368 * Get the Windows NT product type (OSVERSIONINFOW::wProductType).
369 */
370RTDECL(uint8_t) RTSystemGetNtProductType(void);
371
372#endif /* RT_OS_WINDOWS */
373
374/** @} */
375
376RT_C_DECLS_END
377
378#endif /* !IPRT_INCLUDED_system_h */
379
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