Event handling mechanism in Windows
- From: smawsk <sk.smawsk@xxxxxxxxx>
- Date: Mon, 25 Feb 2008 21:14:23 -0800 (PST)
I have posted this question to other groups. But did not find an
answer.
Here's the question. Any thoughts on this is highly appreciated.
===================================================================
Hi,
I have some doubts regarding the event handling process in Windows. I
referred many books (Windows Internals, Programming Applications for
Microsoft
Windows, Windows System Programming) but could not find a complete
picture of the event handling mechanism. I did search on the internet
too.
Can some one please point me towards any resource on the internet or
some book that describes the entire process in detail?
I understood the process in bits and pieces. I have summarised my
understanding of the process below. Please correct me.
I will take the example of a keyboard event. SEE Q-1, Q-2, Q-3, Q-4
AND Q-5 FOR QUESTIONS.
1) User has hit some key on the key board and generates a hardware
interrupt
2) CPU is interrupted by the Interrupt Controller which converts the
IRQ to an interrupt number representing the interrupt.
3) The interrupt number is used as an index into the Interrupt
Dispatch Table to get the address of the Kernel routine to be executed
for that particular interrupt.
4) The Kernel routine calls the Kernel Interrupt Dispatcher which
raises the IRQL to the Device IRQL of the device which raised the
interrupt and starts executing the ISR.
5) The ISR gathers the volatile information from the device and queues
a DPC to be executed later and returns to the dispatcher.
6) The dispatcher lowers the IRQL to the one which was earlier. When
the IRQL is about to drop to DPC/Dispatch Level, the DPC gets
processed.
7) The DPC routine is executed which completes the task of I/O
operation. Now the data in the kernel mode buffer has to be copied to
the address space of the process containing the thread. So it queues
an APC in the thread's APC queue.
=================================================================
Q-1) How does the kenel knows which thread's APC to queue this
APC
request to?
Q-2) Will it be a user mode APC or a kernel mode APC?
Q-3) I assume that APC queue and Message queue are different.
Am I
right?
==================================================================
Jeffrey Richter discusses about this topic in Windows Messaging. He
referrs to something called as RIT (Raw Input Thread). But I could not
find any thing related to RIT in Windows Internals by Solomon.
Does it has something to do with Foreground process and GUI thread?
I am not entirely clear on this topic.
8) The APC is delivered when the thread gets into an "alertable wait"
state.
======================================================================================
Q-4) From this APC queue, how does it gets transferred to the
thread's message queue?
I mean, when GetMessage() is called in the message loop the MSG
structure is filled in with the message ID and the other data.
Where is this message queue implemented. Each GUI thread has a message
queue(s), but where is it implemeted in the thread object. Neither the
KTHREAD block NOR the Thread Environment Block has any reference to
such queue.
Q-5) Does a mouse event also requires an APC? Since there is no data
to be copied to the process address space. And how does the kernel
knows which thread's message queue to put this mouse event to?
======================================================================================
I am totally lost. Some might argue that these details are not
required from a programmers perspective, but this would help me in
better understanding the Operating System.
Thanks in advance.
Warm Regards.
.
- Follow-Ups:
- Re: Event handling mechanism in Windows
- From: Ivan Brugiolo [MSFT]
- Re: Event handling mechanism in Windows
- Prev by Date: Re: CBT hook
- Next by Date: Re: Problem about write to named pipe.
- Previous by thread: prevent hooking by SetWindowsHookEx
- Next by thread: Re: Event handling mechanism in Windows
- Index(es):
Relevant Pages
|
|