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>