assert-r0drv-linux.c revision aa41a82dd75ca56e7d4d979c4ed595df539128dc
1N/A/* $Id$ */
1N/A/** @file
1N/A * IPRT - Assertion Workers, Ring-0 Drivers, Linux.
1N/A */
1N/A
1N/A/*
1N/A * Copyright (C) 2007 Sun Microsystems, Inc.
1N/A *
1N/A * This file is part of VirtualBox Open Source Edition (OSE), as
1N/A * available from http://www.virtualbox.org. This file is free software;
1N/A * you can redistribute it and/or modify it under the terms of the GNU
1N/A * General Public License (GPL) as published by the Free Software
1N/A * Foundation, in version 2 as it comes in the "COPYING" file of the
1N/A * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1N/A * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1N/A *
1N/A * The contents of this file may alternatively be used under the terms
1N/A * of the Common Development and Distribution License Version 1.0
1N/A * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
1N/A * VirtualBox OSE distribution, in which case the provisions of the
1N/A * CDDL are applicable instead of those of the GPL.
1N/A *
1N/A * You may elect to license modified versions of this file under the
1N/A * terms and conditions of either the GPL or the CDDL or both.
1N/A *
1N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1N/A * Clara, CA 95054 USA or visit http://www.sun.com if you need
1N/A * additional information or have any questions.
1N/A */
1N/A
1N/A
1N/A/*******************************************************************************
1N/A* Header Files *
1N/A*******************************************************************************/
1N/A#include "the-linux-kernel.h"
1N/A
1N/A#include <iprt/assert.h>
1N/A#include <iprt/log.h>
1N/A#include <iprt/string.h>
1N/A#include <iprt/stdarg.h>
1N/A#include <iprt/asm.h>
1N/A
1N/A
1N/A/*******************************************************************************
1N/A* Global Variables *
1N/A*******************************************************************************/
1N/A/** The last assert message, 1st part. */
1N/ARTDATADECL(char) g_szRTAssertMsg1[1024];
1N/A/** The last assert message, 2nd part. */
1N/ARTDATADECL(char) g_szRTAssertMsg2[2048];
1N/A/** The last assert message, file name. */
1N/ARTDATADECL(const char *) volatile g_pszRTAssertExpr;
1N/A/** The last assert message, file name. */
1N/ARTDATADECL(const char *) volatile g_pszRTAssertFile;
1N/A/** The last assert message, line number. */
1N/ARTDATADECL(uint32_t) volatile g_u32RTAssertLine;
1N/A/** The last assert message, function name. */
1N/ARTDATADECL(const char *) volatile g_pszRTAssertFunction;
1N/A
1N/A
1N/ARTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
1N/A{
1N/A#ifdef IN_GUEST_R0
1N/A RTLogBackdoorPrintf("\n!!Assertion Failed!!\n"
1N/A "Expression: %s\n"
1N/A "Location : %s(%d) %s\n",
1N/A pszExpr, pszFile, uLine, pszFunction);
1N/A#endif
1N/A
1N/A printk("\r\n!!Assertion Failed!!\r\n"
1N/A "Expression: %s\r\n"
1N/A "Location : %s(%d) %s\r\n",
1N/A pszExpr, pszFile, uLine, pszFunction);
1N/A
1N/A RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
1N/A "\n!!Assertion Failed!!\n"
1N/A "Expression: %s\n"
1N/A "Location : %s(%d) %s\n",
1N/A pszExpr, pszFile, uLine, pszFunction);
1N/A ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertExpr, pszExpr);
1N/A ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertFile, pszFile);
1N/A ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertFunction, pszFunction);
1N/A ASMAtomicUoWriteU32(&g_u32RTAssertLine, uLine);
1N/A}
1N/A
1N/A
1N/ARTDECL(void) AssertMsg2(const char *pszFormat, ...)
1N/A{
1N/A va_list va;
1N/A char szMsg[256];
1N/A
1N/A#ifdef IN_GUEST_R0
1N/A va_start(va, pszFormat);
1N/A RTLogBackdoorPrintfV(pszFormat, va);
1N/A va_end(va);
1N/A#endif
1N/A
1N/A va_start(va, pszFormat);
1N/A RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
1N/A szMsg[sizeof(szMsg) - 1] = '\0';
1N/A va_end(va);
1N/A printk("%s", szMsg);
1N/A
1N/A va_start(va, pszFormat);
1N/A RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, va);
1N/A va_end(va);
1N/A}
1N/A
1N/A
1N/ARTR0DECL(void) RTR0AssertPanicSystem(void)
1N/A{
1N/A panic("%s%s", g_szRTAssertMsg1, g_szRTAssertMsg2);
1N/A}
1N/A
1N/A
1N/A#if defined(RT_OS_LINUX) && defined(IN_MODULE)
1N/A/*
1N/A * When we build this in the Linux kernel module, we wish to make the
1N/A * symbols available to other modules as well.
1N/A */
1N/A# include "the-linux-kernel.h"
1N/AEXPORT_SYMBOL (RTR0AssertPanicSystem);
1N/AEXPORT_SYMBOL (AssertMsg1);
1N/AEXPORT_SYMBOL (AssertMsg2);
1N/A#endif /* RT_OS_LINUX && IN_MODULE */
1N/A