init.cpp revision e207408c05befbd22f8f0a8b233291144c5169a3
/* $Id$ */
/** @file
* IPRT - Init Ring-3.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_DEFAULT
#ifdef RT_OS_WINDOWS
# include <process.h>
#else
# include <unistd.h>
#endif
#include <iprt/initterm.h>
# include <stdlib.h>
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The number of calls to RTR3Init. */
/** Whether we're currently initializing the IPRT. */
static bool volatile g_fInitializing = false;
/** The process path.
* This is used by RTPathProgram and RTProcGetExecutableName and set by rtProcInitName. */
char g_szrtProcExePath[RTPATH_MAX];
/** The length of g_szrtProcExePath. */
/** The length of directory path component of g_szrtProcExePath. */
/** The offset of the process name into g_szrtProcExePath. */
/**
* Program start nanosecond TS.
*/
/**
* Program start microsecond TS.
*/
/**
* Program start millisecond TS.
*/
/**
* The process identifier of the running process.
*/
/**
* The current process priority.
*/
/**
* Internal worker which initializes or re-initializes the
* program path, name and directory globals.
*
* @returns IPRT status code.
* @param pszProgramPath The program path, NULL if not specified.
*/
static int rtR3InitProgramPath(const char *pszProgramPath)
{
/*
* We're reserving 32 bytes here for file names as what not.
*/
if (!pszProgramPath)
{
if (RT_FAILURE(rc))
return rc;
}
else
{
}
/*
* Parse the name.
*/
return VINF_SUCCESS;
}
/**
* Internal initialization worker.
*
* @returns IPRT status code.
* @param fInitSUPLib Whether to call SUPR3Init.
* @param pszProgramPath The program path, NULL if not specified.
*/
{
int rc = VINF_SUCCESS;
/* no entry log flow, because prefixes and thread may freak out. */
/*
* Do reference counting, only initialize the first time around.
*
* We are ASSUMING that nobody will be able to race RTR3Init calls when the
* first one, the real init, is running (second assertion).
*/
if (cUsers != 1)
{
if (fInitSUPLib)
#endif
if (pszProgramPath)
return rc;
}
ASMAtomicWriteBool(&g_fInitializing, true);
# ifdef VBOX
/*
* This MUST be done as the very first thing, before any file is opened.
* The log is opened on demand, but the first log entries may be caused
* by rtThreadInit() below.
*/
if ( pszDisableHostCache != NULL
&& strlen(pszDisableHostCache) > 0
{
}
# endif /* VBOX */
#endif /* !IN_GUEST && !RT_NO_GIP */
/*
* Thread Thread database and adopt the caller thread as 'main'.
* This must be done before everything else or else we'll call into threading
* without having initialized TLS entries and suchlike.
*/
rc = rtThreadInit();
if (RT_FAILURE(rc))
{
ASMAtomicWriteBool(&g_fInitializing, false);
return rc;
}
if (fInitSUPLib)
{
/*
* Init GIP first.
* (The more time for updates before real use, the better.)
*/
}
#endif
/*
* The Process ID.
*/
#ifdef _MSC_VER
#else
g_ProcessSelf = getpid();
#endif
/*
* The executable path, name and directory.
*/
if (RT_FAILURE(rc))
{
ASMAtomicWriteBool(&g_fInitializing, false);
return rc;
}
/*
* The threading is initialized we can safely sleep a bit if GIP
* needs some time to update itself updating.
*/
if (fInitSUPLib && g_pSUPGlobalInfoPage)
{
RTThreadSleep(20);
RTTimeNanoTS();
}
#endif
/*
* Init the program start TSes.
* Do that here to be sure that the GIP time was properly updated the 1st time.
*/
/*
* More stuff to come?
*/
LogFlow(("RTR3Init: returns VINF_SUCCESS\n"));
ASMAtomicWriteBool(&g_fInitializing, false);
return VINF_SUCCESS;
}
{
}
{
}
{
}
RTR3DECL(int) RTR3InitAndSUPLib(void)
{
}
{
}
#if 0 /** @todo implement RTR3Term. */
{
}
#endif