if2
   EXTRNF32 CodeLockProc
   EXTRNF32 CodeUnlockProc
endif


CodeLock_s	STRUC
cl_toe	DB	SIZE toe_s DUP (?)
cl_lhand	DB	SIZE vmlh_s DUP (?)
cl_count	DW	?
cl_flags	DW	?
cl_rangelen	DD	?
cl_startaddr	DD	?
cl_semaphore	DB	SIZE KSEMMTX DUP (?)
CodeLock_s	ENDS

CodeLock_t struc
db size CodeLock_s dup(?)
CodeLock_t ends

FATEA_GROUP	EQU	(0 * SIZE    CodeLock_s  )
NMPIPE_GROUP	EQU	(1 * SIZE    CodeLock_s  )
FSCTL_GROUP	EQU	(2 * SIZE    CodeLock_s  )
FILEIO_GROUP	EQU	(3 * SIZE    CodeLock_s  )
OPLOCK_GROUP	EQU	(4 * SIZE    CodeLock_s  )
DRVLOCK_GROUP	EQU	(5 * SIZE    CodeLock_s  )
NEWNODE_GROUP	EQU	(6 * SIZE    CodeLock_s  )
FSSWAP_GROUP	EQU	(7 * SIZE    CodeLock_s  )
NOTIFY_GROUP	EQU	(8 * SIZE    CodeLock_s  )
NUMCODELOCKGROUPS	EQU	9 
CODE_IS_LOCKED	EQU	1 
CODE_NOT_LOCKED	EQU	0 
CODELOCK_ATTEMPT_COUNT	EQU	3       
CODELOCK_RETRY_WAIT	EQU	250        
CODELOCK_BLOCK_ID	EQU	0C0DE0000H   
CL_ISLOCKED	EQU	01H    
CL_UNLOCKPENDING	EQU	02H    
CL_TOESET	EQU	04H    
CODEUNLOCKDELAY	EQU	02000H   
CodeLock macro group,errlabel
   local clnoerr

   CpuMode  386

   pushfd
   SaveReg  <ebx>
   mov   ebx, group
   CALLF32  CodeLockProc
   RestoreReg <ebx>  
   jnc   clnoerr

   popfd
   stc
   ifnb  <errlabel>     
      jmp   errlabel
   else
      ret
   endif
clnoerr:
   popfd
   CpuMode reset
   ENDM

CodeUnlock  macro group

   CpuMode  386   

   pushfd
   SaveReg  <ebx>

   mov   ebx, group
   CALLF32  CodeUnlockProc

   RestoreReg <ebx>
   popfd

   CpuMode  reset
   ENDM

