Help on FltSendMessage, FilterReplyMessage and FilterGetMessage

Hi,

I am facing a problem while sending messages from mini-filter to a user
mode service and receiving the replies. The problem is as follows:

The mini filter sends a message to the user mode service (windows
service) using the function FltSendMessage with timeout value as NULL. The
user mode service reads the message using the FilterGetMessage API with
overlapped parameter set to NULL. The user mode service then performs some
processing and then replies to the mini-filter using the FilterReplyMessage
message with the correct message id. This works fine when the user mode is
single threaded.

I wanted to make the user mode service multithreaded i.e. the reader
will read the message from the port and spawn a new executor thread which
will post the reply message. Thus there may be 5 consecutive writes by the
mini-filter to the port and there will be 5 threads processing the command
from the mini-filter and while the 5 threads are processing the data there
may be a sixth call that is posted.

In my case however, the read call hangs until the reply is sent by the
executor. i.e. mini-filter sends a command to user mode service. The user
mode service spawns the executor thread. While the executor thread is
executing the command, another call comes in into the user mode service.
However, FilterGetMessage hangs. Once the executor thread sends the reply
the FilterGetMessage function returns E_FAIL.

What could I be doing wrong here?

Thanks in advance,

Vishal

DISCLAIMER

This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.

Hi,

Below is an example code of my user mode client of the mini filter. When
the first read arrives I can see the ‘Before Get’ message followed by ‘After
Get’ message. Now the thread is created and I can see the ‘Before Set’
message. Now another command arrives and I can see the ‘Before Get’ message.
Now if I click ‘Ok’ on the message box ‘Before Get’ the ‘FilterGetMessage’
hangs and then if I click ‘Ok’ on the message box ‘Before set’ there is a
crash in the user mode application.

#include<windows.h>

#include<stdio.h>

#include <fltuser.h>

typedef struct _TestDataType

{

FILTER_MESSAGE_HEADER udtMsgHeader;

char
Buffer[1000];

}TESTDATA;

typedef struct _TestReplyTypeType

{

FILTER_REPLY_HEADER udtReplyHeader;

char
Buffer[1000];

}TESTREPLYDATA;

HANDLE port = NULL;

DWORD WINAPI ThreadProc(LPVOID lpParameter)

{

HRESULT hr = S_OK;

TESTREPLYDATA udtReplyData;

long id = ((long)lpParameter);

MessageBox(NULL,“Before Set”,“Before Set”,0);

udtReplyData.udtReplyHeader.MessageId = id;

udtReplyData.udtReplyHeader.Status = 1;

hr =
FilterReplyMessage(port,(PFILTER_REPLY_HEADER)&udtReplyData,sizeof(udtReplyD
ata));

if(S_OK != hr)

{

printf(“FilterReplyMessage – HR = %d”,hr);

return 1;

}

MessageBox(NULL,“After Set”,“After Set”,0);

return 0;

}

int main()

{

HRESULT
hr = S_OK;

TESTDATA
udtData;

hr = FilterConnectCommunicationPort( L"\TestPort",0, NULL, 0,
NULL, &port );

if(IS_ERROR(hr))

{

return 0;

}

while(1)

{

long nId = 0;

ZeroMemory(&udtData,sizeof(udtData));

MessageBox(NULL,“Before Get”,“Before Get”,0);

hr = FilterGetMessage(port,&udtData.udtMsgHeader,1000,NULL);

if(S_OK != hr)

{

printf(“FilterGetMessage – HR =
%d”,hr);

return 1;

}

MessageBox(NULL,“After Get”,“After Get”,0);

nId = (long)udtData.udtMsgHeader.MessageId;

long nSaveId = nId;

CreateThread(NULL,0,ThreadProc,&nSaveId,0,NULL);

}

return 0;

}

Thanks,

Vishal

_____

From: Vishal Pai [mailto:xxxxx@persistent.co.in]
Sent: Thursday, June 15, 2006 8:48 PM
To: ‘xxxxx@lists.osr.com’
Subject: Help on FltSendMessage, FilterReplyMessage and FilterGetMessage

Hi,

I am facing a problem while sending messages from mini-filter to a user
mode service and receiving the replies. The problem is as follows:

The mini filter sends a message to the user mode service (windows
service) using the function FltSendMessage with timeout value as NULL. The
user mode service reads the message using the FilterGetMessage API with
overlapped parameter set to NULL. The user mode service then performs some
processing and then replies to the mini-filter using the FilterReplyMessage
message with the correct message id. This works fine when the user mode is
single threaded.

I wanted to make the user mode service multithreaded i.e. the reader
will read the message from the port and spawn a new executor thread which
will post the reply message. Thus there may be 5 consecutive writes by the
mini-filter to the port and there will be 5 threads processing the command
from the mini-filter and while the 5 threads are processing the data there
may be a sixth call that is posted.

In my case however, the read call hangs until the reply is sent by the
executor. i.e. mini-filter sends a command to user mode service. The user
mode service spawns the executor thread. While the executor thread is
executing the command, another call comes in into the user mode service.
However, FilterGetMessage hangs. Once the executor thread sends the reply
the FilterGetMessage function returns E_FAIL.

What could I be doing wrong here?

Thanks in advance,

Vishal

DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.</fltuser.h></stdio.h></windows.h>

Hi,

I used the OVERLAP parameter of the FilterGetMessage and everything
works fine.

However, I do not understand the reason behind overlap parameter set to
null and one thread is waiting for read and other thread doing a write after
that. In this case the GETMESSAGE function returns with failure. Could
anybody explain this?

Thanks,

Vishal


From: Vishal Pai [mailto:xxxxx@persistent.co.in]
Sent: Thursday, June 15, 2006 10:46 PM
To: ‘xxxxx@lists.osr.com’
Subject: RE: Help on FltSendMessage, FilterReplyMessage and FilterGetMessage

Hi,

Below is an example code of my user mode client of the mini filter. When
the first read arrives I can see the ‘Before Get’ message followed by ‘After
Get’ message. Now the thread is created and I can see the ‘Before Set’
message. Now another command arrives and I can see the ‘Before Get’ message.
Now if I click ‘Ok’ on the message box ‘Before Get’ the ‘FilterGetMessage’
hangs and then if I click ‘Ok’ on the message box ‘Before set’ there is a
crash in the user mode application.

#include<windows.h>

#include<stdio.h>

#include <fltuser.h>

typedef struct _TestDataType

{

FILTER_MESSAGE_HEADER udtMsgHeader;

char
Buffer[1000];

}TESTDATA;

typedef struct _TestReplyTypeType

{

FILTER_REPLY_HEADER udtReplyHeader;

char
Buffer[1000];

}TESTREPLYDATA;

HANDLE port = NULL;

DWORD WINAPI ThreadProc(LPVOID lpParameter)

{

HRESULT hr = S_OK;

TESTREPLYDATA udtReplyData;

long id = ((long)lpParameter);

MessageBox(NULL,“Before Set”,“Before Set”,0);

udtReplyData.udtReplyHeader.MessageId = id;

udtReplyData.udtReplyHeader.Status = 1;

hr =
FilterReplyMessage(port,(PFILTER_REPLY_HEADER)&udtReplyData,sizeof(udtReplyD
ata));

if(S_OK != hr)

{

printf(“FilterReplyMessage – HR = %d”,hr);

return 1;

}

MessageBox(NULL,“After Set”,“After Set”,0);

return 0;

}

int main()

{

HRESULT
hr = S_OK;

TESTDATA
udtData;

hr = FilterConnectCommunicationPort( L"\TestPort",0, NULL, 0,
NULL, &port );

if(IS_ERROR(hr))

{

return 0;

}

while(1)

{

long nId = 0;

ZeroMemory(&udtData,sizeof(udtData));

MessageBox(NULL,“Before Get”,“Before Get”,0);

hr = FilterGetMessage(port,&udtData.udtMsgHeader,1000,NULL);

if(S_OK != hr)

{

printf(“FilterGetMessage – HR =
%d”,hr);

return 1;

}

MessageBox(NULL,“After Get”,“After Get”,0);

nId = (long)udtData.udtMsgHeader.MessageId;

long nSaveId = nId;

CreateThread(NULL,0,ThreadProc,&nSaveId,0,NULL);

}

return 0;

}

Thanks,

Vishal

_____

From: Vishal Pai [mailto:xxxxx@persistent.co.in]
Sent: Thursday, June 15, 2006 8:48 PM
To: ‘xxxxx@lists.osr.com’
Subject: Help on FltSendMessage, FilterReplyMessage and FilterGetMessage

Hi,

I am facing a problem while sending messages from mini-filter to a user
mode service and receiving the replies. The problem is as follows:

The mini filter sends a message to the user mode service (windows
service) using the function FltSendMessage with timeout value as NULL. The
user mode service reads the message using the FilterGetMessage API with
overlapped parameter set to NULL. The user mode service then performs some
processing and then replies to the mini-filter using the FilterReplyMessage
message with the correct message id. This works fine when the user mode is
single threaded.

I wanted to make the user mode service multithreaded i.e. the reader
will read the message from the port and spawn a new executor thread which
will post the reply message. Thus there may be 5 consecutive writes by the
mini-filter to the port and there will be 5 threads processing the command
from the mini-filter and while the 5 threads are processing the data there
may be a sixth call that is posted.

In my case however, the read call hangs until the reply is sent by the
executor. i.e. mini-filter sends a command to user mode service. The user
mode service spawns the executor thread. While the executor thread is
executing the command, another call comes in into the user mode service.
However, FilterGetMessage hangs. Once the executor thread sends the reply
the FilterGetMessage function returns E_FAIL.

What could I be doing wrong here?

Thanks in advance,

Vishal

DISCLAIMER
==========
This e-mail may contain privileged and confidential information which is the property of Persistent Systems Pvt. Ltd. It is intended only for the use of the individual or entity to which it is addressed. If you are not the intended recipient, you are not authorized to read, retain, copy, print, distribute or use this message. If you have received this communication in error, please notify the sender and delete all copies of this message. Persistent Systems Pvt. Ltd. does not accept any liability for virus infected mails.</fltuser.h></stdio.h></windows.h>