flat assembler
Message board for the users of flat assembler.

Index > Windows > windows APC

Author
Thread Post new topic Reply to topic
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 13 Apr 2010, 19:10
does APC has its purpose, or it just exist to make kernel look bigger and more complex?

Whats the purpose of switching threads to address space of other process?
Whats the reason of implementing apc in kernel?
I would understand it if there wasnt CreateRemoteThread option, it works simmilar, you just switch your thread to another context.
It seems so useless to me...
Post 13 Apr 2010, 19:10
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 13 Apr 2010, 20:55
http://msdn.microsoft.com/en-us/library/ms681951%28VS.85%29.aspx

asmcoder wrote:

I would understand it if there wasnt CreateRemoteThread option, it works simmilar, you just switch your thread to another context.

Care to explain the similarity with the explanation given in the link above? Especially the queuing and the synchronization parts...
Post 13 Apr 2010, 20:55
View user's profile Send private message Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 14 Apr 2010, 06:51
so what can i use apc for? nothing! its exactly same as creating new thread, but i use existing one.
Post 14 Apr 2010, 06:51
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 14 Apr 2010, 08:07
a115433,

Overlapped I/O and timers. QueueUserAPC() is simply implementation detail being exposed to API user at almost no cost.

Exactly the same? Think again. CreateRemoteThread() won't help much if you need to access thread context (e.g. thread-local variables).

Do you think threads are cheap?
Post 14 Apr 2010, 08:07
View user's profile Send private message Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 14 Apr 2010, 08:22
Quote:
QueueUserAPC() is simply implementation detail being exposed to API user at almost no cost.

ok thats the reason i guess.
about overlapped io, its processed in other thread as apc, right?
With method_buffered, because it use buffers loaded to global pages (mapping isnt flushed on context switch), all processes can access this memory.

i have 1 last question about io, when actually does it end? after call to IoCompleteRequest(), or returning from IRP_MJ_XXX handler?

io functions such ReadFile return what exactly? Status of returning from irp handler?
when i will queue overlapped io, and get error_io_pending, that means it was sent to other thread as apc, right? And when it complete, IoCompleteRequest() is called, event set to signaled state, and i can continue. when i terminate process, what happens? irp gets canceled? apc gets canceled? or termination wait untill all irp is completed by IoCompleteRequest()?
Post 14 Apr 2010, 08:22
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 14 Apr 2010, 15:36
a115433 wrote:
about overlapped io, its processed in other thread as apc, right?
Why do you think so? Overlapped I/O is processed by NTOSKRNL almost in the same way as synchronous I/O, only calling thread isn't put in wait state until I/O is complete. I emphasize that: most of I/O request (be it sync or async) is done in the context of calling thread. This request can be processed by driver in context of any thread. The result can be indicated to calling thread by APC (which is done in the context of calling thread).

Most questions are answered in "Inside Microsoft Windows 2000" by David A. Solomon & Mark E. Russinovich.
Post 14 Apr 2010, 15:36
View user's profile Send private message Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 14 Apr 2010, 16:13
yes so when i call async operation, i ask kernel to do it in other thread (apc)?
Post 14 Apr 2010, 16:13
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 14 Apr 2010, 16:32
a115433,

No, NTOSKRNL!ReadFile() executes in context of calling thread and doesn't use APC. I/O manager can post APC to calling thread's APC queue on I/O completion.
Post 14 Apr 2010, 16:32
View user's profile Send private message Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 14 Apr 2010, 18:58
duno ive read some time ago in official msdn that ReadFile with overlapped only queue read task to other thread, so it can return and let other thread process operation.

when i call io function in overlapped mode, i have control over my thread immidietly after executing function, and event is signaled when its finished. so ReadFile execute in context of calling thread, of course, but IO processing (copying buffer from/to dma, reading/writing to port) is executed by other thread, from worker pool.
Post 14 Apr 2010, 18:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.