VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/init.cpp@ 92625

最後變更 在這個檔案從92625是 92625,由 vboxsync 提交於 3 年 前

IPRT/RTR3Init/win: Use RTGetOptArgvFromString instead of CommandLineToArgvW to convert the unicode command line to argv.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Id Revision
檔案大小: 21.4 KB
 
1/* $Id: init.cpp 92625 2021-11-29 12:26:39Z vboxsync $ */
2/** @file
3 * IPRT - Init Ring-3.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#define LOG_GROUP RTLOGGROUP_DEFAULT
32#include <iprt/types.h> /* darwin: UINT32_C and others. */
33
34#ifdef RT_OS_WINDOWS
35# include <process.h>
36# include <iprt/win/windows.h>
37#else
38# include <unistd.h>
39# ifndef RT_OS_OS2
40# include <pthread.h>
41# include <signal.h>
42# include <errno.h>
43# define IPRT_USE_SIG_CHILD_DUMMY
44# endif
45#endif
46#ifdef RT_OS_OS2
47# include <InnoTekLIBC/fork.h>
48# define INCL_DOSMISC
49# include <os2.h>
50#endif
51#include <locale.h>
52
53#include <iprt/initterm.h>
54#include <iprt/asm.h>
55#include <iprt/assert.h>
56#include <iprt/errcore.h>
57#include <iprt/log.h>
58#include <iprt/mem.h>
59#include <iprt/path.h>
60#include <iprt/time.h>
61#include <iprt/string.h>
62#include <iprt/param.h>
63#ifdef RT_OS_WINDOWS
64# include <iprt/getopt.h>
65# include <iprt/utf16.h>
66#endif
67#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
68# include <iprt/file.h>
69# include <VBox/sup.h>
70#endif
71#include <stdlib.h>
72
73#include "init.h"
74#include "internal/alignmentchecks.h"
75#include "internal/path.h"
76#include "internal/process.h"
77#include "internal/thread.h"
78#include "internal/time.h"
79
80
81/*********************************************************************************************************************************
82* Global Variables *
83*********************************************************************************************************************************/
84/** The number of calls to RTR3Init*. */
85static int32_t volatile g_cUsers = 0;
86/** Whether we're currently initializing the IPRT. */
87static bool volatile g_fInitializing = false;
88
89/** The process path.
90 * This is used by RTPathExecDir and RTProcGetExecutablePath and set by rtProcInitName. */
91DECL_HIDDEN_DATA(char) g_szrtProcExePath[RTPATH_MAX];
92/** The length of g_szrtProcExePath. */
93DECL_HIDDEN_DATA(size_t) g_cchrtProcExePath;
94/** The length of directory path component of g_szrtProcExePath. */
95DECL_HIDDEN_DATA(size_t) g_cchrtProcDir;
96/** The offset of the process name into g_szrtProcExePath. */
97DECL_HIDDEN_DATA(size_t) g_offrtProcName;
98
99/** The IPRT init flags. */
100static uint32_t g_fInitFlags;
101
102/** The argument count of the program. */
103static int g_crtArgs = -1;
104/** The arguments of the program (UTF-8). This is "leaked". */
105static char ** g_papszrtArgs;
106/** The original argument vector of the program. */
107static char ** g_papszrtOrgArgs;
108
109/**
110 * Program start nanosecond TS.
111 */
112DECL_HIDDEN_DATA(uint64_t) g_u64ProgramStartNanoTS;
113
114/**
115 * The process identifier of the running process.
116 */
117DECL_HIDDEN_DATA(RTPROCESS) g_ProcessSelf = NIL_RTPROCESS;
118
119/**
120 * The current process priority.
121 */
122DECL_HIDDEN_DATA(RTPROCPRIORITY) g_enmProcessPriority = RTPROCPRIORITY_DEFAULT;
123
124/**
125 * Set if the atexit callback has been called, i.e. indicating
126 * that the process is terminating.
127 */
128DECL_HIDDEN_DATA(bool volatile) g_frtAtExitCalled = false;
129
130#ifdef IPRT_WITH_ALIGNMENT_CHECKS
131/**
132 * Whether alignment checks are enabled.
133 * This is set if the environment variable IPRT_ALIGNMENT_CHECKS is 1.
134 */
135RTDATADECL(bool) g_fRTAlignmentChecks = false;
136#endif
137
138
139#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_NETBSD) || defined(RT_OS_HAIKU) \
140 || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || defined(RT_OS_SOLARIS) /** @todo add host init hooks everywhere. */
141/* Stubs */
142DECLHIDDEN(int) rtR3InitNativeFirst(uint32_t fFlags) { RT_NOREF_PV(fFlags); return VINF_SUCCESS; }
143DECLHIDDEN(int) rtR3InitNativeFinal(uint32_t fFlags) { RT_NOREF_PV(fFlags); return VINF_SUCCESS; }
144DECLHIDDEN(void) rtR3InitNativeObtrusive(uint32_t fFlags) { RT_NOREF_PV(fFlags); }
145#endif
146
147
148/**
149 * atexit callback.
150 *
151 * This makes sure any loggers are flushed and will later also work the
152 * termination callback chain.
153 */
154static void rtR3ExitCallback(void) RT_NOTHROW_DEF
155{
156 ASMAtomicWriteBool(&g_frtAtExitCalled, true);
157
158 if (g_cUsers > 0)
159 {
160 PRTLOGGER pLogger = RTLogGetDefaultInstance();
161 if (pLogger)
162 RTLogFlush(pLogger);
163
164 pLogger = RTLogRelGetDefaultInstance();
165 if (pLogger)
166 RTLogFlush(pLogger);
167 }
168}
169
170
171#ifndef RT_OS_WINDOWS
172/**
173 * Fork callback, child context.
174 */
175static void rtR3ForkChildCallback(void)
176{
177 g_ProcessSelf = getpid();
178}
179#endif /* RT_OS_WINDOWS */
180
181#ifdef RT_OS_OS2
182/** Fork completion callback for OS/2. Only called in the child. */
183static void rtR3ForkOs2ChildCompletionCallback(void *pvArg, int rc, __LIBC_FORKCTX enmCtx)
184{
185 Assert(enmCtx == __LIBC_FORK_CTX_CHILD); NOREF(enmCtx);
186 NOREF(pvArg);
187
188 if (!rc)
189 rtR3ForkChildCallback();
190}
191
192/** Low-level fork callback for OS/2. */
193int rtR3ForkOs2Child(__LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
194{
195 if (enmOperation == __LIBC_FORK_OP_EXEC_CHILD)
196 return pForkHandle->pfnCompletionCallback(pForkHandle, rtR3ForkOs2ChildCompletionCallback, NULL, __LIBC_FORK_CTX_CHILD);
197 return 0;
198}
199
200# define static static volatile /** @todo _FORK_CHILD1 causes unresolved externals in optimized builds. Fix macro. */
201_FORK_CHILD1(0, rtR3ForkOs2Child);
202# undef static
203#endif /* RT_OS_OS2 */
204
205
206
207/**
208 * Internal worker which initializes or re-initializes the
209 * program path, name and directory globals.
210 *
211 * @returns IPRT status code.
212 * @param pszProgramPath The program path, NULL if not specified.
213 */
214static int rtR3InitProgramPath(const char *pszProgramPath)
215{
216 /*
217 * We're reserving 32 bytes here for file names as what not.
218 */
219 if (!pszProgramPath)
220 {
221 int rc = rtProcInitExePath(g_szrtProcExePath, sizeof(g_szrtProcExePath) - 32);
222 if (RT_FAILURE(rc))
223 return rc;
224 }
225 else
226 {
227 size_t cch = strlen(pszProgramPath);
228 Assert(cch > 1);
229 AssertMsgReturn(cch < sizeof(g_szrtProcExePath) - 32, ("%zu\n", cch), VERR_BUFFER_OVERFLOW);
230 memcpy(g_szrtProcExePath, pszProgramPath, cch + 1);
231 }
232
233 /*
234 * Parse the name.
235 */
236 ssize_t offName;
237 g_cchrtProcExePath = RTPathParseSimple(g_szrtProcExePath, &g_cchrtProcDir, &offName, NULL);
238 g_offrtProcName = offName;
239 return VINF_SUCCESS;
240}
241
242
243#ifdef RT_OS_WINDOWS
244/**
245 * Checks the two argument vectors contains the same strings.
246 */
247DECLINLINE(bool) rtR3InitArgvEquals(int cArgs, char **papszArgs1, char **papszArgs2)
248{
249 if (papszArgs1 != papszArgs2)
250 while (cArgs-- > 0)
251 if (strcmp(papszArgs1[cArgs], papszArgs2[cArgs]) != 0)
252 return false;
253 return true;
254}
255#endif
256
257
258/**
259 * Internal worker which initializes or re-initializes the
260 * program path, name and directory globals.
261 *
262 * @returns IPRT status code.
263 * @param fFlags Flags, see RTR3INIT_XXX.
264 * @param cArgs Pointer to the argument count.
265 * @param ppapszArgs Pointer to the argument vector pointer. NULL
266 * allowed if @a cArgs is 0.
267 */
268static int rtR3InitArgv(uint32_t fFlags, int cArgs, char ***ppapszArgs)
269{
270 NOREF(fFlags);
271 if (cArgs)
272 {
273 AssertPtr(ppapszArgs);
274 AssertPtr(*ppapszArgs);
275 char **papszOrgArgs = *ppapszArgs;
276
277 /*
278 * Normally we should only be asked to convert arguments once. If we
279 * are though, it should be the already convered arguments.
280 */
281 if (g_crtArgs != -1)
282 {
283 AssertReturn( g_crtArgs == cArgs
284 && g_papszrtArgs == papszOrgArgs,
285 VERR_WRONG_ORDER); /* only init once! */
286 return VINF_SUCCESS;
287 }
288
289 if (!(fFlags & RTR3INIT_FLAGS_UTF8_ARGV))
290 {
291 /*
292 * Convert the arguments.
293 */
294 char **papszArgs;
295
296#ifdef RT_OS_WINDOWS
297 /* HACK ALERT! Try convert from unicode versions if possible.
298 Unfortunately for us, __wargv is only initialized if we have a unicode
299 main function. So, use getoptarv.cpp code to do the conversions and
300 hope it gives us the same result. (CommandLineToArgvW was not in NT 3.1.) */
301 if ( cArgs == __argc
302 && rtR3InitArgvEquals(cArgs, papszOrgArgs, __argv))
303 {
304 char *pszCmdLine = NULL;
305 int rc = RTUtf16ToUtf8Tag(GetCommandLineW(), &pszCmdLine, "will-leak:rtR3InitArgv");
306 AssertRCReturn(rc, rc);
307
308 int cArgsFromCmdLine = -1;
309 rc = RTGetOptArgvFromString(&papszArgs, &cArgsFromCmdLine, pszCmdLine,
310 RTGETOPTARGV_CNV_QUOTE_MS_CRT | RTGETOPTARGV_CNV_MODIFY_INPUT, NULL);
311 AssertMsgRCReturn(rc, ("pszCmdLine='%s' rc=%Rrc\n", pszCmdLine, rc), rc);
312 AssertMsg(cArgsFromCmdLine == cArgs,
313 ("cArgsFromCmdLine=%d cArgs=%d pszCmdLine='%s' rc=%Rrc\n", cArgsFromCmdLine, cArgs, pszCmdLine));
314 }
315 else
316#endif
317 {
318 papszArgs = (char **)RTMemAllocZTag((cArgs + 1) * sizeof(char *), "will-leak:rtR3InitArgv");
319 if (!papszArgs)
320 return VERR_NO_MEMORY;
321
322 for (int i = 0; i < cArgs; i++)
323 {
324 int rc = RTStrCurrentCPToUtf8(&papszArgs[i], papszOrgArgs[i]);
325 if (RT_FAILURE(rc))
326 {
327 while (i--)
328 RTStrFree(papszArgs[i]);
329 RTMemFree(papszArgs);
330 return rc;
331 }
332 }
333 }
334
335 papszArgs[cArgs] = NULL;
336
337 g_papszrtOrgArgs = papszOrgArgs;
338 g_papszrtArgs = papszArgs;
339 g_crtArgs = cArgs;
340
341 *ppapszArgs = papszArgs;
342 }
343 else
344 {
345 /*
346 * The arguments are already UTF-8, no conversion needed.
347 */
348 g_papszrtOrgArgs = papszOrgArgs;
349 g_papszrtArgs = papszOrgArgs;
350 g_crtArgs = cArgs;
351 }
352 }
353
354 return VINF_SUCCESS;
355}
356
357
358#ifdef IPRT_USE_SIG_CHILD_DUMMY
359/**
360 * Dummy SIGCHILD handler.
361 *
362 * Assigned on rtR3Init only when SIGCHILD handler is set SIGIGN or SIGDEF to
363 * ensure waitpid works properly for the terminated processes.
364 */
365static void rtR3SigChildHandler(int iSignal)
366{
367 NOREF(iSignal);
368}
369#endif /* IPRT_USE_SIG_CHILD_DUMMY */
370
371
372/**
373 * rtR3Init worker.
374 */
375static int rtR3InitBody(uint32_t fFlags, int cArgs, char ***ppapszArgs, const char *pszProgramPath)
376{
377 /*
378 * Early native initialization.
379 */
380 int rc = rtR3InitNativeFirst(fFlags);
381 AssertMsgRCReturn(rc, ("rtR3InitNativeFirst failed with %Rrc\n", rc), rc);
382
383 /*
384 * Disable error popups.
385 */
386#if defined(RT_OS_OS2) /** @todo move to private code. */
387 DosError(FERR_DISABLEHARDERR);
388#endif
389
390 /*
391 * Init C runtime locale before we do anything that may end up converting
392 * paths or we'll end up using the "C" locale for path conversion.
393 */
394 setlocale(LC_CTYPE, "");
395
396 /*
397 * The Process ID.
398 */
399#ifdef _MSC_VER
400 g_ProcessSelf = _getpid(); /* crappy ansi compiler */
401#else
402 g_ProcessSelf = getpid();
403#endif
404
405 /*
406 * Save the init flags.
407 */
408 g_fInitFlags |= fFlags;
409
410#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
411# ifdef VBOX
412 /*
413 * This MUST be done as the very first thing, before any file is opened.
414 * The log is opened on demand, but the first log entries may be caused
415 * by rtThreadInit() below.
416 */
417 const char *pszDisableHostCache = getenv("VBOX_DISABLE_HOST_DISK_CACHE");
418 if ( pszDisableHostCache != NULL
419 && *pszDisableHostCache
420 && strcmp(pszDisableHostCache, "0") != 0)
421 {
422 RTFileSetForceFlags(RTFILE_O_WRITE, RTFILE_O_WRITE_THROUGH, 0);
423 RTFileSetForceFlags(RTFILE_O_READWRITE, RTFILE_O_WRITE_THROUGH, 0);
424 }
425# endif /* VBOX */
426#endif /* !IN_GUEST && !RT_NO_GIP */
427
428 /*
429 * Thread Thread database and adopt the caller thread as 'main'.
430 * This must be done before everything else or else we'll call into threading
431 * without having initialized TLS entries and suchlike.
432 */
433 rc = rtThreadInit();
434 AssertMsgRCReturn(rc, ("Failed to initialize threads, rc=%Rrc!\n", rc), rc);
435
436 /*
437 * The executable path before SUPLib (windows requirement).
438 */
439 rc = rtR3InitProgramPath(pszProgramPath);
440 AssertLogRelMsgRCReturn(rc, ("Failed to get executable directory path, rc=%Rrc!\n", rc), rc);
441
442#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
443 /*
444 * Initialize SUPLib here so the GIP can get going as early as possible
445 * (improves accuracy for the first client).
446 */
447 if (fFlags & (RTR3INIT_FLAGS_SUPLIB | RTR3INIT_FLAGS_TRY_SUPLIB))
448 {
449 rc = SUPR3InitEx( fFlags >> RTR3INIT_FLAGS_SUPLIB_SHIFT
450 ? fFlags >> RTR3INIT_FLAGS_SUPLIB_SHIFT : SUPR3INIT_F_UNRESTRICTED, NULL /*ppSession*/);
451 AssertMsgReturn(RT_SUCCESS(rc) || (fFlags & RTR3INIT_FLAGS_TRY_SUPLIB),
452 ("Failed to initialize the support library, rc=%Rrc!\n", rc), rc);
453 }
454#endif
455
456 /*
457 * Convert arguments.
458 */
459 rc = rtR3InitArgv(fFlags, cArgs, ppapszArgs);
460 AssertLogRelMsgRCReturn(rc, ("Failed to convert the arguments, rc=%Rrc!\n", rc), rc);
461
462#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
463 /*
464 * The threading is initialized, so we can safely sleep a bit if GIP
465 * needs some time to start updating itself. Currently limited to
466 * the first mapping of GIP (u32TransactionId <= 4), quite possible we
467 * could just ditch this now.
468 */
469 /** @todo consider dropping this... */
470 PSUPGLOBALINFOPAGE pGip;
471 if ( (fFlags & (RTR3INIT_FLAGS_SUPLIB | RTR3INIT_FLAGS_TRY_SUPLIB))
472 && (pGip = g_pSUPGlobalInfoPage) != NULL
473 && pGip->u32Magic == SUPGLOBALINFOPAGE_MAGIC)
474 {
475 PSUPGIPCPU pGipCpu = SUPGetGipCpuPtr(pGip);
476 if ( pGipCpu
477 && pGipCpu->u32TransactionId <= 4)
478 {
479 RTThreadSleep(pGip->u32UpdateIntervalNS / RT_NS_1MS + 2);
480 RTTimeNanoTS();
481 }
482 }
483#endif
484
485 /*
486 * Init the program start timestamp TS.
487 * Do that here to be sure that the GIP time was properly updated the 1st time.
488 */
489 g_u64ProgramStartNanoTS = RTTimeNanoTS();
490
491 /*
492 * The remainder cannot easily be undone, so it has to go last.
493 */
494
495 /* Fork and exit callbacks. */
496#if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2)
497 rc = pthread_atfork(NULL, NULL, rtR3ForkChildCallback);
498 AssertMsg(rc == 0, ("%d\n", rc));
499#endif
500 atexit(rtR3ExitCallback);
501
502#ifdef IPRT_USE_SIG_CHILD_DUMMY
503 /*
504 * SIGCHLD must not be ignored (that's default), otherwise posix compliant waitpid
505 * implementations won't work right.
506 */
507 for (;;)
508 {
509 struct sigaction saOld;
510 rc = sigaction(SIGCHLD, 0, &saOld); AssertMsg(rc == 0, ("%d/%d\n", rc, errno));
511 if ( rc != 0
512 || (saOld.sa_flags & SA_SIGINFO)
513 || ( saOld.sa_handler != SIG_IGN
514 && saOld.sa_handler != SIG_DFL)
515 )
516 break;
517
518 /* Try install dummy handler. */
519 struct sigaction saNew = saOld;
520 saNew.sa_flags = SA_NOCLDSTOP | SA_RESTART;
521 saNew.sa_handler = rtR3SigChildHandler;
522 rc = sigemptyset(&saNew.sa_mask); AssertMsg(rc == 0, ("%d/%d\n", rc, errno));
523 struct sigaction saOld2;
524 rc = sigaction(SIGCHLD, &saNew, &saOld2); AssertMsg(rc == 0, ("%d/%d\n", rc, errno));
525 if ( rc != 0
526 || ( saOld2.sa_handler == saOld.sa_handler
527 && !(saOld2.sa_flags & SA_SIGINFO))
528 )
529 break;
530
531 /* Race during dynamic load, restore and try again... */
532 sigaction(SIGCHLD, &saOld2, NULL);
533 RTThreadYield();
534 }
535#endif /* IPRT_USE_SIG_CHILD_DUMMY */
536
537#ifdef IPRT_WITH_ALIGNMENT_CHECKS
538 /*
539 * Enable alignment checks.
540 */
541 const char *pszAlignmentChecks = getenv("IPRT_ALIGNMENT_CHECKS");
542 g_fRTAlignmentChecks = pszAlignmentChecks != NULL
543 && pszAlignmentChecks[0] == '1'
544 && pszAlignmentChecks[1] == '\0';
545 if (g_fRTAlignmentChecks)
546 IPRT_ALIGNMENT_CHECKS_ENABLE();
547#endif
548
549 /*
550 * Final native initialization.
551 */
552 rc = rtR3InitNativeFinal(fFlags);
553 AssertMsgRCReturn(rc, ("rtR3InitNativeFinal failed with %Rrc\n", rc), rc);
554
555 return VINF_SUCCESS;
556}
557
558
559/**
560 * Internal initialization worker.
561 *
562 * @returns IPRT status code.
563 * @param fFlags Flags, see RTR3INIT_XXX.
564 * @param cArgs Pointer to the argument count.
565 * @param ppapszArgs Pointer to the argument vector pointer. NULL
566 * allowed if @a cArgs is 0.
567 * @param pszProgramPath The program path. Pass NULL if we're to figure it
568 * out ourselves.
569 */
570static int rtR3Init(uint32_t fFlags, int cArgs, char ***ppapszArgs, const char *pszProgramPath)
571{
572 /* no entry log flow, because prefixes and thread may freak out. */
573 Assert(!(fFlags & ~RTR3INIT_FLAGS_VALID_MASK));
574 Assert(!(fFlags & RTR3INIT_FLAGS_DLL) || cArgs == 0);
575
576 /*
577 * Do reference counting, only initialize the first time around.
578 *
579 * We are ASSUMING that nobody will be able to race RTR3Init* calls when the
580 * first one, the real init, is running (second assertion).
581 */
582 int32_t cUsers = ASMAtomicIncS32(&g_cUsers);
583 if (cUsers != 1)
584 {
585 AssertMsg(cUsers > 1, ("%d\n", cUsers));
586 Assert(!g_fInitializing);
587
588#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
589 /* Initialize the support library if requested. We've always ignored the
590 status code here for some reason, making the two flags same. */
591 if (fFlags & (RTR3INIT_FLAGS_SUPLIB | RTR3INIT_FLAGS_TRY_SUPLIB))
592 {
593 SUPR3InitEx( fFlags >> RTR3INIT_FLAGS_SUPLIB_SHIFT
594 ? fFlags >> RTR3INIT_FLAGS_SUPLIB_SHIFT : SUPR3INIT_F_UNRESTRICTED, NULL /*ppSession*/);
595 g_fInitFlags |= fFlags & (RTR3INIT_FLAGS_SUPLIB | RTR3INIT_FLAGS_TRY_SUPLIB | RTR3INIT_FLAGS_SUPLIB_MASK);
596 }
597#endif
598 g_fInitFlags |= fFlags & RTR3INIT_FLAGS_UTF8_ARGV;
599
600 if ( !(fFlags & RTR3INIT_FLAGS_UNOBTRUSIVE)
601 && (g_fInitFlags & RTR3INIT_FLAGS_UNOBTRUSIVE))
602 {
603 g_fInitFlags &= ~RTR3INIT_FLAGS_UNOBTRUSIVE;
604 g_fInitFlags |= fFlags & RTR3INIT_FLAGS_STANDALONE_APP;
605 rtR3InitNativeObtrusive(g_fInitFlags | fFlags);
606 rtThreadReInitObtrusive();
607 }
608 else
609 Assert(!(fFlags & RTR3INIT_FLAGS_STANDALONE_APP) || (g_fInitFlags & RTR3INIT_FLAGS_STANDALONE_APP));
610
611 int rc = VINF_SUCCESS;
612 if (pszProgramPath)
613 rc = rtR3InitProgramPath(pszProgramPath);
614 if (RT_SUCCESS(rc))
615 rc = rtR3InitArgv(fFlags, cArgs, ppapszArgs);
616 return rc;
617 }
618
619 /*
620 * Do the initialization.
621 */
622 ASMAtomicWriteBool(&g_fInitializing, true);
623 int rc = rtR3InitBody(fFlags, cArgs, ppapszArgs, pszProgramPath);
624 ASMAtomicWriteBool(&g_fInitializing, false);
625 if (RT_FAILURE(rc))
626 {
627 /* failure */
628 ASMAtomicDecS32(&g_cUsers);
629 return rc;
630 }
631
632 /* success */
633 LogFlow(("rtR3Init: returns VINF_SUCCESS\n"));
634 return VINF_SUCCESS;
635}
636
637
638RTR3DECL(int) RTR3InitExe(int cArgs, char ***ppapszArgs, uint32_t fFlags)
639{
640 Assert(!(fFlags & RTR3INIT_FLAGS_DLL));
641 return rtR3Init(fFlags, cArgs, ppapszArgs, NULL);
642}
643
644
645RTR3DECL(int) RTR3InitExeNoArguments(uint32_t fFlags)
646{
647 Assert(!(fFlags & RTR3INIT_FLAGS_DLL));
648 return rtR3Init(fFlags, 0, NULL, NULL);
649}
650
651
652RTR3DECL(int) RTR3InitDll(uint32_t fFlags)
653{
654 Assert(!(fFlags & RTR3INIT_FLAGS_DLL));
655 return rtR3Init(fFlags | RTR3INIT_FLAGS_DLL, 0, NULL, NULL);
656}
657
658
659RTR3DECL(int) RTR3InitEx(uint32_t iVersion, uint32_t fFlags, int cArgs, char ***ppapszArgs, const char *pszProgramPath)
660{
661 AssertReturn(iVersion == RTR3INIT_VER_CUR, VERR_NOT_SUPPORTED);
662 return rtR3Init(fFlags, cArgs, ppapszArgs, pszProgramPath);
663}
664
665
666RTR3DECL(bool) RTR3InitIsInitialized(void)
667{
668 return g_cUsers >= 1 && !g_fInitializing;
669}
670
671
672RTR3DECL(bool) RTR3InitIsUnobtrusive(void)
673{
674 return RT_BOOL(g_fInitFlags & RTR3INIT_FLAGS_UNOBTRUSIVE);
675}
676
677
678#if 0 /** @todo implement RTR3Term. */
679RTR3DECL(void) RTR3Term(void)
680{
681}
682#endif
683
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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