VirtualBox

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

Last change on this file since 92059 was 85121, checked in by vboxsync, 4 years ago

iprt/cdefs.h: Refactored the typedef use of DECLCALLBACK as well as DECLCALLBACKMEMBER to wrap the whole expression, similar to the DECLR?CALLBACKMEMBER macros. This allows adding a throw() at the end when compiling with the VC++ compiler to indicate that the callbacks won't throw anything, so we can stop supressing the C5039 warning about passing functions that can potential throw C++ exceptions to extern C code that can't necessarily cope with such (unwind,++). Introduced a few _EX variations that allows specifying different/no calling convention too, as that's handy when dynamically resolving host APIs. Fixed numerous places missing DECLCALLBACK and such. Left two angry @todos regarding use of CreateThread. bugref:9794

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