[1] | 1 | /* $Id: initterm-r0drv-darwin.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[8245] | 3 | * IPRT - Initialization & Termination, R0 Driver, Darwin.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
[5999] | 11 | *
|
---|
[96407] | 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 | *
|
---|
[5999] | 25 | * The contents of this file may alternatively be used under the terms
|
---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 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
|
---|
[5999] | 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.
|
---|
[96407] | 33 | *
|
---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[1] | 35 | */
|
---|
| 36 |
|
---|
| 37 |
|
---|
[57358] | 38 | /*********************************************************************************************************************************
|
---|
| 39 | * Header Files *
|
---|
| 40 | *********************************************************************************************************************************/
|
---|
[1] | 41 | #include "the-darwin-kernel.h"
|
---|
[22052] | 42 | #include "internal/iprt.h"
|
---|
| 43 |
|
---|
[76452] | 44 | #include <iprt/errcore.h>
|
---|
[1] | 45 | #include <iprt/assert.h>
|
---|
[40856] | 46 | #include <iprt/dbg.h>
|
---|
[207] | 47 | #include "internal/initterm.h"
|
---|
[1] | 48 |
|
---|
| 49 |
|
---|
[37575] | 50 |
|
---|
[57358] | 51 | /*********************************************************************************************************************************
|
---|
| 52 | * Global Variables *
|
---|
| 53 | *********************************************************************************************************************************/
|
---|
[1] | 54 | /** Pointer to the lock group used by IPRT. */
|
---|
[85124] | 55 | DECL_HIDDEN_DATA(lck_grp_t *) g_pDarwinLockGroup = NULL;
|
---|
[37575] | 56 | /** Pointer to the ast_pending function, if found. */
|
---|
[85124] | 57 | DECL_HIDDEN_DATA(PFNR0DARWINASTPENDING) g_pfnR0DarwinAstPending = NULL;
|
---|
[37575] | 58 | /** Pointer to the cpu_interrupt function, if found. */
|
---|
[85124] | 59 | DECL_HIDDEN_DATA(PFNR0DARWINCPUINTERRUPT) g_pfnR0DarwinCpuInterrupt = NULL;
|
---|
[83074] | 60 | #ifdef DEBUG
|
---|
| 61 | /** Pointer to the vm_fault_external function - used once for debugging @bugref{9466}. */
|
---|
[85124] | 62 | DECL_HIDDEN_DATA(PFNR0DARWINVMFAULTEXTERNAL) g_pfnR0DarwinVmFaultExternal = NULL;
|
---|
[83074] | 63 | #endif
|
---|
[1] | 64 |
|
---|
| 65 |
|
---|
[36555] | 66 | DECLHIDDEN(int) rtR0InitNative(void)
|
---|
[1] | 67 | {
|
---|
[57274] | 68 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
| 69 |
|
---|
[1] | 70 | /*
|
---|
| 71 | * Create the lock group.
|
---|
| 72 | */
|
---|
| 73 | g_pDarwinLockGroup = lck_grp_alloc_init("IPRT", LCK_GRP_ATTR_NULL);
|
---|
| 74 | AssertReturn(g_pDarwinLockGroup, VERR_NO_MEMORY);
|
---|
| 75 |
|
---|
[19919] | 76 | /*
|
---|
| 77 | * Initialize the preemption hacks.
|
---|
| 78 | */
|
---|
| 79 | int rc = rtThreadPreemptDarwinInit();
|
---|
[37575] | 80 | if (RT_SUCCESS(rc))
|
---|
| 81 | {
|
---|
| 82 | /*
|
---|
| 83 | * Try resolve kernel symbols we need but apple don't wish to give us.
|
---|
| 84 | */
|
---|
[40856] | 85 | RTDBGKRNLINFO hKrnlInfo;
|
---|
| 86 | rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0 /*fFlags*/);
|
---|
[37575] | 87 | if (RT_SUCCESS(rc))
|
---|
| 88 | {
|
---|
[40856] | 89 | RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "ast_pending", (void **)&g_pfnR0DarwinAstPending);
|
---|
[85167] | 90 | printf("ast_pending=%p\n", (void *)(uintptr_t)g_pfnR0DarwinAstPending);
|
---|
[40856] | 91 | RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "cpu_interrupt", (void **)&g_pfnR0DarwinCpuInterrupt);
|
---|
[85167] | 92 | printf("cpu_interrupt=%p\n", (void *)(uintptr_t)g_pfnR0DarwinCpuInterrupt);
|
---|
[83074] | 93 | #ifdef DEBUG
|
---|
| 94 | RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "vm_fault_external", (void **)&g_pfnR0DarwinVmFaultExternal);
|
---|
[85167] | 95 | printf("vm_fault_external=%p\n", (void *)(uintptr_t)g_pfnR0DarwinVmFaultExternal);
|
---|
[83074] | 96 | #endif
|
---|
[40856] | 97 | RTR0DbgKrnlInfoRelease(hKrnlInfo);
|
---|
[37575] | 98 | }
|
---|
| 99 | if (RT_FAILURE(rc))
|
---|
| 100 | {
|
---|
| 101 | printf("rtR0InitNative: warning! failed to resolve special kernel symbols\n");
|
---|
| 102 | rc = VINF_SUCCESS;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
[19919] | 105 | if (RT_FAILURE(rc))
|
---|
| 106 | rtR0TermNative();
|
---|
| 107 |
|
---|
[57274] | 108 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
[19919] | 109 | return rc;
|
---|
[1] | 110 | }
|
---|
| 111 |
|
---|
| 112 |
|
---|
[36555] | 113 | DECLHIDDEN(void) rtR0TermNative(void)
|
---|
[1] | 114 | {
|
---|
[57274] | 115 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
| 116 |
|
---|
[1] | 117 | /*
|
---|
[19919] | 118 | * Preemption hacks before the lock group.
|
---|
| 119 | */
|
---|
| 120 | rtThreadPreemptDarwinTerm();
|
---|
| 121 |
|
---|
| 122 | /*
|
---|
[1] | 123 | * Free the lock group.
|
---|
| 124 | */
|
---|
| 125 | if (g_pDarwinLockGroup)
|
---|
| 126 | {
|
---|
| 127 | lck_grp_free(g_pDarwinLockGroup);
|
---|
| 128 | g_pDarwinLockGroup = NULL;
|
---|
| 129 | }
|
---|
[57274] | 130 |
|
---|
| 131 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
[1] | 132 | }
|
---|
| 133 |
|
---|