2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync/* $Id$ */
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync/** @file
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * IPRT Testcase - mach_kernel symbol resolving hack.
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync */
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync/*
9a930fd7bd4d35c0ac75e4c83edb31b71bd3a635vboxsync * Copyright (C) 2011-2012 Oracle Corporation
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync *
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * available from http://www.virtualbox.org. This file is free software;
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * General Public License (GPL) as published by the Free Software
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync *
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * The contents of this file may alternatively be used under the terms
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * of the Common Development and Distribution License Version 1.0
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * VirtualBox OSE distribution, in which case the provisions of the
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * CDDL are applicable instead of those of the GPL.
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync *
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * You may elect to license modified versions of this file under the
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync * terms and conditions of either the GPL or the CDDL or both.
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync */
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync
ac745d5632c669204b297e18e1dc44b7f0677530vboxsync
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync/*******************************************************************************
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync* Header Files *
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync*******************************************************************************/
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync#include <iprt/dbg.h>
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync#include <iprt/err.h>
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync#include <iprt/string.h>
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync#include <iprt/test.h>
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsyncstatic void dotest(void)
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync{
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync RTDBGKRNLINFO hKrnlInfo;
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync RTTESTI_CHECK_RC_RETV(RTR0DbgKrnlInfoOpen(&hKrnlInfo, 0), VINF_SUCCESS);
2c7bf00c39a7fe5e20b84d786cfad01c63e85c2fvboxsync static const char * const s_apszSyms[] =
2c7bf00c39a7fe5e20b84d786cfad01c63e85c2fvboxsync {
2c7bf00c39a7fe5e20b84d786cfad01c63e85c2fvboxsync "ast_pending",
ac745d5632c669204b297e18e1dc44b7f0677530vboxsync "cpu_interrupt",
2c7bf00c39a7fe5e20b84d786cfad01c63e85c2fvboxsync "dtrace_register",
2c7bf00c39a7fe5e20b84d786cfad01c63e85c2fvboxsync "dtrace_suspend",
9a930fd7bd4d35c0ac75e4c83edb31b71bd3a635vboxsync "kext_alloc",
9a930fd7bd4d35c0ac75e4c83edb31b71bd3a635vboxsync "kext_free",
9a930fd7bd4d35c0ac75e4c83edb31b71bd3a635vboxsync "vm_map_protect"
2c7bf00c39a7fe5e20b84d786cfad01c63e85c2fvboxsync };
2c7bf00c39a7fe5e20b84d786cfad01c63e85c2fvboxsync for (unsigned i = 0; i < RT_ELEMENTS(s_apszSyms); i++)
2c7bf00c39a7fe5e20b84d786cfad01c63e85c2fvboxsync {
ac745d5632c669204b297e18e1dc44b7f0677530vboxsync void *pvValue = NULL;
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync int rc = RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], &pvValue);
ac745d5632c669204b297e18e1dc44b7f0677530vboxsync RTTestIPrintf(RTTESTLVL_ALWAYS, "%Rrc %p %s\n", rc, pvValue, s_apszSyms[i]);
ac745d5632c669204b297e18e1dc44b7f0677530vboxsync RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
ac745d5632c669204b297e18e1dc44b7f0677530vboxsync if (RT_SUCCESS(rc))
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync RTTESTI_CHECK_RC(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, s_apszSyms[i], NULL), VINF_SUCCESS);
2c7bf00c39a7fe5e20b84d786cfad01c63e85c2fvboxsync }
ac745d5632c669204b297e18e1dc44b7f0677530vboxsync
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync RTTESTI_CHECK_RC(RTR0DbgKrnlInfoQuerySymbol(hKrnlInfo, NULL, "no_such_symbol_name_really", NULL), VERR_SYMBOL_NOT_FOUND);
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync RTTESTI_CHECK(RTR0DbgKrnlInfoRelease(hKrnlInfo) == 0);
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync RTTESTI_CHECK(RTR0DbgKrnlInfoRelease(NIL_RTDBGKRNLINFO) == 0);
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync}
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsyncint main(int argc, char **argv)
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync{
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync RTTEST hTest;
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync RTEXITCODE rcExit = RTTestInitAndCreate("tstRTDarwinMachKernel", &hTest);
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync if (rcExit != RTEXITCODE_SUCCESS)
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync return rcExit;
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync RTTestBanner(hTest);
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync
3aab2e687794ef6731b5b1b8ede1668afc6bc4ebvboxsync dotest();
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync return RTTestSummaryAndDestroy(hTest);
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync}
2c4363d85aea1af6eb54340ba34fe0013895214bvboxsync