diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:49:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 16:49:04 +0000 |
commit | 16f504a9dca3fe3b70568f67b7d41241ae485288 (patch) | |
tree | c60f36ada0496ba928b7161059ba5ab1ab224f9d /src/VBox/Runtime/testcase/tstRTR0MemUserKernelDriver.cpp | |
parent | Initial commit. (diff) | |
download | virtualbox-upstream.tar.xz virtualbox-upstream.zip |
Adding upstream version 7.0.6-dfsg.upstream/7.0.6-dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/VBox/Runtime/testcase/tstRTR0MemUserKernelDriver.cpp | 236 |
1 files changed, 236 insertions, 0 deletions
diff --git a/src/VBox/Runtime/testcase/tstRTR0MemUserKernelDriver.cpp b/src/VBox/Runtime/testcase/tstRTR0MemUserKernelDriver.cpp new file mode 100644 index 00000000..17b5cc26 --- /dev/null +++ b/src/VBox/Runtime/testcase/tstRTR0MemUserKernelDriver.cpp @@ -0,0 +1,236 @@ +/* $Id: tstRTR0MemUserKernelDriver.cpp $ */ +/** @file + * IPRT R0 Testcase - Thread Preemption, driver program. + */ + +/* + * Copyright (C) 2009-2022 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * The contents of this file may alternatively be used under the terms + * of the Common Development and Distribution License Version 1.0 + * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included + * in the VirtualBox distribution, in which case the provisions of the + * CDDL are applicable instead of those of the GPL. + * + * You may elect to license modified versions of this file under the + * terms and conditions of either the GPL or the CDDL or both. + * + * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include <iprt/initterm.h> + +#include <iprt/errcore.h> +#include <iprt/path.h> +#include <iprt/param.h> +#include <iprt/stream.h> +#include <iprt/string.h> +#include <iprt/test.h> +#include <iprt/thread.h> +#ifdef VBOX +# include <VBox/sup.h> +# include "tstRTR0MemUserKernel.h" +#endif + + +/** + * Entry point. + */ +extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp) +{ + RT_NOREF3(argc, argv, envp); +#ifndef VBOX + RTPrintf("tstSup: SKIPPED\n"); + return 0; +#else + /* + * Init. + */ + RTTEST hTest; + int rc = RTTestInitAndCreate("tstRTR0MemUserKernel", &hTest); + if (rc) + return rc; + RTTestBanner(hTest); + + uint8_t *pbPage = (uint8_t *)RTTestGuardedAllocTail(hTest, PAGE_SIZE); + if (!pbPage) + { + RTTestFailed(hTest, "RTTestGuardedAllocTail failed with rc=%Rrc\n", rc); + return RTTestSummaryAndDestroy(hTest); + } + + PSUPDRVSESSION pSession; + rc = SUPR3Init(&pSession); + if (RT_FAILURE(rc)) + { + RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc); + return RTTestSummaryAndDestroy(hTest); + } + + char szPath[RTPATH_MAX]; + rc = RTPathExecDir(szPath, sizeof(szPath)); + if (RT_SUCCESS(rc)) + rc = RTPathAppend(szPath, sizeof(szPath), "tstRTR0MemUserKernel.r0"); + if (RT_FAILURE(rc)) + { + RTTestFailed(hTest, "Failed constructing .r0 filename (rc=%Rrc)", rc); + return RTTestSummaryAndDestroy(hTest); + } + + void *pvImageBase; + rc = SUPR3LoadServiceModule(szPath, "tstRTR0MemUserKernel", + "TSTRTR0MemUserKernelSrvReqHandler", + &pvImageBase); + if (RT_FAILURE(rc)) + { + RTTestFailed(hTest, "SUPR3LoadServiceModule(%s,,,) failed with rc=%Rrc\n", szPath, rc); + return RTTestSummaryAndDestroy(hTest); + } + + /* test request */ + struct + { + SUPR0SERVICEREQHDR Hdr; + char szMsg[256]; + } Req; + + /* + * Sanity checks. + */ + RTTestSub(hTest, "Sanity"); + Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; + Req.Hdr.cbReq = sizeof(Req); + Req.szMsg[0] = '\0'; + RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, + TSTRTR0MEMUSERKERNEL_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS); + if (RT_FAILURE(rc)) + return RTTestSummaryAndDestroy(hTest); + RTTESTI_CHECK_MSG(Req.szMsg[0] == '\0', ("%s", Req.szMsg)); + if (Req.szMsg[0] != '\0') + return RTTestSummaryAndDestroy(hTest); + + Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; + Req.Hdr.cbReq = sizeof(Req); + Req.szMsg[0] = '\0'; + RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, + TSTRTR0MEMUSERKERNEL_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS); + if (RT_FAILURE(rc)) + return RTTestSummaryAndDestroy(hTest); + RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, RT_STR_TUPLE("!42failure42")), ("%s", Req.szMsg)); + if (strncmp(Req.szMsg, RT_STR_TUPLE("!42failure42"))) + return RTTestSummaryAndDestroy(hTest); + + /* + * Basic tests, bail out on failure. + */ + RTTestSub(hTest, "Basics"); + Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; + Req.Hdr.cbReq = sizeof(Req); + Req.szMsg[0] = '\0'; + RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, + TSTRTR0MEMUSERKERNEL_BASIC, (uintptr_t)pbPage, &Req.Hdr), VINF_SUCCESS); + if (RT_FAILURE(rc)) + return RTTestSummaryAndDestroy(hTest); + if (Req.szMsg[0] == '!') + { + RTTestIFailed("%s", &Req.szMsg[1]); + return RTTestSummaryAndDestroy(hTest); + } + if (Req.szMsg[0]) + RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); + + /* + * Good buffer, bail out on failure. + */ + RTTestSub(hTest, "Good buffer"); + Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; + Req.Hdr.cbReq = sizeof(Req); + Req.szMsg[0] = '\0'; + RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, + TSTRTR0MEMUSERKERNEL_GOOD, (uintptr_t)pbPage, &Req.Hdr), VINF_SUCCESS); + if (RT_FAILURE(rc)) + return RTTestSummaryAndDestroy(hTest); + if (Req.szMsg[0] == '!') + { + RTTestIFailed("%s", &Req.szMsg[1]); + return RTTestSummaryAndDestroy(hTest); + } + if (Req.szMsg[0]) + RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); + + /* + * Bad buffer, bail out on failure. + */ + RTTestSub(hTest, "Bad buffer"); + Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; + Req.Hdr.cbReq = sizeof(Req); + Req.szMsg[0] = '\0'; + RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, + TSTRTR0MEMUSERKERNEL_BAD, (uintptr_t)pbPage + PAGE_SIZE, &Req.Hdr), VINF_SUCCESS); + if (RT_FAILURE(rc)) + return RTTestSummaryAndDestroy(hTest); + if (Req.szMsg[0] == '!') + { + RTTestIFailed("%s", &Req.szMsg[1]); + return RTTestSummaryAndDestroy(hTest); + } + if (Req.szMsg[0]) + RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); + + /* + * Bad buffer, bail out on failure. + */ + RTTestSub(hTest, "Kernel buffer"); + Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC; + Req.Hdr.cbReq = sizeof(Req); + Req.szMsg[0] = '\0'; + RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1, + TSTRTR0MEMUSERKERNEL_INVALID_ADDRESS, (uintptr_t)pvImageBase, &Req.Hdr), VINF_SUCCESS); + if (RT_FAILURE(rc)) + return RTTestSummaryAndDestroy(hTest); + if (Req.szMsg[0] == '!') + { + RTTestIFailed("%s", &Req.szMsg[1]); + return RTTestSummaryAndDestroy(hTest); + } + if (Req.szMsg[0]) + RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg); + + /* + * Done. + */ + return RTTestSummaryAndDestroy(hTest); +#endif +} + + +#if !defined(VBOX_WITH_HARDENING) || !defined(RT_OS_WINDOWS) +/** + * Main entry point. + */ +int main(int argc, char **argv, char **envp) +{ + return TrustedMain(argc, argv, envp); +} +#endif + |