assert-r0drv-solaris.c revision 9c11b89c71ca727d975c39f2719063501ddcd03d
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/* $Id$ */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/** @file
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * IPRT - Assertion Workers, Ring-0 Drivers, Solaris.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/*
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * available from http://www.virtualbox.org. This file is free software;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * The contents of this file may alternatively be used under the terms
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * of the Common Development and Distribution License Version 1.0
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution, in which case the provisions of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * CDDL are applicable instead of those of the GPL.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync *
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * You may elect to license modified versions of this file under the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * terms and conditions of either the GPL or the CDDL or both.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync *
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * additional information or have any questions.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync/*******************************************************************************
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync* Header Files *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync*******************************************************************************/
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#include "the-solaris-kernel.h"
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync#include "internal/iprt.h"
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#include <iprt/assert.h>
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync#include <iprt/asm.h>
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#include <iprt/log.h>
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#include <iprt/stdarg.h>
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync#include <iprt/string.h>
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
8e034cd2a6b0c86697554278e970163287003bb9vboxsync/*******************************************************************************
8e034cd2a6b0c86697554278e970163287003bb9vboxsync* Global Variables *
8e034cd2a6b0c86697554278e970163287003bb9vboxsync*******************************************************************************/
8e034cd2a6b0c86697554278e970163287003bb9vboxsync/** The last assert message, 1st part. */
8e034cd2a6b0c86697554278e970163287003bb9vboxsyncRTDATADECL(char) g_szRTAssertMsg1[1024];
8e034cd2a6b0c86697554278e970163287003bb9vboxsync/** The last assert message, 2nd part. */
8e034cd2a6b0c86697554278e970163287003bb9vboxsyncRTDATADECL(char) g_szRTAssertMsg2[2048];
d606b96aa8a4be8f7d2da410f982889804c27b92vboxsync/** The last assert message, expression. */
d606b96aa8a4be8f7d2da410f982889804c27b92vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertExpr;
8e034cd2a6b0c86697554278e970163287003bb9vboxsync/** The last assert message, file name. */
d606b96aa8a4be8f7d2da410f982889804c27b92vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertFile;
8e034cd2a6b0c86697554278e970163287003bb9vboxsync/** The last assert message, line number. */
d606b96aa8a4be8f7d2da410f982889804c27b92vboxsyncRTDATADECL(uint32_t volatile) g_u32RTAssertLine;
8e034cd2a6b0c86697554278e970163287003bb9vboxsync/** The last assert message, function name. */
d606b96aa8a4be8f7d2da410f982889804c27b92vboxsyncRTDATADECL(const char * volatile) g_pszRTAssertFunction;
8e034cd2a6b0c86697554278e970163287003bb9vboxsync
8e034cd2a6b0c86697554278e970163287003bb9vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsyncRTDECL(void) AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync{
2c203bb219df5391ed7f3888c85e12a4e47817davboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#ifdef IN_GUEST_R0
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync RTLogBackdoorPrintf("\n!!Assertion Failed!!\n"
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync "Expression: %s\n"
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync "Location : %s(%d) %s\n",
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync pszExpr, pszFile, uLine, pszFunction);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#endif
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
089c21a647af46044cad04a78cfdcfae814d2105vboxsync uprintf("\r\n!!Assertion Failed!!\r\n"
089c21a647af46044cad04a78cfdcfae814d2105vboxsync "Expression: %s\r\n"
089c21a647af46044cad04a78cfdcfae814d2105vboxsync "Location : %s(%d) %s\r\n",
089c21a647af46044cad04a78cfdcfae814d2105vboxsync pszExpr, pszFile, uLine, pszFunction);
8e034cd2a6b0c86697554278e970163287003bb9vboxsync
8e034cd2a6b0c86697554278e970163287003bb9vboxsync RTStrPrintf(g_szRTAssertMsg1, sizeof(g_szRTAssertMsg1),
8e034cd2a6b0c86697554278e970163287003bb9vboxsync "\n!!Assertion Failed!!\n"
8e034cd2a6b0c86697554278e970163287003bb9vboxsync "Expression: %s\n"
8e034cd2a6b0c86697554278e970163287003bb9vboxsync "Location : %s(%d) %s\n",
8e034cd2a6b0c86697554278e970163287003bb9vboxsync pszExpr, pszFile, uLine, pszFunction);
d606b96aa8a4be8f7d2da410f982889804c27b92vboxsync ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertExpr, (void *)pszExpr);
94a797b56cdb77ca5b26cb678b13144edc9ebb55vboxsync ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertFile, (void *)pszFile);
94a797b56cdb77ca5b26cb678b13144edc9ebb55vboxsync ASMAtomicUoWritePtr((void * volatile *)&g_pszRTAssertFunction, (void *)pszFunction);
8e034cd2a6b0c86697554278e970163287003bb9vboxsync ASMAtomicUoWriteU32(&g_u32RTAssertLine, uLine);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync}
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsyncRTDECL(void) AssertMsg2(const char *pszFormat, ...)
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync{
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync va_list va;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync char szMsg[256];
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#ifdef IN_GUEST_R0
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync va_start(va, pszFormat);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync RTLogBackdoorPrintfV(pszFormat, va);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync va_end(va);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#endif
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync va_start(va, pszFormat);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync RTStrPrintfV(szMsg, sizeof(szMsg) - 1, pszFormat, va);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync szMsg[sizeof(szMsg) - 1] = '\0';
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync va_end(va);
089c21a647af46044cad04a78cfdcfae814d2105vboxsync uprintf("%s", szMsg);
8e034cd2a6b0c86697554278e970163287003bb9vboxsync
8e034cd2a6b0c86697554278e970163287003bb9vboxsync va_start(va, pszFormat);
8e034cd2a6b0c86697554278e970163287003bb9vboxsync RTStrPrintfV(g_szRTAssertMsg2, sizeof(g_szRTAssertMsg2), pszFormat, va);
8e034cd2a6b0c86697554278e970163287003bb9vboxsync va_end(va);
8e034cd2a6b0c86697554278e970163287003bb9vboxsync}
8e034cd2a6b0c86697554278e970163287003bb9vboxsync
8e034cd2a6b0c86697554278e970163287003bb9vboxsync
8e034cd2a6b0c86697554278e970163287003bb9vboxsyncRTR0DECL(void) RTR0AssertPanicSystem(void)
8e034cd2a6b0c86697554278e970163287003bb9vboxsync{
8e034cd2a6b0c86697554278e970163287003bb9vboxsync const char *psz = &g_szRTAssertMsg2[0];
8e034cd2a6b0c86697554278e970163287003bb9vboxsync const char *pszEnd = &g_szRTAssertMsg2[sizeof(g_szRTAssertMsg2)];
8e034cd2a6b0c86697554278e970163287003bb9vboxsync while (psz < pszEnd && (*psz == ' ' || *psz == '\t' || *psz == '\n' || *psz == '\r'))
8e034cd2a6b0c86697554278e970163287003bb9vboxsync psz++;
8e034cd2a6b0c86697554278e970163287003bb9vboxsync
8e034cd2a6b0c86697554278e970163287003bb9vboxsync if (psz >= pszEnd || *psz)
8e034cd2a6b0c86697554278e970163287003bb9vboxsync assfail(psz, g_pszRTAssertFile, g_u32RTAssertLine);
8e034cd2a6b0c86697554278e970163287003bb9vboxsync else
8e034cd2a6b0c86697554278e970163287003bb9vboxsync assfail(g_szRTAssertMsg1, g_pszRTAssertFile, g_u32RTAssertLine);
2c203bb219df5391ed7f3888c85e12a4e47817davboxsync g_szRTAssertMsg2[0] = '\0';
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync}
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync