home *** CD-ROM | disk | FTP | other *** search
- /***
- *lock.c - Lock/Unlock space
- *
- * Copyright (c) 1989-1992, Microsoft Corporation. All rights reserved.
- *
- *******************************************************************************/
-
- #include <version.h>
- #include <vmassert.h>
- #include <stdlib.h>
- #include <vmm.h>
- #include <vmbm.h>
-
- /*** PVmLockHbk
- *
- * Purpose: Lock in the allocated space
- *
- * Input:
- * hbk The handle to lock down.
- *
- * Output:
- * Returns:
- * A physical pointer to the memory, or a NULL on error.
- *
- * Exceptions:
- *
- * Notes:
- *
- * There is an implicit assumption that if the memory is already locked,
- * a load will take you to the same physical place!
- *
- * It is assumed that any allocation over a page is allocated by page
- *
- *************************************************************************/
- PVOID VMFUNC __PVmLockHbk(
- HBK hbk
- ) {
- PHDB phdb;
-
- Assert( hbk != NULL);
-
- if (!_fVmInit || (unsigned long)hbk < (unsigned long)_hbkMin || (unsigned long)hbk >= (unsigned long)_hbkMax)
- return NULL;
-
- phdb = __PVmLoadVp((VPVOID) hbk, FALSE);
-
- Assert( phdb != NULL );
-
- if (!phdb || phdb->fFree)
- return FALSE;
-
- // if it has never been locked, bring it into memory
- if( !phdb->cLock )
- {
- if(phdb->fByPage)
- phdb = __PVmLockVpCb((VPVOID) hbk, phdb->cPage * (unsigned long) cbVmPage);
- else
- {
- Assert(CbGetSize(phdb->cbSize) < cbVmPage);
- phdb = __PVmLockVp((VPVOID) hbk);
- }
- }
-
- // if the pointer was obtained, then up the lock count
- if( phdb )
- {
- if (phdb->cLock == cMaxLock)
- return(NULL);
- phdb->cLock++;
- }
-
- // return the vm pointer
- return((PVOID) ((phdb != NULL) ? ++phdb : NULL));
- }
-
-
- /*** PVmUnlockHbk
- *
- * Purpose: Unlock the locked page
- *
- * Input:
- * hbk The handle to lock down.
- *
- * Output:
- * Returns:
- *
- * Exceptions:
- *
- * Notes:
- * It is assumed that any allocation over a page is allocated by page
- *
- *************************************************************************/
- void VMFUNC __VmUnlockHbk(
- HBK hbk,
- int fDirty
- ) {
- PHDB phdb;
-
- Assert( hbk != NULL );
-
- if (!_fVmInit || (unsigned long)hbk < (unsigned long)_hbkMin || (unsigned long)hbk >= (unsigned long)_hbkMax)
- return;
-
- // if the page is locked, I don't care that the lock count gets
- // saved because it is locked in memory and can't be swapped out
- // once the lock count goes to zero, I can swap out, but the swapped
- // out copy has zero too.
- phdb = __PVmLoadVp((VPVOID) hbk, FALSE);
-
- if ( !phdb || phdb->fFree || !phdb->cLock )
- return;
-
- Assert( phdb->fFree == FALSE );
-
- phdb->cLock--;
-
- // If this is the last lock, then unlock the page
- if( !phdb->cLock )
- {
- if(phdb->fByPage)
- __VmUnlockVpCb((VPVOID) hbk, phdb->cPage * (unsigned long) cbVmPage, fDirty);
- else
- {
- Assert(CbGetSize(phdb->cbSize) < cbVmPage);
- __VmUnlockVp((VPVOID) hbk, fDirty);
- }
- }
- }
-
- /*** CVmLockHbk
- *
- * Purpose: Get the current HBK lock count
- *
- * Input:
- * hbk The handle to get the count of.
- *
- * Output:
- * Returns:
- *
- * Exceptions:
- *
- * Notes:
- * PVmLockMember is not included in this count
- *
- *
- *************************************************************************/
- unsigned VMFUNC __CVmLockHbk(
- HBK hbk
- ) {
- PHDB phdb;
-
- Assert( hbk != NULL);
-
- if (!_fVmInit || (unsigned long)hbk < (unsigned long)_hbkMin || (unsigned long)hbk >= (unsigned long)_hbkMax)
- return 0;
-
- phdb = __PVmLoadVp((VPVOID) hbk, FALSE);
-
- Assert( phdb != NULL );
- Assert( phdb->fFree == FALSE );
-
- if (!phdb || phdb->fFree)
- return 0;
-
- return(phdb->cLock);
- }
-