Named Pipes (kernel mode) - Help needed - Newbie

I’m developing a driver based on the MS Ramdrive driver, I need to send some data from the driver to a Named Pipe, (a service running in user mode hosts the pipe and is succefully tested also on heavy load simulations).

I use ZwOpenFile and ZwRead/Write, but nothing occurs (the driver never connect to the pipe), what’s wrong?
I read some old post related, but I see no real answer to the problem.

Thanks,

J.A.


Here’s my code:

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

ULONG dwMode;
NTSTATUS ntStatus;
int i;
LARGE_INTEGER duetime = {1000};
HANDLE hPipe;
ULONG cbRead;
ULONG cbWritten;
PWSTR lpszPipename = ‘\\.\PIPE\RamDrvOut’;
OBJECT_ATTRIBUTES objectAttributes;
UNICODE_STRING fullFileName;
IO_STATUS_BLOCK ioStatus;

RtlInitUnicodeString (&fullFileName, lpszPipename);

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

// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<90; i++)

{

ntStatus = ZwCreateFile (&hPipe,
SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
&objectAttributes,&ioStatus,
NULL,FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);

// Break if the pipe handle is valid.

if (hPipe != INVALID_HANDLE_VALUE)
{
break;
}

// Exit if an error other than ERROR_PIPE_BUSY occurs.
//if (ioStatus.Status != 231L/*ERROR_PIPE_BUSY*/)
//{
// return FALSE;
//}

ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
KeDelayExecutionThread(KernelMode ,FALSE, &duetime);

}

if (hPipe == INVALID_HANDLE_VALUE )
return 0;

ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &offset, sizeof(offset), NULL, NULL);

if (ntStatus == STATUS_SUCCESS)

{

ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &bufSize, sizeof(bufSize), NULL, NULL);

}

if (ntStatus == STATUS_SUCCESS)
{

do
{

// Read from the pipe.
ntStatus = ZwReadFile (hPipe, NULL, NULL, NULL,&ioStatus, pBuf, bufSize, NULL, NULL);
if (ntStatus != STATUS_SUCCESS && /*GetLastError()*/ ioStatus.Status != 324L /*ERROR_MORE_DATA*/)
break;

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

}

ZwClose(hPipe);
return (ntStatus == STATUS_SUCCESS);

}

J.A.:

The real pipe name is “??\pipe\RamDrvOut”, so try:

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

HTH,
Ken


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Saturday, February 05, 2005 10:39 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Named Pipes (kernel mode) - Help needed - Newbie

I’m developing a driver based on the MS Ramdrive driver, I need to send some
data from the driver to a Named Pipe, (a service running in user mode hosts
the pipe and is succefully tested also on heavy load simulations).

I use ZwOpenFile and ZwRead/Write, but nothing occurs (the driver never
connect to the pipe), what’s wrong?
I read some old post related, but I see no real answer to the problem.

Thanks,

J.A.


Here’s my code:

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

ULONG dwMode;
NTSTATUS ntStatus;
int i;
LARGE_INTEGER duetime = {1000};
HANDLE hPipe;
ULONG cbRead;
ULONG cbWritten;
PWSTR lpszPipename = ‘\\.\PIPE\RamDrvOut’;
OBJECT_ATTRIBUTES objectAttributes;
UNICODE_STRING fullFileName;
IO_STATUS_BLOCK ioStatus;

RtlInitUnicodeString (&fullFileName, lpszPipename);

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

// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<90; i++)

{

ntStatus = ZwCreateFile (&hPipe,
SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
&objectAttributes,&ioStatus,
NULL,FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);

// Break if the pipe handle is valid.

if (hPipe != INVALID_HANDLE_VALUE)
{
break;
}

// Exit if an error other than ERROR_PIPE_BUSY occurs.
//if (ioStatus.Status != 231L/*ERROR_PIPE_BUSY*/)
//{
// return FALSE;
//}

ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
KeDelayExecutionThread(KernelMode ,FALSE, &duetime);

}

if (hPipe == INVALID_HANDLE_VALUE )
return 0;

ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &offset,
sizeof(offset), NULL, NULL);

if (ntStatus == STATUS_SUCCESS)

{

ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &bufSize,
sizeof(bufSize), NULL, NULL);

}

if (ntStatus == STATUS_SUCCESS)
{

do
{

// Read from the pipe.
ntStatus = ZwReadFile (hPipe, NULL, NULL,
NULL,&ioStatus, pBuf, bufSize, NULL, NULL);
if (ntStatus != STATUS_SUCCESS &&
/*GetLastError()*/ ioStatus.Status != 324L /*ERROR_MORE_DATA*/)
break;

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

}

ZwClose(hPipe);
return (ntStatus == STATUS_SUCCESS);

}


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

I revised my code, with you suggestion, but no change, the pipe server (a win32
service not running in kernel mode) still waiting for some connection. also I
changes the pipe name at my pipeserver, testing all naming possibilities, but no
change.

I’ll valuate any help, Thanks

J.Angel

“Ken Cross” escribió en el mensaje news:xxxxx@ntdev…
| J.A.:
|
| The real pipe name is “??\pipe\RamDrvOut”, so try:
|
| RtlInitUnicodeString (&fullFileName, L"\??\pipe\RamDrvOut");
|
| HTH,
| Ken
|
|
|
|
|
| From: xxxxx@lists.osr.com
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Saturday, February 05, 2005 10:39 AM
| To: Windows System Software Devs Interest List
| Subject: [ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| I’m developing a driver based on the MS Ramdrive driver, I need to send some
| data from the driver to a Named Pipe, (a service running in user mode hosts
| the pipe and is succefully tested also on heavy load simulations).
|
| I use ZwOpenFile and ZwRead/Write, but nothing occurs (the driver never
| connect to the pipe), what’s wrong?
| I read some old post related, but I see no real answer to the problem.
|
| Thanks,
|
| J.A.
|

|
| Here’s my code:
|
|
|
| BOOL RdPipe(ULONG offset, void* pBuf,ULONG bufSize)
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename = ‘\\.\PIPE\RamDrvOut’;
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
|
| RtlInitUnicodeString (&fullFileName, lpszPipename);
|
| InitializeObjectAttributes (&objectAttributes, &fullFileName,
| OBJ_CASE_INSENSITIVE, NULL, NULL);
|
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
|
| {
|
| ntStatus = ZwCreateFile (&hPipe,
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
| &objectAttributes,&ioStatus,
| NULL,FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN_IF,
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
|
| if (hPipe != INVALID_HANDLE_VALUE)
| {
| break;
| }
|
| // Exit if an error other than ERROR_PIPE_BUSY occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
| // return FALSE;
| //}
|
| ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
|
| if (hPipe == INVALID_HANDLE_VALUE )
| return 0;
|
| ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &offset,
| sizeof(offset), NULL, NULL);
|
| if (ntStatus == STATUS_SUCCESS)
|
| {
|
| ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &bufSize,
| sizeof(bufSize), NULL, NULL);
|
| }
|
| if (ntStatus == STATUS_SUCCESS)
| {
|
| do
| {
|
| // Read from the pipe.
| ntStatus = ZwReadFile (hPipe, NULL, NULL,
| NULL,&ioStatus, pBuf, bufSize, NULL, NULL);
| if (ntStatus != STATUS_SUCCESS &&
| /GetLastError()/ ioStatus.Status != 324L /ERROR_MORE_DATA/)
| break;
|
| } while (ntStatus != STATUS_SUCCESS); // repeat loop if
| ERROR_MORE_DATA
|
| }
|
| ZwClose(hPipe);
| return (ntStatus == STATUS_SUCCESS);
|
| }
|
| —
| 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
|
|

When I was playing with Pipes in drivers, I had to write it like this:

“\DosDevices\pipe\RamDrvOut”

I might be crazy, but it worked for me… :wink:

Andrew

From: “J.Angel”
Reply-To: “Windows System Software Devs Interest List”
To: “Windows System Software Devs Interest List”
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
Date: Mon, 7 Feb 2005 23:10:56 -0400

I revised my code, with you suggestion, but no change, the pipe server (a
win32
service not running in kernel mode) still waiting for some connection. also
I
changes the pipe name at my pipeserver, testing all naming possibilities,
but no
change.

I’ll valuate any help, Thanks

J.Angel

“Ken Cross” escribió en el mensaje news:xxxxx@ntdev…
| J.A.:
|
| The real pipe name is “??\pipe\RamDrvOut”, so try:
|
| RtlInitUnicodeString (&fullFileName, L"\??\pipe\RamDrvOut");
|
| HTH,
| Ken
|
|
|
|
|
| From: xxxxx@lists.osr.com
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Saturday, February 05, 2005 10:39 AM
| To: Windows System Software Devs Interest List
| Subject: [ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| I’m developing a driver based on the MS Ramdrive driver, I need to send
some
| data from the driver to a Named Pipe, (a service running in user mode
hosts
| the pipe and is succefully tested also on heavy load simulations).
|
| I use ZwOpenFile and ZwRead/Write, but nothing occurs (the driver never
| connect to the pipe), what’s wrong?
| I read some old post related, but I see no real answer to the problem.
|
| Thanks,
|
| J.A.
|

|
| Here’s my code:
|
|
|
| BOOL RdPipe(ULONG offset, void* pBuf,ULONG bufSize)
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename = ‘\\.\PIPE\RamDrvOut’;
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
|
| RtlInitUnicodeString (&fullFileName, lpszPipename);
|
| InitializeObjectAttributes (&objectAttributes, &fullFileName,
| OBJ_CASE_INSENSITIVE, NULL, NULL);
|
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
|
| {
|
| ntStatus = ZwCreateFile (&hPipe,
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
| &objectAttributes,&ioStatus,
| NULL,FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN_IF,
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
|
| if (hPipe != INVALID_HANDLE_VALUE)
| {
| break;
| }
|
| // Exit if an error other than ERROR_PIPE_BUSY occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
| // return FALSE;
| //}
|
| ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
|
| if (hPipe == INVALID_HANDLE_VALUE )
| return 0;
|
| ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &offset,
| sizeof(offset), NULL, NULL);
|
| if (ntStatus == STATUS_SUCCESS)
|
| {
|
| ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &bufSize,
| sizeof(bufSize), NULL, NULL);
|
| }
|
| if (ntStatus == STATUS_SUCCESS)
| {
|
| do
| {
|
| // Read from the pipe.
| ntStatus = ZwReadFile (hPipe, NULL, NULL,
| NULL,&ioStatus, pBuf, bufSize, NULL, NULL);
| if (ntStatus != STATUS_SUCCESS &&
| /GetLastError()/ ioStatus.Status != 324L /ERROR_MORE_DATA/)
| break;
|
| } while (ntStatus != STATUS_SUCCESS); // repeat loop if
| ERROR_MORE_DATA
|
| }
|
| ZwClose(hPipe);
| return (ntStatus == STATUS_SUCCESS);
|
| }
|
| —
| 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@hotmail.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The name depends upon whether the pipe is local or remote. Local named pipes are implemented via the named pipe file system (NPFS). Remote named pipes are implemented via LanManRedirector and LanManServer; on the “server” end the named pipe is then implemented by the NPFS implementation local to that system.

The ??\pipe would correspond to a symbolic link name. Since \DosDevices is nothing more than a symbolic link to ?? these names are equivalent.

If you are unable to open the named pipe then the name is certainly wrong. Also, keep in mind that ZwCreateFile can only be used to *open* an existing named pipe, not to create a new one (use IoCreateFile to create a new named pipe, passing the NAMED_PIPE_CREATE_PARAMETERS as the “ExtraCreateParameters”. You can get the structure of this from the debugger using "dt nt!_NAMED_PIPE_CREATE_PARAMETERS).

Why the naming is wrong is of course what you’ll have to track down. Set a breakpoint in the named pipe file system’s create function (“bp npfs!NpFsdCreate”). See if it gets called. If not, the name is not even getting through the object manager. If it IS getting as far as the NPFS driver, compare it to the name you see going into NPFS when the Win32 service creates the named pipe (you will need to trap the call to NpFsdCreateNamedPipe - “bp npfs!NpFsdCreateNamedPipe”). That will get you through local named pipes.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Andrew Nielsen
Sent: Monday, February 07, 2005 10:20 PM
To: ntdev redirect
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

When I was playing with Pipes in drivers, I had to write it like this:

“\DosDevices\pipe\RamDrvOut”

I might be crazy, but it worked for me… :wink:

Andrew

From: “J.Angel”
Reply-To: “Windows System Software Devs Interest List”
To: “Windows System Software Devs Interest List”
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
Date: Mon, 7 Feb 2005 23:10:56 -0400

I revised my code, with you suggestion, but no change, the pipe server (a
win32
service not running in kernel mode) still waiting for some connection. also
I
changes the pipe name at my pipeserver, testing all naming possibilities,
but no
change.

I’ll valuate any help, Thanks

J.Angel

“Ken Cross” escribi? en el mensaje news:xxxxx@ntdev…
| J.A.:
|
| The real pipe name is “??\pipe\RamDrvOut”, so try:
|
| RtlInitUnicodeString (&fullFileName, L"\??\pipe\RamDrvOut");
|
| HTH,
| Ken
|
|
|
|
|
| From: xxxxx@lists.osr.com
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Saturday, February 05, 2005 10:39 AM
| To: Windows System Software Devs Interest List
| Subject: [ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| I’m developing a driver based on the MS Ramdrive driver, I need to send
some
| data from the driver to a Named Pipe, (a service running in user mode
hosts
| the pipe and is succefully tested also on heavy load simulations).
|
| I use ZwOpenFile and ZwRead/Write, but nothing occurs (the driver never
| connect to the pipe), what’s wrong?
| I read some old post related, but I see no real answer to the problem.
|
| Thanks,
|
| J.A.
|

|
| Here’s my code:
|
|
|
| BOOL RdPipe(ULONG offset, void* pBuf,ULONG bufSize)
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename = ‘\\.\PIPE\RamDrvOut’;
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
|
| RtlInitUnicodeString (&fullFileName, lpszPipename);
|
| InitializeObjectAttributes (&objectAttributes, &fullFileName,
| OBJ_CASE_INSENSITIVE, NULL, NULL);
|
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
|
| {
|
| ntStatus = ZwCreateFile (&hPipe,
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
| &objectAttributes,&ioStatus,
| NULL,FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN_IF,
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
|
| if (hPipe != INVALID_HANDLE_VALUE)
| {
| break;
| }
|
| // Exit if an error other than ERROR_PIPE_BUSY occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
| // return FALSE;
| //}
|
| ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
|
| if (hPipe == INVALID_HANDLE_VALUE )
| return 0;
|
| ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &offset,
| sizeof(offset), NULL, NULL);
|
| if (ntStatus == STATUS_SUCCESS)
|
| {
|
| ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &bufSize,
| sizeof(bufSize), NULL, NULL);
|
| }
|
| if (ntStatus == STATUS_SUCCESS)
| {
|
| do
| {
|
| // Read from the pipe.
| ntStatus = ZwReadFile (hPipe, NULL, NULL,
| NULL,&ioStatus, pBuf, bufSize, NULL, NULL);
| if (ntStatus != STATUS_SUCCESS &&
| /GetLastError()/ ioStatus.Status != 324L /ERROR_MORE_DATA/)
| break;
|
| } while (ntStatus != STATUS_SUCCESS); // repeat loop if
| ERROR_MORE_DATA
|
| }
|
| ZwClose(hPipe);
| return (ntStatus == STATUS_SUCCESS);
|
| }
|
| —
| 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@hotmail.com
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@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

It really does work – I’m using a virtually identical setup with no
problems.

You should use FILE_OPEN rather than FILE_OPEN_IF since it cannot create it.

What error code are you getting (in ntStatus)?

Also, you should use “if (NT_SUCCESS(ntStatus))”, not “if (ntStatus ==
STATUS_SUCCESS)”.

Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Monday, February 07, 2005 10:11 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

I revised my code, with you suggestion, but no change, the pipe server (a
win32
service not running in kernel mode) still waiting for some connection. also
I
changes the pipe name at my pipeserver, testing all naming possibilities,
but no
change.

I’ll valuate any help, Thanks

J.Angel

“Ken Cross” escribi? en el mensaje news:xxxxx@ntdev…
| J.A.:
|
| The real pipe name is “??\pipe\RamDrvOut”, so try:
|
| RtlInitUnicodeString (&fullFileName, L"\??\pipe\RamDrvOut");
|
| HTH,
| Ken
|
|
|
|
|
| From: xxxxx@lists.osr.com
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Saturday, February 05, 2005 10:39 AM
| To: Windows System Software Devs Interest List
| Subject: [ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| I’m developing a driver based on the MS Ramdrive driver, I need to send
some
| data from the driver to a Named Pipe, (a service running in user mode
hosts
| the pipe and is succefully tested also on heavy load simulations).
|
| I use ZwOpenFile and ZwRead/Write, but nothing occurs (the driver never
| connect to the pipe), what’s wrong?
| I read some old post related, but I see no real answer to the problem.
|
| Thanks,
|
| J.A.
|

|
| Here’s my code:
|
|
|
| BOOL RdPipe(ULONG offset, void* pBuf,ULONG bufSize)
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename = ‘\\.\PIPE\RamDrvOut’;
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
|
| RtlInitUnicodeString (&fullFileName, lpszPipename);
|
| InitializeObjectAttributes (&objectAttributes, &fullFileName,
| OBJ_CASE_INSENSITIVE, NULL, NULL);
|
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
|
| {
|
| ntStatus = ZwCreateFile (&hPipe,
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
| &objectAttributes,&ioStatus,
| NULL,FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN_IF,
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
|
| if (hPipe != INVALID_HANDLE_VALUE)
| {
| break;
| }
|
| // Exit if an error other than ERROR_PIPE_BUSY occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
| // return FALSE;
| //}
|
| ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
|
| if (hPipe == INVALID_HANDLE_VALUE )
| return 0;
|
| ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &offset,
| sizeof(offset), NULL, NULL);
|
| if (ntStatus == STATUS_SUCCESS)
|
| {
|
| ntStatus = ZwWriteFile(hPipe, NULL, NULL, NULL, &ioStatus, &bufSize,
| sizeof(bufSize), NULL, NULL);
|
| }
|
| if (ntStatus == STATUS_SUCCESS)
| {
|
| do
| {
|
| // Read from the pipe.
| ntStatus = ZwReadFile (hPipe, NULL, NULL,
| NULL,&ioStatus, pBuf, bufSize, NULL, NULL);
| if (ntStatus != STATUS_SUCCESS &&
| /GetLastError()/ ioStatus.Status != 324L /ERROR_MORE_DATA/)
| break;
|
| } while (ntStatus != STATUS_SUCCESS); // repeat loop if
| ERROR_MORE_DATA
|
| }
|
| ZwClose(hPipe);
| return (ntStatus == STATUS_SUCCESS);
|
| }
|
| —
| 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

OK, I follow the suggestion and modified my source, now the pipe connects OK, but ZwWriteFile fails.

I’ll valuate any help, Thanks

J.Angel


My “NEW” SOURCE:

BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)

{
ULONG dwMode;
NTSTATUS ntStatus;
int i = 0;
LARGE_INTEGER duetime = {1000};
HANDLE hPipe;
ULONG cbRead;
ULONG cbWritten;
PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
OBJECT_ATTRIBUTES objectAttributes;
UNICODE_STRING fullFileName;
IO_STATUS_BLOCK ioStatus;
RtlInitUnicodeString (&fullFileName, lpszPipename);
InitializeObjectAttributes (&objectAttributes, &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<90; i++)
{
ntStatus = ZwCreateFile (&hPipe,
SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
&objectAttributes,
&ioStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,//FILE_OPEN_IF
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);
// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE )
{
break;
}
// Exit if an error other than ERROR_PIPE_BUSY occurs.
//if (ioStatus.Status != 231L/*ERROR_PIPE_BUSY*/)
//{
// return FALSE;
//}
KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
}
if (hPipe == INVALID_HANDLE_VALUE)
return -1;
ntStatus = ZwWriteFile(
hPipe,
NULL,
NULL,
NULL,
&ioStatus,
&offset,
sizeof(offset),
NULL,
NULL
);
if (NT_SUCCESS(ntStatus))
{
//
ntStatus = ZwWriteFile(
hPipe,
NULL,
NULL,
NULL,
&ioStatus,
&bufSize,
sizeof(bufSize),
NULL,
NULL
);
}
if (NT_SUCCESS(ntStatus))
{
ntStatus = ZwWriteFile(
hPipe,
NULL,
NULL,
NULL,
&ioStatus,
pBuf,
bufSize,
NULL,
NULL
);
}
ZwClose(hPipe);
return ntStatus;
}

It’s difficult to help without complete information.

Which write is failing? All of them? What are the error codes for ntStatus
and ioStatus.Status? How is the pipe created in the user-mode application?
Is the user-mode application receiving any errors? Can you write to the
pipe with other applications?

There’s a good chance that if you can answer these questions, the problem
will become obvious.

Ken


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Wednesday, February 09, 2005 10:27 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

OK, I follow the suggestion and modified my source, now the pipe connects
OK, but ZwWriteFile fails.

I’ll valuate any help, Thanks

J.Angel


My “NEW” SOURCE:

BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)

{

ULONG dwMode;
NTSTATUS ntStatus;
int i = 0;
LARGE_INTEGER duetime = {1000};
HANDLE hPipe;
ULONG cbRead;
ULONG cbWritten;
PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
OBJECT_ATTRIBUTES objectAttributes;
UNICODE_STRING fullFileName;
IO_STATUS_BLOCK ioStatus;
RtlInitUnicodeString (&fullFileName, lpszPipename);
InitializeObjectAttributes (&objectAttributes,
&fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<90; i++)
{

ntStatus = ZwCreateFile (&hPipe,

SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,

&objectAttributes,
&ioStatus,
NULL,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_READ | FILE_SHARE_WRITE,
FILE_OPEN,//FILE_OPEN_IF
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0);

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE )
{

break;

}
// Exit if an error other than ERROR_PIPE_BUSY
occurs.
//if (ioStatus.Status != 231L/*ERROR_PIPE_BUSY*/)
//{

// return FALSE;

//}
KeDelayExecutionThread(KernelMode ,FALSE, &duetime);

}
if (hPipe == INVALID_HANDLE_VALUE)

return -1;

ntStatus = ZwWriteFile(

hPipe,
NULL,
NULL,
NULL,
&ioStatus,
&offset,
sizeof(offset),
NULL,
NULL
);

if (NT_SUCCESS(ntStatus))
{
//

ntStatus = ZwWriteFile(

hPipe,
NULL,
NULL,
NULL,
&ioStatus,
&bufSize,
sizeof(bufSize),
NULL,
NULL
);

}
if (NT_SUCCESS(ntStatus))
{

ntStatus = ZwWriteFile(

hPipe,
NULL,
NULL,
NULL,
&ioStatus,
pBuf,
bufSize,
NULL,
NULL
);

}
ZwClose(hPipe);
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 Ken,

That’s what I can see,

All the writes fails

The pipe is created with the following parametes :
access mode: PIPE_ACCESS_DUPLEX
pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE| PIPE_NOWAIT

I tested this pipe with the following code on a MFC window app w/o throubles (near the same code I use for kernel mode). works fine also with heavy load.

Thanks,
J.Angel


BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
{
BOOL fSuccess;
int i;
HANDLE hPipe;
DWORD cbWritten;
LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<10; i++)
{
hPipe = CreateFile(
lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // no security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE)
{
break;
}
// Exit if an error other than ERROR_PIPE_BUSY occurs.
//if (GetLastError() != 231L/*ERROR_PIPE_BUSY*/)
//{
// return FALSE;
//}
Sleep(100);
}
if (hPipe == INVALID_HANDLE_VALUE && i == 90)
return 0;
fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG), &cbWritten, NULL);
if (fSuccess)
{
fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG), &cbWritten, NULL);
}

if (fSuccess)
{
fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize, &cbWritten, NULL);
}
CloseHandle(hPipe);
return (fSuccess);
}

“Ken Cross” escribi? en el mensaje news:xxxxx@ntdev…
| It’s difficult to help without complete information.
|
| Which write is failing? All of them? What are the error codes for ntStatus
| and ioStatus.Status? How is the pipe created in the user-mode application?
| Is the user-mode application receiving any errors? Can you write to the
| pipe with other applications?
|
| There’s a good chance that if you can answer these questions, the problem
| will become obvious.
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Wednesday, February 09, 2005 10:27 PM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| OK, I follow the suggestion and modified my source, now the pipe connects
| OK, but ZwWriteFile fails.
|
| I’ll valuate any help, Thanks
|
| J.Angel
|
|

|
| My “NEW” SOURCE:
|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
|
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i = 0;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
| RtlInitUnicodeString (&fullFileName, lpszPipename);
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
|
| &objectAttributes,
| &ioStatus,
| NULL,
| FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN,//FILE_OPEN_IF
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE )
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE)
|
| return -1;
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &offset,
| sizeof(offset),
| NULL,
| NULL
| );
|
| if (NT_SUCCESS(ntStatus))
| {
| //
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &bufSize,
| sizeof(bufSize),
| NULL,
| NULL
| );
|
| }
| if (NT_SUCCESS(ntStatus))
| {
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| pBuf,
| bufSize,
| NULL,
| NULL
| );
|
| }
| ZwClose(hPipe);
| 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
|
|

You’re still missing the most important piece of information: What error
are you getting from ZwWriteFile?

Ken


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Thursday, February 10, 2005 9:56 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken,

That’s what I can see,

All the writes fails

The pipe is created with the following parametes :
access mode: PIPE_ACCESS_DUPLEX
pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE| PIPE_NOWAIT

I tested this pipe with the following code on a MFC window app w/o throubles
(near the same code I use for kernel mode). works fine also with heavy load.

Thanks,
J.Angel


BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
{

BOOL fSuccess;
int i;
HANDLE hPipe;
DWORD cbWritten;
LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<10; i++)
{

hPipe = CreateFile(

lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // no security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE)
{

break;

}
// Exit if an error other than ERROR_PIPE_BUSY
occurs.
//if (GetLastError() != 231L/*ERROR_PIPE_BUSY*/)
//{

// return FALSE;

//}
Sleep(100);

}
if (hPipe == INVALID_HANDLE_VALUE && i == 90)

return 0;

fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG),
&cbWritten, NULL);
if (fSuccess)
{

fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG),
&cbWritten, NULL);

}
if (fSuccess)
{

fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize,
&cbWritten, NULL);

}
CloseHandle(hPipe);
return (fSuccess);

}

“Ken Cross” > escribi? en
el mensaje news:xxxxx@ntdev news:xxxxx
| It’s difficult to help without complete information.
|
| Which write is failing? All of them? What are the error codes for
ntStatus
| and ioStatus.Status? How is the pipe created in the user-mode
application?
| Is the user-mode application receiving any errors? Can you write to the
| pipe with other applications?
|
| There’s a good chance that if you can answer these questions, the problem
| will become obvious.
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
mailto:xxxxx
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Wednesday, February 09, 2005 10:27 PM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| OK, I follow the suggestion and modified my source, now the pipe connects
| OK, but ZwWriteFile fails.
|
| I’ll valuate any help, Thanks
|
| J.Angel
|
|

|
| My “NEW” SOURCE:
|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
|
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i = 0;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
| RtlInitUnicodeString (&fullFileName, lpszPipename);
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
|
| &objectAttributes,
| &ioStatus,
| NULL,
| FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN,//FILE_OPEN_IF
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE )
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE)
|
| return -1;
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &offset,
| sizeof(offset),
| NULL,
| NULL
| );
|
| if (NT_SUCCESS(ntStatus))
| {
| //
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &bufSize,
| sizeof(bufSize),
| NULL,
| NULL
| );
|
| }
| if (NT_SUCCESS(ntStatus))
| {
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| pBuf,
| bufSize,
| NULL,
| NULL
| );
|
| }
| ZwClose(hPipe);
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256
http:
|
| You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’

| To unsubscribe send a blank email to xxxxx@lists.osr.com
mailto:xxxxx
|
| —
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</mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx>

Sorry by the delay Ken, but I must to suspend my research due a support request
from a customer.
Sorry, by dont include that data.

These are the NTSTAUS retuned:

00000107 87.14696533 WPipe Open OK
00000108 87.14706925 Err@ WrPIPE-Write1
00000109 87.14708741 NTStatus: STATUS_INVALID_HANDLE
00000110 87.14711926 IO nfo: FILE_OPENED
00000111 87.14714943 IO NTStatus: 0xFD7AD328
00000112 87.14718742 Err@ WrPIPE-Write2
00000113 87.14720335 NTStatus: STATUS_INVALID_HANDLE
00000114 87.14721731 IO nfo: FILE_OPENED
00000115 87.14723324 IO NTStatus: 0xFD7AD328
00000116 87.14726928 Err@ WrPIPE-Write3
00000117 87.14728520 NTStatus: STATUS_INVALID_HANDLE
00000118 87.14729945 IO nfo: FILE_OPENED
00000119 87.14731537 IO NTStatus: 0xFD7AD328
00000120 87.14740030 WPipe Closed OK

(I Updated my dbgPrint function, now it translates the ntStatus, if an ntStaus
isn’t listed, it prints the HEX value).

“Ken Cross” escribió en el mensaje news:xxxxx@ntdev…
You’re still missing the most important piece of information: What error
are you getting from ZwWriteFile?

Ken



From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Thursday, February 10, 2005 9:56 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken,

That’s what I can see,

All the writes fails

The pipe is created with the following parametes :
access mode: PIPE_ACCESS_DUPLEX
pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE| PIPE_NOWAIT

I tested this pipe with the following code on a MFC window app w/o throubles
(near the same code I use for kernel mode). works fine also with heavy load.

Thanks,
J.Angel


BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
{

BOOL fSuccess;
int i;
HANDLE hPipe;
DWORD cbWritten;
LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<10; i++)
{

hPipe = CreateFile(

lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // no security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE)
{

break;

}
// Exit if an error other than ERROR_PIPE_BUSY
occurs.
//if (GetLastError() != 231L/ERROR_PIPE_BUSY/)
//{

// return FALSE;

//}
Sleep(100);

}
if (hPipe == INVALID_HANDLE_VALUE && i == 90)

return 0;

fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG),
&cbWritten, NULL);
if (fSuccess)
{

fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG),
&cbWritten, NULL);

}
if (fSuccess)
{

fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize,
&cbWritten, NULL);

}
CloseHandle(hPipe);
return (fSuccess);

}

“Ken Cross” > escribió en
el mensaje news:xxxxx@ntdev news:xxxxx
| It’s difficult to help without complete information.
|
| Which write is failing? All of them? What are the error codes for
ntStatus
| and ioStatus.Status? How is the pipe created in the user-mode
application?
| Is the user-mode application receiving any errors? Can you write to the
| pipe with other applications?
|
| There’s a good chance that if you can answer these questions, the problem
| will become obvious.
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
mailto:xxxxx
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Wednesday, February 09, 2005 10:27 PM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| OK, I follow the suggestion and modified my source, now the pipe connects
| OK, but ZwWriteFile fails.
|
| I’ll valuate any help, Thanks
|
| J.Angel
|
|

|
| My “NEW” SOURCE:
|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
|
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i = 0;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
| RtlInitUnicodeString (&fullFileName, lpszPipename);
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
|
| &objectAttributes,
| &ioStatus,
| NULL,
| FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN,//FILE_OPEN_IF
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE )
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE)
|
| return -1;
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &offset,
| sizeof(offset),
| NULL,
| NULL
| );
|
| if (NT_SUCCESS(ntStatus))
| {
| //
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &bufSize,
| sizeof(bufSize),
| NULL,
| NULL
| );
|
| }
| if (NT_SUCCESS(ntStatus))
| {
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| pBuf,
| bufSize,
| NULL,
| NULL
| );
|
| }
| ZwClose(hPipe);
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256
http:
|
| You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’

| To unsubscribe send a blank email to xxxxx@lists.osr.com
mailto:xxxxx
|
| —
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</mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx>

Thanks Ken,

Regards,
J.Angel

“J.Angel” escribió en el mensaje news:xxxxx@ntdev…
| Sorry by the delay Ken, but I must to suspend my research due a support
request
| from a customer.
| Sorry, by dont include that data.
|
| These are the NTSTAUS retuned:
|
| 00000107 87.14696533 WPipe Open OK
| 00000108 87.14706925 Err@ WrPIPE-Write1
| 00000109 87.14708741 NTStatus: STATUS_INVALID_HANDLE
| 00000110 87.14711926 IO nfo: FILE_OPENED
| 00000111 87.14714943 IO NTStatus: 0xFD7AD328
| 00000112 87.14718742 Err@ WrPIPE-Write2
| 00000113 87.14720335 NTStatus: STATUS_INVALID_HANDLE
| 00000114 87.14721731 IO nfo: FILE_OPENED
| 00000115 87.14723324 IO NTStatus: 0xFD7AD328
| 00000116 87.14726928 Err@ WrPIPE-Write3
| 00000117 87.14728520 NTStatus: STATUS_INVALID_HANDLE
| 00000118 87.14729945 IO nfo: FILE_OPENED
| 00000119 87.14731537 IO NTStatus: 0xFD7AD328
| 00000120 87.14740030 WPipe Closed OK
|
| (I Updated my dbgPrint function, now it translates the ntStatus, if an ntStaus
| isn’t listed, it prints the HEX value).
|
|
| “Ken Cross” escribió en el mensaje news:xxxxx@ntdev…
| You’re still missing the most important piece of information: What error
| are you getting from ZwWriteFile?
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Thursday, February 10, 2005 9:56 AM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| Thanks Ken,
|
| That’s what I can see,
|
| All the writes fails
|
| The pipe is created with the following parametes :
| access mode: PIPE_ACCESS_DUPLEX
| pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE| PIPE_NOWAIT
|
| I tested this pipe with the following code on a MFC window app w/o throubles
| (near the same code I use for kernel mode). works fine also with heavy load.
|
| Thanks,
| J.Angel
|

|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
| {
|
| BOOL fSuccess;
| int i;
| HANDLE hPipe;
| DWORD cbWritten;
| LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<10; i++)
| {
|
| hPipe = CreateFile(
|
| lpszPipename, // pipe name
| GENERIC_READ | // read and write access
| GENERIC_WRITE,
| 0, // no sharing
| NULL, // no security attributes
| OPEN_EXISTING, // opens existing pipe
| 0, // default attributes
| NULL); // no template file
|
|
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE)
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (GetLastError() != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| Sleep(100);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE && i == 90)
|
| return 0;
|
| fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG),
| &cbWritten, NULL);
| if (fSuccess)
| {
|
| fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG),
| &cbWritten, NULL);
|
| }
| if (fSuccess)
| {
|
| fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize,
| &cbWritten, NULL);
|
| }
| CloseHandle(hPipe);
| return (fSuccess);
|
| }
|
|
|
| “Ken Cross” > escribió en
| el mensaje news:xxxxx@ntdev news:xxxxx
|| It’s difficult to help without complete information.
||
|| Which write is failing? All of them? What are the error codes for
| ntStatus
|| and ioStatus.Status? How is the pipe created in the user-mode
| application?
|| Is the user-mode application receiving any errors? Can you write to the
|| pipe with other applications?
||
|| There’s a good chance that if you can answer these questions, the problem
|| will become obvious.
||
|| Ken
||
||
||
||
|| From: xxxxx@lists.osr.com
| mailto:xxxxx
|| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
|| Sent: Wednesday, February 09, 2005 10:27 PM
|| To: Windows System Software Devs Interest List
|| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
||
||
|| OK, I follow the suggestion and modified my source, now the pipe connects
|| OK, but ZwWriteFile fails.
||
|| I’ll valuate any help, Thanks
||
|| J.Angel
||
||

||
|| My “NEW” SOURCE:
||
||
|| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
||
|| {
||
|| ULONG dwMode;
|| NTSTATUS ntStatus;
|| int i = 0;
|| LARGE_INTEGER duetime = {1000};
|| HANDLE hPipe;
|| ULONG cbRead;
|| ULONG cbWritten;
|| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
|| OBJECT_ATTRIBUTES objectAttributes;
|| UNICODE_STRING fullFileName;
|| IO_STATUS_BLOCK ioStatus;
|| RtlInitUnicodeString (&fullFileName, lpszPipename);
|| InitializeObjectAttributes (&objectAttributes,
|| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
|| // Try to open a named pipe; wait for it, if necessary.
|| for ( i = 0; i<90; i++)
|| {
||
|| ntStatus = ZwCreateFile (&hPipe,
||
|| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
||
|| &objectAttributes,
|| &ioStatus,
|| NULL,
|| FILE_ATTRIBUTE_NORMAL,
|| FILE_SHARE_READ | FILE_SHARE_WRITE,
|| FILE_OPEN,//FILE_OPEN_IF
|| FILE_SYNCHRONOUS_IO_NONALERT,
|| NULL,
|| 0);
||
|| // Break if the pipe handle is valid.
|| if (hPipe != INVALID_HANDLE_VALUE )
|| {
||
|| break;
||
|| }
|| // Exit if an error other than ERROR_PIPE_BUSY
|| occurs.
|| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
|| //{
||
|| // return FALSE;
||
|| //}
|| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
||
|| }
|| if (hPipe == INVALID_HANDLE_VALUE)
||
|| return -1;
||
|| ntStatus = ZwWriteFile(
||
|| hPipe,
|| NULL,
|| NULL,
|| NULL,
|| &ioStatus,
|| &offset,
|| sizeof(offset),
|| NULL,
|| NULL
|| );
||
|| if (NT_SUCCESS(ntStatus))
|| {
|| //
||
|| ntStatus = ZwWriteFile(
||
|| hPipe,
|| NULL,
|| NULL,
|| NULL,
|| &ioStatus,
|| &bufSize,
|| sizeof(bufSize),
|| NULL,
|| NULL
|| );
||
|| }
|| if (NT_SUCCESS(ntStatus))
|| {
||
|| ntStatus = ZwWriteFile(
||
|| hPipe,
|| NULL,
|| NULL,
|| NULL,
|| &ioStatus,
|| pBuf,
|| bufSize,
|| NULL,
|| NULL
|| );
||
|| }
|| ZwClose(hPipe);
|| return ntStatus;
||
|| }
||
|| —
|| Questions? First check the Kernel Driver FAQ at
|| http://www.osronline.com/article.cfm?id=256
| http:
||
|| You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
|
|| To unsubscribe send a blank email to xxxxx@lists.osr.com
| mailto:xxxxx
||
|| —
| 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
|
|
|
|</mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx>

JA:

It’s a little hard to see exactly what’s going on, but are you checking
NTStatus after the ZwCreateFile? FWIW, here’s the code I use, which works
fine:

RtlInitUnicodeString( &sPipeName, L"\??\pipe\" MY_PIPENAME );

InitializeObjectAttributes(
&objAttributes,
&sPipeName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
0,
NULL );

for( iRetry=0; iRetry <= 3; iRetry++ )
{
LARGE_INTEGER iDelay;

//
// Open the pipe. ZwCreateFile is used instead of FltCreateFile
// because FltCreateFile starts with instances attached below our
// driver, and we know that it won’t be found there. Note that
// callers of ZwCreateFile must be running at IRQL = PASSIVE_LEVEL.
//
status = ZwCreateFile(
&PipeHandle, // File handle
FILE_WRITE_DATA | SYNCHRONIZE, // Desired access
&objAttributes, // Attributes
&IoSb, // IO Status Block
NULL, // Allocation size
0, // File attributes
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, //
File share
FILE_OPEN, // Create disposition (must exist)
FILE_NON_DIRECTORY_FILE,// Create options
NULL, // EA buffer
0 ); // EA size

if( STATUS_PIPE_NOT_AVAILABLE != status )
break;

//
// If a pipe is not available, pause a random period of time from
100 to 500 ms.
//
if( iRetry == 0 )
{
LARGE_INTEGER iSeed;
KeQuerySystemTime( &iSeed );
iDelay.QuadPart = DELAY_ONE_MILLISECOND * ( 100 + (
RtlRandomEx( &iSeed.LowPart ) % 400 ) );
}

KeDelayExecutionThread( KernelMode, FALSE, &iDelay );
}

if( !NT_SUCCESS(status) )
{
DoTraceMessage( FKDEBUG_ANY, “PIPE: Failed to open %wZ (retry
count=%d): %!STATUS!”,
&sPipeName, iRetry, status );
return status;
}

HTH,
Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Sunday, February 20, 2005 5:04 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Sorry by the delay Ken, but I must to suspend my research due a support
request
from a customer.
Sorry, by dont include that data.

These are the NTSTAUS retuned:

00000107 87.14696533 WPipe Open OK
00000108 87.14706925 Err@ WrPIPE-Write1
00000109 87.14708741 NTStatus: STATUS_INVALID_HANDLE
00000110 87.14711926 IO nfo: FILE_OPENED
00000111 87.14714943 IO NTStatus: 0xFD7AD328
00000112 87.14718742 Err@ WrPIPE-Write2
00000113 87.14720335 NTStatus: STATUS_INVALID_HANDLE
00000114 87.14721731 IO nfo: FILE_OPENED
00000115 87.14723324 IO NTStatus: 0xFD7AD328
00000116 87.14726928 Err@ WrPIPE-Write3
00000117 87.14728520 NTStatus: STATUS_INVALID_HANDLE
00000118 87.14729945 IO nfo: FILE_OPENED
00000119 87.14731537 IO NTStatus: 0xFD7AD328
00000120 87.14740030 WPipe Closed OK

(I Updated my dbgPrint function, now it translates the ntStatus, if an
ntStaus
isn’t listed, it prints the HEX value).

“Ken Cross” escribi? en el mensaje news:xxxxx@ntdev…
You’re still missing the most important piece of information: What error
are you getting from ZwWriteFile?

Ken



From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Thursday, February 10, 2005 9:56 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken,

That’s what I can see,

All the writes fails

The pipe is created with the following parametes :
access mode: PIPE_ACCESS_DUPLEX
pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE| PIPE_NOWAIT

I tested this pipe with the following code on a MFC window app w/o throubles
(near the same code I use for kernel mode). works fine also with heavy load.

Thanks,
J.Angel


BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
{

BOOL fSuccess;
int i;
HANDLE hPipe;
DWORD cbWritten;
LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<10; i++)
{

hPipe = CreateFile(

lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // no security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE)
{

break;

}
// Exit if an error other than ERROR_PIPE_BUSY
occurs.
//if (GetLastError() != 231L/ERROR_PIPE_BUSY/)
//{

// return FALSE;

//}
Sleep(100);

}
if (hPipe == INVALID_HANDLE_VALUE && i == 90)

return 0;

fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG),
&cbWritten, NULL);
if (fSuccess)
{

fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG),
&cbWritten, NULL);

}
if (fSuccess)
{

fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize,
&cbWritten, NULL);

}
CloseHandle(hPipe);
return (fSuccess);

}

“Ken Cross” > escribi? en
el mensaje news:xxxxx@ntdev news:xxxxx
| It’s difficult to help without complete information.
|
| Which write is failing? All of them? What are the error codes for
ntStatus
| and ioStatus.Status? How is the pipe created in the user-mode
application?
| Is the user-mode application receiving any errors? Can you write to the
| pipe with other applications?
|
| There’s a good chance that if you can answer these questions, the problem
| will become obvious.
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
mailto:xxxxx
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Wednesday, February 09, 2005 10:27 PM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| OK, I follow the suggestion and modified my source, now the pipe connects
| OK, but ZwWriteFile fails.
|
| I’ll valuate any help, Thanks
|
| J.Angel
|
|

|
| My “NEW” SOURCE:
|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
|
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i = 0;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
| RtlInitUnicodeString (&fullFileName, lpszPipename);
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
|
| &objectAttributes,
| &ioStatus,
| NULL,
| FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN,//FILE_OPEN_IF
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE )
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE)
|
| return -1;
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &offset,
| sizeof(offset),
| NULL,
| NULL
| );
|
| if (NT_SUCCESS(ntStatus))
| {
| //
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &bufSize,
| sizeof(bufSize),
| NULL,
| NULL
| );
|
| }
| if (NT_SUCCESS(ntStatus))
| {
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| pBuf,
| bufSize,
| NULL,
| NULL
| );
|
| }
| ZwClose(hPipe);
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256
http:
|
| You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’

| To unsubscribe send a blank email to xxxxx@lists.osr.com
mailto:xxxxx
|
| —
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</mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx>

Thanks Ken, I modified my code using the code provided, also now I catch the NTSTATUS, just before ZwCreateFile, this was the result:

RAMDISK:
Windows 2000 Ramdisk Driver - Version 1.0 built on Feb 21 2005 21:12:04
RAMDISK:
Creating drive letter = \DosDevices\J:
WPIPE-FileOpen
NTStatus: 0xC000003B <— this is the ststus returned by ZwCreateFile, I found no reference on this code.
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0

Err@ WrPIPE-Write1
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write2
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write3
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
WPipe Closed

Regards,
J.Angel


“Ken Cross” escribi? en el mensaje news:xxxxx@ntdev…
JA:

It’s a little hard to see exactly what’s going on, but are you checking
NTStatus after the ZwCreateFile? FWIW, here’s the code I use, which works
fine:

RtlInitUnicodeString( &sPipeName, L"\??\pipe\" MY_PIPENAME );

InitializeObjectAttributes(
&objAttributes,
&sPipeName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
0,
NULL );

for( iRetry=0; iRetry <= 3; iRetry++ )
{
LARGE_INTEGER iDelay;

//
// Open the pipe. ZwCreateFile is used instead of FltCreateFile
// because FltCreateFile starts with instances attached below our
// driver, and we know that it won’t be found there. Note that
// callers of ZwCreateFile must be running at IRQL = PASSIVE_LEVEL.
//
status = ZwCreateFile(
&PipeHandle, // File handle
FILE_WRITE_DATA | SYNCHRONIZE, // Desired access
&objAttributes, // Attributes
&IoSb, // IO Status Block
NULL, // Allocation size
0, // File attributes
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, //
File share
FILE_OPEN, // Create disposition (must exist)
FILE_NON_DIRECTORY_FILE,// Create options
NULL, // EA buffer
0 ); // EA size

if( STATUS_PIPE_NOT_AVAILABLE != status )
break;

//
// If a pipe is not available, pause a random period of time from
100 to 500 ms.
//
if( iRetry == 0 )
{
LARGE_INTEGER iSeed;
KeQuerySystemTime( &iSeed );
iDelay.QuadPart = DELAY_ONE_MILLISECOND * ( 100 + (
RtlRandomEx( &iSeed.LowPart ) % 400 ) );
}

KeDelayExecutionThread( KernelMode, FALSE, &iDelay );
}

if( !NT_SUCCESS(status) )
{
DoTraceMessage( FKDEBUG_ANY, “PIPE: Failed to open %wZ (retry
count=%d): %!STATUS!”,
&sPipeName, iRetry, status );
return status;
}

HTH,
Ken

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Sunday, February 20, 2005 5:04 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Sorry by the delay Ken, but I must to suspend my research due a support
request
from a customer.
Sorry, by dont include that data.

These are the NTSTAUS retuned:

00000107 87.14696533 WPipe Open OK
00000108 87.14706925 Err@ WrPIPE-Write1
00000109 87.14708741 NTStatus: STATUS_INVALID_HANDLE
00000110 87.14711926 IO nfo: FILE_OPENED
00000111 87.14714943 IO NTStatus: 0xFD7AD328
00000112 87.14718742 Err@ WrPIPE-Write2
00000113 87.14720335 NTStatus: STATUS_INVALID_HANDLE
00000114 87.14721731 IO nfo: FILE_OPENED
00000115 87.14723324 IO NTStatus: 0xFD7AD328
00000116 87.14726928 Err@ WrPIPE-Write3
00000117 87.14728520 NTStatus: STATUS_INVALID_HANDLE
00000118 87.14729945 IO nfo: FILE_OPENED
00000119 87.14731537 IO NTStatus: 0xFD7AD328
00000120 87.14740030 WPipe Closed OK

(I Updated my dbgPrint function, now it translates the ntStatus, if an
ntStaus
isn’t listed, it prints the HEX value).

“Ken Cross” escribi? en el mensaje news:xxxxx@ntdev…
You’re still missing the most important piece of information: What error
are you getting from ZwWriteFile?

Ken



From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Thursday, February 10, 2005 9:56 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken,

That’s what I can see,

All the writes fails

The pipe is created with the following parametes :
access mode: PIPE_ACCESS_DUPLEX
pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE| PIPE_NOWAIT

I tested this pipe with the following code on a MFC window app w/o throubles
(near the same code I use for kernel mode). works fine also with heavy load.

Thanks,
J.Angel


BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
{

BOOL fSuccess;
int i;
HANDLE hPipe;
DWORD cbWritten;
LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<10; i++)
{

hPipe = CreateFile(

lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // no security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE)
{

break;

}
// Exit if an error other than ERROR_PIPE_BUSY
occurs.
//if (GetLastError() != 231L/ERROR_PIPE_BUSY/)
//{

// return FALSE;

//}
Sleep(100);

}
if (hPipe == INVALID_HANDLE_VALUE && i == 90)

return 0;

fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG),
&cbWritten, NULL);
if (fSuccess)
{

fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG),
&cbWritten, NULL);

}
if (fSuccess)
{

fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize,
&cbWritten, NULL);

}
CloseHandle(hPipe);
return (fSuccess);

}

“Ken Cross” > escribi? en
el mensaje news:xxxxx@ntdev news:xxxxx
| It’s difficult to help without complete information.
|
| Which write is failing? All of them? What are the error codes for
ntStatus
| and ioStatus.Status? How is the pipe created in the user-mode
application?
| Is the user-mode application receiving any errors? Can you write to the
| pipe with other applications?
|
| There’s a good chance that if you can answer these questions, the problem
| will become obvious.
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
mailto:xxxxx
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Wednesday, February 09, 2005 10:27 PM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| OK, I follow the suggestion and modified my source, now the pipe connects
| OK, but ZwWriteFile fails.
|
| I’ll valuate any help, Thanks
|
| J.Angel
|
|

|
| My “NEW” SOURCE:
|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
|
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i = 0;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
| RtlInitUnicodeString (&fullFileName, lpszPipename);
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
|
| &objectAttributes,
| &ioStatus,
| NULL,
| FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN,//FILE_OPEN_IF
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE )
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE)
|
| return -1;
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &offset,
| sizeof(offset),
| NULL,
| NULL
| );
|
| if (NT_SUCCESS(ntStatus))
| {
| //
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &bufSize,
| sizeof(bufSize),
| NULL,
| NULL
| );
|
| }
| if (NT_SUCCESS(ntStatus))
| {
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| pBuf,
| bufSize,
| NULL,
| NULL
| );
|
| }
| ZwClose(hPipe);
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256
http:
|
| You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’

| To unsubscribe send a blank email to xxxxx@lists.osr.com
mailto:xxxxx
|
| —
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</mailto:xxxxx></http:></mailto:xxxxx></news:xxxxx>

This is in ntstatus.h:

#define STATUS_OBJECT_PATH_SYNTAX_BAD ((NTSTATUS)0xC000003BL)

For whatever reason the driver you are calling does not like this request.

Regards,

Tony

Tony Mason

Consulting Partner

OSR Open Systems Resources, Inc.

http://www.osr.com http:</http:>


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Monday, February 21, 2005 9:36 PM
To: ntdev redirect
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken, I modified my code using the code provided, also now I catch the NTSTATUS, just before ZwCreateFile, this was the result:

RAMDISK:
Windows 2000 Ramdisk Driver - Version 1.0 built on Feb 21 2005 21:12:04
RAMDISK:
Creating drive letter = \DosDevices\J:
WPIPE-FileOpen
NTStatus: 0xC000003B <— this is the ststus returned by ZwCreateFile, I found no reference on this code.
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0

Err@ WrPIPE-Write1
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write2
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write3
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
WPipe Closed

Regards,

J.Angel


“Ken Cross” > escribi? en el mensaje news:xxxxx@ntdev news:xxxxx

JA:

It’s a little hard to see exactly what’s going on, but are you checking
NTStatus after the ZwCreateFile? FWIW, here’s the code I use, which works
fine:

RtlInitUnicodeString( &sPipeName, L"\??\pipe\ <file:> " MY_PIPENAME );

InitializeObjectAttributes(
&objAttributes,
&sPipeName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
0,
NULL );

for( iRetry=0; iRetry <= 3; iRetry++ )
{
LARGE_INTEGER iDelay;

//
// Open the pipe. ZwCreateFile is used instead of FltCreateFile
// because FltCreateFile starts with instances attached below our
// driver, and we know that it won’t be found there. Note that
// callers of ZwCreateFile must be running at IRQL = PASSIVE_LEVEL.
//
status = ZwCreateFile(
&PipeHandle, // File handle
FILE_WRITE_DATA | SYNCHRONIZE, // Desired access
&objAttributes, // Attributes
&IoSb, // IO Status Block
NULL, // Allocation size
0, // File attributes
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, //
File share
FILE_OPEN, // Create disposition (must exist)
FILE_NON_DIRECTORY_FILE,// Create options
NULL, // EA buffer
0 ); // EA size

if( STATUS_PIPE_NOT_AVAILABLE != status )
break;

//
// If a pipe is not available, pause a random period of time from
100 to 500 ms.
//
if( iRetry == 0 )
{
LARGE_INTEGER iSeed;
KeQuerySystemTime( &iSeed );
iDelay.QuadPart = DELAY_ONE_MILLISECOND * ( 100 + (
RtlRandomEx( &iSeed.LowPart ) % 400 ) );
}

KeDelayExecutionThread( KernelMode, FALSE, &iDelay );
}

if( !NT_SUCCESS(status) )
{
DoTraceMessage( FKDEBUG_ANY, “PIPE: Failed to open %wZ (retry
count=%d): %!STATUS!”,
&sPipeName, iRetry, status );
return status;
}

HTH,
Ken

-----Original Message-----
From: xxxxx@lists.osr.com mailto:xxxxx
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Sunday, February 20, 2005 5:04 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Sorry by the delay Ken, but I must to suspend my research due a support
request
from a customer.
Sorry, by dont include that data.

These are the NTSTAUS retuned:

00000107 87.14696533 WPipe Open OK
00000108 87.14706925 Err@ WrPIPE-Write1
00000109 87.14708741 NTStatus: STATUS_INVALID_HANDLE
00000110 87.14711926 IO nfo: FILE_OPENED
00000111 87.14714943 IO NTStatus: 0xFD7AD328
00000112 87.14718742 Err@ WrPIPE-Write2
00000113 87.14720335 NTStatus: STATUS_INVALID_HANDLE
00000114 87.14721731 IO nfo: FILE_OPENED
00000115 87.14723324 IO NTStatus: 0xFD7AD328
00000116 87.14726928 Err@ WrPIPE-Write3
00000117 87.14728520 NTStatus: STATUS_INVALID_HANDLE
00000118 87.14729945 IO nfo: FILE_OPENED
00000119 87.14731537 IO NTStatus: 0xFD7AD328
00000120 87.14740030 WPipe Closed OK

(I Updated my dbgPrint function, now it translates the ntStatus, if an
ntStaus
isn’t listed, it prints the HEX value).

“Ken Cross” > escribi? en el mensaje news:xxxxx@ntdev news:xxxxx
You’re still missing the most important piece of information: What error
are you getting from ZwWriteFile?

Ken

________________________________

From: xxxxx@lists.osr.com mailto:xxxxx
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Thursday, February 10, 2005 9:56 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken,

That’s what I can see,

All the writes fails

The pipe is created with the following parametes :
access mode: PIPE_ACCESS_DUPLEX
pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE| PIPE_NOWAIT

I tested this pipe with the following code on a MFC window app w/o throubles
(near the same code I use for kernel mode). works fine also with heavy load.

Thanks,
J.Angel
________________________________

BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
{

BOOL fSuccess;
int i;
HANDLE hPipe;
DWORD cbWritten;
LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<10; i++)
{

hPipe = CreateFile(

lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // no security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE)
{

break;

}
// Exit if an error other than ERROR_PIPE_BUSY
occurs.
//if (GetLastError() != 231L/ERROR_PIPE_BUSY/)
//{

// return FALSE;

//}
Sleep(100);

}
if (hPipe == INVALID_HANDLE_VALUE && i == 90)

return 0;

fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG),
&cbWritten, NULL);
if (fSuccess)
{

fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG),
&cbWritten, NULL);

}
if (fSuccess)
{

fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize,
&cbWritten, NULL);

}
CloseHandle(hPipe);
return (fSuccess);

}

“Ken Cross” mailto:xxxxx > > escribi? en
el mensaje news:xxxxx@ntdev news:xxxxx news:xxxxx > …
| It’s difficult to help without complete information.
|
| Which write is failing? All of them? What are the error codes for
ntStatus
| and ioStatus.Status? How is the pipe created in the user-mode
application?
| Is the user-mode application receiving any errors? Can you write to the
| pipe with other applications?
|
| There’s a good chance that if you can answer these questions, the problem
| will become obvious.
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com mailto:xxxxx
mailto:xxxxx >
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Wednesday, February 09, 2005 10:27 PM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| OK, I follow the suggestion and modified my source, now the pipe connects
| OK, but ZwWriteFile fails.
|
| I’ll valuate any help, Thanks
|
| J.Angel
|
|

|
| My “NEW” SOURCE:
|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
|
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i = 0;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
| RtlInitUnicodeString (&fullFileName, lpszPipename);
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
|
| &objectAttributes,
| &ioStatus,
| NULL,
| FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN,//FILE_OPEN_IF
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE )
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE)
|
| return -1;
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &offset,
| sizeof(offset),
| NULL,
| NULL
| );
|
| if (NT_SUCCESS(ntStatus))
| {
| //
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &bufSize,
| sizeof(bufSize),
| NULL,
| NULL
| );
|
| }
| if (NT_SUCCESS(ntStatus))
| {
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| pBuf,
| bufSize,
| NULL,
| NULL
| );
|
| }
| ZwClose(hPipe);
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256 http:
http: >
|
| You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’

| To unsubscribe send a blank email to xxxxx@lists.osr.com mailto:xxxxx
mailto:xxxxx >
|
| —
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 http:

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


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

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


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</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></http:></mailto:xxxxx></mailto:xxxxx></http:></http:></mailto:xxxxx></mailto:xxxxx></news:xxxxx></news:xxxxx></mailto:xxxxx></mailto:xxxxx></news:xxxxx></mailto:xxxxx></file:></news:xxxxx>

winerror -s 0xc000003b
161 ERROR_BAD_PATHNAME <–> c000003b STATUS_OBJECT_PATH_SYNTAX_BAD

-p


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Monday, February 21, 2005 6:36 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken, I modified my code using the code provided, also now I catch the NTSTATUS, just before ZwCreateFile, this was the result:

RAMDISK:
Windows 2000 Ramdisk Driver - Version 1.0 built on Feb 21 2005 21:12:04
RAMDISK:
Creating drive letter = \DosDevices\J:
WPIPE-FileOpen
NTStatus: 0xC000003B <— this is the ststus returned by ZwCreateFile, I found no reference on this code.
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0

Err@ WrPIPE-Write1
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write2
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write3
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
WPipe Closed

Regards,
J.Angel


“Ken Cross” > escribi? en el mensaje news:xxxxx@ntdev news:xxxxx
JA:

It’s a little hard to see exactly what’s going on, but are you checking
NTStatus after the ZwCreateFile? FWIW, here’s the code I use, which works
fine:

RtlInitUnicodeString( &sPipeName, L"\??\pipe\ <file:> " MY_PIPENAME );

InitializeObjectAttributes(
&objAttributes,
&sPipeName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
0,
NULL );

for( iRetry=0; iRetry <= 3; iRetry++ )
{
LARGE_INTEGER iDelay;

//
// Open the pipe. ZwCreateFile is used instead of FltCreateFile
// because FltCreateFile starts with instances attached below our
// driver, and we know that it won’t be found there. Note that
// callers of ZwCreateFile must be running at IRQL = PASSIVE_LEVEL.
//
status = ZwCreateFile(
&PipeHandle, // File handle
FILE_WRITE_DATA | SYNCHRONIZE, // Desired access
&objAttributes, // Attributes
&IoSb, // IO Status Block
NULL, // Allocation size
0, // File attributes
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, //
File share
FILE_OPEN, // Create disposition (must exist)
FILE_NON_DIRECTORY_FILE,// Create options
NULL, // EA buffer
0 ); // EA size

if( STATUS_PIPE_NOT_AVAILABLE != status )
break;

//
// If a pipe is not available, pause a random period of time from
100 to 500 ms.
//
if( iRetry == 0 )
{
LARGE_INTEGER iSeed;
KeQuerySystemTime( &iSeed );
iDelay.QuadPart = DELAY_ONE_MILLISECOND * ( 100 + (
RtlRandomEx( &iSeed.LowPart ) % 400 ) );
}

KeDelayExecutionThread( KernelMode, FALSE, &iDelay );
}

if( !NT_SUCCESS(status) )
{
DoTraceMessage( FKDEBUG_ANY, “PIPE: Failed to open %wZ (retry
count=%d): %!STATUS!”,
&sPipeName, iRetry, status );
return status;
}

HTH,
Ken

-----Original Message-----
From: xxxxx@lists.osr.com mailto:xxxxx
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Sunday, February 20, 2005 5:04 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Sorry by the delay Ken, but I must to suspend my research due a support
request
from a customer.
Sorry, by dont include that data.

These are the NTSTAUS retuned:

00000107 87.14696533 WPipe Open OK
00000108 87.14706925 Err@ WrPIPE-Write1
00000109 87.14708741 NTStatus: STATUS_INVALID_HANDLE
00000110 87.14711926 IO nfo: FILE_OPENED
00000111 87.14714943 IO NTStatus: 0xFD7AD328
00000112 87.14718742 Err@ WrPIPE-Write2
00000113 87.14720335 NTStatus: STATUS_INVALID_HANDLE
00000114 87.14721731 IO nfo: FILE_OPENED
00000115 87.14723324 IO NTStatus: 0xFD7AD328
00000116 87.14726928 Err@ WrPIPE-Write3
00000117 87.14728520 NTStatus: STATUS_INVALID_HANDLE
00000118 87.14729945 IO nfo: FILE_OPENED
00000119 87.14731537 IO NTStatus: 0xFD7AD328
00000120 87.14740030 WPipe Closed OK

(I Updated my dbgPrint function, now it translates the ntStatus, if an
ntStaus
isn’t listed, it prints the HEX value).

“Ken Cross” > escribi? en el mensaje news:xxxxx@ntdev news:xxxxx
You’re still missing the most important piece of information: What error
are you getting from ZwWriteFile?

Ken



From: xxxxx@lists.osr.com mailto:xxxxx
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Thursday, February 10, 2005 9:56 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken,

That’s what I can see,

All the writes fails

The pipe is created with the following parametes :
access mode: PIPE_ACCESS_DUPLEX
pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE| PIPE_NOWAIT

I tested this pipe with the following code on a MFC window app w/o throubles
(near the same code I use for kernel mode). works fine also with heavy load.

Thanks,
J.Angel


BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
{

BOOL fSuccess;
int i;
HANDLE hPipe;
DWORD cbWritten;
LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<10; i++)
{

hPipe = CreateFile(

lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // no security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE)
{

break;

}
// Exit if an error other than ERROR_PIPE_BUSY
occurs.
//if (GetLastError() != 231L/ERROR_PIPE_BUSY/)
//{

// return FALSE;

//}
Sleep(100);

}
if (hPipe == INVALID_HANDLE_VALUE && i == 90)

return 0;

fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG),
&cbWritten, NULL);
if (fSuccess)
{

fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG),
&cbWritten, NULL);

}
if (fSuccess)
{

fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize,
&cbWritten, NULL);

}
CloseHandle(hPipe);
return (fSuccess);

}

“Ken Cross” mailto:xxxxx > > escribi? en
el mensaje news:xxxxx@ntdev news:xxxxx news:xxxxx > …
| It’s difficult to help without complete information.
|
| Which write is failing? All of them? What are the error codes for
ntStatus
| and ioStatus.Status? How is the pipe created in the user-mode
application?
| Is the user-mode application receiving any errors? Can you write to the
| pipe with other applications?
|
| There’s a good chance that if you can answer these questions, the problem
| will become obvious.
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com mailto:xxxxx
mailto:xxxxx >
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Wednesday, February 09, 2005 10:27 PM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie
|
|
| OK, I follow the suggestion and modified my source, now the pipe connects
| OK, but ZwWriteFile fails.
|
| I’ll valuate any help, Thanks
|
| J.Angel
|
|

|
| My “NEW” SOURCE:
|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
|
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i = 0;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
| RtlInitUnicodeString (&fullFileName, lpszPipename);
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
|
| &objectAttributes,
| &ioStatus,
| NULL,
| FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN,//FILE_OPEN_IF
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE )
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE)
|
| return -1;
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &offset,
| sizeof(offset),
| NULL,
| NULL
| );
|
| if (NT_SUCCESS(ntStatus))
| {
| //
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &bufSize,
| sizeof(bufSize),
| NULL,
| NULL
| );
|
| }
| if (NT_SUCCESS(ntStatus))
| {
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| pBuf,
| bufSize,
| NULL,
| NULL
| );
|
| }
| ZwClose(hPipe);
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256 http:
http: >
|
| You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’

| To unsubscribe send a blank email to xxxxx@lists.osr.com mailto:xxxxx
mailto:xxxxx >
|
| —
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256 http:

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


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

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


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</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></http:></mailto:xxxxx></mailto:xxxxx></http:></http:></mailto:xxxxx></mailto:xxxxx></news:xxxxx></news:xxxxx></mailto:xxxxx></mailto:xxxxx></news:xxxxx></mailto:xxxxx></file:></news:xxxxx>

JA:

STATUS_OBJECT_PATH_SYNTAX_BAD indicates that there’s something wrong with
the string you’re using for the name of the pipe.

Check your string and make sure it is something like
L"\??\pipe\RamDrvOut". Print it in your debug output to be sure.

Ken


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Monday, February 21, 2005 9:36 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken, I modified my code using the code provided, also now I catch the
NTSTATUS, just before ZwCreateFile, this was the result:

RAMDISK:
Windows 2000 Ramdisk Driver - Version 1.0 built on Feb 21 2005 21:12:04
RAMDISK:
Creating drive letter = \DosDevices\J:
WPIPE-FileOpen
NTStatus: 0xC000003B <— this is the ststus returned by ZwCreateFile, I
found no reference on this code.
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0

Err@ WrPIPE-Write1
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write2
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write3
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
WPipe Closed

Regards,
J.Angel


“Ken Cross” >
escribi? en el mensaje news:xxxxx@ntdev news:xxxxx
JA:

It’s a little hard to see exactly what’s going on, but are you
checking
NTStatus after the ZwCreateFile? FWIW, here’s the code I use, which
works
fine:

RtlInitUnicodeString( &sPipeName, L"\??\pipe\
<file:> " MY_PIPENAME );

InitializeObjectAttributes(
&objAttributes,
&sPipeName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
0,
NULL );

for( iRetry=0; iRetry <= 3; iRetry++ )
{
LARGE_INTEGER iDelay;

//
// Open the pipe. ZwCreateFile is used instead of FltCreateFile
// because FltCreateFile starts with instances attached below our
// driver, and we know that it won’t be found there. Note that
// callers of ZwCreateFile must be running at IRQL = PASSIVE_LEVEL.
//
status = ZwCreateFile(
&PipeHandle, // File handle
FILE_WRITE_DATA | SYNCHRONIZE, // Desired access
&objAttributes, // Attributes
&IoSb, // IO Status Block
NULL, // Allocation size
0, // File attributes
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, //
File share
FILE_OPEN, // Create disposition (must exist)
FILE_NON_DIRECTORY_FILE,// Create options
NULL, // EA buffer
0 ); // EA size

if( STATUS_PIPE_NOT_AVAILABLE != status )
break;

//
// If a pipe is not available, pause a random period of time from
100 to 500 ms.
//
if( iRetry == 0 )
{
LARGE_INTEGER iSeed;
KeQuerySystemTime( &iSeed );
iDelay.QuadPart = DELAY_ONE_MILLISECOND * ( 100 + (
RtlRandomEx( &iSeed.LowPart ) % 400 ) );
}

KeDelayExecutionThread( KernelMode, FALSE, &iDelay );
}

if( !NT_SUCCESS(status) )
{
DoTraceMessage( FKDEBUG_ANY, “PIPE: Failed to open %wZ (retry
count=%d): %!STATUS!”,
&sPipeName, iRetry, status );
return status;
}

HTH,
Ken

-----Original Message-----
From: xxxxx@lists.osr.com
mailto:xxxxx
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Sunday, February 20, 2005 5:04 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Sorry by the delay Ken, but I must to suspend my research due a
support
request
from a customer.
Sorry, by dont include that data.

These are the NTSTAUS retuned:

00000107 87.14696533 WPipe Open OK
00000108 87.14706925 Err@ WrPIPE-Write1
00000109 87.14708741 NTStatus: STATUS_INVALID_HANDLE
00000110 87.14711926 IO nfo: FILE_OPENED
00000111 87.14714943 IO NTStatus: 0xFD7AD328
00000112 87.14718742 Err@ WrPIPE-Write2
00000113 87.14720335 NTStatus: STATUS_INVALID_HANDLE
00000114 87.14721731 IO nfo: FILE_OPENED
00000115 87.14723324 IO NTStatus: 0xFD7AD328
00000116 87.14726928 Err@ WrPIPE-Write3
00000117 87.14728520 NTStatus: STATUS_INVALID_HANDLE
00000118 87.14729945 IO nfo: FILE_OPENED
00000119 87.14731537 IO NTStatus: 0xFD7AD328
00000120 87.14740030 WPipe Closed OK

(I Updated my dbgPrint function, now it translates the ntStatus, if
an
ntStaus
isn’t listed, it prints the HEX value).

“Ken Cross” >
escribi? en el mensaje news:xxxxx@ntdev news:xxxxx
You’re still missing the most important piece of information: What
error
are you getting from ZwWriteFile?

Ken

________________________________

From: xxxxx@lists.osr.com
mailto:xxxxx
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Thursday, February 10, 2005 9:56 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken,

That’s what I can see,

All the writes fails

The pipe is created with the following parametes :
access mode: PIPE_ACCESS_DUPLEX
pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE|
PIPE_NOWAIT

I tested this pipe with the following code on a MFC window app w/o
throubles
(near the same code I use for kernel mode). works fine also with
heavy load.

Thanks,
J.Angel
________________________________

BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
{

BOOL fSuccess;
int i;
HANDLE hPipe;
DWORD cbWritten;
LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<10; i++)
{

hPipe = CreateFile(

lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // no security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE)
{

break;

}
// Exit if an error other than ERROR_PIPE_BUSY
occurs.
//if (GetLastError() != 231L/ERROR_PIPE_BUSY/)
//{

// return FALSE;

//}
Sleep(100);

}
if (hPipe == INVALID_HANDLE_VALUE && i == 90)

return 0;

fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG),
&cbWritten, NULL);
if (fSuccess)
{

fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG),
&cbWritten, NULL);

}
if (fSuccess)
{

fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize,
&cbWritten, NULL);

}
CloseHandle(hPipe);
return (fSuccess);

}

“Ken Cross”
mailto:xxxxx > > escribi? en
el mensaje news:xxxxx@ntdev news:xxxxx news:xxxxxnews:xxxxx > …
| It’s difficult to help without complete information.
|
| Which write is failing? All of them? What are the error codes
for
ntStatus
| and ioStatus.Status? How is the pipe created in the user-mode
application?
| Is the user-mode application receiving any errors? Can you write
to the
| pipe with other applications?
|
| There’s a good chance that if you can answer these questions, the
problem
| will become obvious.
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
mailto:xxxxx
mailto:xxxxxmailto:xxxxx >
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Wednesday, February 09, 2005 10:27 PM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed -
Newbie
|
|
| OK, I follow the suggestion and modified my source, now the pipe
connects
| OK, but ZwWriteFile fails.
|
| I’ll valuate any help, Thanks
|
| J.Angel
|
|

|
| My “NEW” SOURCE:
|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
|
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i = 0;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
| RtlInitUnicodeString (&fullFileName, lpszPipename);
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
|
| &objectAttributes,
| &ioStatus,
| NULL,
| FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN,//FILE_OPEN_IF
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE )
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE)
|
| return -1;
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &offset,
| sizeof(offset),
| NULL,
| NULL
| );
|
| if (NT_SUCCESS(ntStatus))
| {
| //
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &bufSize,
| sizeof(bufSize),
| NULL,
| NULL
| );
|
| }
| if (NT_SUCCESS(ntStatus))
| {
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| pBuf,
| bufSize,
| NULL,
| NULL
| );
|
| }
| ZwClose(hPipe);
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256
http:
http:http: >
|
| You are currently subscribed to ntdev as: unknown lmsubst tag
argument: ‘’

| To unsubscribe send a blank email to
xxxxx@lists.osr.com mailto:xxxxx
mailto:xxxxxmailto:xxxxx >
|
| —
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
http:

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


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

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


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</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></http:></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></http:></http:></http:></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></news:xxxxx></news:xxxxx></news:xxxxx></mailto:xxxxx></mailto:xxxxx></news:xxxxx></mailto:xxxxx></file:></news:xxxxx>

OK, thanks Ken, now the PIPE is working as I designed, mi mistake was ever at
the same line of text, the pipe path, I declared it as “////??//pipe/RamDrvOut”
because followed the Path rules of the ActiveDirectory (big mistake), now it
works fine. W/O Issues.

Thanks again.
:slight_smile: (Y)

J.A. Acosta.


“Ken Cross” escribió en el mensaje news:xxxxx@ntdev…
JA:

STATUS_OBJECT_PATH_SYNTAX_BAD indicates that there’s something wrong with
the string you’re using for the name of the pipe.

Check your string and make sure it is something like
L"\??\pipe\RamDrvOut". Print it in your debug output to be sure.

Ken



From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Monday, February 21, 2005 9:36 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken, I modified my code using the code provided, also now I catch the
NTSTATUS, just before ZwCreateFile, this was the result:

RAMDISK:
Windows 2000 Ramdisk Driver - Version 1.0 built on Feb 21 2005 21:12:04
RAMDISK:
Creating drive letter = \DosDevices\J:
WPIPE-FileOpen
NTStatus: 0xC000003B <— this is the ststus returned by ZwCreateFile, I
found no reference on this code.
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0

Err@ WrPIPE-Write1
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write2
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
Err@ WrPIPE-Write3
NTStatus: STATUS_INVALID_HANDLE
IO nfo: FILE_SUPERSEDED
IO NTStatus: 0x0
WPipe Closed

Regards,
J.Angel


“Ken Cross” >
escribió en el mensaje news:xxxxx@ntdev news:xxxxx
JA:

It’s a little hard to see exactly what’s going on, but are you
checking
NTStatus after the ZwCreateFile? FWIW, here’s the code I use, which
works
fine:

RtlInitUnicodeString( &sPipeName, L"\??\pipe\
<file:> " MY_PIPENAME );

InitializeObjectAttributes(
&objAttributes,
&sPipeName,
OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
0,
NULL );

for( iRetry=0; iRetry <= 3; iRetry++ )
{
LARGE_INTEGER iDelay;

//
// Open the pipe. ZwCreateFile is used instead of FltCreateFile
// because FltCreateFile starts with instances attached below our
// driver, and we know that it won’t be found there. Note that
// callers of ZwCreateFile must be running at IRQL = PASSIVE_LEVEL.
//
status = ZwCreateFile(
&PipeHandle, // File handle
FILE_WRITE_DATA | SYNCHRONIZE, // Desired access
&objAttributes, // Attributes
&IoSb, // IO Status Block
NULL, // Allocation size
0, // File attributes
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, //
File share
FILE_OPEN, // Create disposition (must exist)
FILE_NON_DIRECTORY_FILE,// Create options
NULL, // EA buffer
0 ); // EA size

if( STATUS_PIPE_NOT_AVAILABLE != status )
break;

//
// If a pipe is not available, pause a random period of time from
100 to 500 ms.
//
if( iRetry == 0 )
{
LARGE_INTEGER iSeed;
KeQuerySystemTime( &iSeed );
iDelay.QuadPart = DELAY_ONE_MILLISECOND * ( 100 + (
RtlRandomEx( &iSeed.LowPart ) % 400 ) );
}

KeDelayExecutionThread( KernelMode, FALSE, &iDelay );
}

if( !NT_SUCCESS(status) )
{
DoTraceMessage( FKDEBUG_ANY, “PIPE: Failed to open %wZ (retry
count=%d): %!STATUS!”,
&sPipeName, iRetry, status );
return status;
}

HTH,
Ken

-----Original Message-----
From: xxxxx@lists.osr.com
mailto:xxxxx
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Sunday, February 20, 2005 5:04 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Sorry by the delay Ken, but I must to suspend my research due a
support
request
from a customer.
Sorry, by dont include that data.

These are the NTSTAUS retuned:

00000107 87.14696533 WPipe Open OK
00000108 87.14706925 Err@ WrPIPE-Write1
00000109 87.14708741 NTStatus: STATUS_INVALID_HANDLE
00000110 87.14711926 IO nfo: FILE_OPENED
00000111 87.14714943 IO NTStatus: 0xFD7AD328
00000112 87.14718742 Err@ WrPIPE-Write2
00000113 87.14720335 NTStatus: STATUS_INVALID_HANDLE
00000114 87.14721731 IO nfo: FILE_OPENED
00000115 87.14723324 IO NTStatus: 0xFD7AD328
00000116 87.14726928 Err@ WrPIPE-Write3
00000117 87.14728520 NTStatus: STATUS_INVALID_HANDLE
00000118 87.14729945 IO nfo: FILE_OPENED
00000119 87.14731537 IO NTStatus: 0xFD7AD328
00000120 87.14740030 WPipe Closed OK

(I Updated my dbgPrint function, now it translates the ntStatus, if
an
ntStaus
isn’t listed, it prints the HEX value).

“Ken Cross” >
escribió en el mensaje news:xxxxx@ntdev news:xxxxx
You’re still missing the most important piece of information: What
error
are you getting from ZwWriteFile?

Ken



From: xxxxx@lists.osr.com
mailto:xxxxx
[mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
Sent: Thursday, February 10, 2005 9:56 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed - Newbie

Thanks Ken,

That’s what I can see,

All the writes fails

The pipe is created with the following parametes :
access mode: PIPE_ACCESS_DUPLEX
pipe mode: PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE|
PIPE_NOWAIT

I tested this pipe with the following code on a MFC window app w/o
throubles
(near the same code I use for kernel mode). works fine also with
heavy load.

Thanks,
J.Angel


BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
{

BOOL fSuccess;
int i;
HANDLE hPipe;
DWORD cbWritten;
LPTSTR lpszPipename = “\\.\pipe\RamDrvOut”;
// Try to open a named pipe; wait for it, if necessary.
for ( i = 0; i<10; i++)
{

hPipe = CreateFile(

lpszPipename, // pipe name
GENERIC_READ | // read and write access
GENERIC_WRITE,
0, // no sharing
NULL, // no security attributes
OPEN_EXISTING, // opens existing pipe
0, // default attributes
NULL); // no template file

// Break if the pipe handle is valid.
if (hPipe != INVALID_HANDLE_VALUE)
{

break;

}
// Exit if an error other than ERROR_PIPE_BUSY
occurs.
//if (GetLastError() != 231L/ERROR_PIPE_BUSY/)
//{

// return FALSE;

//}
Sleep(100);

}
if (hPipe == INVALID_HANDLE_VALUE && i == 90)

return 0;

fSuccess = WriteFile(hPipe, &offset, sizeof(ULONG),
&cbWritten, NULL);
if (fSuccess)
{

fSuccess = WriteFile(hPipe,&bufSize, sizeof(ULONG),
&cbWritten, NULL);

}
if (fSuccess)
{

fSuccess = WriteFile(hPipe, pBuf, (DWORD) bufSize,
&cbWritten, NULL);

}
CloseHandle(hPipe);
return (fSuccess);

}

“Ken Cross”
mailto:xxxxx > > escribió en
el mensaje news:xxxxx@ntdev news:xxxxx news:xxxxxnews:xxxxx > …
| It’s difficult to help without complete information.
|
| Which write is failing? All of them? What are the error codes
for
ntStatus
| and ioStatus.Status? How is the pipe created in the user-mode
application?
| Is the user-mode application receiving any errors? Can you write
to the
| pipe with other applications?
|
| There’s a good chance that if you can answer these questions, the
problem
| will become obvious.
|
| Ken
|
|
|
|
| From: xxxxx@lists.osr.com
mailto:xxxxx
mailto:xxxxxmailto:xxxxx >
| [mailto:xxxxx@lists.osr.com] On Behalf Of J.Angel
| Sent: Wednesday, February 09, 2005 10:27 PM
| To: Windows System Software Devs Interest List
| Subject: Re:[ntdev] Named Pipes (kernel mode) - Help needed -
Newbie
|
|
| OK, I follow the suggestion and modified my source, now the pipe
connects
| OK, but ZwWriteFile fails.
|
| I’ll valuate any help, Thanks
|
| J.Angel
|
|

|
| My “NEW” SOURCE:
|
|
| BOOL WrPipe(ULONG offset,PVOID pBuf,ULONG bufSize)
|
| {
|
| ULONG dwMode;
| NTSTATUS ntStatus;
| int i = 0;
| LARGE_INTEGER duetime = {1000};
| HANDLE hPipe;
| ULONG cbRead;
| ULONG cbWritten;
| PWSTR lpszPipename =L"\\??\pipe\RamDrvIn");
| OBJECT_ATTRIBUTES objectAttributes;
| UNICODE_STRING fullFileName;
| IO_STATUS_BLOCK ioStatus;
| RtlInitUnicodeString (&fullFileName, lpszPipename);
| InitializeObjectAttributes (&objectAttributes,
| &fullFileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
| // Try to open a named pipe; wait for it, if necessary.
| for ( i = 0; i<90; i++)
| {
|
| ntStatus = ZwCreateFile (&hPipe,
|
| SYNCHRONIZE | GENERIC_READ | GENERIC_WRITE ,
|
| &objectAttributes,
| &ioStatus,
| NULL,
| FILE_ATTRIBUTE_NORMAL,
| FILE_SHARE_READ | FILE_SHARE_WRITE,
| FILE_OPEN,//FILE_OPEN_IF
| FILE_SYNCHRONOUS_IO_NONALERT,
| NULL,
| 0);
|
| // Break if the pipe handle is valid.
| if (hPipe != INVALID_HANDLE_VALUE )
| {
|
| break;
|
| }
| // Exit if an error other than ERROR_PIPE_BUSY
| occurs.
| //if (ioStatus.Status != 231L/ERROR_PIPE_BUSY/)
| //{
|
| // return FALSE;
|
| //}
| KeDelayExecutionThread(KernelMode ,FALSE, &duetime);
|
| }
| if (hPipe == INVALID_HANDLE_VALUE)
|
| return -1;
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &offset,
| sizeof(offset),
| NULL,
| NULL
| );
|
| if (NT_SUCCESS(ntStatus))
| {
| //
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| &bufSize,
| sizeof(bufSize),
| NULL,
| NULL
| );
|
| }
| if (NT_SUCCESS(ntStatus))
| {
|
| ntStatus = ZwWriteFile(
|
| hPipe,
| NULL,
| NULL,
| NULL,
| &ioStatus,
| pBuf,
| bufSize,
| NULL,
| NULL
| );
|
| }
| ZwClose(hPipe);
| return ntStatus;
|
| }
|
| —
| Questions? First check the Kernel Driver FAQ at
| http://www.osronline.com/article.cfm?id=256
http:
http:http: >
|
| You are currently subscribed to ntdev as: unknown lmsubst tag
argument: ‘’

| To unsubscribe send a blank email to
xxxxx@lists.osr.com mailto:xxxxx
mailto:xxxxxmailto:xxxxx >
|
| —
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
http:

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


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

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


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</mailto:xxxxx></mailto:xxxxx></http:></mailto:xxxxx></http:></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></http:></http:></http:></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></news:xxxxx></news:xxxxx></news:xxxxx></mailto:xxxxx></mailto:xxxxx></news:xxxxx></mailto:xxxxx></file:></news:xxxxx>