VirtualBox

source: vbox/trunk/include/iprt/initterm.h@ 106086

Last change on this file since 106086 was 106086, checked in by vboxsync, 7 months ago

IPRT/initterm.h: Don't expose RTR3Term() if we actually don't implement it (yet).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 KB
Line 
1/** @file
2 * IPRT - Runtime Init/Term.
3 */
4
5/*
6 * Copyright (C) 2006-2024 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_initterm_h
37#define IPRT_INCLUDED_initterm_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/cdefs.h>
43#include <iprt/types.h>
44
45RT_C_DECLS_BEGIN
46
47/** @defgroup grp_rt IPRT C/C++ APIs
48 * @{
49 */
50
51/** @defgroup grp_rt_initterm RTInit/RTTerm - Initialization and Termination
52 *
53 * APIs for initializing and terminating the IPRT, optionally it can also
54 * convert input arguments to UTF-8 (in ring-3).
55 *
56 * @sa RTOnce, RTOnceEx.
57 *
58 * @{
59 */
60
61#ifdef IN_RING3
62
63/** @name RTR3INIT_FLAGS_XXX - RTR3Init* flags.
64 * @see RTR3InitExeNoArguments, RTR3InitExe, RTR3InitDll, RTR3InitEx
65 * @{ */
66/** Initializing IPRT from a DLL. */
67# define RTR3INIT_FLAGS_DLL RT_BIT(0)
68/** The caller ensures that the argument vector is UTF-8. */
69# define RTR3INIT_FLAGS_UTF8_ARGV RT_BIT(1)
70/** Indicates that this is a standalone application without any additional
71 * shared libraries in the application directory. Mainly windows loader mess. */
72# define RTR3INIT_FLAGS_STANDALONE_APP RT_BIT(2)
73/** We are sharing a process space, so we need to behave. */
74# define RTR3INIT_FLAGS_UNOBTRUSIVE RT_BIT(3)
75
76/** Initialize SUPLib (must not fail). */
77# define RTR3INIT_FLAGS_SUPLIB RT_BIT(16)
78/** Try initialize SUPLib and ignore failures. */
79# define RTR3INIT_FLAGS_TRY_SUPLIB RT_BIT(17)
80/** Shift count for passing thru SUPR3INIT_F_XXX flags. */
81# define RTR3INIT_FLAGS_SUPLIB_SHIFT 18
82/** The mask covering the passthru SUPR3INIT_F_XXX flags. */
83# define RTR3INIT_FLAGS_SUPLIB_MASK UINT32_C(0xfffc0000)
84
85/** Valid flag mask. */
86# define RTR3INIT_FLAGS_VALID_MASK UINT32_C(0xffff000f)
87/** @} */
88
89/** @name RTR3InitEx version
90 * @{ */
91/** Version 1. */
92# define RTR3INIT_VER_1 UINT32_C(1)
93/** Version 2 - new flags, rearranged a bit. */
94# define RTR3INIT_VER_2 UINT32_C(2)
95/** The current version. */
96# define RTR3INIT_VER_CUR RTR3INIT_VER_2
97/** @} */
98
99/**
100 * Initializes the runtime library.
101 *
102 * @returns iprt status code.
103 * @param fFlags Flags, see RTR3INIT_FLAGS_XXX.
104 */
105RTR3DECL(int) RTR3InitExeNoArguments(uint32_t fFlags);
106
107/**
108 * Initializes the runtime library.
109 *
110 * @returns iprt status code.
111 * @param cArgs Pointer to the argument count.
112 * @param ppapszArgs Pointer to the argument vector pointer.
113 * @param fFlags Flags, see RTR3INIT_FLAGS_XXX.
114 */
115RTR3DECL(int) RTR3InitExe(int cArgs, char ***ppapszArgs, uint32_t fFlags);
116
117/**
118 * Initializes the runtime library.
119 *
120 * @returns iprt status code.
121 * @param fFlags Flags, see RTR3INIT_FLAGS_XXX.
122 */
123RTR3DECL(int) RTR3InitDll(uint32_t fFlags);
124
125/**
126 * Initializes the runtime library and possibly also SUPLib too.
127 *
128 * Avoid this interface, it's not considered stable.
129 *
130 * @returns IPRT status code.
131 * @param iVersion The interface version. Must be 0 atm.
132 * @param fFlags Flags, see RTR3INIT_FLAGS_XXX.
133 * @param cArgs Pointer to the argument count.
134 * @param ppapszArgs Pointer to the argument vector pointer. NULL
135 * allowed if @a cArgs is 0.
136 * @param pszProgramPath The program path. Pass NULL if we're to figure it
137 * out ourselves.
138 */
139RTR3DECL(int) RTR3InitEx(uint32_t iVersion, uint32_t fFlags, int cArgs, char ***ppapszArgs, const char *pszProgramPath);
140
141#if 0 /** @todo implement RTR3Term. */
142/**
143 * Terminates the runtime library.
144 */
145RTR3DECL(void) RTR3Term(void);
146#endif
147
148/**
149 * Is IPRT succesfully initialized?
150 *
151 * @returns true/false.
152 */
153RTR3DECL(bool) RTR3InitIsInitialized(void);
154
155/**
156 * Are we running in unobtrusive mode?
157 * @returns true/false.
158 */
159RTR3DECL(bool) RTR3InitIsUnobtrusive(void);
160
161#endif /* IN_RING3 */
162
163
164#ifdef IN_RING0
165/**
166 * Initializes the ring-0 driver runtime library.
167 *
168 * @returns iprt status code.
169 * @param fReserved Flags reserved for the future.
170 */
171RTR0DECL(int) RTR0Init(unsigned fReserved);
172
173/**
174 * Terminates the ring-0 driver runtime library.
175 */
176RTR0DECL(void) RTR0Term(void);
177
178/**
179 * Forcibily terminates the ring-0 driver runtime library.
180 *
181 * This should be used when statically linking the IPRT. Module using dynamic
182 * linking shall use RTR0Term. If you're not sure, use RTR0Term!
183 */
184RTR0DECL(void) RTR0TermForced(void);
185#endif
186
187#ifdef IN_RC
188/**
189 * Initializes the raw-mode context runtime library.
190 *
191 * @returns iprt status code.
192 *
193 * @param u64ProgramStartNanoTS The startup timestamp.
194 */
195RTRCDECL(int) RTRCInit(uint64_t u64ProgramStartNanoTS);
196
197/**
198 * Terminates the raw-mode context runtime library.
199 */
200RTRCDECL(void) RTRCTerm(void);
201#endif
202
203
204/**
205 * Termination reason.
206 */
207typedef enum RTTERMREASON
208{
209 /** Normal exit. iStatus contains the exit code. */
210 RTTERMREASON_EXIT = 1,
211 /** Any abnormal exit. iStatus is 0 and has no meaning. */
212 RTTERMREASON_ABEND,
213 /** Killed by a signal. The iStatus contains the signal number. */
214 RTTERMREASON_SIGNAL,
215 /** The IPRT module is being unloaded. iStatus is 0 and has no meaning. */
216 RTTERMREASON_UNLOAD
217} RTTERMREASON;
218
219/** Whether lazy clean up is Okay or not.
220 * When the process is exiting, it is a waste of time to for instance free heap
221 * memory or close open files. OTOH, when the runtime is unloaded from the
222 * process, it is important to release absolutely all resources to prevent
223 * resource leaks. */
224#define RTTERMREASON_IS_LAZY_CLEANUP_OK(enmReason) ((enmReason) != RTTERMREASON_UNLOAD)
225
226
227/**
228 * IPRT termination callback function.
229 *
230 * @param enmReason The cause of the termination.
231 * @param iStatus The meaning of this depends on enmReason.
232 * @param pvUser User argument passed to RTTermRegisterCallback.
233 */
234typedef DECLCALLBACKTYPE(void, FNRTTERMCALLBACK,(RTTERMREASON enmReason, int32_t iStatus, void *pvUser));
235/** Pointer to an IPRT termination callback function. */
236typedef FNRTTERMCALLBACK *PFNRTTERMCALLBACK;
237
238
239/**
240 * Registers a termination callback.
241 *
242 * This is intended for performing clean up during IPRT termination. Frequently
243 * paired with lazy initialization thru RTOnce.
244 *
245 * The callbacks are called in LIFO order.
246 *
247 * @returns IPRT status code.
248 *
249 * @param pfnCallback The callback function.
250 * @param pvUser The user argument for the callback.
251 *
252 * @remarks May need to acquire a fast mutex or critical section, so use with
253 * some care in ring-0 context.
254 *
255 * @remarks Be very careful using this from code that may be unloaded before
256 * IPRT terminates. Unlike some atexit and on_exit implementations,
257 * IPRT will not automatically unregister callbacks when a module gets
258 * unloaded.
259 */
260RTDECL(int) RTTermRegisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
261
262/**
263 * Deregister a termination callback.
264 *
265 * @returns VINF_SUCCESS if found, VERR_NOT_FOUND if the callback/pvUser pair
266 * wasn't found.
267 *
268 * @param pfnCallback The callback function.
269 * @param pvUser The user argument for the callback.
270 */
271RTDECL(int) RTTermDeregisterCallback(PFNRTTERMCALLBACK pfnCallback, void *pvUser);
272
273/**
274 * Runs the termination callback queue.
275 *
276 * Normally called by an internal IPRT termination function, but may also be
277 * called by external code immediately prior to terminating IPRT if it is in a
278 * better position to state the termination reason and/or status.
279 *
280 * @param enmReason The reason why it's called.
281 * @param iStatus The associated exit status or signal number.
282 */
283RTDECL(void) RTTermRunCallbacks(RTTERMREASON enmReason, int32_t iStatus);
284
285/** @} */
286
287/** @} */
288
289RT_C_DECLS_END
290
291
292#endif /* !IPRT_INCLUDED_initterm_h */
293
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette