VirtualBox

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

Last change on this file since 5999 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.9 KB
Line 
1/* $Id: init.cpp 5999 2007-12-07 15:05:06Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Init Ring-3.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.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/*******************************************************************************
30* Header Files *
31*******************************************************************************/
32#define LOG_GROUP RTLOGGROUP_DEFAULT
33#ifdef RT_OS_WINDOWS
34# include <process.h>
35#else
36# include <unistd.h>
37#endif
38
39#include <iprt/runtime.h>
40#include <iprt/path.h>
41#include <iprt/assert.h>
42#include <iprt/log.h>
43#include <iprt/time.h>
44#include <iprt/err.h>
45#include <iprt/string.h>
46#include <iprt/param.h>
47#ifndef IN_GUEST
48# include <iprt/file.h>
49# include <VBox/sup.h>
50# include <stdlib.h>
51#endif
52#include "internal/path.h"
53#include "internal/process.h"
54#include "internal/thread.h"
55#include "internal/thread.h"
56#include "internal/time.h"
57
58
59/*******************************************************************************
60* Global Variables *
61*******************************************************************************/
62/** Program path.
63 * The size is hardcoded, so we'll have to check for overflow when setting it
64 * since some hosts might support longer paths.
65 * @internal
66 */
67char g_szrtProgramPath[RTPATH_MAX];
68
69/**
70 * Program start nanosecond TS.
71 */
72uint64_t g_u64ProgramStartNanoTS;
73
74/**
75 * Program start microsecond TS.
76 */
77uint64_t g_u64ProgramStartMicroTS;
78
79/**
80 * Program start millisecond TS.
81 */
82uint64_t g_u64ProgramStartMilliTS;
83
84/**
85 * The process identifier of the running process.
86 */
87RTPROCESS g_ProcessSelf = NIL_RTPROCESS;
88
89/**
90 * The current process priority.
91 */
92RTPROCPRIORITY g_enmProcessPriority = RTPROCPRIORITY_DEFAULT;
93
94
95/**
96 * Initalizes the runtime library.
97 *
98 * @returns iprt status code.
99 *
100 * @param fInitSUPLib Set if SUPInit() shall be called during init (default).
101 * Clear if not to call it.
102 * @param cbReserve The number of bytes of contiguous memory that should be reserved by
103 * the runtime / support library.
104 * Set this to 0 if no reservation is required. (default)
105 * Set this to ~0 if the maximum amount supported by the VM is to be
106 * attempted reserved, or the maximum available.
107 * This argument only applies if fInitSUPLib is true and we're in ring-3 HC.
108 */
109RTR3DECL(int) RTR3Init(bool fInitSUPLib, size_t cbReserve)
110{
111 /* no entry log flow, because prefixes and thread may freak out. */
112
113#ifndef IN_GUEST
114# ifdef VBOX
115 /*
116 * This MUST be done as the very first thing, before any file is opened.
117 * The log is opened on demand, but the first log entries may be caused
118 * by rtThreadInit() below.
119 */
120 const char *pszDisableHostCache = getenv("VBOX_DISABLE_HOST_DISK_CACHE");
121 if ( pszDisableHostCache != NULL
122 && strlen(pszDisableHostCache) > 0
123 && strcmp(pszDisableHostCache, "0") != 0)
124 {
125 RTFileSetForceFlags(RTFILE_O_WRITE, RTFILE_O_WRITE_THROUGH, 0);
126 RTFileSetForceFlags(RTFILE_O_READWRITE, RTFILE_O_WRITE_THROUGH, 0);
127 }
128# endif /* VBOX */
129#endif /* !IN_GUEST */
130
131 /*
132 * Thread Thread database and adopt the caller thread as 'main'.
133 * This must be done before everything else or else we'll call into threading
134 * without having initialized TLS entries and suchlike.
135 */
136 int rc = rtThreadInit();
137 if (RT_FAILURE(rc))
138 {
139 AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
140 return rc;
141 }
142
143#ifndef IN_GUEST
144 if (fInitSUPLib)
145 {
146 /*
147 * Init GIP first.
148 * (The more time for updates before real use, the better.)
149 */
150 SUPInit(NULL, cbReserve);
151 }
152#endif
153
154 /*
155 * Init the program start TSes.
156 */
157 g_u64ProgramStartNanoTS = RTTimeNanoTS();
158 g_u64ProgramStartMicroTS = g_u64ProgramStartNanoTS / 1000;
159 g_u64ProgramStartMilliTS = g_u64ProgramStartNanoTS / 1000000;
160
161#ifndef IN_GUEST
162 /*
163 * The threading is initialized we can safely sleep a bit if GIP
164 * needs some time to update itself updating.
165 */
166 if (fInitSUPLib && g_pSUPGlobalInfoPage)
167 {
168 RTThreadSleep(20);
169 RTTimeNanoTS();
170 }
171#endif
172
173 /*
174 * Get the executable path.
175 *
176 * We're also checking the depth here since we'll be
177 * appending filenames to the executable path. Currently
178 * we assume 16 bytes are what we need.
179 */
180 char szPath[RTPATH_MAX - 16];
181 rc = RTPathProgram(szPath, sizeof(szPath));
182 if (RT_FAILURE(rc))
183 {
184 AssertMsgFailed(("Failed to get executable directory path, rc=%d!\n", rc));
185 return rc;
186 }
187
188 /*
189 * The Process ID.
190 */
191#ifdef _MSC_VER
192 g_ProcessSelf = _getpid(); /* crappy ansi compiler */
193#else
194 g_ProcessSelf = getpid();
195#endif
196
197 /*
198 * More stuff to come.
199 */
200
201 LogFlow(("RTR3Init: returns VINF_SUCCESS\n"));
202 return VINF_SUCCESS;
203}
204
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