1 | /* $Id: tstRTR0DbgKrnlInfoDriver.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT R0 Testcase - Debug kernel information, driver program.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2023 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/initterm.h>
|
---|
42 |
|
---|
43 | #include <iprt/errcore.h>
|
---|
44 | #include <iprt/path.h>
|
---|
45 | #include <iprt/param.h>
|
---|
46 | #include <iprt/stream.h>
|
---|
47 | #include <iprt/string.h>
|
---|
48 | #include <iprt/test.h>
|
---|
49 | #ifdef VBOX
|
---|
50 | # include <VBox/sup.h>
|
---|
51 | # include "tstRTR0DbgKrnlInfo.h"
|
---|
52 | #endif
|
---|
53 |
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Entry point.
|
---|
57 | */
|
---|
58 | extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
|
---|
59 | {
|
---|
60 | RT_NOREF(argc, argv, envp);
|
---|
61 | #ifndef VBOX
|
---|
62 | RTPrintf("tstSup: SKIPPED\n");
|
---|
63 | return 0;
|
---|
64 | #else
|
---|
65 | /*
|
---|
66 | * Init.
|
---|
67 | */
|
---|
68 | RTTEST hTest;
|
---|
69 | int rc = RTTestInitAndCreate("tstRTR0DbgKrnlInfo", &hTest);
|
---|
70 | if (rc)
|
---|
71 | return rc;
|
---|
72 | RTTestBanner(hTest);
|
---|
73 |
|
---|
74 | uint8_t *pbPage = (uint8_t *)RTTestGuardedAllocTail(hTest, PAGE_SIZE);
|
---|
75 | if (!pbPage)
|
---|
76 | {
|
---|
77 | RTTestFailed(hTest, "RTTestGuardedAllocTail failed with rc=%Rrc\n", rc);
|
---|
78 | return RTTestSummaryAndDestroy(hTest);
|
---|
79 | }
|
---|
80 |
|
---|
81 | PSUPDRVSESSION pSession;
|
---|
82 | rc = SUPR3Init(&pSession);
|
---|
83 | if (RT_FAILURE(rc))
|
---|
84 | {
|
---|
85 | RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
|
---|
86 | return RTTestSummaryAndDestroy(hTest);
|
---|
87 | }
|
---|
88 |
|
---|
89 | char szPath[RTPATH_MAX];
|
---|
90 | rc = RTPathExecDir(szPath, sizeof(szPath));
|
---|
91 | if (RT_SUCCESS(rc))
|
---|
92 | rc = RTPathAppend(szPath, sizeof(szPath), "tstRTR0DbgKrnlInfo.r0");
|
---|
93 | if (RT_FAILURE(rc))
|
---|
94 | {
|
---|
95 | RTTestFailed(hTest, "Failed constructing .r0 filename (rc=%Rrc)", rc);
|
---|
96 | return RTTestSummaryAndDestroy(hTest);
|
---|
97 | }
|
---|
98 |
|
---|
99 | void *pvImageBase;
|
---|
100 | rc = SUPR3LoadServiceModule(szPath, "tstRTR0DbgKrnlInfo",
|
---|
101 | "TSTR0DbgKrnlInfoSrvReqHandler",
|
---|
102 | &pvImageBase);
|
---|
103 | if (RT_FAILURE(rc))
|
---|
104 | {
|
---|
105 | RTTestFailed(hTest, "SUPR3LoadServiceModule(%s,,,) failed with rc=%Rrc\n", szPath, rc);
|
---|
106 | return RTTestSummaryAndDestroy(hTest);
|
---|
107 | }
|
---|
108 |
|
---|
109 | /* test request */
|
---|
110 | struct
|
---|
111 | {
|
---|
112 | SUPR0SERVICEREQHDR Hdr;
|
---|
113 | char szMsg[256];
|
---|
114 | } Req;
|
---|
115 |
|
---|
116 | /*
|
---|
117 | * Sanity checks.
|
---|
118 | */
|
---|
119 | RTTestSub(hTest, "Sanity");
|
---|
120 | Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
|
---|
121 | Req.Hdr.cbReq = sizeof(Req);
|
---|
122 | Req.szMsg[0] = '\0';
|
---|
123 | RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0DbgKrnlInfo", sizeof("tstRTR0DbgKrnlInfo") - 1,
|
---|
124 | TSTRTR0DBGKRNLINFO_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS);
|
---|
125 | if (RT_FAILURE(rc))
|
---|
126 | return RTTestSummaryAndDestroy(hTest);
|
---|
127 | RTTESTI_CHECK_MSG(Req.szMsg[0] == '\0', ("%s", Req.szMsg));
|
---|
128 | if (Req.szMsg[0] != '\0')
|
---|
129 | return RTTestSummaryAndDestroy(hTest);
|
---|
130 |
|
---|
131 | Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
|
---|
132 | Req.Hdr.cbReq = sizeof(Req);
|
---|
133 | Req.szMsg[0] = '\0';
|
---|
134 | RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0DbgKrnlInfo", sizeof("tstRTR0DbgKrnlInfo") - 1,
|
---|
135 | TSTRTR0DBGKRNLINFO_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS);
|
---|
136 | if (RT_FAILURE(rc))
|
---|
137 | return RTTestSummaryAndDestroy(hTest);
|
---|
138 | RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, RT_STR_TUPLE("!42failure42")), ("%s", Req.szMsg));
|
---|
139 | if (strncmp(Req.szMsg, RT_STR_TUPLE("!42failure42")))
|
---|
140 | return RTTestSummaryAndDestroy(hTest);
|
---|
141 |
|
---|
142 | /*
|
---|
143 | * Basic tests, bail out on failure.
|
---|
144 | */
|
---|
145 | RTTestSub(hTest, "Basics");
|
---|
146 | Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
|
---|
147 | Req.Hdr.cbReq = sizeof(Req);
|
---|
148 | Req.szMsg[0] = '\0';
|
---|
149 | RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0DbgKrnlInfo", sizeof("tstRTR0DbgKrnlInfo") - 1,
|
---|
150 | TSTRTR0DBGKRNLINFO_BASIC, 0, &Req.Hdr), VINF_SUCCESS);
|
---|
151 | if (RT_FAILURE(rc))
|
---|
152 | return RTTestSummaryAndDestroy(hTest);
|
---|
153 | if (Req.szMsg[0] == '!')
|
---|
154 | {
|
---|
155 | RTTestIFailed("%s", &Req.szMsg[1]);
|
---|
156 | return RTTestSummaryAndDestroy(hTest);
|
---|
157 | }
|
---|
158 | if (Req.szMsg[0])
|
---|
159 | RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
|
---|
160 |
|
---|
161 | /*
|
---|
162 | * Done.
|
---|
163 | */
|
---|
164 | return RTTestSummaryAndDestroy(hTest);
|
---|
165 | #endif
|
---|
166 | }
|
---|
167 |
|
---|
168 |
|
---|
169 | #if !defined(VBOX_WITH_HARDENING) || !defined(RT_OS_WINDOWS)
|
---|
170 | /**
|
---|
171 | * Main entry point.
|
---|
172 | */
|
---|
173 | int main(int argc, char **argv, char **envp)
|
---|
174 | {
|
---|
175 | return TrustedMain(argc, argv, envp);
|
---|
176 | }
|
---|
177 | #endif
|
---|
178 |
|
---|