VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/solaris/initterm-r0drv-solaris.c@ 48097

Last change on this file since 48097 was 47304, checked in by vboxsync, 12 years ago

spaces.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1/* $Id: initterm-r0drv-solaris.c 47304 2013-07-22 14:23:00Z vboxsync $ */
2/** @file
3 * IPRT - Initialization & Termination, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
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* Header Files *
30*******************************************************************************/
31#include "the-solaris-kernel.h"
32#include "internal/iprt.h"
33
34#include <iprt/assert.h>
35#include <iprt/err.h>
36#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
37# include <iprt/asm-amd64-x86.h>
38#endif
39#include "internal/initterm.h"
40
41
42/*******************************************************************************
43* Global Variables *
44*******************************************************************************/
45/** Kernel debug info handle. */
46RTDBGKRNLINFO g_hKrnlDbgInfo;
47/** Indicates that the spl routines (and therefore a bunch of other ones too)
48 * will set EFLAGS::IF and break code that disables interrupts. */
49bool g_frtSolSplSetsEIF = false;
50/** timeout_generic address. */
51PFNSOL_timeout_generic g_pfnrtR0Sol_timeout_generic = NULL;
52/** untimeout_generic address. */
53PFNSOL_untimeout_generic g_pfnrtR0Sol_untimeout_generic = NULL;
54/** cyclic_reprogram address. */
55PFNSOL_cyclic_reprogram g_pfnrtR0Sol_cyclic_reprogram = NULL;
56/** page_noreloc_supported address. */
57PFNSOL_page_noreloc_supported g_pfnrtR0Sol_page_noreloc_supported = NULL;
58/** Whether to use the kernel page freelist. */
59bool g_frtSolUseKflt = false;
60/** Whether we've completed R0 initialization. */
61bool g_frtSolInitDone = false;
62/** Whether to use old-style xc_call interface. */
63bool g_frtSolOldIPI = false;
64/** Whether to use old-style xc_call interface using one ulong_t as the CPU set
65 * representation. */
66bool g_frtSolOldIPIUlong = false;
67/** The xc_call callout table structure. */
68RTR0FNSOLXCCALL g_rtSolXcCall;
69/** Whether to use the old-style installctx()/removectx() routines. */
70bool g_frtSolOldThreadCtx = false;
71/** The thread-context hooks callout table structure. */
72RTR0FNSOLTHREADCTX g_rtSolThreadCtx;
73/** Thread preemption offset. */
74size_t g_offrtSolThreadPreempt;
75/** Host scheduler preemption offset. */
76size_t g_offrtSolCpuPreempt;
77/** Host scheduler force preemption offset. */
78size_t g_offrtSolCpuForceKernelPreempt;
79/* Resolve using dl_lookup (remove if no longer relevant for supported S10 versions) */
80extern void contig_free(void *addr, size_t size);
81#pragma weak contig_free
82/** contig_free address. */
83PFNSOL_contig_free g_pfnrtR0Sol_contig_free = contig_free;
84
85DECLHIDDEN(int) rtR0InitNative(void)
86{
87 /*
88 * IPRT has not yet been initialized at this point, so use Solaris' native cmn_err() for logging.
89 */
90 int rc = RTR0DbgKrnlInfoOpen(&g_hKrnlDbgInfo, 0 /* fFlags */);
91 if (RT_SUCCESS(rc))
92 {
93#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
94 /*
95 * Detect whether spl*() is preserving the interrupt flag or not.
96 * This is a problem on S10.
97 */
98 RTCCUINTREG uOldFlags = ASMIntDisableFlags();
99 int iOld = splr(DISP_LEVEL);
100 if (ASMIntAreEnabled())
101 g_frtSolSplSetsEIF = true;
102 splx(iOld);
103 if (ASMIntAreEnabled())
104 g_frtSolSplSetsEIF = true;
105 ASMSetFlags(uOldFlags);
106#else
107 /* PORTME: See if the amd64/x86 problem applies to this architecture. */
108#endif
109
110 /*
111 * Mandatory: Preemption offsets.
112 */
113 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "cpu_t", "cpu_runrun", &g_offrtSolCpuPreempt);
114 if (RT_FAILURE(rc))
115 {
116 cmn_err(CE_NOTE, "Failed to find cpu_t::cpu_runrun!\n");
117 goto errorbail;
118 }
119
120 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "cpu_t", "cpu_kprunrun", &g_offrtSolCpuForceKernelPreempt);
121 if (RT_FAILURE(rc))
122 {
123 cmn_err(CE_NOTE, "Failed to find cpu_t::cpu_kprunrun!\n");
124 goto errorbail;
125 }
126
127 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "kthread_t", "t_preempt", &g_offrtSolThreadPreempt);
128 if (RT_FAILURE(rc))
129 {
130 cmn_err(CE_NOTE, "Failed to find kthread_t::t_preempt!\n");
131 goto errorbail;
132 }
133 cmn_err(CE_CONT, "!cpu_t::cpu_runrun @ 0x%lx (%ld)\n", g_offrtSolCpuPreempt, g_offrtSolCpuPreempt);
134 cmn_err(CE_CONT, "!cpu_t::cpu_kprunrun @ 0x%lx (%ld)\n", g_offrtSolCpuForceKernelPreempt, g_offrtSolCpuForceKernelPreempt);
135 cmn_err(CE_CONT, "!kthread_t::t_preempt @ 0x%lx (%ld)\n", g_offrtSolThreadPreempt, g_offrtSolThreadPreempt);
136
137 /*
138 * Mandatory: CPU cross call infrastructure. Refer the-solaris-kernel.h for details.
139 */
140 rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "xc_init_cpu", NULL /* ppvSymbol */);
141 if (RT_SUCCESS(rc))
142 {
143 if (ncpus > IPRT_SOL_NCPUS)
144 {
145 cmn_err(CE_NOTE, "rtR0InitNative: CPU count mismatch! ncpus=%d IPRT_SOL_NCPUS=%d\n", ncpus, IPRT_SOL_NCPUS);
146 rc = VERR_NOT_SUPPORTED;
147 goto errorbail;
148 }
149 g_rtSolXcCall.u.pfnSol_xc_call = (void *)xc_call;
150 }
151 else
152 {
153 g_frtSolOldIPI = true;
154 g_rtSolXcCall.u.pfnSol_xc_call_old = (void *)xc_call;
155 if (max_cpuid + 1 == sizeof(ulong_t) * 8)
156 {
157 g_frtSolOldIPIUlong = true;
158 g_rtSolXcCall.u.pfnSol_xc_call_old_ulong = (void *)xc_call;
159 }
160 else if (max_cpuid + 1 != IPRT_SOL_NCPUS)
161 {
162 cmn_err(CE_NOTE, "rtR0InitNative: cpuset_t size mismatch! max_cpuid=%d IPRT_SOL_NCPUS=%d\n", max_cpuid,
163 IPRT_SOL_NCPUS);
164 rc = VERR_NOT_SUPPORTED;
165 goto errorbail;
166 }
167 }
168
169 /*
170 * Mandatory: Thread-context hooks.
171 */
172 rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "exitctx", NULL /* ppvSymbol */);
173 if (RT_SUCCESS(rc))
174 {
175 g_rtSolThreadCtx.Install.pfnSol_installctx = (void *)installctx;
176 g_rtSolThreadCtx.Remove.pfnSol_removectx = (void *)removectx;
177 }
178 else
179 {
180 g_frtSolOldThreadCtx = true;
181 g_rtSolThreadCtx.Install.pfnSol_installctx_old = (void *)installctx;
182 g_rtSolThreadCtx.Remove.pfnSol_removectx_old = (void *)removectx;
183 }
184
185 /*
186 * Optional: Timeout hooks.
187 */
188 RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "timeout_generic",
189 (void **)&g_pfnrtR0Sol_timeout_generic);
190 RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "untimeout_generic",
191 (void **)&g_pfnrtR0Sol_untimeout_generic);
192 if ((g_pfnrtR0Sol_timeout_generic == NULL) != (g_pfnrtR0Sol_untimeout_generic == NULL))
193 {
194 static const char *s_apszFn[2] = { "timeout_generic", "untimeout_generic" };
195 bool iMissingFn = g_pfnrtR0Sol_timeout_generic == NULL;
196 cmn_err(CE_NOTE, "rtR0InitNative: Weird! Found %s but not %s!\n", s_apszFn[!iMissingFn], s_apszFn[iMissingFn]);
197 g_pfnrtR0Sol_timeout_generic = NULL;
198 g_pfnrtR0Sol_untimeout_generic = NULL;
199 }
200 RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "cyclic_reprogram",
201 (void **)&g_pfnrtR0Sol_cyclic_reprogram);
202
203 /*
204 * Optional: Querying page no-relocation support.
205 */
206 RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /*pszModule */, "page_noreloc_supported",
207 (void **)&g_pfnrtR0Sol_page_noreloc_supported);
208
209 /*
210 * Weak binding failures: contig_free
211 */
212 if (g_pfnrtR0Sol_contig_free == NULL)
213 {
214 rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "contig_free", (void **)&g_pfnrtR0Sol_contig_free);
215 if (RT_FAILURE(rc))
216 {
217 cmn_err(CE_NOTE, "rtR0InitNative: failed to find contig_free!\n");
218 goto errorbail;
219 }
220 }
221
222 g_frtSolInitDone = true;
223 return VINF_SUCCESS;
224 }
225 else
226 {
227 cmn_err(CE_NOTE, "RTR0DbgKrnlInfoOpen failed. rc=%d\n", rc);
228 return rc;
229 }
230
231errorbail:
232 RTR0DbgKrnlInfoRelease(g_hKrnlDbgInfo);
233 return rc;
234}
235
236
237DECLHIDDEN(void) rtR0TermNative(void)
238{
239 RTR0DbgKrnlInfoRelease(g_hKrnlDbgInfo);
240 g_frtSolInitDone = false;
241}
242
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