NT4/private/nw/rdr/lockcode.c
2020-09-30 17:12:29 +02:00

169 lines
3.3 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*++
Copyright (c) 1994 Microsoft Corporation
Module Name:
lockcode.c
Abstract:
Author:
Chuck Lenzmeier (chuckl) 30-Jan-1994
Manny Weiser (mannyw) 17-May-1994
Revision History:
--*/
#include "Procs.h"
#ifndef QFE_BUILD
#ifdef ALLOC_PRAGMA
#pragma alloc_text( PAGE, NwReferenceUnlockableCodeSection )
#pragma alloc_text( PAGE, NwDereferenceUnlockableCodeSection )
#endif
extern BOOLEAN TimerStop; // From Timer.c
//
// The debug trace level
//
#define Dbg (DEBUG_TRACE_CREATE)
VOID
NwReferenceUnlockableCodeSection (
VOID
)
{
ULONG oldCount;
//
// Lock the lockable code database.
//
ExAcquireResourceExclusive( &NwUnlockableCodeResource, TRUE );
//
// Increment the reference count for the section.
//
oldCount = NwSectionDescriptor.ReferenceCount++;
if ( oldCount == 0 && NwSectionDescriptor.Handle == NULL ) {
//
// This is the first reference to the section. Start the timer.
// Lock our code.
//
NwSectionDescriptor.Handle = MmLockPagableCodeSection( NwSectionDescriptor.Base );
StartTimer( );
} else {
//
// This is not the first reference to the section. The section
// had better be locked!
//
ASSERT( NwSectionDescriptor.Handle != NULL );
//
// Restart the timer if the rdr was stopped but didn't unload.
//
if (TimerStop == TRUE) {
StartTimer();
}
}
DebugTrace(+0, Dbg, "NwReferenceCodeSection %d\n", NwSectionDescriptor.ReferenceCount );
ExReleaseResource( &NwUnlockableCodeResource );
return;
} // NwReferenceUnlockableCodeSection
VOID
NwDereferenceUnlockableCodeSection (
VOID
)
{
ULONG newCount;
//
// Lock the lockable code database.
//
ExAcquireResourceExclusive( &NwUnlockableCodeResource, TRUE );
ASSERT( NwSectionDescriptor.Handle != NULL );
ASSERT( NwSectionDescriptor.ReferenceCount > 0 &&
NwSectionDescriptor.ReferenceCount < 0x7FFF );
//
// Decrement the reference count for the section.
//
newCount = --NwSectionDescriptor.ReferenceCount;
DebugTrace(+0, Dbg, "NwDereferenceCodeSection %d\n", NwSectionDescriptor.ReferenceCount );
ExReleaseResource( &NwUnlockableCodeResource );
return;
} // NwDereferenceUnlockableCodeSection
BOOLEAN
NwUnlockCodeSections(
IN BOOLEAN BlockIndefinitely
)
{
//
// Lock the lockable code database.
//
if (!ExAcquireResourceExclusive( &NwUnlockableCodeResource, BlockIndefinitely )) {
return FALSE; // Avoid potential deadlock in timer.c
}
DebugTrace(+0, Dbg, "NwUnlockCodeSections %d\n", NwSectionDescriptor.ReferenceCount );
if ( NwSectionDescriptor.ReferenceCount == 0 ) {
if ( NwSectionDescriptor.Handle != NULL ) {
//
// This is the last reference to the section. Stop the timer and
// unlock the code.
//
StopTimer();
MmUnlockPagableImageSection( NwSectionDescriptor.Handle );
NwSectionDescriptor.Handle = NULL;
}
ExReleaseResource( &NwUnlockableCodeResource );
return TRUE;
}
ExReleaseResource( &NwUnlockableCodeResource );
return FALSE;
}
#endif