threadctxhooks-r0drv-solaris.c revision bf7f26a344eebf65d659702a25a18fee915573cc
/* $Id$ */
/** @file
* IPRT - Thread-Context Hook, Ring-0 Driver, Solaris.
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "the-solaris-kernel.h"
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* The internal thread-context object.
*/
typedef struct RTTHREADCTXINT
{
/** Magic value (RTTHREADCTXINT_MAGIC). */
/** The thread handle (owner) for which the context-hooks are registered. */
/** Pointer to the registered thread-context hook. */
/** User argument passed to the thread-context hook. */
void *pvUser;
/** Whether this handle has any hooks registered or not. */
bool fRegistered;
/** Number of references to this object. */
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** Validates a thread-context hook handle and returns rc if not valid. */
do { \
} while (0)
/**
* Hook function for the thread-preempting event.
*
* @param pvThreadCtxInt Opaque pointer to the internal thread-context
* object.
*
* @remarks Called with the with preemption disabled!
*/
static void rtThreadCtxHooksSolPreempting(void *pvThreadCtxInt)
{
if (pThis->fRegistered)
{
}
}
/**
* Hook function for the thread-resumed event.
*
* @param pvThreadCtxInt Opaque pointer to the internal thread-context
* object.
*/
static void rtThreadCtxHooksSolResumed(void *pvThreadCtxInt)
{
if (pThis->fRegistered)
{
}
}
/**
* Hook function for the thread-free event.
*
* @param pvThreadCtxInt Opaque pointer to the internal thread-context
* object.
* @param fIsExec Whether this event is triggered due to exec().
*/
{
AssertMsgReturnVoid(pThis->u32Magic == RTTHREADCTXINT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis));
if (RT_UNLIKELY(!cRefs))
{
/* Should never happen. */
return;
}
if (!cRefs)
{
}
}
{
if (RT_UNLIKELY(!pThis))
return VERR_NO_MEMORY;
pThis->fRegistered = false;
/*
* installctx() allocates memory and thus cannot be used in RTThreadCtxHooksRegister() which can be used
* with preemption disabled. We allocate the context-hooks here and use 'fRegistered' to determine if we can
* invoke the consumer's hook or not.
*/
if (g_frtSolOldThreadCtx)
{
NULL, /* fork */
NULL, /* lwp_create */
}
else
{
NULL, /* fork */
NULL, /* lwp_create */
NULL, /* exit */
}
*phThreadCtx = pThis;
return VINF_SUCCESS;
}
{
return cRefs;
}
{
if (pThis == NIL_RTTHREADCTX)
return 0;
pThis->fRegistered = false;
&& cRefs == 1)
{
/*
* removectx() will invoke rtThreadCtxHooksSolFree() and there is no way to bypass it and still use
* rtThreadCtxHooksSolFree() at the same time. Hence the convulated reference counting.
*
* When this function is called from the owner thread and is the last reference, we call removectx() which
* will invoke rtThreadCtxHooksSolFree() with cRefs = 1 and that will then free the hook object.
*
* When the function is called from a different thread, we simply decrement the reference. Whenever the
* ring-0 thread dies, Solaris will call rtThreadCtxHooksSolFree() which will free the hook object.
*/
int rc;
if (g_frtSolOldThreadCtx)
{
NULL, /* fork */
NULL, /* lwp_create */
}
else
{
NULL, /* fork */
NULL, /* lwp_create */
NULL, /* exit */
}
#ifdef VBOX_STRICT
#endif
cRefs = 0;
}
else if (!cRefs)
{
/*
* The ring-0 thread for this hook object has already died. Free up the object as we have no more references.
*/
}
return cRefs;
}
RTDECL(int) RTThreadCtxHooksRegister(RTTHREADCTX hThreadCtx, PFNRTTHREADCTXHOOK pfnThreadCtxHook, void *pvUser)
{
/*
* Validate input.
*/
if (pThis == NIL_RTTHREADCTX)
return VINF_SUCCESS;
AssertMsgReturn(pThis->u32Magic == RTTHREADCTXINT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis),
/*
* Register the callback.
*/
pThis->fRegistered = true;
return VINF_SUCCESS;
}
{
/*
* Validate input.
*/
if (pThis == NIL_RTTHREADCTX)
return VINF_SUCCESS;
AssertMsgReturn(pThis->u32Magic == RTTHREADCTXINT_MAGIC, ("pThis->u32Magic=%RX32 pThis=%p\n", pThis->u32Magic, pThis),
/*
* Deregister the callback.
*/
pThis->fRegistered = false;
return VINF_SUCCESS;
}