VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTR0DbgKrnlInfo.cpp@ 56770

Last change on this file since 56770 was 56770, checked in by vboxsync, 9 years ago

tstRTR0DbgKrnlInfo: don't leak the stuff and don't panic the host with strict builds.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: tstRTR0DbgKrnlInfo.cpp 56770 2015-07-03 12:00:07Z vboxsync $ */
2/** @file
3 * IPRT R0 Testcase - Debug kernel information.
4 */
5
6/*
7 * Copyright (C) 2012-2015 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* Header Files *
29*******************************************************************************/
30#include <iprt/thread.h>
31
32#include <iprt/asm-amd64-x86.h>
33#include <iprt/err.h>
34#include <iprt/time.h>
35#include <iprt/string.h>
36#include <VBox/sup.h>
37#include <iprt/dbg.h>
38#include "tstRTR0DbgKrnlInfo.h"
39#include "tstRTR0Common.h"
40
41
42/**
43 * Service request callback function.
44 *
45 * @returns VBox status code.
46 * @param pSession The caller's session.
47 * @param u64Arg 64-bit integer argument.
48 * @param pReqHdr The request header. Input / Output. Optional.
49 */
50DECLEXPORT(int) TSTR0DbgKrnlInfoSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,
51 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr)
52{
53 NOREF(pSession);
54 if (u64Arg)
55 return VERR_INVALID_PARAMETER;
56 if (!VALID_PTR(pReqHdr))
57 return VERR_INVALID_PARAMETER;
58 char *pszErr = (char *)(pReqHdr + 1);
59 size_t cchErr = pReqHdr->cbReq - sizeof(*pReqHdr);
60 if (cchErr < 32 || cchErr >= 0x10000)
61 return VERR_INVALID_PARAMETER;
62 *pszErr = '\0';
63
64 /*
65 * The big switch.
66 */
67 bool fSavedMayPanic = RTAssertSetMayPanic(false); /* Don't crash the host with strict builds! */
68 RTDBGKRNLINFO hKrnlInfo = NIL_RTDBGKRNLINFO;
69 switch (uOperation)
70 {
71 case TSTRTR0DBGKRNLINFO_SANITY_OK:
72 break;
73
74 case TSTRTR0DBGKRNLINFO_SANITY_FAILURE:
75 RTStrPrintf(pszErr, cchErr, "!42failure42%1024s", "");
76 break;
77
78 case TSTRTR0DBGKRNLINFO_BASIC:
79 {
80 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoOpen(&hKrnlInfo, 1), VERR_INVALID_PARAMETER);
81 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoOpen(NULL, 0), VERR_INVALID_PARAMETER);
82 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0), VINF_SUCCESS);
83
84 size_t offMemb;
85 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQueryMember(NULL, "Test", "Test", &offMemb), VERR_INVALID_HANDLE);
86 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQueryMember(hKrnlInfo, NULL, "Test", &offMemb), VERR_INVALID_PARAMETER);
87 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQueryMember(hKrnlInfo, "Test", NULL, &offMemb), VERR_INVALID_PARAMETER);
88 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQueryMember(hKrnlInfo, "Test", "Test", NULL), VERR_INVALID_PARAMETER);
89
90 void *pvSymbol;
91 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQuerySymbol(NULL, "Test", "Test", &pvSymbol), VERR_INVALID_HANDLE);
92 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, "TestModule", "Test", &pvSymbol), VERR_MODULE_NOT_FOUND);
93 RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, NULL, &pvSymbol), VERR_INVALID_PARAMETER);
94
95 RTDBGKRNLINFO hTmp = hKrnlInfo;
96 hKrnlInfo = NIL_RTDBGKRNLINFO;
97 RTR0DbgKrnlInfoRelease(hKrnlInfo);
98 uint32_t cRefs;
99 RTR0TESTR0_CHECK_MSG((cRefs = RTR0DbgKrnlInfoRelease(hKrnlInfo)) == 0, ("cRefs=%#x", cRefs));
100 break;
101 }
102
103 /** @todo check member retreival based on target platform. */
104 /** @todo check symbol lookups based on target platform. */
105
106 default:
107 RTStrPrintf(pszErr, cchErr, "!Unknown test #%d", uOperation);
108 break;
109 }
110 if (hKrnlInfo != NIL_RTDBGKRNLINFO)
111 RTR0DbgKrnlInfoRelease(hKrnlInfo);
112 RTAssertSetMayPanic(fSavedMayPanic);
113
114 /* The error indicator is the '!' in the message buffer. */
115 return VINF_SUCCESS;
116}
117
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette