Some Help Needed: Named Pipes Client

I still developing a virtual device driver based on the MS Ramdisk demo.

I Run a named pipe host (overlaped) in user mode w/o problems when my clients is also in user mode, also my driver in kernel mode can write to this pipe very good, but when read, the pipe host (in user mode) return an error 232 (ERROR_NO_DATA), the pipe is configured as PIPE_WAIT, the driver at NTSTATUS returns 0x103 (status_pending), (the driver previously performs two writes to the pipe, before to read the pipe w/o disconecting), also the driver returns at IOstatus: IO NFO FILE_OPENED, NT_STATUS (IO_STATUS) 0L (SUCCESS ?)

Whats going on, what can I do, looks like a client that don’t know that the pipe is in blocking mode (PIPE_WAIT).

Thanks,
J.A. Acosta


This is my kernel mode pipe client code:BOOL RdPipe(ULONG offset, void* pBuf,ULONG bufSize){NTSTATUS ntStatus;int i = 0;LARGE_INTEGER duetime = {1000};//PWSTR lpszPipename = L"\??\pipe\RamDrvIn";HANDLE hPipe; OBJECT_ATTRIBUTES objectAttributes;UNICODE_STRING fullFileName;IO_STATUS_BLOCK ioStatus;RtlInitUnicodeString (&fullFileName, L"\??\pipe\RamDrvIn");InitializeObjectAttributes (&objectAttributes, &fullFileName, OBJ_CASE_INSENSITIVE|OBJ_PERMANENT , NULL, NULL);// Try to open a named pipe; wait for it, if necessary. InitializeObjectAttributes (&objectAttributes, &fullFileName, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);Dump(“RdPipe++ Offset:0x%X Sz:%i”,offset,bufSize);// Try to open a named pipe; wait for it, if necessary.for ( i = 0; i<30; i++){ ntStatus = ZwCreateFile (&hPipe,FILE_WRITE_DATA | FILE_READ_DATA | SYNCHRONIZE,&objectAttributes,&ioStatus,NULL,0,FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,FILE_OPEN,//FILE_NON_DIRECTORY_FILE,NULL,0);// Break if the pipe handle is valid. if( STATUS_PIPE_NOT_AVAILABLE != ntStatus )break;KeDelayExecutionThread(KernelMode ,FALSE, &duetime);}if( !NT_SUCCESS(ntStatus) ){ReportError(ntStatus,&ioStatus,“RdPIPE-Open-Failed”);return -1;} if (hPipe == INVALID_HANDLE_VALUE ){return -1;}ntStatus = ZwWriteFile(hPipe,NULL,NULL,NULL,&ioStatus,&offset,sizeof(offset),NULL,NULL);if (!NT_SUCCESS(ntStatus)){ReportError(ntStatus,&ioStatus,“RdPIPE-Write1”);ZwClose(hPipe); return -1;}ntStatus = ZwWriteFile(hPipe,NULL,NULL,NULL,&ioStatus,&bufSize,sizeof(bufSize),NULL,NULL);if (!NT_SUCCESS(ntStatus)){ReportError(ntStatus,&ioStatus,“RdPIPE-Write2”);ZwClose(hPipe); return -1;}do { // Read from the pipe. ntStatus = ZwReadFile (hPipe, NULL, NULL, NULL,&ioStatus, pBuf, bufSize, NULL, NULL);ReportError(ntStatus,&ioStatus,“RdPIPE-Read(3) here the error”);if (!NT_SUCCESS(ntStatus) && /*GetLastError()*/ ioStatus.Status != 324L /*ERROR_MORE_DATA*/) break; } while (!NT_SUCCESS(ntStatus)); // repeat loop if ERROR_MORE_DATA if (!NT_SUCCESS(ntStatus)){ReportError(ntStatus,&ioStatus,“RdPIPE-Read(3)”);ZwClose(hPipe); return -1;}ntStatus = ZwClose(hPipe); if(!NT_SUCCESS(ntStatus))ReportError(ntStatus,&ioStatus,“RdPIPE-Close”);Dump(“RdPipe–”);return ntStatus; }

JA:

You must either specify FILE_SYNCHRONOUS_IO_NONALERT in the Create Options
or wait for the operation to complete:

if( STATUS_PENDING == ntStatus )
{
ZwWaitForSingleObject( hPipe, FALSE, NULL );
ntStatus = IoSb.Status;
}

HTH,
Ken


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Monday, March 07, 2005 8:12 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Some Help Needed: Named Pipes Client

I still developing a virtual device driver based on the MS Ramdisk demo.

I Run a named pipe host (overlaped) in user mode w/o problems when my
clients is also in user mode, also my driver in kernel mode can write to
this pipe very good, but when read, the pipe host (in user mode) return an
error 232 (ERROR_NO_DATA), the pipe is configured as PIPE_WAIT, the driver
at NTSTATUS returns 0x103 (status_pending), (the driver previously performs
two writes to the pipe, before to read the pipe w/o disconecting), also the
driver returns at IOstatus: IO NFO FILE_OPENED, NT_STATUS (IO_STATUS) 0L
(SUCCESS ?)

Whats going on, what can I do, looks like a client that don’t know that the
pipe is in blocking mode (PIPE_WAIT).

Thanks,
J.A. Acosta


This is my kernel mode pipe client code:

BOOL RdPipe(ULONG offset, void* pBuf,ULONG bufSize)
{

NTSTATUS ntStatus;

int i = 0;

LARGE_INTEGER duetime = {1000};

//PWSTR lpszPipename = L"\??\pipe\RamDrvIn";

HANDLE hPipe;

OBJECT_ATTRIBUTES objectAttributes;

UNICODE_STRING fullFileName;

IO_STATUS_BLOCK ioStatus;

RtlInitUnicodeString (&fullFileName,
L"\??\pipe\RamDrvIn");

InitializeObjectAttributes (&objectAttributes,
&fullFileName, OBJ_CASE_INSENSITIVE|OBJ_PERMANENT , NULL, NULL);

// Try to open a named pipe; wait for it, if necessary.

InitializeObjectAttributes (&objectAttributes,
&fullFileName, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);

Dump(“RdPipe++ Offset:0x%X Sz:%i”,offset,bufSize);

// Try to open a named pipe; wait for it, if necessary.

for ( i = 0; i<30; i++)

{

ntStatus = ZwCreateFile (&hPipe,

FILE_WRITE_DATA | FILE_READ_DATA | SYNCHRONIZE,

&objectAttributes,

&ioStatus,

NULL,

0,

FILE_SHARE_READ | FILE_SHARE_WRITE |
FILE_SHARE_DELETE ,

FILE_OPEN,//

FILE_NON_DIRECTORY_FILE,

NULL,

0);

// Break if the pipe handle is valid.

if( STATUS_PIPE_NOT_AVAILABLE != ntStatus )

break;

KeDelayExecutionThread(KernelMode ,FALSE, &duetime);

}

if( !NT_SUCCESS(ntStatus) )

{

ReportError(ntStatus,&ioStatus,“RdPIPE-Open-Failed”);

return -1;

}

if (hPipe == INVALID_HANDLE_VALUE )

{

return -1;

}

ntStatus = ZwWriteFile(

hPipe,

NULL,

NULL,

NULL,

&ioStatus,

&offset,

sizeof(offset),

NULL,

NULL

);

if (!NT_SUCCESS(ntStatus))

{

ReportError(ntStatus,&ioStatus,“RdPIPE-Write1”);

ZwClose(hPipe);

return -1;

}

ntStatus = ZwWriteFile(

hPipe,

NULL,

NULL,

NULL,

&ioStatus,

&bufSize,

sizeof(bufSize),

NULL,

NULL

);

if (!NT_SUCCESS(ntStatus))

{

ReportError(ntStatus,&ioStatus,“RdPIPE-Write2”);

ZwClose(hPipe);

return -1;

}

do

{

// Read from the pipe.

ntStatus = ZwReadFile (

hPipe,

NULL,

NULL,

NULL,

&ioStatus,

pBuf,

bufSize,

NULL,

NULL);

ReportError(ntStatus,&ioStatus,“RdPIPE-Read(3) here
the error”);

if (!NT_SUCCESS(ntStatus) && /*GetLastError()*/
ioStatus.Status != 324L /*ERROR_MORE_DATA*/)

break;

} while (!NT_SUCCESS(ntStatus)); // repeat loop if
ERROR_MORE_DATA

if (!NT_SUCCESS(ntStatus))

{

ReportError(ntStatus,&ioStatus,“RdPIPE-Read(3)”);

ZwClose(hPipe);

return -1;

}

ntStatus = ZwClose(hPipe);

if(!NT_SUCCESS(ntStatus))

ReportError(ntStatus,&ioStatus,“RdPIPE-Close”);

Dump(“RdPipe–”);

return ntStatus;

}


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Thanks, how i can include the “ZwWaitForSingleObject” instruction (I can’t find
it on any Header in my SDK/DDK) ?

I tried with FILE_SYNCHRONOUS_IO_NONALERT , but now the pipe returns an error
997 (Overlaped IO: ERROR_IO_PENDING).

Regards,
J.A.Acosta

“Ken Cross” escribió en el mensaje news:xxxxx@ntdev…
| JA:
|
| You must either specify FILE_SYNCHRONOUS_IO_NONALERT in the Create Options
| or wait for the operation to complete:
|
| if( STATUS_PENDING == ntStatus )
| {
| ZwWaitForSingleObject( hPipe, FALSE, NULL );
| ntStatus = IoSb.Status;
| }
|
| HTH,
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Monday, March 07, 2005 8:12 AM
| To: Windows System Software Devs Interest List
| Subject: [ntdev] Some Help Needed: Named Pipes Client
|
|
| I still developing a virtual device driver based on the MS Ramdisk demo.
|
| I Run a named pipe host (overlaped) in user mode w/o problems when my
| clients is also in user mode, also my driver in kernel mode can write to
| this pipe very good, but when read, the pipe host (in user mode) return an
| error 232 (ERROR_NO_DATA), the pipe is configured as PIPE_WAIT, the driver
| at NTSTATUS returns 0x103 (status_pending), (the driver previously performs
| two writes to the pipe, before to read the pipe w/o disconecting), also the
| driver returns at IOstatus: IO NFO FILE_OPENED, NT_STATUS (IO_STATUS) 0L
| (SUCCESS ?)
|
| Whats going on, what can I do, looks like a client that don’t know that the
| pipe is in blocking mode (PIPE_WAIT).
|
| Thanks,
| J.A. Acosta
|

|
| This is my kernel mode pipe client code:
|
|
| BOOL RdPipe(ULONG offset, void* pBuf,ULONG bufSize)
| {
|
| NTSTATUS ntStatus;
|
| int i = 0;
|
| LARGE_INTEGER duetime = {1000};
|
| //PWSTR lpszPipename = L"\??\pipe\RamDrvIn";
|
| HANDLE hPipe;
|
| OBJECT_ATTRIBUTES objectAttributes;
|
| UNICODE_STRING fullFileName;
|
| IO_STATUS_BLOCK ioStatus;
|
| RtlInitUnicodeString (&fullFileName,
| L"\??\pipe\RamDrvIn");
|
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE|OBJ_PERMANENT , NULL, NULL);
|
| // Try to open a named pipe; wait for it, if necessary.
|
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);
|
| Dump(“RdPipe++ Offset:0x%X Sz:%i”,offset,bufSize);
|
| // Try to open a named pipe; wait for it, if necessary.
|
| for ( i = 0; i<30; i++)
|
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| FILE_WRITE_DATA | FILE_READ_DATA | SYNCHRONIZE,
|
| &objectAttributes,
|
| &ioStatus,
|
| NULL,
|
| 0,
|
| FILE_SHARE_READ | FILE_SHARE_WRITE |
| FILE_SHARE_DELETE ,
|
| FILE_OPEN,//
|
| FILE_NON_DIRECTORY_FILE,
|
| NULL,
|
| 0);
|
| // Break if the pipe handle is valid.
|
| if( STATUS_PIPE_NOT_AVAILABLE != ntStatus )
|
| break;
|
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
|
| if( !NT_SUCCESS(ntStatus) )
|
| {
|
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Open-Failed”);
|
| return -1;
|
| }
|
| if (hPipe == INVALID_HANDLE_VALUE )
|
| {
|
| return -1;
|
| }
|
| ntStatus = ZwWriteFile(
|
| hPipe,
|
| NULL,
|
| NULL,
|
| NULL,
|
| &ioStatus,
|
| &offset,
|
| sizeof(offset),
|
| NULL,
|
| NULL
|
| );
|
| if (!NT_SUCCESS(ntStatus))
|
| {
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Write1”);
|
| ZwClose(hPipe);
|
| return -1;
|
| }
|
| ntStatus = ZwWriteFile(
|
| hPipe,
|
| NULL,
|
| NULL,
|
| NULL,
|
| &ioStatus,
|
| &bufSize,
|
| sizeof(bufSize),
|
| NULL,
|
| NULL
|
| );
|
| if (!NT_SUCCESS(ntStatus))
|
| {
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Write2”);
|
| ZwClose(hPipe);
|
| return -1;
|
| }
|
| do
|
| {
|
| // Read from the pipe.
|
| ntStatus = ZwReadFile (
|
| hPipe,
|
| NULL,
|
| NULL,
|
| NULL,
|
| &ioStatus,
|
| pBuf,
|
| bufSize,
|
| NULL,
|
| NULL);
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Read(3) here
| the error”);
|
| if (!NT_SUCCESS(ntStatus) && /GetLastError()/
| ioStatus.Status != 324L /ERROR_MORE_DATA/)
|
| break;
|
| } while (!NT_SUCCESS(ntStatus)); // repeat loop if
| ERROR_MORE_DATA
|
| if (!NT_SUCCESS(ntStatus))
|
| {
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Read(3)”);
|
| ZwClose(hPipe);
|
| return -1;
|
| }
|
| ntStatus = ZwClose(hPipe);
|
| if(!NT_SUCCESS(ntStatus))
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Close”);
|
| Dump(“RdPipe–”);
|
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256
|
| You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
| To unsubscribe send a blank email to xxxxx@lists.osr.com
|
|

It’s defined in ntifs.h, which requires the IFS kit.

Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Monday, March 07, 2005 6:45 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Some Help Needed: Named Pipes Client

Thanks, how i can include the “ZwWaitForSingleObject” instruction (I can’t
find
it on any Header in my SDK/DDK) ?

I tried with FILE_SYNCHRONOUS_IO_NONALERT , but now the pipe returns an
error
997 (Overlaped IO: ERROR_IO_PENDING).

Regards,
J.A.Acosta

“Ken Cross” escribi? en el mensaje news:xxxxx@ntdev…
| JA:
|
| You must either specify FILE_SYNCHRONOUS_IO_NONALERT in the Create Options
| or wait for the operation to complete:
|
| if( STATUS_PENDING == ntStatus )
| {
| ZwWaitForSingleObject( hPipe, FALSE, NULL );
| ntStatus = IoSb.Status;
| }
|
| HTH,
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Monday, March 07, 2005 8:12 AM
| To: Windows System Software Devs Interest List
| Subject: [ntdev] Some Help Needed: Named Pipes Client
|
|
| I still developing a virtual device driver based on the MS Ramdisk demo.
|
| I Run a named pipe host (overlaped) in user mode w/o problems when my
| clients is also in user mode, also my driver in kernel mode can write to
| this pipe very good, but when read, the pipe host (in user mode) return an
| error 232 (ERROR_NO_DATA), the pipe is configured as PIPE_WAIT, the driver
| at NTSTATUS returns 0x103 (status_pending), (the driver previously
performs
| two writes to the pipe, before to read the pipe w/o disconecting), also
the
| driver returns at IOstatus: IO NFO FILE_OPENED, NT_STATUS (IO_STATUS) 0L
| (SUCCESS ?)
|
| Whats going on, what can I do, looks like a client that don’t know that
the
| pipe is in blocking mode (PIPE_WAIT).
|
| Thanks,
| J.A. Acosta
|

|
| This is my kernel mode pipe client code:
|
|
| BOOL RdPipe(ULONG offset, void* pBuf,ULONG bufSize)
| {
|
| NTSTATUS ntStatus;
|
| int i = 0;
|
| LARGE_INTEGER duetime = {1000};
|
| //PWSTR lpszPipename = L"\??\pipe\RamDrvIn";
|
| HANDLE hPipe;
|
| OBJECT_ATTRIBUTES objectAttributes;
|
| UNICODE_STRING fullFileName;
|
| IO_STATUS_BLOCK ioStatus;
|
| RtlInitUnicodeString (&fullFileName,
| L"\??\pipe\RamDrvIn");
|
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE|OBJ_PERMANENT , NULL, NULL);
|
| // Try to open a named pipe; wait for it, if necessary.
|
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL);
|
| Dump(“RdPipe++ Offset:0x%X Sz:%i”,offset,bufSize);
|
| // Try to open a named pipe; wait for it, if necessary.
|
| for ( i = 0; i<30; i++)
|
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| FILE_WRITE_DATA | FILE_READ_DATA | SYNCHRONIZE,
|
| &objectAttributes,
|
| &ioStatus,
|
| NULL,
|
| 0,
|
| FILE_SHARE_READ | FILE_SHARE_WRITE |
| FILE_SHARE_DELETE ,
|
| FILE_OPEN,//
|
| FILE_NON_DIRECTORY_FILE,
|
| NULL,
|
| 0);
|
| // Break if the pipe handle is valid.
|
| if( STATUS_PIPE_NOT_AVAILABLE != ntStatus )
|
| break;
|
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
|
| if( !NT_SUCCESS(ntStatus) )
|
| {
|
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Open-Failed”);
|
| return -1;
|
| }
|
| if (hPipe == INVALID_HANDLE_VALUE )
|
| {
|
| return -1;
|
| }
|
| ntStatus = ZwWriteFile(
|
| hPipe,
|
| NULL,
|
| NULL,
|
| NULL,
|
| &ioStatus,
|
| &offset,
|
| sizeof(offset),
|
| NULL,
|
| NULL
|
| );
|
| if (!NT_SUCCESS(ntStatus))
|
| {
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Write1”);
|
| ZwClose(hPipe);
|
| return -1;
|
| }
|
| ntStatus = ZwWriteFile(
|
| hPipe,
|
| NULL,
|
| NULL,
|
| NULL,
|
| &ioStatus,
|
| &bufSize,
|
| sizeof(bufSize),
|
| NULL,
|
| NULL
|
| );
|
| if (!NT_SUCCESS(ntStatus))
|
| {
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Write2”);
|
| ZwClose(hPipe);
|
| return -1;
|
| }
|
| do
|
| {
|
| // Read from the pipe.
|
| ntStatus = ZwReadFile (
|
| hPipe,
|
| NULL,
|
| NULL,
|
| NULL,
|
| &ioStatus,
|
| pBuf,
|
| bufSize,
|
| NULL,
|
| NULL);
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Read(3) here
| the error”);
|
| if (!NT_SUCCESS(ntStatus) && /GetLastError()/
| ioStatus.Status != 324L /ERROR_MORE_DATA/)
|
| break;
|
| } while (!NT_SUCCESS(ntStatus)); // repeat loop if
| ERROR_MORE_DATA
|
| if (!NT_SUCCESS(ntStatus))
|
| {
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Read(3)”);
|
| ZwClose(hPipe);
|
| return -1;
|
| }
|
| ntStatus = ZwClose(hPipe);
|
| if(!NT_SUCCESS(ntStatus))
|
| ReportError(ntStatus,&ioStatus,“RdPIPE-Close”);
|
| Dump(“RdPipe–”);
|
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256
|
| You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
| To unsubscribe send a blank email to xxxxx@lists.osr.com
|
|


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@comcast.net
To unsubscribe send a blank email to xxxxx@lists.osr.com

Since you don’t have the IFS, use this sequence instead of using
ZwWaitForSingleObject() :

ObReferenceObjectByHandle()
KeWaitForSingleObject()
ObDereferenceObject()

I’m not 100% sure, if the create is pending, if it’ll work. Experts could
answer to this.

M-A

“J.Angel” a écrit dans le message de news:
xxxxx@ntdev…
> Thanks, how i can include the “ZwWaitForSingleObject” instruction (I can’t
> find
> it on any Header in my SDK/DDK) ?
>
> I tried with FILE_SYNCHRONOUS_IO_NONALERT , but now the pipe returns an
> error
> 997 (Overlaped IO: ERROR_IO_PENDING).
>
> Regards,
> J.A.Acosta
>
>
> “Ken Cross” escribió en el mensaje
> news:xxxxx@ntdev…
> | JA:
> |
> | You must either specify FILE_SYNCHRONOUS_IO_NONALERT in the Create
> Options
> | or wait for the operation to complete:
> |
> | if( STATUS_PENDING == ntStatus )
> | {
> | ZwWaitForSingleObject( hPipe, FALSE, NULL );
> | ntStatus = IoSb.Status;
> | }
> |
> | HTH,
> | Ken
> |