Valgrind for Windows Wiki
Status: Pre-Alpha
Brought to you by:
cschwarz1
This page describes how system calls on different Windows systems are performed.
System Call Stub:
0000 b8nnnnnnnn mov eax,nnnnnnnn
0005 bassssssss mov edx,SharedUserData!SystemCallStub
000a ff12 call dword ptr [edx]
000c c2mmmm ret mmmm
-or-
000c c3 ret
ntdll!KiFastSystemCall:
0000 8bd4 mov edx,esp
0002 0f34 sysenter
ntdll!KiFastSystemCallRet:
0004 c3 ret
Stack layout at the time of 'sysenter'
ESP+0x00 address of 'ret mmmm' or 'ret' in system call stub
+0x04 caller of system call stub
+0x08 1st syscall argument
+0x0c 2nd syscall argument
+0x10 3rd syscall argument
+0x14 4th syscall argument
+0x18 5th syscall argument
+0x1c 6th syscall argument
...
System Call Stub 1:
0000 b8nnnnnnnn mov eax,nnnnnnnn
0005 33c9 xor ecx,ecx
0007 8d542404 lea edx,[esp+4]
000b 64ff15c0000000 call dword ptr fs:[0C0h]
0012 83c404 add esp,4
0015 c2mmmm ret mmmm
-or-
0015 c3 ret
System Call Stub 2:
0000 b8nnnnnnnn mov eax,nnnnnnnn
0005 b9uuuuuuuu mov ecx,uuuuuuuu
000a 8d542404 lea edx,[esp+4]
000e 64ff15c0000000 call dword ptr fs:[0C0h]
0015 83c404 add esp,4
0018 c2mmmm ret mmmm
-or-
0018 c3 ret
wow64cpu!X86SwitchTo64BitMode:
0000 eassssssss3300 jmp 0033:ssssssss
Stack layout at the time of 'jmp 0033:ssssssss'
ESP+0x00 address of 'add esp,4' in system call stub
+0x04 caller of system call stub
+0x08 1st syscall argument
+0x0c 2nd syscall argument
+0x10 3rd syscall argument
+0x14 4th syscall argument
+0x18 5th syscall argument
+0x1c 6th syscall argument
...
System Call Stub:
0000 4c8bd1 mov r10,rcx
0003 b8nnnnnnnn mov eax,nnnnnnnn
0008 0f05 syscall
000a c3 ret
Stack layout at the time of 'syscall'
RSP+0x00 caller of system call stub
+0x08 reserved (1st syscall argument is in RCX)
+0x10 reserved (2nd syscall argument is in RDX)
+0x18 reserved (3rd syscall argument is in R8)
+0x20 reserved (4th syscall argument is in R9)
+0x28 5th syscall argument
+0x30 6th syscall argument
...