1 | /* $Id: tstRTDarwinMachKernel.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT Testcase - mach_kernel symbol resolving hack.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2022 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 <iprt/dbg.h>
|
---|
42 | #include <iprt/err.h>
|
---|
43 | #include <iprt/string.h>
|
---|
44 | #include <iprt/test.h>
|
---|
45 |
|
---|
46 |
|
---|
47 | /*********************************************************************************************************************************
|
---|
48 | * Global Variables *
|
---|
49 | *********************************************************************************************************************************/
|
---|
50 | const char *g_pszTestKernel = "/no-such-file";
|
---|
51 |
|
---|
52 |
|
---|
53 | static void dotest(void)
|
---|
54 | {
|
---|
55 | RTDBGKRNLINFO hKrnlInfo;
|
---|
56 | RTTESTI_CHECK_RC_RETV(RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0), VINF_SUCCESS);
|
---|
57 | static const char * const s_apszSyms[] =
|
---|
58 | {
|
---|
59 | "ast_pending",
|
---|
60 | "cpu_interrupt",
|
---|
61 | "dtrace_register",
|
---|
62 | "dtrace_suspend",
|
---|
63 | "kext_alloc",
|
---|
64 | "kext_free",
|
---|
65 | "vm_map_protect"
|
---|
66 | };
|
---|
67 | for (unsigned i = 0; i < RT_ELEMENTS(s_apszSyms); i++)
|
---|
68 | {
|
---|
69 | void *pvValue = NULL;
|
---|
70 | int rc = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], &pvValue);
|
---|
71 | RTTestIPrintf(RTTESTLVL_ALWAYS, "%Rrc %p %s\n", rc, pvValue, s_apszSyms[i]);
|
---|
72 | RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
|
---|
73 | if (RT_SUCCESS(rc))
|
---|
74 | RTTESTI_CHECK_RC(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], NULL), VINF_SUCCESS);
|
---|
75 | }
|
---|
76 |
|
---|
77 | RTTESTI_CHECK_RC(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "no_such_symbol_name_really", NULL), VERR_SYMBOL_NOT_FOUND);
|
---|
78 | RTTESTI_CHECK(RTR0DbgKrnlInfoRelease(hKrnlInfo) == 0);
|
---|
79 | RTTESTI_CHECK(RTR0DbgKrnlInfoRelease(NIL_RTDBGKRNLINFO) == 0);
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | int main(int argc, char **argv)
|
---|
84 | {
|
---|
85 | RTTEST hTest;
|
---|
86 | RTEXITCODE rcExit = RTTestInitAndCreate("tstRTDarwinMachKernel", &hTest);
|
---|
87 | if (rcExit != RTEXITCODE_SUCCESS)
|
---|
88 | return rcExit;
|
---|
89 | RTTestBanner(hTest);
|
---|
90 |
|
---|
91 | /* Optional kernel path as argument. */
|
---|
92 | if (argc == 2)
|
---|
93 | g_pszTestKernel = argv[1];
|
---|
94 | #ifndef RT_OS_DARWIN
|
---|
95 | else
|
---|
96 | return RTTestSkipAndDestroy(hTest, "not on darwin");
|
---|
97 | #endif
|
---|
98 |
|
---|
99 | dotest();
|
---|
100 |
|
---|
101 | return RTTestSummaryAndDestroy(hTest);
|
---|
102 | }
|
---|
103 |
|
---|