ZwWriteFile and APC

Hello,
I’m tring to use APC in ZwWriteFile and I am failing.

I wrote a driver that writes to a file and I pass an APC as an argument
to ZwWriteFile() but the APC function never called.

Is someone have any experience with APC in the kernel ?

Thanks.

OS

I’m afraid that you’re outside my range. I’m not a kernel person,
really. I know what the third arg is for because it’s the same in
user-mode.

Why are you calling CompareStringW instead of, say, memcmp, in the
kernel?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@citrix.co.jp
Sent: Monday, November 25, 2002 8:03 PM
To: NT Developers Interest List
Subject: [ntdev] RE: [kernel32!gpSysLocHashN]

Hi, benson

Thanks your information.

I met memory access violation during calling CompareStringW. so I would
like to know about it. I confirmed that Parameters passed to
CompareStringW were correct. However, memory access violation ocuured.

I analyzed userdump. I think this caused that memory area refered to
*(Kernel32!gpSysLocHashN + 0x1c) has already been corrupted for some
reason.

What do you think of it?

Thanks,
Futoshi

Debug Notes

Microsoft (R) Windows Debugger Version 6.1.0009.0
Copyright (c) Microsoft Corporation. All rights reserved.

Loading Dump File [G:\NEC\30364636\DUMP]
User Dump File: Only application data is available

Windows 2000 Version 2195 UP Free x86 compatible
Product: Server, suite: TerminalServer
System Uptime: not available
Process Uptime: not available
Symbol search path is:
srv*\debug8j\symsrv*http://msdl.microsoft.com/download/symbols
;srv*\debug8j\symsrv*http://msdl.microsoft.com/download/symbols
Executable search path is:



(204.99c): Access violation - code c0000005 (!!! second chance !!!)
eax=0000004f ebx=00000000 ecx=00000061 edx=00230004 esi=e7ffffff
edi=04335548
eip=77e58c02 esp=0335f040 ebp=0335f0a8 iopl=0 nv up ei pl nz na
pe
nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
KERNEL32!CompareStringW+24a:
77e58c02 8b0482 mov eax,[edx+eax*4]
ds:0023:00230140=???
0:020> r
eax=0000004f ebx=00000000 ecx=00000061 edx=00230004 esi=e7ffffff
edi=04335548
eip=77e58c02 esp=0335f040 ebp=0335f0a8 iopl=0 nv up ei pl nz na
pe
nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000202
KERNEL32!CompareStringW+24a:
77e58c02 8b0482 mov eax,[edx+eax*4]
ds:0023:00230140=???
0:020> kv <- the below call stack explain that the server is about to
query TS-CAL for cliet to COM on the MS License Server.
ChildEBP RetAddr Args to Child
0335f0a8 77e5a0c5 77a4d308 00000000 77a4d308
KERNEL32!CompareStringW+0x24a
(FPO: [Non-Fpo])
0335f0cc 77a4da75 77a4d308 04335548 77a4d2f0 KERNEL32!lstrcmpiW+0x1d
(FPO:
[2,0,2])
0335f0e8 77a4d1b4 04335548 77a4d308 00000009 OLE32!wCompareDllName+0x18
(FPO: [Non-Fpo])
0335f31c 77a4d0f0 00000017 00095190 0335f3b8
OLE32!CClassCache::CDllPathEntry::NegotiateDllInstantiationProperties2+0
xce
(FPO: [Non-Fpo])
0335f348 77a4c081 00000017 00000000 00095190
OLE32!CClassCache::CDllPathEntry::NegotiateDllInstantiationProperties+0x
6a
(FPO: [Non-Fpo])
0335f39c 77a7188d 77b031a0 0335f7bc 0335f3b8
OLE32!CClientContextActivator::
CheckInprocClass+0x8a (FPO: [Non-Fpo])
0335f5e8 77a7183a 77b031a0 0335f7bc 0335fd6c
OLE32!CClientContextActivator::
GetClassObject+0x4f (FPO: [Non-Fpo])
0335f5fc 77a4ebc5 0335f7bc 0335fd6c 77a4b238
OLE32!ActivationPropertiesIn::DelegateGetClassObject+0x46 (FPO: [2,0,1])
0335fd78 77a717f9 00000000 00000417 00000000
OLE32!ICoGetClassObject+0x2a5
(FPO: [Non-Fpo])
0335fda4 77a71779 0335fdec 00000417 00000000
OLE32!CComActivator::DoGetClassObject+0x76 (FPO: [Non-Fpo]) 0335fdc4
77a91334 0335fdec 00000417 00000000 OLE32!CoGetClassObject+0x19
(FPO: [Non-Fpo])
0335fe04 77a6ac72 042f2e00 69372ba4 0335fe38 OLE32!FindClassMoniker+0x49
(FPO: [Non-Fpo])
0335fe3c 77364b24 042f2e00 69372ba4 0335fe60
OLE32!MkParseDisplayName+0x9a
(FPO: [Non-Fpo])
0335fe6c 77364a75 69372ba4 69372f38 0335fec0 ACTIVEDS!GetObjectW+0xa7
(FPO:
[Non-Fpo])
0335fe80 69374dd1 69372ba4 69372f38 0335fec0 ACTIVEDS!ADsGetObject+0x13
(FPO: [3,0,0])
0335fecc 69375177 0335fef0 0335ff1c 0335ff20
mstlsapi!GetLicenseSettingsObject+0x7b (FPO: [Non-Fpo]) 0335ff40
6d55454e 00000000 00000000 d5cf8a7b
mstlsapi!GetAllEnterpriseServers+0x59 (FPO: [Non-Fpo]) 0335ffb4 77e587dd
00000318 d5cf8a7b 2cbc84eb ICAAPI!LicenseServerCachingThread+0x2f4 (FPO:
[Non-Fpo]) 0335ffec 00000000 6d55425a 00000318 00000000
KERNEL32!BaseThreadStart+0x52
(FPO: [Non-Fpo])
0:020> u KERNEL32!CompareStringW KERNEL32!CompareStringW+0x24a
KERNEL32!CompareStringW:
77e58af4 55 push ebp
77e58af5 8bec mov ebp,esp
77e58af7 83ec5c sub esp,0x5c
77e58afa 8b0d1804eb77 mov ecx,[KERNEL32!gSystemLocale
(77eb0418)]
77e58b00 53 push ebx
77e58b01 8b5d08 mov ebx,[ebp+0x8]
<- the first parameter, which is locale
77e58b04 56 push esi
77e58b05 8b750c mov esi,[ebp+0xc]
<- the third parameter
77e58b08 57 push edi
77e58b09 81e6ffffffbf and esi,0xbfffffff
77e58b0f 3bd9 cmp
ebx,ecx <-compare the specified
locale with system locale
77e58b11 0f85ba170000 jne KERNEL32!CompareStringW+0x1f
(77e5a2d1)
77e58b17 a190f3ea77 mov eax,[KERNEL32!gpSysLocHashN
(77eaf390)]
77e58b1c 8945dc mov [ebp-0x24],eax
<- [ebp - 0x24] pointed KERNEL32!gpSysLocHashN
77e58b1f 8b7ddc mov edi,[ebp-0x24]
77e58b22 8b4d1c mov ecx,[ebp+0x1c]
77e58b25 33d2 xor edx,edx
77e58b27 6681fb1204 cmp bx,0x412
77e58b2c 0f94c2 sete dl
77e58b2f 83c8ff or eax,0xffffffff
77e58b32 85ff test edi,edi
77e58b34 0f84065a0000 je KERNEL32!CompareStringW+0x89a
(77e5e540)
77e58b3a 837f2400 cmp dword ptr [edi+0x24],0x0
77e58b3e 0f85fc590000 jne KERNEL32!CompareStringW+0x89a
(77e5e540)
77e58b44 394514 cmp [ebp+0x14],eax
77e58b47 0f8ff3590000 jnle KERNEL32!CompareStringW+0x89a
(77e5e540)
77e58b4d 3bc8 cmp ecx,eax
77e58b4f 0f8ff3590000 jnle KERNEL32!CompareStringW+0x8a1
(77e5e548)
77e58b55 83fe01 cmp esi,0x1
77e58b58 0f87e2590000 jnbe KERNEL32!CompareStringW+0x89a
(77e5e540)
77e58b5e 83fa01 cmp edx,0x1
77e58b61 0f84d9590000 je KERNEL32!CompareStringW+0x89a
(77e5e540)
77e58b67 8b5510 mov edx,[ebp+0x10]
77e58b6a 8b7d18 mov edi,[ebp+0x18]
77e58b6d 33db xor ebx,ebx
77e58b6f 895508 mov [ebp+0x8],edx
77e58b72 3bd3 cmp edx,ebx
77e58b74 897d1c mov [ebp+0x1c],edi
77e58b77 0f849e8affff je KERNEL32!CompareStringW+0x88f
(77e5161b)
77e58b7d 3bfb cmp edi,ebx
77e58b7f 0f84968affff je KERNEL32!CompareStringW+0x88f
(77e5161b)
77e58b85 6a02 push 0x2
77e58b87 59 pop ecx
77e58b88 668b02 mov ax,[edx]
77e58b8b 663b07 cmp ax,[edi]
77e58b8e 0f8415140000 je KERNEL32!CompareStringW+0x109
(77e59fa9)
77e58b94 668b02 mov ax,[edx]
77e58b97 663b07 cmp ax,[edi]
77e58b9a 0f8401150000 je KERNEL32!CompareStringW+0x1e1
(77e5a0a1)
77e58ba0 8b4ddc mov ecx,[ebp-0x24]
77e58ba3 895dc8 mov [ebp-0x38],ebx
77e58ba6 f7de neg esi
77e58ba8 1bf6 sbb esi,esi
77e58baa 33c0 xor eax,eax
77e58bac 81e6000000e8 and esi,0xe8000000
77e58bb2 895dd8 mov [ebp-0x28],ebx
77e58bb5 4e dec esi
77e58bb6 395920 cmp [ecx+0x20],ebx
77e58bb9 895db4 mov [ebp-0x4c],ebx
77e58bbc 895dd4 mov [ebp-0x2c],ebx
77e58bbf 0f95c0 setne al
77e58bc2 90 nop
77e58bc3 40 inc eax
77e58bc4 895dcc mov [ebp-0x34],ebx
77e58bc7 0c04 or al,0x4
77e58bc9 895dbc mov [ebp-0x44],ebx
77e58bcc 8945e8 mov [ebp-0x18],eax
77e58bcf 668b02 mov ax,[edx]
77e58bd2 663bc3 cmp ax,bx
77e58bd5 895db8 mov [ebp-0x48],ebx
77e58bd8 895dfc mov [ebp-0x4],ebx
77e58bdb 895d0c mov [ebp+0xc],ebx
77e58bde 8975c4 mov [ebp-0x3c],esi
77e58be1 0f84ef000000 je KERNEL32!CompareStringW+0x7ed
(77e58cd6)
77e58be7 8b7d1c mov edi,[ebp+0x1c]
77e58bea 668b0f mov cx,[edi]
77e58bed 6685c9 test cx,cx
77e58bf0 0f84db000000 je KERNEL32!CompareStringW+0x7e8
(77e58cd1)
77e58bf6 8b55dc mov
edx,[ebp-0x24] <-[ebp - 0x24] pointed
to
the kernel32!gpSysLocHashN
77e58bf9 0fb7c0 movzx eax,ax
77e58bfc 8b521c mov edx,[edx+0x1c]
77e58bff 0fb7c9 movzx ecx,cx
77e58c02 8b0482 mov eax,[edx+eax*4] <- Access violation
occurred at this instruction
0:020> ?edx <- edx has already pointed to invalid area according to the
following Evaluate expression: 2293764 = 00230004 0:020> dd 00230004 l1
00230004 ???
0:020> ?ebp - 24 <-edx is related with value of [ebp - 0x24]. That is
kernel32!gpSysLocHashN.
<-and then the previous edx value is [edx +
0x1c]. That is *(kernel32!gpSysLocHashN + 0x1c),
<-which is [00230004]
Evaluate expression: 53866628 = 0335f084
0:020> dd 0335f084 l1
0335f084 00074920
0:020> dd gpSysLocHashN l1
77eaf390 00074920
0:020> dd 00074920
00074920 00000411 001bbfe2 001bc072 7ffd8004 // <-0x00000411 is Japanse
Locale 00074930 7ffd8de6 00000000 00000000 00230004
00074940 00000000 00000000 00000000 00000000
00074950 00000000 00000000 00000000 00000000
00074960 00090126 00080100 00000008 00000001
00074970 00074990 00074ab0 00074bd0 00074cf0
00074980 00074e10 00074f30 00075050 00075170
00074990 00000100 77fcfa20 ffffffff 00000000

0:020> dd 0335f0a8
0335f0a8 0335f0e8 77e5a0c5 77a4d308 00000000 // These are parameters of
kernel32!CompareStringW
0335f0b8 77a4d308 ffffffff 04335548 04335548 // This is no
problem.
0335f0c8 77e5a0a8 00000001 77a4da75 77a4d308
0335f0d8 04335548 77a4d2f0 77a4d308 000000c0
0335f0e8 0335f31c 77a4d1b4 04335548 77a4d308
0335f0f8 00000009 80004005 00000000 77b03710
0335f108 00095170 0335f5a4 00000407 00000000
0335f118 00000000 00000000 77a4ad08 00000000
0:020> du 77a4d308
77a4d308 “OLE32.DLL” // this string is null-terminated
0:020> du 04335548
04335548 “adsldp.dll”// this string is null-terminated
0:020> u KERNEL32!lstrcmpiW KERNEL32!lstrcmpiW+0x1d
KERNEL32!lstrcmpiW:
77e5a0a8 53 push ebx
77e5a0a9 8b5c240c mov ebx,[esp+0xc]
77e5a0ad 57 push edi
77e5a0ae 8b7c240c mov edi,[esp+0xc]
77e5a0b2 6aff push 0xff <- null terminated string and
auto
calculate length
77e5a0b4 53 push ebx
77e5a0b5 6aff push 0xff <- null terminated string and
auto
calculate length
77e5a0b7 57 push edi
77e5a0b8 6a01 push 0x1 <- ignore case
77e5a0ba e8d9d7ffff call KERNEL32!GetThreadLocale (77e57898)
77e5a0bf 50 push eax <-0x00000411 is Japanse Locale
77e5a0c0 e82feaffff call KERNEL32!CompareStringW (77e58af4)

-----Original Message-----
From: benson [mailto:xxxxx@MAIL.DCHBK.US]
Sent: Monday, November 25, 2002 10:10 PM
To: NT Developers Interest List
Subject: [ntdev] RE: [kernel32!gpSysLocHashN]

It is looking to see if you want to consider zenkaku and hankaku kana to
be equivalent.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@citrix.co.jp
Sent: Monday, November 25, 2002 6:19 AM
To: NT Developers Interest List
Subject: [ntdev] [kernel32!gpSysLocHashN]

Hi, All

I have a quick question about the global variable in kernel32.dll.

whenever kernel32!CompareStringW is called, kernel32!gpSysLocHashN is
referenced at the head of it . What does this global variable manage? I
think the head of data structure is the system Locale.

I don’t think why it need to reference in CompareStringW.
Would you tell me in detail if someone knows about the reason?

Thanks,
Futoshi


You are currently subscribed to ntdev as: xxxxx@dchbk.us
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@citrix.co.jp To
unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@dchbk.us
To unsubscribe send a blank email to %%email.unsub%%

osmlist wrote:

Is someone have any experience with APC in the kernel ?

Sure. The guys at Microsoft who work in the internals have the system
know all about APCs. They didn’t expose the APC mechanics for use in
device drivers because (I assume) they thought we’d never have a need to
use them.

So what are you trying to do that led you into trying to create your own
APC object?

Incidentally, how about giving us a real name to go with your anonymous
e-mail account?


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Now teaming with John Hyde for USB Device Engineering Seminars
Check out our schedule at http://www.oneysoft.com

my driver get a lot of information that need to be wriiten to the disk 10MB/sec.
The right method is to do it asynchronous.
I prefere to use with a lot of small buffers (64K).
If I will write to the disk using an event I need to use KeWaitForMultipleObjects
and then I limit to 64 events.
I thought to use the APC to resolve that limit.

Another option is to use Completion Port in the kernel, another thing that I don’t
know how to do that in the kernel (I wrote programs in user mode that used
CompletionPort).

“Walter Oney” wrote in message news:LYRIS-8415-85664-2002.11.26-12.08.03–osmlist#xxxxx@lists.osr.com…
> osmlist wrote:
> > Is someone have any experience with APC in the kernel ?
>
> Sure. The guys at Microsoft who work in the internals have the system
> know all about APCs. They didn’t expose the APC mechanics for use in
> device drivers because (I assume) they thought we’d never have a need to
> use them.
>
> So what are you trying to do that led you into trying to create your own
> APC object?
>
> Incidentally, how about giving us a real name to go with your anonymous
> e-mail account?
>
> –
> Walter Oney, Consulting and Training
> Basic and Advanced Driver Programming Seminars
> Now teaming with John Hyde for USB Device Engineering Seminars
> Check out our schedule at http://www.oneysoft.com
>
> —
> You are currently subscribed to ntdev as: xxxxx@hotmail.com
> To unsubscribe send a blank email to %%email.unsub%%
>

The APC will not fire if APCs have been disabled for this thread. Did you
are your caller call KeEnterCriticalRegion or raise IRQL to APC_LEVEL either
directly or using ExAcquireFastMutex ?


Nar Ganapathy
Windows Core OS group
This posting is provided “AS IS” with no warranties, and confers no rights.

“osmlist” wrote in message news:xxxxx@ntdev…
>
> Hello,
> I’m tring to use APC in ZwWriteFile and I am failing.
>
> I wrote a driver that writes to a file and I pass an APC as an argument
> to ZwWriteFile() but the APC function never called.
>
> Is someone have any experience with APC in the kernel ?
>
> Thanks.
>
> OS
>
>
>
>
>

Roll your own Irp from IoBuildAsynchronousFsdRequest. There are a lots of
pointers in this forum about this.

Bi

-----Original Message-----
From: osmlist [mailto:xxxxx@hotmail.com]
Sent: Tuesday, November 26, 2002 9:37 AM
To: NT Developers Interest List
Cc: Walter Oney
Subject: [ntdev] Re: ZwWriteFile and APC

my driver get a lot of information that need to be wriiten to the disk
10MB/sec.
The right method is to do it asynchronous.
I prefere to use with a lot of small buffers (64K).
If I will write to the disk using an event I need to use
KeWaitForMultipleObjects
and then I limit to 64 events.
I thought to use the APC to resolve that limit.

Another option is to use Completion Port in the kernel, another thing that I
don’t
know how to do that in the kernel (I wrote programs in user mode that used
CompletionPort).

“Walter Oney” < xxxxx@oneysoft.com mailto:xxxxx > wrote
in message
news:LYRIS-8415-85664-2002.11.26-12.08.03–osmlist#xxxxx@lists.osr.com
news:lyris-8415-85664-2002.11.26-12.08.03--osmlistm> …
> osmlist wrote:
> > Is someone have any experience with APC in the kernel ?
>
> Sure. The guys at Microsoft who work in the internals have the system
> know all about APCs. They didn’t expose the APC mechanics for use in
> device drivers because (I assume) they thought we’d never have a need to
> use them.
>
> So what are you trying to do that led you into trying to create your own
> APC object?
>
> Incidentally, how about giving us a real name to go with your anonymous
> e-mail account?
>
> –
> Walter Oney, Consulting and Training
> Basic and Advanced Driver Programming Seminars
> Now teaming with John Hyde for USB Device Engineering Seminars
> Check out our schedule at http://www.oneysoft.com
http:
>
> —
> You are currently subscribed to ntdev as: xxxxx@hotmail.com
mailto:xxxxx
> To unsubscribe send a blank email to %%email.unsub%%
mailto:
>

You are currently subscribed to ntdev as: xxxxx@appstream.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:></mailto:xxxxx></http:></news:lyris-8415-85664-2002.11.26-12.08.03–osmlist></mailto:xxxxx>

This statement could be written more clearly. APCs will not fire the
following reasons,

  1. The thread’s IRQL is >= APC_LEVEL. This can happen if the driver
    explicitly raised the IRQL or called ExAcquireFastMutex.
  2. The thread disabled APCs by calling KeEnterCriticalRegion
  3. The thread was attached to process A when the IO was issued but detached
    before the IO completed.


Nar Ganapathy
Windows Core OS group
This posting is provided “AS IS” with no warranties, and confers no rights.

“Nar Ganapathy[MS]” wrote in message
news:xxxxx@ntdev…
>
> The APC will not fire if APCs have been disabled for this thread. Did you
> are your caller call KeEnterCriticalRegion or raise IRQL to APC_LEVEL
either
> directly or using ExAcquireFastMutex ?
>
> –
> Nar Ganapathy
> Windows Core OS group
> This posting is provided “AS IS” with no warranties, and confers no
rights.
>
> “osmlist” wrote in message news:xxxxx@ntdev…
> >
> > Hello,
> > I’m tring to use APC in ZwWriteFile and I am failing.
> >
> > I wrote a driver that writes to a file and I pass an APC as an argument
> > to ZwWriteFile() but the APC function never called.
> >
> > Is someone have any experience with APC in the kernel ?
> >
> > Thanks.
> >
> > OS
> >
> >
> >
> >
> >
>
>
>
>

Correction to 3 below.

  1. The thread was not attached when the IO was issued but attached itself to
    a different process before the IO completed. This will cause the APC to be
    blocked until the thread is detached.


Nar Ganapathy
Windows Core OS group
This posting is provided “AS IS” with no warranties, and confers no rights.

“Nar Ganapathy[MS]” wrote in message
news:xxxxx@ntdev…
>
> This statement could be written more clearly. APCs will not fire the
> following reasons,
>
> 1. The thread’s IRQL is >= APC_LEVEL. This can happen if the driver
> explicitly raised the IRQL or called ExAcquireFastMutex.
> 2. The thread disabled APCs by calling KeEnterCriticalRegion
> 3. The thread was attached to process A when the IO was issued but
detached
> before the IO completed.
>
> –
> Nar Ganapathy
> Windows Core OS group
> This posting is provided “AS IS” with no warranties, and confers no
rights.
>
> “Nar Ganapathy[MS]” wrote in message
> news:xxxxx@ntdev…
> >
> > The APC will not fire if APCs have been disabled for this thread. Did
you
> > are your caller call KeEnterCriticalRegion or raise IRQL to APC_LEVEL
> either
> > directly or using ExAcquireFastMutex ?
> >
> > –
> > Nar Ganapathy
> > Windows Core OS group
> > This posting is provided “AS IS” with no warranties, and confers no
> rights.
> >
> > “osmlist” wrote in message news:xxxxx@ntdev…
> > >
> > > Hello,
> > > I’m tring to use APC in ZwWriteFile and I am failing.
> > >
> > > I wrote a driver that writes to a file and I pass an APC as an
argument
> > > to ZwWriteFile() but the APC function never called.
> > >
> > > Is someone have any experience with APC in the kernel ?
> > >
> > > Thanks.
> > >
> > > OS
> > >
> > >
> > >
> > >
> > >
> >
> >
> >
> >
>
>
>
>

> know all about APCs. They didn’t expose the APC mechanics for use in

device drivers because (I assume) they thought we’d never have a
need to
use them.

Yes, the driver can trigger an APC in user process if the user process
will call ReadFileEx with a function pointer, and the driver will just
complete this IRP.

Max

“Maxim S. Shatskih” wrote:

Yes, the driver can trigger an APC in user process if the user process
will call ReadFileEx with a function pointer, and the driver will just
complete this IRP.

Well, if that’s what he was trying to do, I obviously misunderstood and
overreacted. It sounded to me as though he had created his own APC
object and was wondering why it wasn’t being scheduled in kernel mode.


Walter Oney, Consulting and Training
Basic and Advanced Driver Programming Seminars
Now teaming with John Hyde for USB Device Engineering Seminars
Check out our schedule at http://www.oneysoft.com

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine.
When the completion routine called my buffer was with a valide data.
That data I want to write to a file as fast as possible, because I want to
use that buffer again and send it again to the lower device to read more
data.
So I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects.
But then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to write it
back to the file system using completion port. With this metod I will allocate
the buffer in user mode and will transfer it to the driver using
METHOD_OUT_DIRECT and I don’t need and threads in the kernel.

If any one know how to do that as I suggest it the second and the third way
or any other comments please write back.

Thanks a lot,

OS.

And what about to build your own IRP for the IRP_MJ_WRITE and send
it to file system as well as you do it with your device. Then in the
completion
routine you can free your buffer for the other request to your device.
Btw, do you currently use the ZwWriteFile inside your completion
routine?
Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 1:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine.
When the completion routine called my buffer was with a valide data.
That data I want to write to a file as fast as possible, because I want
to
use that buffer again and send it again to the lower device to read more
data.
So I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects.
But then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to
write it
back to the file system using completion port. With this metod I will
allocate
the buffer in user mode and will transfer it to the driver using
METHOD_OUT_DIRECT and I don’t need and threads in the kernel.

If any one know how to do that as I suggest it the second and the third
way
or any other comments please write back.

Thanks a lot,

OS.


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

Zpr?vaYes I thought also about this method, and it is possible.
I that way (of using IoBuildAsynchronousFsdRequest) how / where do you specify
the file name?

About using ZwWriteFile inside a completion routine, the answer is Yes, WHY??

OS.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 3:27 PM
Subject: [ntdev] Re: ZwWriteFile and APC

And what about to build your own IRP for the IRP_MJ_WRITE and send
it to file system as well as you do it with your device. Then in the completion
routine you can free your buffer for the other request to your device.
Btw, do you currently use the ZwWriteFile inside your completion routine?
Paul
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 1:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine.
When the completion routine called my buffer was with a valide data.
That data I want to write to a file as fast as possible, because I want to
use that buffer again and send it again to the lower device to read more
data.
So I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects.
But then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to write it
back to the file system using completion port. With this metod I will allocate
the buffer in user mode and will transfer it to the driver using
METHOD_OUT_DIRECT and I don’t need and threads in the kernel.

If any one know how to do that as I suggest it the second and the third way
or any other comments please write back.

Thanks a lot,

OS.


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

It’s not good, because file Zw routines should be called only at
PASSIVE_LEVEL and your completion routine can be called
at <= DISPATCH_LEVEL. You must have some other thread
and call the FSD from it, passing it the buffer to write from your
completion routine. You can use some kind of queue - insert
items from your completion routine and remove them in your
thread.

To your first question I’m asnwering by another question ;-)))
“And how do you specify the file name for ZwWriteFile?”

Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 2:46 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes I thought also about this method, and it is possible.
I that way (of using IoBuildAsynchronousFsdRequest) how / where do you
specify
the file name?

About using ZwWriteFile inside a completion routine, the answer is Yes,
WHY??

OS.

----- Original Message -----

From: Paul Hrdina mailto:xxxxx
To: NT Developers Interest List mailto:xxxxx
Sent: Wednesday, November 27, 2002 3:27 PM
Subject: [ntdev] Re: ZwWriteFile and APC

And what about to build your own IRP for the IRP_MJ_WRITE and send
it to file system as well as you do it with your device. Then in the
completion
routine you can free your buffer for the other request to your device.
Btw, do you currently use the ZwWriteFile inside your completion
routine?
Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 1:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine.
When the completion routine called my buffer was with a valide data.
That data I want to write to a file as fast as possible, because I want
to
use that buffer again and send it again to the lower device to read more
data.
So I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects.
But then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to
write it
back to the file system using completion port. With this metod I will
allocate
the buffer in user mode and will transfer it to the driver using
METHOD_OUT_DIRECT and I don’t need and threads in the kernel.

If any one know how to do that as I suggest it the second and the third
way
or any other comments please write back.

Thanks a lot,

OS.


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></mailto:xxxxx>

Zpr?vaActualy you right.
I’m signaling an event (one of the 64) and there is a thread that responsible
for doing the write operation.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 4:10 PM
Subject: [ntdev] Re: ZwWriteFile and APC

It’s not good, because file Zw routines should be called only at
PASSIVE_LEVEL and your completion routine can be called
at <= DISPATCH_LEVEL. You must have some other thread
and call the FSD from it, passing it the buffer to write from your
completion routine. You can use some kind of queue - insert
items from your completion routine and remove them in your
thread.

To your first question I’m asnwering by another question ;-)))
“And how do you specify the file name for ZwWriteFile?”

Paul
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 2:46 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes I thought also about this method, and it is possible.
I that way (of using IoBuildAsynchronousFsdRequest) how / where do you specify
the file name?

About using ZwWriteFile inside a completion routine, the answer is Yes, WHY??

OS.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 3:27 PM
Subject: [ntdev] Re: ZwWriteFile and APC

And what about to build your own IRP for the IRP_MJ_WRITE and send
it to file system as well as you do it with your device. Then in the completion
routine you can free your buffer for the other request to your device.
Btw, do you currently use the ZwWriteFile inside your completion routine?
Paul
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 1:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine.
When the completion routine called my buffer was with a valide data.
That data I want to write to a file as fast as possible, because I want to
use that buffer again and send it again to the lower device to read more
data.
So I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects.
But then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to write it
back to the file system using completion port. With this metod I will allocate
the buffer in user mode and will transfer it to the driver using
METHOD_OUT_DIRECT and I don’t need and threads in the kernel.

If any one know how to do that as I suggest it the second and the third way
or any other comments please write back.

Thanks a lot,

OS.


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

Why 64 events? One kernel queue (KQUEUE) or one semaphore
together with a spin lock can do the same task. Then you have to
wait only for one (or two with the termination event) synchronization
object and when the wait is satisfied you have to remove an entry
from the queue and process it.
Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 3:54 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Actualy you right.
I’m signaling an event (one of the 64) and there is a thread that
responsible
for doing the write operation.

----- Original Message -----
From: Paul Hrdina mailto:xxxxx
To: NT Developers Interest List mailto:xxxxx
Sent: Wednesday, November 27, 2002 4:10 PM
Subject: [ntdev] Re: ZwWriteFile and APC

It’s not good, because file Zw routines should be called only at
PASSIVE_LEVEL and your completion routine can be called
at <= DISPATCH_LEVEL. You must have some other thread
and call the FSD from it, passing it the buffer to write from your
completion routine. You can use some kind of queue - insert
items from your completion routine and remove them in your
thread.

To your first question I’m asnwering by another question ;-)))
“And how do you specify the file name for ZwWriteFile?”

Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 2:46 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes I thought also about this method, and it is possible.
I that way (of using IoBuildAsynchronousFsdRequest) how / where do you
specify
the file name?

About using ZwWriteFile inside a completion routine, the answer is Yes,
WHY??

OS.

----- Original Message -----

From: Paul mailto:xxxxx Hrdina
To: NT Developers Interest List mailto:xxxxx
Sent: Wednesday, November 27, 2002 3:27 PM
Subject: [ntdev] Re: ZwWriteFile and APC

And what about to build your own IRP for the IRP_MJ_WRITE and send
it to file system as well as you do it with your device. Then in the
completion
routine you can free your buffer for the other request to your device.
Btw, do you currently use the ZwWriteFile inside your completion
routine?
Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 1:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine.
When the completion routine called my buffer was with a valide data.
That data I want to write to a file as fast as possible, because I want
to
use that buffer again and send it again to the lower device to read more
data.
So I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects.
But then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to
write it
back to the file system using completion port. With this metod I will
allocate
the buffer in user mode and will transfer it to the driver using
METHOD_OUT_DIRECT and I don’t need and threads in the kernel.

If any one know how to do that as I suggest it the second and the third
way
or any other comments please write back.

Thanks a lot,

OS.


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

Zpr?vaYes but then you need to do the write operation. and I want to do it
asynchronous so you need to supply an event to the ZwWrite function
and then you need a thread that will wait on multiple objects that limit
to 64 objects. So Instead of using another thread I’m using the same
thread that the completion routine signals.

OS
----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 5:57 PM
Subject: [ntdev] Re: ZwWriteFile and APC

Why 64 events? One kernel queue (KQUEUE) or one semaphore
together with a spin lock can do the same task. Then you have to
wait only for one (or two with the termination event) synchronization
object and when the wait is satisfied you have to remove an entry
from the queue and process it.
Paul
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 3:54 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Actualy you right.
I’m signaling an event (one of the 64) and there is a thread that responsible
for doing the write operation.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 4:10 PM
Subject: [ntdev] Re: ZwWriteFile and APC

It’s not good, because file Zw routines should be called only at
PASSIVE_LEVEL and your completion routine can be called
at <= DISPATCH_LEVEL. You must have some other thread
and call the FSD from it, passing it the buffer to write from your
completion routine. You can use some kind of queue - insert
items from your completion routine and remove them in your
thread.

To your first question I’m asnwering by another question ;-)))
“And how do you specify the file name for ZwWriteFile?”

Paul
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 2:46 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes I thought also about this method, and it is possible.
I that way (of using IoBuildAsynchronousFsdRequest) how / where do you specify
the file name?

About using ZwWriteFile inside a completion routine, the answer is Yes, WHY??

OS.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 3:27 PM
Subject: [ntdev] Re: ZwWriteFile and APC

And what about to build your own IRP for the IRP_MJ_WRITE and send
it to file system as well as you do it with your device. Then in the completion
routine you can free your buffer for the other request to your device.
Btw, do you currently use the ZwWriteFile inside your completion routine?
Paul
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 1:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine.
When the completion routine called my buffer was with a valide data.
That data I want to write to a file as fast as possible, because I want to
use that buffer again and send it again to the lower device to read more
data.
So I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects.
But then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to write it
back to the file system using completion port. With this metod I will allocate
the buffer in user mode and will transfer it to the driver using
METHOD_OUT_DIRECT and I don’t need and threads in the kernel.

If any one know how to do that as I suggest it the second and the third way
or any other comments please write back.

Thanks a lot,

OS.


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

I don’t understand you… Forget the ZwWriteFile and focus on
IoBuildAsynchronousFsdRequest. You haven’t answered my
question yet - so you should know that the file must always
be opened first using IoCreateFile (or ZwCreateFile) and then
you can do something with it. So you get a handle and then
you can call some file ZwXxxx routines, but when you want to
call the FSD directly, you should obtain file object pointer.
Use ObReferenceObjectByHandle to do this and then you also
need device object to pass it to IoCallDriver. Obtain it using
IoGetRelatedDeviceObject. Finally, how to specify the file object
in the request? Set the FileObject in the next Irp stack location
to your file object pointer and then you can finally call the FSD.
And the FSD should post the request to its worker thread so
it will be done asynchronously - which is what you want to do.
Paul

PS: Don’t forget to call IoSetCompletionRoutine before IoCallDriver
;-))).

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 5:11 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes but then you need to do the write operation. and I want to do it
asynchronous so you need to supply an event to the ZwWrite function
and then you need a thread that will wait on multiple objects that limit

to 64 objects. So Instead of using another thread I’m using the same
thread that the completion routine signals.

OS

----- Original Message -----
From: Paul Hrdina mailto:xxxxx
To: NT Developers Interest List mailto:xxxxx
Sent: Wednesday, November 27, 2002 5:57 PM
Subject: [ntdev] Re: ZwWriteFile and APC

Why 64 events? One kernel queue (KQUEUE) or one semaphore
together with a spin lock can do the same task. Then you have to
wait only for one (or two with the termination event) synchronization
object and when the wait is satisfied you have to remove an entry
from the queue and process it.
Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 3:54 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Actualy you right.
I’m signaling an event (one of the 64) and there is a thread that
responsible
for doing the write operation.

----- Original Message -----
From: Paul mailto:xxxxx Hrdina
To: NT Developers Interest List mailto:xxxxx
Sent: Wednesday, November 27, 2002 4:10 PM
Subject: [ntdev] Re: ZwWriteFile and APC

It’s not good, because file Zw routines should be called only at
PASSIVE_LEVEL and your completion routine can be called
at <= DISPATCH_LEVEL. You must have some other thread
and call the FSD from it, passing it the buffer to write from your
completion routine. You can use some kind of queue - insert
items from your completion routine and remove them in your
thread.

To your first question I’m asnwering by another question ;-)))
“And how do you specify the file name for ZwWriteFile?”

Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 2:46 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes I thought also about this method, and it is possible.
I that way (of using IoBuildAsynchronousFsdRequest) how / where do you
specify
the file name?

About using ZwWriteFile inside a completion routine, the answer is Yes,
WHY??

OS.

----- Original Message -----

From: Paul mailto:xxxxx Hrdina
To: NT mailto:xxxxx Developers Interest List
Sent: Wednesday, November 27, 2002 3:27 PM
Subject: [ntdev] Re: ZwWriteFile and APC

And what about to build your own IRP for the IRP_MJ_WRITE and send
it to file system as well as you do it with your device. Then in the
completion
routine you can free your buffer for the other request to your device.
Btw, do you currently use the ZwWriteFile inside your completion
routine?
Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 1:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine.
When the completion routine called my buffer was with a valide data.
That data I want to write to a file as fast as possible, because I want
to
use that buffer again and send it again to the lower device to read more
data.
So I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects.
But then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to
write it
back to the file system using completion port. With this metod I will
allocate
the buffer in user mode and will transfer it to the driver using
METHOD_OUT_DIRECT and I don’t need and threads in the kernel.

If any one know how to do that as I suggest it the second and the third
way
or any other comments please write back.

Thanks a lot,

OS.


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

ZprávaThanks Paul,
Yes you just remaind me the ObReferenceObjectByHandle and
IoGetRelatedDeviceObject and then you right in this way I don’t need
all the 64 events.

Maybe I’ll implement it using that way.

But once again,
Is anyone know how to use in the kernel APC and Completion port
(ZwCreateIoCompletion and ZwRemoveIoCompletion)

OS.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 6:47 PM
Subject: [ntdev] Re: ZwWriteFile and APC

I don’t understand you… Forget the ZwWriteFile and focus on
IoBuildAsynchronousFsdRequest. You haven’t answered my
question yet - so you should know that the file must always
be opened first using IoCreateFile (or ZwCreateFile) and then
you can do something with it. So you get a handle and then
you can call some file ZwXxxx routines, but when you want to
call the FSD directly, you should obtain file object pointer.
Use ObReferenceObjectByHandle to do this and then you also
need device object to pass it to IoCallDriver. Obtain it using
IoGetRelatedDeviceObject. Finally, how to specify the file object
in the request? Set the FileObject in the next Irp stack location
to your file object pointer and then you can finally call the FSD.
And the FSD should post the request to its worker thread so
it will be done asynchronously - which is what you want to do.
Paul

PS: Don’t forget to call IoSetCompletionRoutine before IoCallDriver ;-))).

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 5:11 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes but then you need to do the write operation. and I want to do it
asynchronous so you need to supply an event to the ZwWrite function
and then you need a thread that will wait on multiple objects that limit
to 64 objects. So Instead of using another thread I’m using the same
thread that the completion routine signals.

OS
----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 5:57 PM
Subject: [ntdev] Re: ZwWriteFile and APC

Why 64 events? One kernel queue (KQUEUE) or one semaphore
together with a spin lock can do the same task. Then you have to
wait only for one (or two with the termination event) synchronization
object and when the wait is satisfied you have to remove an entry
from the queue and process it.
Paul
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 3:54 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Actualy you right.
I’m signaling an event (one of the 64) and there is a thread that
responsible
for doing the write operation.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 4:10 PM
Subject: [ntdev] Re: ZwWriteFile and APC

It’s not good, because file Zw routines should be called only at
PASSIVE_LEVEL and your completion routine can be called
at <= DISPATCH_LEVEL. You must have some other thread
and call the FSD from it, passing it the buffer to write from your
completion routine. You can use some kind of queue - insert
items from your completion routine and remove them in your
thread.

To your first question I’m asnwering by another question ;-)))
“And how do you specify the file name for ZwWriteFile?”

Paul
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 2:46 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes I thought also about this method, and it is possible.
I that way (of using IoBuildAsynchronousFsdRequest) how / where do you
specify
the file name?

About using ZwWriteFile inside a completion routine, the answer is Yes,
WHY??

OS.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 3:27 PM
Subject: [ntdev] Re: ZwWriteFile and APC

And what about to build your own IRP for the IRP_MJ_WRITE and send
it to file system as well as you do it with your device. Then in the
completion
routine you can free your buffer for the other request to your device.
Btw, do you currently use the ZwWriteFile inside your completion routine?
Paul
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 1:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine.
When the completion routine called my buffer was with a valide data.
That data I want to write to a file as fast as possible, because I want to
use that buffer again and send it again to the lower device to read more
data.
So I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects.
But then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to
write it
back to the file system using completion port. With this metod I will
allocate
the buffer in user mode and will transfer it to the driver using
METHOD_OUT_DIRECT and I don’t need and threads in the kernel.

If any one know how to do that as I suggest it the second and the third way
or any other comments please write back.

Thanks a lot,

OS.


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to %%email.unsub%%

You’re so occupied by thinking about usage of completion ports.
They were probably not designed to be used by kernel mode
components by Microsoft, because there is no available API
to utilize them in kernel mode. I stongly recommend you to go
the way I uncovered rather than trying to do something foolishly.
Being in kernel mode you have the same potential as the completion
ports represent in user mode, so why don’t you use them?
Paul

PS: As far as APC is concerned, you don’t need it if you’re all
in kernel mode. This is important mainly for doing something
in the context of some user thread (and process), like access
to user mode memory, manage user handles etc.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 6:13 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Zpr?vaThanks Paul,
Yes you just remaind me the ObReferenceObjectByHandle and
IoGetRelatedDeviceObject and then you right in this way I don’t need all
the 64 events.

Maybe I’ll implement it using that way.

But once again,
Is anyone know how to use in the kernel APC and Completion port
(ZwCreateIoCompletion and ZwRemoveIoCompletion)

OS.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 6:47 PM
Subject: [ntdev] Re: ZwWriteFile and APC

I don’t understand you… Forget the ZwWriteFile and focus on
IoBuildAsynchronousFsdRequest. You haven’t answered my question yet - so
you should know that the file must always be opened first using
IoCreateFile (or ZwCreateFile) and then you can do something with it. So
you get a handle and then you can call some file ZwXxxx routines, but
when you want to call the FSD directly, you should obtain file object
pointer. Use ObReferenceObjectByHandle to do this and then you also need
device object to pass it to IoCallDriver. Obtain it using
IoGetRelatedDeviceObject. Finally, how to specify the file object in the
request? Set the FileObject in the next Irp stack location to your file
object pointer and then you can finally call the FSD. And the FSD should
post the request to its worker thread so it will be done asynchronously

  • which is what you want to do. Paul

PS: Don’t forget to call IoSetCompletionRoutine before IoCallDriver
;-))).

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 5:11 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes but then you need to do the write operation. and I want to do it
asynchronous so you need to supply an event to the ZwWrite function and
then you need a thread that will wait on multiple objects that limit to
64 objects. So Instead of using another thread I’m using the same thread
that the completion routine signals.

OS
----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 5:57 PM
Subject: [ntdev] Re: ZwWriteFile and APC

Why 64 events? One kernel queue (KQUEUE) or one semaphore together with
a spin lock can do the same task. Then you have to wait only for one (or
two with the termination event) synchronization object and when the wait
is satisfied you have to remove an entry from the queue and process it.
Paul -----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 3:54 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Actualy you right.
I’m signaling an event (one of the 64) and there is a thread that
responsible for doing the write operation.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 4:10 PM
Subject: [ntdev] Re: ZwWriteFile and APC

It’s not good, because file Zw routines should be called only at
PASSIVE_LEVEL and your completion routine can be called at <=
DISPATCH_LEVEL. You must have some other thread and call the FSD from
it, passing it the buffer to write from your completion routine. You can
use some kind of queue - insert items from your completion routine and
remove them in your thread.

To your first question I’m asnwering by another question ;-))) “And how
do you specify the file name for ZwWriteFile?”

Paul
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 2:46 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Yes I thought also about this method, and it is possible.
I that way (of using IoBuildAsynchronousFsdRequest) how / where do you
specify the file name?

About using ZwWriteFile inside a completion routine, the answer is Yes,
WHY??

OS.

----- Original Message -----
From: Paul Hrdina
To: NT Developers Interest List
Sent: Wednesday, November 27, 2002 3:27 PM
Subject: [ntdev] Re: ZwWriteFile and APC

And what about to build your own IRP for the IRP_MJ_WRITE and send it to
file system as well as you do it with your device. Then in the
completion routine you can free your buffer for the other request to
your device. Btw, do you currently use the ZwWriteFile inside your
completion routine? Paul -----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of osmlist
Sent: Wednesday, November 27, 2002 1:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: ZwWriteFile and APC

Again and maybe more clear I will try to describe what am I tring to do.

I allocated a bunch of buffers.
I have a system thread.
In the system thread I built my own IRP for each buffer and called to a
lower device (IoCallDriver) with a completion routine. When the
completion routine called my buffer was with a valide data. That data I
want to write to a file as fast as possible, because I want to use that
buffer again and send it again to the lower device to read more data. So
I thought to write to the file using asynchronously.

One way is to use ZwWriteFile with an event.
In this method I need to wait on the event to know when the operation
completes. So I wrote another thread that wait on multiple objects. But
then I limit to 64 events (and then to 64 buffers).

Another way I thought to use an APC method.

As a third method I thought to use a completion port in the kernel.

And for final I thought to transfer the buffer to user mode and then to
write it back to the file system using completion port. With this metod
I will allocate the buffer in user mode and will transfer it to the
driver using METHOD_OUT_DIRECT and I don’t need and threads in the
kernel.

If any one know how to do that as I suggest it the second and the third
way or any other comments please write back.

Thanks a lot,

OS.


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com To
unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com To
unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com To
unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@hotmail.com To
unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntdev as: xxxxx@compelson.com
To unsubscribe send a blank email to %%email.unsub%%