1 | /* $Id: initterm-r0drv-darwin.cpp 85167 2020-07-10 10:06:55Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Initialization & Termination, R0 Driver, Darwin.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 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-darwin-kernel.h"
|
---|
32 | #include "internal/iprt.h"
|
---|
33 |
|
---|
34 | #include <iprt/errcore.h>
|
---|
35 | #include <iprt/assert.h>
|
---|
36 | #include <iprt/dbg.h>
|
---|
37 | #include "internal/initterm.h"
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | /*********************************************************************************************************************************
|
---|
42 | * Global Variables *
|
---|
43 | *********************************************************************************************************************************/
|
---|
44 | /** Pointer to the lock group used by IPRT. */
|
---|
45 | DECL_HIDDEN_DATA(lck_grp_t *) g_pDarwinLockGroup = NULL;
|
---|
46 | /** Pointer to the ast_pending function, if found. */
|
---|
47 | DECL_HIDDEN_DATA(PFNR0DARWINASTPENDING) g_pfnR0DarwinAstPending = NULL;
|
---|
48 | /** Pointer to the cpu_interrupt function, if found. */
|
---|
49 | DECL_HIDDEN_DATA(PFNR0DARWINCPUINTERRUPT) g_pfnR0DarwinCpuInterrupt = NULL;
|
---|
50 | #ifdef DEBUG
|
---|
51 | /** Pointer to the vm_fault_external function - used once for debugging @bugref{9466}. */
|
---|
52 | DECL_HIDDEN_DATA(PFNR0DARWINVMFAULTEXTERNAL) g_pfnR0DarwinVmFaultExternal = NULL;
|
---|
53 | #endif
|
---|
54 |
|
---|
55 |
|
---|
56 | DECLHIDDEN(int) rtR0InitNative(void)
|
---|
57 | {
|
---|
58 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * Create the lock group.
|
---|
62 | */
|
---|
63 | g_pDarwinLockGroup = lck_grp_alloc_init("IPRT", LCK_GRP_ATTR_NULL);
|
---|
64 | AssertReturn(g_pDarwinLockGroup, VERR_NO_MEMORY);
|
---|
65 |
|
---|
66 | /*
|
---|
67 | * Initialize the preemption hacks.
|
---|
68 | */
|
---|
69 | int rc = rtThreadPreemptDarwinInit();
|
---|
70 | if (RT_SUCCESS(rc))
|
---|
71 | {
|
---|
72 | /*
|
---|
73 | * Try resolve kernel symbols we need but apple don't wish to give us.
|
---|
74 | */
|
---|
75 | RTDBGKRNLINFO hKrnlInfo;
|
---|
76 | rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0 /*fFlags*/);
|
---|
77 | if (RT_SUCCESS(rc))
|
---|
78 | {
|
---|
79 | RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "ast_pending", (void **)&g_pfnR0DarwinAstPending);
|
---|
80 | printf("ast_pending=%p\n", (void *)(uintptr_t)g_pfnR0DarwinAstPending);
|
---|
81 | RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "cpu_interrupt", (void **)&g_pfnR0DarwinCpuInterrupt);
|
---|
82 | printf("cpu_interrupt=%p\n", (void *)(uintptr_t)g_pfnR0DarwinCpuInterrupt);
|
---|
83 | #ifdef DEBUG
|
---|
84 | RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "vm_fault_external", (void **)&g_pfnR0DarwinVmFaultExternal);
|
---|
85 | printf("vm_fault_external=%p\n", (void *)(uintptr_t)g_pfnR0DarwinVmFaultExternal);
|
---|
86 | #endif
|
---|
87 | RTR0DbgKrnlInfoRelease(hKrnlInfo);
|
---|
88 | }
|
---|
89 | if (RT_FAILURE(rc))
|
---|
90 | {
|
---|
91 | printf("rtR0InitNative: warning! failed to resolve special kernel symbols\n");
|
---|
92 | rc = VINF_SUCCESS;
|
---|
93 | }
|
---|
94 | }
|
---|
95 | if (RT_FAILURE(rc))
|
---|
96 | rtR0TermNative();
|
---|
97 |
|
---|
98 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
99 | return rc;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | DECLHIDDEN(void) rtR0TermNative(void)
|
---|
104 | {
|
---|
105 | IPRT_DARWIN_SAVE_EFL_AC();
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * Preemption hacks before the lock group.
|
---|
109 | */
|
---|
110 | rtThreadPreemptDarwinTerm();
|
---|
111 |
|
---|
112 | /*
|
---|
113 | * Free the lock group.
|
---|
114 | */
|
---|
115 | if (g_pDarwinLockGroup)
|
---|
116 | {
|
---|
117 | lck_grp_free(g_pDarwinLockGroup);
|
---|
118 | g_pDarwinLockGroup = NULL;
|
---|
119 | }
|
---|
120 |
|
---|
121 | IPRT_DARWIN_RESTORE_EFL_AC();
|
---|
122 | }
|
---|
123 |
|
---|