1 | /* $Id: initterm-r0drv-darwin.cpp 44528 2013-02-04 14:27:54Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Initialization & Termination, R0 Driver, Darwin.
|
---|
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-darwin-kernel.h"
|
---|
32 | #include "internal/iprt.h"
|
---|
33 |
|
---|
34 | #include <iprt/err.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 | lck_grp_t *g_pDarwinLockGroup = NULL;
|
---|
46 | /** Pointer to the ast_pending function, if found. */
|
---|
47 | PFNR0DARWINASTPENDING g_pfnR0DarwinAstPending = NULL;
|
---|
48 | /** Pointer to the cpu_interrupt function, if found. */
|
---|
49 | PFNR0DARWINCPUINTERRUPT g_pfnR0DarwinCpuInterrupt = NULL;
|
---|
50 |
|
---|
51 |
|
---|
52 | DECLHIDDEN(int) rtR0InitNative(void)
|
---|
53 | {
|
---|
54 | /*
|
---|
55 | * Create the lock group.
|
---|
56 | */
|
---|
57 | g_pDarwinLockGroup = lck_grp_alloc_init("IPRT", LCK_GRP_ATTR_NULL);
|
---|
58 | AssertReturn(g_pDarwinLockGroup, VERR_NO_MEMORY);
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * Initialize the preemption hacks.
|
---|
62 | */
|
---|
63 | int rc = rtThreadPreemptDarwinInit();
|
---|
64 | if (RT_SUCCESS(rc))
|
---|
65 | {
|
---|
66 | /*
|
---|
67 | * Try resolve kernel symbols we need but apple don't wish to give us.
|
---|
68 | */
|
---|
69 | RTDBGKRNLINFO hKrnlInfo;
|
---|
70 | rc = RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0 /*fFlags*/);
|
---|
71 | if (RT_SUCCESS(rc))
|
---|
72 | {
|
---|
73 | RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "ast_pending", (void **)&g_pfnR0DarwinAstPending);
|
---|
74 | printf("ast_pending=%p\n", g_pfnR0DarwinAstPending);
|
---|
75 | RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "cpu_interrupt", (void **)&g_pfnR0DarwinCpuInterrupt);
|
---|
76 | printf("cpu_interrupt=%p\n", g_pfnR0DarwinCpuInterrupt);
|
---|
77 | RTR0DbgKrnlInfoRelease(hKrnlInfo);
|
---|
78 | }
|
---|
79 | if (RT_FAILURE(rc))
|
---|
80 | {
|
---|
81 | printf("rtR0InitNative: warning! failed to resolve special kernel symbols\n");
|
---|
82 | rc = VINF_SUCCESS;
|
---|
83 | }
|
---|
84 | }
|
---|
85 | if (RT_FAILURE(rc))
|
---|
86 | rtR0TermNative();
|
---|
87 |
|
---|
88 | return rc;
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | DECLHIDDEN(void) rtR0TermNative(void)
|
---|
93 | {
|
---|
94 | /*
|
---|
95 | * Preemption hacks before the lock group.
|
---|
96 | */
|
---|
97 | rtThreadPreemptDarwinTerm();
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * Free the lock group.
|
---|
101 | */
|
---|
102 | if (g_pDarwinLockGroup)
|
---|
103 | {
|
---|
104 | lck_grp_free(g_pDarwinLockGroup);
|
---|
105 | g_pDarwinLockGroup = NULL;
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|