VirtualBox

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

Last change on this file since 8170 was 8170, checked in by vboxsync, 16 years ago

Rebranding: replacing more innotek strings.

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