tstRTR0DbgKrnlInfo.cpp revision 68fce2926ac031f46c25460569296f66620e9d52
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/* $Id$ */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/** @file
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * IPRT R0 Testcase - Debug kernel information.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/*
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * Copyright (C) 2012 Oracle Corporation
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * available from http://www.virtualbox.org. This file is free software;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * you can redistribute it and/or modify it under the terms of the GNU
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * General Public License (GPL) as published by the Free Software
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * The contents of this file may alternatively be used under the terms
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * of the Common Development and Distribution License Version 1.0
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * VirtualBox OSE distribution, in which case the provisions of the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * CDDL are applicable instead of those of the GPL.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * You may elect to license modified versions of this file under the
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * terms and conditions of either the GPL or the CDDL or both.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync/*******************************************************************************
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync* Header Files *
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync*******************************************************************************/
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync#include <iprt/thread.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/asm-amd64-x86.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/err.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/time.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/string.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <VBox/sup.h>
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include <iprt/dbg.h>
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync#include "tstRTR0DbgKrnlInfo.h"
956a0e3c076406b83d635174a201fd8761ee5133vboxsync#include "tstRTR0Common.h"
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync/**
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * Service request callback function.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * @returns VBox status code.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * @param pSession The caller's session.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * @param u64Arg 64-bit integer argument.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * @param pReqHdr The request header. Input / Output. Optional.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsyncDECLEXPORT(int) TSTR0DbgKrnlInfoSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,
956a0e3c076406b83d635174a201fd8761ee5133vboxsync uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync{
956a0e3c076406b83d635174a201fd8761ee5133vboxsync NOREF(pSession);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (u64Arg)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return VERR_INVALID_PARAMETER;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (!VALID_PTR(pReqHdr))
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return VERR_INVALID_PARAMETER;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync char *pszErr = (char *)(pReqHdr + 1);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync size_t cchErr = pReqHdr->cbReq - sizeof(*pReqHdr);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync if (cchErr < 32 || cchErr >= 0x10000)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync return VERR_INVALID_PARAMETER;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync *pszErr = '\0';
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /*
956a0e3c076406b83d635174a201fd8761ee5133vboxsync * The big switch.
956a0e3c076406b83d635174a201fd8761ee5133vboxsync */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync switch (uOperation)
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync case TSTRTR0DBGKRNLINFO_SANITY_OK:
956a0e3c076406b83d635174a201fd8761ee5133vboxsync break;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync case TSTRTR0DBGKRNLINFO_SANITY_FAILURE:
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTStrPrintf(pszErr, cchErr, "!42failure42%1024s", "");
956a0e3c076406b83d635174a201fd8761ee5133vboxsync break;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync case TSTRTR0DBGKRNLINFO_BASIC:
956a0e3c076406b83d635174a201fd8761ee5133vboxsync {
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTDBGKRNLINFO hKrnlInfo;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoOpen(&hKrnlInfo, 1), VERR_INVALID_PARAMETER);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoOpen(NULL, 0), VERR_INVALID_PARAMETER);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0), VINF_SUCCESS);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync size_t offMemb;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQueryMember(NULL, "Test", "Test", &offMemb), VERR_INVALID_HANDLE);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQueryMember(hKrnlInfo, NULL, "Test", &offMemb), VERR_INVALID_PARAMETER);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQueryMember(hKrnlInfo, "Test", NULL, &offMemb), VERR_INVALID_PARAMETER);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQueryMember(hKrnlInfo, "Test", "Test", NULL), VERR_INVALID_PARAMETER);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync void *pvSymbol;
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQuerySymbol(NULL, "Test", "Test", &pvSymbol), VERR_INVALID_HANDLE);
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, "TestModule", "Test", &pvSymbol), VERR_MODULE_NOT_FOUND);
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync RTR0TESTR0_CHECK_RC_BREAK(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, NULL, &pvSymbol), VERR_INVALID_PARAMETER);
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync break;
68fb2428898c55a7172e6a75a0a8d7ce259919bdvboxsync }
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** @todo check member retreival based on target platform. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync /** @todo check symbol lookups based on target platform. */
956a0e3c076406b83d635174a201fd8761ee5133vboxsync
956a0e3c076406b83d635174a201fd8761ee5133vboxsync default:
956a0e3c076406b83d635174a201fd8761ee5133vboxsync RTStrPrintf(pszErr, cchErr, "!Unknown test #%d", uOperation);
956a0e3c076406b83d635174a201fd8761ee5133vboxsync break;
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync }
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync /* The error indicator is the '!' in the message buffer. */
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync return VINF_SUCCESS;
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync}
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync
a15d881e9ec9bffe9b27ae4174efb8d4dc4a0e17vboxsync