semfastmutex-r0drv-nt.cpp revision 7a99c98125959dcc22e09cf74a744ccf37c0e55b
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * IPRT - Fast Mutex Semaphores, Ring-0 Driver, NT.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * available from http://www.virtualbox.org. This file is free software;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * General Public License (GPL) as published by the Free Software
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * The contents of this file may alternatively be used under the terms
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * of the Common Development and Distribution License Version 1.0
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * VirtualBox OSE distribution, in which case the provisions of the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * CDDL are applicable instead of those of the GPL.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * You may elect to license modified versions of this file under the
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * terms and conditions of either the GPL or the CDDL or both.
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
b8908d384db2324f04a2f68a13e67ea32ebf609avboxsync * additional information or have any questions.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/*******************************************************************************
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync* Header Files *
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync*******************************************************************************/
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync/*******************************************************************************
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync* Structures and Typedefs *
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync*******************************************************************************/
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Wrapper for the linux semaphore structure.
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync /** Magic value (RTSEMFASTMUTEX_MAGIC). */
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync /** the NT fast mutex. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncRTDECL(int) RTSemFastMutexCreate(PRTSEMFASTMUTEX pMutexSem)
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync * Allocate.
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync pFastInt = (PRTSEMFASTMUTEXINTERNAL)RTMemAlloc(sizeof(*pFastInt));
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync * Initialize.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncRTDECL(int) RTSemFastMutexDestroy(RTSEMFASTMUTEX MutexSem)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Validate.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt->u32Magic, pFastInt));
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync /* It's not very clear what this Contention field really means. Seems to be a counter for the number of times contention occurred. (see e.g. http://winprogger.com/?p=6)
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync * The following assertion is therefor wrong:
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Assert(pFastInt->Mutex.Contention == 0);
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsyncRTDECL(int) RTSemFastMutexRequest(RTSEMFASTMUTEX MutexSem)
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync * Validate.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync PRTSEMFASTMUTEXINTERNAL pFastInt = (PRTSEMFASTMUTEXINTERNAL)MutexSem;
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));
6754e49069315bd28137abb0f9241e3aeb99a97evboxsync * ExAcquireFastMutex will set the IRQL to APC regardless of our current
8b98c71a5a01d215eafbc3605cb7a66cc91ea774vboxsync * level. Lowering the IRQL may screw things up, so to allow this.
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync# if 0 /** @todo enable this when the logger has been fixed. */
9c0076729ec8138e89ce8a6af9a772b68f1f8dc7vboxsync# else /* the gentler approach. */
return VINF_SUCCESS;
if ( !pFastInt
AssertMsgFailed(("pFastInt->u32Magic=%RX32 pMutexInt=%p\n", pFastInt ? pFastInt->u32Magic : 0, pFastInt));
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;