So, to summarize the flow of a native API call from User Mode
User Mode program calls either NtXxx or ZwXxx, both of which point to the same location.
All native API calls from User Mode have a body that simply loads an index into EAX, executes SystemCallStub, and returns.
SystemCallStub saves a pointer to the top of the User Mode stack into EDX and executes a SYSENTER instruction.
SYSENTER disables interrupts, switches the thread into Kernel Mode and executes the instruction located in the SYSENTER_EIP_MSR (which on XP SP1 is KiFastCallEntry).
KiFastCallEntry builds a trap frame so it knows where to go when returning back to User Mode, enables interrupts, and jumps into KiSystemService
KiSystemService, amongst doing other things, copies the parameters from the User stack (pointed to by EDX) and takes the value previously stored in EAX and executes the function located at KiServiceTable[EAX].
The native API now executes in Kernel Mode with the previous mode of the thread set to User Mode.
This indicates the caller came from User Mode. If you are going to remember one thing about this exercise, remember this! We?ll talk about it much more later in this article.
Now that we have gone through a gross amount of detail for the User Mode portion, we should be able to zip right through the Kernel Mode variants.
Partager