VirtualBox

source: vbox/trunk/src/VBox/Runtime/r0drv/darwin/initterm-r0drv-darwin.cpp@ 109128

Last change on this file since 109128 was 109128, checked in by vboxsync, 12 days ago

IPRT/r0drv: Build adjustments for darwin.arm64. jiraref:VBP-1653

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.5 KB
Line 
1/* $Id: initterm-r0drv-darwin.cpp 109128 2025-05-01 01:31:56Z vboxsync $ */
2/** @file
3 * IPRT - Initialization & Termination, R0 Driver, Darwin.
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include "the-darwin-kernel.h"
42#include "internal/iprt.h"
43
44#include <iprt/errcore.h>
45#include <iprt/assert.h>
46#include <iprt/dbg.h>
47#include "internal/initterm.h"
48
49
50/*********************************************************************************************************************************
51* Internal Functions *
52*********************************************************************************************************************************/
53#if defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
54static int rtR0DarwinFallbackCpuNumber(void);
55#endif
56
57
58
59/*********************************************************************************************************************************
60* Global Variables *
61*********************************************************************************************************************************/
62/** Pointer to the lock group used by IPRT. */
63DECL_HIDDEN_DATA(lck_grp_t *) g_pDarwinLockGroup = NULL;
64/** Pointer to the ast_pending function, if found. */
65DECL_HIDDEN_DATA(PFNR0DARWINASTPENDING) g_pfnR0DarwinAstPending = NULL;
66/** Pointer to the cpu_interrupt function, if found. */
67DECL_HIDDEN_DATA(PFNR0DARWINCPUINTERRUPT) g_pfnR0DarwinCpuInterrupt = NULL;
68#ifdef DEBUG
69/** Pointer to the vm_fault_external function - used once for debugging @bugref{9466}. */
70DECL_HIDDEN_DATA(PFNR0DARWINVMFAULTEXTERNAL) g_pfnR0DarwinVmFaultExternal = NULL;
71#endif
72
73#if defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
74/** Pointer to cpu_xcall (private arm API). */
75DECL_HIDDEN_DATA(PFN_DARWIN_CPU_XCALL_T) g_pfnR0DarwinCpuXCall = NULL;
76/** Pointer to cpu_broadcast_xcall (private arm API). */
77DECL_HIDDEN_DATA(PFN_DARWIN_CPU_BROADCAST_XCALL_T) g_pfnR0DarwinCpuBroadcastXCall = NULL;
78/** Pointer to cpu_number (private API on arm). */
79DECL_HIDDEN_DATA(PFN_DARWIN_CPU_NUMBER_T) g_pfnR0DarwinCpuNumber = rtR0DarwinFallbackCpuNumber;
80
81/**
82 * Fallback for g_pfnR0DarwinCpuNumber, just so we won't crash if it isn't found.
83 */
84static int rtR0DarwinFallbackCpuNumber(void)
85{
86 return 0;
87}
88#endif /* RT_ARCH_ARM64 || RT_ARCH_ARM32 */
89
90
91
92DECLHIDDEN(int) rtR0InitNative(void)
93{
94 IPRT_DARWIN_SAVE_EFL_AC();
95
96 /*
97 * Create the lock group.
98 */
99 g_pDarwinLockGroup = lck_grp_alloc_init("IPRT", LCK_GRP_ATTR_NULL);
100 AssertReturn(g_pDarwinLockGroup, VERR_NO_MEMORY);
101
102 /*
103 * Initialize the preemption hacks.
104 */
105 int rc = rtThreadPreemptDarwinInit();
106 if (RT_SUCCESS(rc))
107 {
108 /*
109 * Try resolve kernel symbols we need but apple don't wish to give us.
110 */
111 RTDBGKRNLINFO hKrnlInfo;
112 rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0 /*fFlags*/);
113 if (RT_SUCCESS(rc))
114 {
115#define GET_FUNCTION(a_VarType, a_VarName, a_szSymbol) do { \
116 PFNRT pfn = RTR0DbgKrnlInfoGetFunction(hKrnlInfo, NULL, a_szSymbol); \
117 printf("rtR0InitNative: " a_szSymbol "=%llx\n", (unsigned long long)(uintptr_t)pfn); \
118 if (pfn != NULL) \
119 a_VarName = (a_VarType)pfn; \
120 } while (0)
121
122 GET_FUNCTION(PFNR0DARWINASTPENDING, g_pfnR0DarwinAstPending, "ast_pending");
123 GET_FUNCTION(PFNR0DARWINCPUINTERRUPT, g_pfnR0DarwinCpuInterrupt, "cpu_interrupt");
124#ifdef DEBUG
125 GET_FUNCTION(PFNR0DARWINVMFAULTEXTERNAL, g_pfnR0DarwinVmFaultExternal, "vm_fault_external");
126#endif
127#if defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
128 GET_FUNCTION(PFN_DARWIN_CPU_XCALL_T, g_pfnR0DarwinCpuXCall, "cpu_xcall");
129 GET_FUNCTION(PFN_DARWIN_CPU_BROADCAST_XCALL_T, g_pfnR0DarwinCpuBroadcastXCall, "cpu_broadcast_xcall");
130 GET_FUNCTION(PFN_DARWIN_CPU_NUMBER_T, g_pfnR0DarwinCpuNumber, "cpu_number");
131 if (!g_pfnR0DarwinCpuNumber)
132 g_pfnR0DarwinCpuNumber = rtR0DarwinFallbackCpuNumber;
133#endif
134
135#undef GET_FUNCTION
136 RTR0DbgKrnlInfoRelease(hKrnlInfo);
137 }
138 if (RT_FAILURE(rc))
139 {
140 printf("rtR0InitNative: warning! failed to resolve special kernel symbols\n");
141 rc = VINF_SUCCESS;
142 }
143 }
144 if (RT_FAILURE(rc))
145 rtR0TermNative();
146
147 IPRT_DARWIN_RESTORE_EFL_AC();
148 return rc;
149}
150
151
152DECLHIDDEN(void) rtR0TermNative(void)
153{
154 IPRT_DARWIN_SAVE_EFL_AC();
155
156 /*
157 * Preemption hacks before the lock group.
158 */
159 rtThreadPreemptDarwinTerm();
160
161 /*
162 * Free the lock group.
163 */
164 if (g_pDarwinLockGroup)
165 {
166 lck_grp_free(g_pDarwinLockGroup);
167 g_pDarwinLockGroup = NULL;
168 }
169
170 IPRT_DARWIN_RESTORE_EFL_AC();
171}
172
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