VirtualBox

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

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

Runtime/r0drv/solaris: Fix Solaris 10 breakage due to incompatible offsets in critical structures.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette