VirtualBox

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

Last change on this file since 57181 was 54643, checked in by vboxsync, 10 years ago

Runtime/r0drv/solaris: (c) year missed update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.6 KB
Line 
1/* $Id: initterm-r0drv-solaris.c 54643 2015-03-05 10:46:27Z vboxsync $ */
2/** @file
3 * IPRT - Initialization & Termination, Ring-0 Driver, Solaris.
4 */
5
6/*
7 * Copyright (C) 2006-2015 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 in the thread structure. */
74size_t g_offrtSolThreadPreempt;
75/** Thread ID offset in the thread structure. */
76size_t g_offrtSolThreadId;
77/** The interrupt (pinned) thread pointer offset in the thread structure. */
78size_t g_offrtSolThreadIntrThread;
79/** The dispatcher lock pointer offset in the thread structure. */
80size_t g_offrtSolThreadLock;
81/** The process pointer offset in the thread structure. */
82size_t g_offrtSolThreadProc;
83/** Host scheduler preemption offset. */
84size_t g_offrtSolCpuPreempt;
85/** Host scheduler force preemption offset. */
86size_t g_offrtSolCpuForceKernelPreempt;
87/* Resolve using dl_lookup (remove if no longer relevant for supported S10 versions) */
88extern void contig_free(void *addr, size_t size);
89#pragma weak contig_free
90/** contig_free address. */
91PFNSOL_contig_free g_pfnrtR0Sol_contig_free = contig_free;
92
93DECLHIDDEN(int) rtR0InitNative(void)
94{
95 /*
96 * IPRT has not yet been initialized at this point, so use Solaris' native cmn_err() for logging.
97 */
98 int rc = RTR0DbgKrnlInfoOpen(&g_hKrnlDbgInfo, 0 /* fFlags */);
99 if (RT_SUCCESS(rc))
100 {
101#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
102 /*
103 * Detect whether spl*() is preserving the interrupt flag or not.
104 * This is a problem on S10.
105 */
106 RTCCUINTREG uOldFlags = ASMIntDisableFlags();
107 int iOld = splr(DISP_LEVEL);
108 if (ASMIntAreEnabled())
109 g_frtSolSplSetsEIF = true;
110 splx(iOld);
111 if (ASMIntAreEnabled())
112 g_frtSolSplSetsEIF = true;
113 ASMSetFlags(uOldFlags);
114#else
115 /* PORTME: See if the amd64/x86 problem applies to this architecture. */
116#endif
117 /*
118 * Mandatory: Preemption offsets.
119 */
120 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "cpu_t", "cpu_runrun", &g_offrtSolCpuPreempt);
121 if (RT_FAILURE(rc))
122 {
123 cmn_err(CE_NOTE, "Failed to find cpu_t::cpu_runrun!\n");
124 goto errorbail;
125 }
126
127 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "cpu_t", "cpu_kprunrun", &g_offrtSolCpuForceKernelPreempt);
128 if (RT_FAILURE(rc))
129 {
130 cmn_err(CE_NOTE, "Failed to find cpu_t::cpu_kprunrun!\n");
131 goto errorbail;
132 }
133
134 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "kthread_t", "t_preempt", &g_offrtSolThreadPreempt);
135 if (RT_FAILURE(rc))
136 {
137 cmn_err(CE_NOTE, "Failed to find kthread_t::t_preempt!\n");
138 goto errorbail;
139 }
140
141 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "kthread_t", "t_did", &g_offrtSolThreadId);
142 if (RT_FAILURE(rc))
143 {
144 cmn_err(CE_NOTE, "Failed to find kthread_t::t_did!\n");
145 goto errorbail;
146 }
147
148 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "kthread_t", "t_intr", &g_offrtSolThreadIntrThread);
149 if (RT_FAILURE(rc))
150 {
151 cmn_err(CE_NOTE, "Failed to find kthread_t::t_intr!\n");
152 goto errorbail;
153 }
154
155 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "kthread_t", "t_lockp", &g_offrtSolThreadLock);
156 if (RT_FAILURE(rc))
157 {
158 cmn_err(CE_NOTE, "Failed to find kthread_t::t_lockp!\n");
159 goto errorbail;
160 }
161
162 rc = RTR0DbgKrnlInfoQueryMember(g_hKrnlDbgInfo, "kthread_t", "t_procp", &g_offrtSolThreadProc);
163 if (RT_FAILURE(rc))
164 {
165 cmn_err(CE_NOTE, "Failed to find kthread_t::t_procp!\n");
166 goto errorbail;
167 }
168 cmn_err(CE_CONT, "!cpu_t::cpu_runrun @ 0x%lx (%ld)\n", g_offrtSolCpuPreempt, g_offrtSolCpuPreempt);
169 cmn_err(CE_CONT, "!cpu_t::cpu_kprunrun @ 0x%lx (%ld)\n", g_offrtSolCpuForceKernelPreempt, g_offrtSolCpuForceKernelPreempt);
170 cmn_err(CE_CONT, "!kthread_t::t_preempt @ 0x%lx (%ld)\n", g_offrtSolThreadPreempt, g_offrtSolThreadPreempt);
171 cmn_err(CE_CONT, "!kthread_t::t_did @ 0x%lx (%ld)\n", g_offrtSolThreadId, g_offrtSolThreadId);
172 cmn_err(CE_CONT, "!kthread_t::t_intr @ 0x%lx (%ld)\n", g_offrtSolThreadIntrThread, g_offrtSolThreadIntrThread);
173 cmn_err(CE_CONT, "!kthread_t::t_lockp @ 0x%lx (%ld)\n", g_offrtSolThreadLock, g_offrtSolThreadLock);
174 cmn_err(CE_CONT, "!kthread_t::t_procp @ 0x%lx (%ld)\n", g_offrtSolThreadProc, g_offrtSolThreadProc);
175
176 /*
177 * Mandatory: CPU cross call infrastructure. Refer the-solaris-kernel.h for details.
178 */
179 rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "xc_init_cpu", NULL /* ppvSymbol */);
180 if (RT_SUCCESS(rc))
181 {
182 if (ncpus > IPRT_SOL_NCPUS)
183 {
184 cmn_err(CE_NOTE, "rtR0InitNative: CPU count mismatch! ncpus=%d IPRT_SOL_NCPUS=%d\n", ncpus, IPRT_SOL_NCPUS);
185 rc = VERR_NOT_SUPPORTED;
186 goto errorbail;
187 }
188 g_rtSolXcCall.u.pfnSol_xc_call = (void *)xc_call;
189 }
190 else
191 {
192 g_frtSolOldIPI = true;
193 g_rtSolXcCall.u.pfnSol_xc_call_old = (void *)xc_call;
194 if (max_cpuid + 1 == sizeof(ulong_t) * 8)
195 {
196 g_frtSolOldIPIUlong = true;
197 g_rtSolXcCall.u.pfnSol_xc_call_old_ulong = (void *)xc_call;
198 }
199 else if (max_cpuid + 1 != IPRT_SOL_NCPUS)
200 {
201 cmn_err(CE_NOTE, "rtR0InitNative: cpuset_t size mismatch! max_cpuid=%d IPRT_SOL_NCPUS=%d\n", max_cpuid,
202 IPRT_SOL_NCPUS);
203 rc = VERR_NOT_SUPPORTED;
204 goto errorbail;
205 }
206 }
207
208 /*
209 * Mandatory: Thread-context hooks.
210 */
211 rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "exitctx", NULL /* ppvSymbol */);
212 if (RT_SUCCESS(rc))
213 {
214 g_rtSolThreadCtx.Install.pfnSol_installctx = (void *)installctx;
215 g_rtSolThreadCtx.Remove.pfnSol_removectx = (void *)removectx;
216 }
217 else
218 {
219 g_frtSolOldThreadCtx = true;
220 g_rtSolThreadCtx.Install.pfnSol_installctx_old = (void *)installctx;
221 g_rtSolThreadCtx.Remove.pfnSol_removectx_old = (void *)removectx;
222 }
223
224 /*
225 * Optional: Timeout hooks.
226 */
227 RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "timeout_generic",
228 (void **)&g_pfnrtR0Sol_timeout_generic);
229 RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "untimeout_generic",
230 (void **)&g_pfnrtR0Sol_untimeout_generic);
231 if ((g_pfnrtR0Sol_timeout_generic == NULL) != (g_pfnrtR0Sol_untimeout_generic == NULL))
232 {
233 static const char *s_apszFn[2] = { "timeout_generic", "untimeout_generic" };
234 bool iMissingFn = g_pfnrtR0Sol_timeout_generic == NULL;
235 cmn_err(CE_NOTE, "rtR0InitNative: Weird! Found %s but not %s!\n", s_apszFn[!iMissingFn], s_apszFn[iMissingFn]);
236 g_pfnrtR0Sol_timeout_generic = NULL;
237 g_pfnrtR0Sol_untimeout_generic = NULL;
238 }
239 RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "cyclic_reprogram",
240 (void **)&g_pfnrtR0Sol_cyclic_reprogram);
241
242 /*
243 * Optional: Querying page no-relocation support.
244 */
245 RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /*pszModule */, "page_noreloc_supported",
246 (void **)&g_pfnrtR0Sol_page_noreloc_supported);
247
248 /*
249 * Weak binding failures: contig_free
250 */
251 if (g_pfnrtR0Sol_contig_free == NULL)
252 {
253 rc = RTR0DbgKrnlInfoQuerySymbol(g_hKrnlDbgInfo, NULL /* pszModule */, "contig_free",
254 (void **)&g_pfnrtR0Sol_contig_free);
255 if (RT_FAILURE(rc))
256 {
257 cmn_err(CE_NOTE, "rtR0InitNative: failed to find contig_free!\n");
258 goto errorbail;
259 }
260 }
261
262 g_frtSolInitDone = true;
263 return VINF_SUCCESS;
264 }
265 else
266 {
267 cmn_err(CE_NOTE, "RTR0DbgKrnlInfoOpen failed. rc=%d\n", rc);
268 return rc;
269 }
270
271errorbail:
272 RTR0DbgKrnlInfoRelease(g_hKrnlDbgInfo);
273 return rc;
274}
275
276
277DECLHIDDEN(void) rtR0TermNative(void)
278{
279 RTR0DbgKrnlInfoRelease(g_hKrnlDbgInfo);
280 g_frtSolInitDone = false;
281}
282
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