title "Critical Section Support"
;++
;
; Copyright (c) 1991 Microsoft Corporation
;
; Module Name:
;
; critsect.asm
;
; Abstract:
;
; This module implements functions to support user mode critical sections.
;
; Author:
;
; Bryan M. Willman (bryanwi) 2-Oct-91
;
; Environment:
;
; Any mode.
;
; Revision History:
;
;--
.486p
.xlist
include ks386.inc
include callconv.inc ; calling convention macros
include mac386.inc
.list
_DATA SEGMENT DWORD PUBLIC 'DATA'
public _LdrpLockPrefixTable
_LdrpLockPrefixTable label dword
dd offset FLAT:Lock1
dd offset FLAT:Lock2
dd offset FLAT:Lock3
dd offset FLAT:Lock4
dd offset FLAT:Lock5
dd offset FLAT:Lock6
dd offset FLAT:Lock7
dd 0
_DATA ENDS
_TEXT SEGMENT PARA PUBLIC 'CODE'
ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
EXTRNP _RtlpWaitForCriticalSection,1
EXTRNP _RtlpUnWaitCriticalSection,1
if DEVL
EXTRNP _RtlpNotOwnerCriticalSection,1
endif
if DBG
EXTRNP _RtlpCriticalSectionIsOwned,1
endif
CriticalSection equ [esp + 4]
page , 132
subttl "RtlEnterCriticalSection"
;++
;
; NTSTATUS
; RtlEnterCriticalSection(
; IN PRTL_CRITICAL_SECTION CriticalSection
; )
;
; Routine Description:
;
; This function enters a critical section.
;
; Arguments:
;
; CriticalSection - supplies a pointer to a critical section.
;
; Return Value:
;
; STATUS_SUCCESS or raises an exception if an error occured.
;
;--
align 16
cPublicProc _RtlEnterCriticalSection,1
cPublicFpo 1,0
mov ecx,fs:PcTeb ; get current TEB address
mov edx,CriticalSection ; get address of critical section
cmp CsSpinCount[edx],0 ; check if spin count is zero
jne short Ent40 ; if ne, spin count specified
;
; Attempt to acquire critical section.
;
Lock1: ;
lock inc dword ptr CsLockCount[edx] ; increment lock count
jnz short Ent20 ; if nz, already owned
;
; Set critical section owner and initialize recursion count.
;
Ent10:
if DBG
cmp CsOwningThread[edx],0
je @F
stdCall _RtlpCriticalSectionIsOwned, <edx>
mov ecx,fs:PcTeb ; get current TEB address
mov edx,CriticalSection ; get address of critical section
@@:
endif ; DBG
mov eax,TbClientId + 4[ecx] ; get current client ID
mov CsOwningThread[edx],eax ; set critical section owner
mov dword ptr CsRecursionCount[edx],1 ; set recursion count
if DBG
inc dword ptr TbCountOfOwnedCriticalSections[ecx] ; increment owned count
mov eax,CsDebugInfo[edx] ; get debug information address
inc dword ptr CsEntryCount[eax] ; increment entry count
endif ; DBG
xor eax,eax ; set success status
stdRET _RtlEnterCriticalSection
;
; The critical section is already owned, but may be owned by the current thread.
;
align 16
Ent20: mov eax,TbClientId + 4[ecx] ; get current client ID
cmp CsOwningThread[edx],eax ; check if current thread is owner
jne short Ent30 ; if ne, current thread not owner
inc dword ptr CsRecursionCount[edx] ; increment recursion count
if DBG
mov eax,CsDebugInfo[edx] ; get debug information address
inc dword ptr CsEntryCount[eax] ; increment entry count
endif ; DBG
xor eax,eax ; set success status
stdRET _RtlEnterCriticalSection
;
; The critcal section is owned by another thread and the current thread must
; wait for ownership.
;
Ent30: stdCall _RtlpWaitForCriticalSection, <edx> ; wait for ownership
mov ecx,fs:PcTeb ; get current TEB address
mov edx,CriticalSection ; get address of critical section
jmp Ent10 ; set owner and recursion count
;
; A nonzero spin count is specified.
;
align 16
Ent40: mov eax,TbClientId + 4[ecx] ; get current client ID
cmp CsOwningThread[edx],eax ; check if current thread is owner
jne short Ent50 ; if ne, current thread not owner
;
; The critical section is owned by the current thread. Increment the lock
; count and the recursion count.
;
Lock6: ;
lock inc dword ptr CsLockCount[edx] ; increment lock count
inc dword ptr CsRecursionCount[edx] ; increment recursion count
if DBG
mov eax,CsDebugInfo[edx] ; get debug information address
inc dword ptr CsEntryCount[eax] ; increment entry count
endif ; DBG
xor eax,eax ; set success status
stdRET _RtlEnterCriticalSection
;
; A nonzero spin count is specified and the current thread is not the owner.
;
align 16
Ent50: push CsSpinCount[edx] ; get spin count value
Ent60: mov eax,-1 ; set comparand value
mov ecx,0 ; set exchange value
Lock7:
lock cmpxchg dword ptr CsLockCount[edx],ecx ; attempt to acquire critical section
jnz short Ent70 ; if nz, critical section not acquired
;
; The critical section has been acquired. Set the owning thread and the initial
; recursion count.
;
add esp,4 ; remove spin count from stack
mov ecx,fs:PcTeb ; get current TEB address
mov eax,TbClientId + 4[ecx] ; get current client ID
mov CsOwningThread[edx],eax ; set critical section owner
mov dword ptr CsRecursionCount[edx],1 ; set recursion count
if DBG
inc dword ptr TbCountOfOwnedCriticalSections[ecx] ; increment owned count
mov eax,CsDebugInfo[edx] ; get debug information address
inc dword ptr CsEntryCount[eax] ; increment entry count
endif ; DBG
xor eax,eax ; set success status
stdRET _RtlEnterCriticalSection
;
; The critical section is currently owned. Spin until it is either unowned
; or the spin count has reached zero.
;
; If waiters are present, don't spin on the lock since we will never see it go free
;
Ent70: cmp CsLockCount[edx],1 ; check if waiters are present,
jge short Ent76 ; if ge 1, then do not spin
Ent75: YIELD
cmp CsLockCount[edx],-1 ; check if lock is owned
je short Ent60 ; if e, lock is not owned
dec dword ptr [esp] ; decrement spin count
jnz short Ent75 ; if nz, continue spinning
Ent76: add esp,4 ; remove spin count from stack
mov ecx,fs:PcTeb ; get current TEB address
jmp Lock1 ;
stdENDP _RtlEnterCriticalSection
page , 132
subttl "RtlLeaveCriticalSection"
;++
;
; NTSTATUS
; RtlLeaveCriticalSection(
; IN PRTL_CRITICAL_SECTION CriticalSection
; )
;
; Routine Description:
;
; This function leaves a critical section.
;
; Arguments:
;
; CriticalSection - supplies a pointer to a critical section.
;
; Return Value:
;
; STATUS_SUCCESS or raises an exception if an error occured.
;
;--
align 16
cPublicProc _RtlLeaveCriticalSection,1
cPublicFpo 1,0
mov edx,CriticalSection
if DBG
mov ecx,fs:PcTeb ; (ecx) == NtCurrentTeb()
mov eax,TbClientId+4[ecx] ; (eax) == NtCurrentTeb()->ClientId.UniqueThread
cmp eax,CsOwningThread[edx]
je @F
stdCall _RtlpNotOwnerCriticalSection, <edx>
mov eax,STATUS_INVALID_OWNER
stdRET _RtlLeaveCriticalSection
@@:
endif ; DBG
xor eax,eax ; Assume STATUS_SUCCESS
dec dword ptr CsRecursionCount[edx]
jnz leave_recurs ; skip if only leaving recursion
mov CsOwningThread[edx],eax ; clear owning thread id
if DBG
mov ecx,fs:PcTeb ; (ecx) == NtCurrentTeb()
dec dword ptr TbCountOfOwnedCriticalSections[ecx]
endif ; DBG
Lock2:
lock dec dword ptr CsLockCount[edx] ; interlocked dec of
; CriticalSection->LockCount
jge @F
stdRET _RtlLeaveCriticalSection
@@:
stdCall _RtlpUnWaitCriticalSection, <edx>
xor eax,eax ; return STATUS_SUCCESS
stdRET _RtlLeaveCriticalSection
align 16
leave_recurs:
Lock3:
lock dec dword ptr CsLockCount[edx] ; interlocked dec of
; CriticalSection->LockCount
stdRET _RtlLeaveCriticalSection
_RtlLeaveCriticalSection endp
page ,132
subttl "RtlTryEnterCriticalSection"
;++
;
; BOOL
; RtlTryEnterCriticalSection(
; IN PRTL_CRITICAL_SECTION CriticalSection
; )
;
; Routine Description:
;
; This function attempts to enter a critical section without blocking.
;
; Arguments:
;
; CriticalSection (a0) - Supplies a pointer to a critical section.
;
; Return Value:
;
; If the critical section was successfully entered, then a value of TRUE
; is returned as the function value. Otherwise, a value of FALSE is returned.
;
;--
CriticalSection equ [esp + 4]
cPublicProc _RtlTryEnterCriticalSection,1
cPublicFpo 1,0
mov ecx,CriticalSection ; interlocked inc of
mov eax, -1 ; set value to compare against
mov edx, 0 ; set value to set
Lock4:
lock cmpxchg dword ptr CsLockCount[ecx],edx ; Attempt to acquire critsect
jnz short tec10 ; if nz, critsect already owned
mov eax,fs:TbClientId+4 ; (eax) == NtCurrentTeb()->ClientId.UniqueThread
mov CsOwningThread[ecx],eax
mov dword ptr CsRecursionCount[ecx],1
if DBG
mov eax,fs:PcTeb ; (ecx) == NtCurrentTeb()
inc dword ptr TbCountOfOwnedCriticalSections[eax]
endif ; DBG
mov eax, 1 ; set successful status
stdRET _RtlTryEnterCriticalSection
tec10:
;
; The critical section is already owned. If it is owned by another thread,
; return FALSE immediately. If it is owned by this thread, we must increment
; the lock count here.
;
mov eax, fs:TbClientId+4 ; (eax) == NtCurrentTeb()->ClientId.UniqueThread
cmp CsOwningThread[ecx], eax
jz tec20 ; if eq, this thread is already the owner
xor eax, eax ; set failure status
YIELD
stdRET _RtlTryEnterCriticalSection
tec20:
;
; This thread is already the owner of the critical section. Perform an atomic
; increment of the LockCount and a normal increment of the RecursionCount and
; return success.
;
Lock5:
lock inc dword ptr CsLockCount[ecx]
inc dword ptr CsRecursionCount[ecx]
mov eax, 1
stdRET _RtlTryEnterCriticalSection
stdENDP _RtlTryEnterCriticalSection
_TEXT ends
end
CriticalSection的ASM原代码
时间: 2024-09-12 02:50:38
CriticalSection的ASM原代码的相关文章
Jsp分页原代码,及用法
js|分页 Jsp分页原代码,及用法 1.定义一个分页的Tag Bean,以便用户在Jsp页中使用自定义标签,用户在使用时可以相应的描述 package BSC.tree; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; import javax.servlet.jsp.tagext.TagSupport; import javax.servlet.http.HttpServletResponse; import or
一个显示原代码的asp程序
一个显示原代码的asp程序 我们都知道asp这一类的服务器端处理的程序,其好处之一就是只向客户端输出标准的Html流.因此可以起到向客户隐藏细节的作用.也就是说当我们在浏览器中键入asp程序的网址后只能看见标准的Html文件,而不能看见asp的内容.但有时,例如在一个asp的教学站点,我们有必要显示asp文件的内容,或者你愿意将你的原代码与人享,通过一个程序将代码显示出来. 下面是我编写的一个asp程序,view_code.asp,它提供两种提交方式: 一种是用表格提交,即你知道了该源文件的物理
GB与BIG5内码转换COM原代码
转换 这个COM用到了一个VC的资源文件.就是字典.大家可以去61.134.75.70/download/gb2big5.zip下载 原代码如下: '//////////////////////////////////////////'中文名称:GB与BIG5内码互换控件'英文名称:GB2BIG5'作者:Blood'版本:1.0'制作时间:2002.3.5'版权所有 Blood 2002 - 2003'////////////////////////////////////////// Opti
exe格式软件如何反编译成原代码
问题描述 我又一个exe格式的小软件,现在需要它的原代码,希望各位高手指导如何做.
怎样在C#中导出/导入数据(急求原代码)??
问题描述 怎样在C#中导出/导入数据(急求原代码)??各位大哥.大姐知道的麻烦帮下小弟. 解决方案 解决方案二:你说的不对啊,C#可以实现数据的导出/导入你的数据在哪里,是数据库的话,是哪个厂商的?SQLServer,Oracle?说的详细点.解决方案三:听楼主的话,建议楼主还是从基本学起吧,现在这个问题真是无法具体回答.解决方案四:一看就是倒分的,我来jf解决方案五:LZ问的问题有难度解决方案六:LZ是不是想从EXCEL模板导入导出数据?解决方案七:明知是到分,我也顶一下解决方案八:顶一下解决
请问谁有asp.net(c#)繁体版本access的论坛原代码
问题描述 请问谁有asp.net(c#)繁体版本access的论坛有原代码的?请联系我QQ:308258255价格合理就购买!
加亮显示ASP文章原代码(转)
加亮显示ASP文章原代码 加入时间:2000年10月29日 来源网站:中华技术网 <%@ LANGUAGE="VBSCRIPT" %><% Option Explicit %><%'File: CodeBrws.asp'Overview: This formats and writes the text of the selected page for' the View Script Button 'This file is provided as pa
c#-中文分词,原代码有么?字符串分词
问题描述 中文分词,原代码有么?字符串分词 中文分词,原代码有么?字符串分词,分词系统可以用别人已有的么?.....求大神指教 解决方案 有的,比如盘古分词,自己google下.
大侠有谁做过电话投票系统,给点经验,或者原代码啊!!
问题描述 现在准备做一个电话投票系统,本人是新手,希望提供一些好的建议,或者是原代码啊!在此谢过了! 解决方案 解决方案二:电话投票系统?往外投,还是接受投票??解决方案三:楼上的说的有意思mark~解决方案四:callcenter?...厉害!解决方案五:关注一个!解决方案六:电话投票系统用语音识别技术解决方案七:callcenter?...厉害!解决方案八:不是CALLCENTERqery(义薄云天)说的:电话投票系统用语音卡识别技术就是"快男投票"电话投票系统一样的啊解决方案九: