VirtualBox

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

Last change on this file since 78286 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

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