/* $Id$ */
/** @file
* IPRT - Initialization & Termination, Ring-0 Driver, Solaris.
*/
/*
* Copyright (C) 2006-2015 Oracle Corporation
*
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-solaris-kernel.h"
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
# include <iprt/asm-amd64-x86.h>
#endif
#include "internal/initterm.h"
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Kernel debug info handle. */
/** Indicates that the spl routines (and therefore a bunch of other ones too)
* will set EFLAGS::IF and break code that disables interrupts. */
bool g_frtSolSplSetsEIF = false;
/** timeout_generic address. */
/** untimeout_generic address. */
/** cyclic_reprogram address. */
/** page_noreloc_supported address. */
/** Whether to use the kernel page freelist. */
bool g_frtSolUseKflt = false;
/** Whether we've completed R0 initialization. */
bool g_frtSolInitDone = false;
/** Whether to use old-style xc_call interface. */
bool g_frtSolOldIPI = false;
/** Whether to use old-style xc_call interface using one ulong_t as the CPU set
* representation. */
bool g_frtSolOldIPIUlong = false;
/** The xc_call callout table structure. */
/** Whether to use the old-style installctx()/removectx() routines. */
bool g_frtSolOldThreadCtx = false;
/** The thread-context hooks callout table structure. */
/** Thread preemption offset in the thread structure. */
/** Thread ID offset in the thread structure. */
/** The interrupt (pinned) thread pointer offset in the thread structure. */
/** The dispatcher lock pointer offset in the thread structure. */
/** The process pointer offset in the thread structure. */
/** Host scheduler preemption offset. */
/** Host scheduler force preemption offset. */
/* Resolve using dl_lookup (remove if no longer relevant for supported S10 versions) */
/** contig_free address. */
{
/*
* IPRT has not yet been initialized at this point, so use Solaris' native cmn_err() for logging.
*/
if (RT_SUCCESS(rc))
{
#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
/*
* Detect whether spl*() is preserving the interrupt flag or not.
* This is a problem on S10.
*/
if (ASMIntAreEnabled())
g_frtSolSplSetsEIF = true;
if (ASMIntAreEnabled())
g_frtSolSplSetsEIF = true;
#else
#endif
/*
* Mandatory: Preemption offsets.
*/
if (RT_FAILURE(rc))
{
goto errorbail;
}
rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "cpu_t", "cpu_kprunrun", &g_offrtSolCpuForceKernelPreempt);
if (RT_FAILURE(rc))
{
goto errorbail;
}
rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "kthread_t", "t_preempt", &g_offrtSolThreadPreempt);
if (RT_FAILURE(rc))
{
goto errorbail;
}
if (RT_FAILURE(rc))
{
goto errorbail;
}
rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "kthread_t", "t_intr", &g_offrtSolThreadIntrThread);
if (RT_FAILURE(rc))
{
goto errorbail;
}
if (RT_FAILURE(rc))
{
goto errorbail;
}
if (RT_FAILURE(rc))
{
goto errorbail;
}
cmn_err(CE_CONT, "!cpu_t::cpu_kprunrun @ 0x%lx (%ld)\n", g_offrtSolCpuForceKernelPreempt, g_offrtSolCpuForceKernelPreempt);
cmn_err(CE_CONT, "!kthread_t::t_preempt @ 0x%lx (%ld)\n", g_offrtSolThreadPreempt, g_offrtSolThreadPreempt);
cmn_err(CE_CONT, "!kthread_t::t_intr @ 0x%lx (%ld)\n", g_offrtSolThreadIntrThread, g_offrtSolThreadIntrThread);
cmn_err(CE_CONT, "!kthread_t::t_lockp @ 0x%lx (%ld)\n", g_offrtSolThreadLock, g_offrtSolThreadLock);
cmn_err(CE_CONT, "!kthread_t::t_procp @ 0x%lx (%ld)\n", g_offrtSolThreadProc, g_offrtSolThreadProc);
/*
* Mandatory: CPU cross call infrastructure. Refer the-solaris-kernel.h for details.
*/
rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "xc_init_cpu", NULL /* ppvSymbol */);
if (RT_SUCCESS(rc))
{
if (ncpus > IPRT_SOL_NCPUS)
{
cmn_err(CE_NOTE, "rtR0InitNative: CPU count mismatch! ncpus=%d IPRT_SOL_NCPUS=%d\n", ncpus, IPRT_SOL_NCPUS);
goto errorbail;
}
}
else
{
g_frtSolOldIPI = true;
{
g_frtSolOldIPIUlong = true;
}
{
cmn_err(CE_NOTE, "rtR0InitNative: cpuset_t size mismatch! max_cpuid=%d IPRT_SOL_NCPUS=%d\n", max_cpuid,
goto errorbail;
}
}
/*
* Mandatory: Thread-context hooks.
*/
rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "exitctx", NULL /* ppvSymbol */);
if (RT_SUCCESS(rc))
{
}
else
{
g_frtSolOldThreadCtx = true;
}
/*
* Optional: Timeout hooks.
*/
(void **)&g_pfnrtR0Sol_timeout_generic);
(void **)&g_pfnrtR0Sol_untimeout_generic);
{
cmn_err(CE_NOTE, "rtR0InitNative: Weird! Found %s but not %s!\n", s_apszFn[!iMissingFn], s_apszFn[iMissingFn]);
}
(void **)&g_pfnrtR0Sol_cyclic_reprogram);
/*
* Optional: Querying page no-relocation support.
*/
(void **)&g_pfnrtR0Sol_page_noreloc_supported);
/*
* Weak binding failures: contig_free
*/
if (g_pfnrtR0Sol_contig_free == NULL)
{
(void **)&g_pfnrtR0Sol_contig_free);
if (RT_FAILURE(rc))
{
goto errorbail;
}
}
g_frtSolInitDone = true;
return VINF_SUCCESS;
}
else
{
return rc;
}
return rc;
}
{
g_frtSolInitDone = false;
}