Does Mutex make a system call?

CRITICAL_SECTION lock (input) and unlock (exit) are effective because CS Testing is performed in user space without making a kernel system call that the mutex does. Unlocking is performed entirely in user space, while ReleaseMutex requires a system call.

I just read these sentences in this book .
What does the kernel system mean? Could you give me a function name?

I am an English beginner. I interpreted them like that.

  • CS Verification does not use a system call.
  • Mutex testing uses a system call. (But I do not know the name of the function. Let me know)
  • Unlocking CS does not cause a system call.
  • Unlocking Mutex requires a system call. (But I do not know the name of the function. Let me know)

Another question.

  • I think CRITICAL_SECTION can call WaitForSingleObject functions or families. Do these functions require a system call? They probably do it. Therefore, CS testing does not use a system call, it is very strange for me.
+3
source share
4 answers

The implementation of critical partitions on Windows has changed over the years, but it has always been a combination of user mode and kernel calls.

CRITICAL_SECTION is a structure containing updated values ​​in user mode, a handle to a kernel mode object - EVENT or something like that, and debugging information.

EnterCriticalSection . , (, ). set-and-set , , WaitForSignleObject. InitializeCriticalSectionAndSpinCount, EnterCriticalSection , .

"" / EnterCriticialSection Windows 7 (64- ) inline

0:000> u rtlentercriticalsection rtlentercriticalsection+35
ntdll!RtlEnterCriticalSection:
00000000`77ae2fc0 fff3            push    rbx
00000000`77ae2fc2 4883ec20        sub     rsp,20h
; RCX points to the critical section rcx+8 is the LockCount
00000000`77ae2fc6 f00fba710800    lock btr dword ptr [rcx+8],0
00000000`77ae2fcc 488bd9          mov     rbx,rcx
00000000`77ae2fcf 0f83e9b1ffff    jae     ntdll!RtlEnterCriticalSection+0x31 (00000000`77ade1be)
; got the critical section - update the owner thread and recursion count
00000000`77ae2fd5 65488b042530000000 mov   rax,qword ptr gs:[30h]
00000000`77ae2fde 488b4848        mov     rcx,qword ptr [rax+48h]
00000000`77ae2fe2 c7430c01000000  mov     dword ptr [rbx+0Ch],1
00000000`77ae2fe9 33c0            xor     eax,eax
00000000`77ae2feb 48894b10        mov     qword ptr [rbx+10h],rcx
00000000`77ae2fef 4883c420        add     rsp,20h
00000000`77ae2ff3 5b              pop     rbx
00000000`77ae2ff4 c3              ret

, , , , . , . , .

Mutex, NtWaitForSingleObject NtReleaseMutant

+5

, ( ) . ReleaseMutex().

kernel32.dll ( , - . ntdll.dll) - .

, Mutex . , CRITICAL_SECTION .

+3

, .

NTDLL, , ​​ ( ). kernel32.dll - .

, , . "", ( ).

+1

, , , . - .

+1
source

Source: https://habr.com/ru/post/1795923/


All Articles