Re: Kernel Space -> User Space IPC



Micky wrote:
Hi all,

I'm a newbie to kernel programming :-)
I am writing a network mini-redirector and I want to know how I can asynchronously send 'messages' from the kernel space (the redirector) to the user space (for example a console application) and receive ACK or something similar.
In the WDK help I couldn't find documentation about any of the standard IPC mechanisms. But I read here in the newsgroup that you are using it. (Pipes, memory mapped files,...).
LPC may be problematic for me because it is synchronous.
I can't use ALPC because I'm writing for XP.

Is there a way to send the user-space such messages?
Is there a way to write a 'Listener' for a specific app at kernel mode?
If I still use LPC and the LPC server (user-space) is down will it block the kernel?
Is it possible to use LPC as non-blocking?


Hi Micky,

It depends. You threw in the word "network" which means any machine, and that makes a big difference in limiting your design solution space. It is local machine only, they are are quite a few ways.

You can also use one that covers both. For our framework, we use RPC binding both a SOCKET channel (ncacn_ip_tcp) and a LOCAL RPC channel (ncalrpc) which if I recall Windows use named pipes beneath the hood.

Once that binding is establish, the client can connect to one to begin communications with the server. In general, these are sychronoous function call, but there is an asycrhonous RPC as well. Not hard at all to use it and using it depends on your needs for scaling multi-threaded client/server frameworks.

At the higher level, COM is for Local macines, and DCOM is for networking. Both use RPC at its root.

But it all depends on what you design needs. You can use SOCKETS directly and that will work for network host or local host (127.0.01) connections.

If all you want is a broadcast, you can register a message and broadcast it for your client to receive.

The ACK could be the return value on the ONReceiverMessage Handle().

We use this simple idea to signal signals to various listening servers or clients running on the local machine:

#include <stdio.h>
#include <afx.h>

BOOL PostWm(const char *msg, const DWORD dwTimeout = 0)
{
UINT wm = RegisterWindowMessage(msg);
if (wm != 0) {
DWORD dwResult = 0;
if (dwTimeout) {
int res = SendMessageTimeout(HWND_BROADCAST,wm,0,0,
SMTO_ABORTIFHUNG | SMTO_NORMAL,
dwTimeout*1000,
&dwResult);
return res != 0;
}
SendMessage(HWND_BROADCAST,wm,0,0);
return TRUE;
} else {
}
return FALSE;
}

int main(char argc, char *argv[])
{
if (argc < 2) {
printf("syntax: wcPostwm <registered win32 message> [timeout]\n");
printf("\n");
printf("Current Registered Win32 messages:\n");
printf("----------------------------------\n");
printf("Wildcat.Server.Shutdown Shutdown Wildcat! server\n");
printf("Wildcat.Shutdown.Client Shutdown all clients\n");
printf("Wildcat.Shutdown.xxxxxx Shutdown specific client\n");
printf("Wildcat.Server.PackMail Signal server mail packer\n");
printf("Wildcat.Clearstats.Wconline Clear WcOnline Statistics\n");
printf("Wildcat.MailRouter.wcsmtp Signal wcSMTP mail router\n");
return 0;
}

DWORD dwTimeout = 0;
if (argv[2]) dwTimeout = atoi(argv[2]);
if (!PostWm(argv[1],dwTimeout)) {
printf("Error %d Posting Message\n",GetLastError());
return 1;
}
return 0;
}

The listener would register the message, like the WCSMTP applet does on start up:

UINT WM_WCCLIENTSHUTDOWN =
RegisterWindowMessage("wildcat.shutdown.client");
UINT WM_WCSMTPSHUTDOWN =
RegisterWindowMessage("wildcat.shutdown.wcsmtp");
UINT WM_WCMAILROUTER =
RegisterWindowMessage("wildcat.mailrouter.wcsmtp");

and creates a message map handler for it:

BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
.....
ON_REGISTERED_MESSAGE(WM_WCCLIENTSHUTDOWN, OnClientShutdown)
ON_REGISTERED_MESSAGE(WM_WCSMTPSHUTDOWN, OnClientShutdown)
ON_REGISTERED_MESSAGE(WM_WCMAILROUTER, OnMailRouter)
END_MESSAGE_MAP();

You can also use CopyData message functions if you need to send data to the client.

If you need more than this, like for remote IPC, then take a look at SOCKETS, or RPC or DCOM/COM.

Hope this provides some insight.

--
HLS


.



Relevant Pages

  • Re: [2.6.24.3][net] bug: TCP 3rd handshake abnormal timeouts
    ... I didn't know where to write to the "network guys". ... It's hard to explain and describe a problem when you know people will ask you hundreds of questions related to application-level problems, or not reply because web/mysql problems are so common and generally not related to any kernel issue. ... you should try disabling it to rule out any possible bug in the ... I have the conntrack on both the client and server, and unfortunately can't disable it now on the client, however I will test today and disable it on the server, after I get some sleep. ...
    (Linux-Kernel)
  • A question about disk-cacheing
    ... I had the following experiences with linux network file system clients. ... it run 6-8 times faster than with Novell/ncpfs client. ... The linux kernel, the kernel ...
    (Linux-Kernel)
  • Re: Root toolkits on Windows
    ... If the kernel has been compromised and the virus is getting info from the ... Legalities of doing so depend on network policies and who ... At the moment I can't remember the common MS product CSLID ... I would prefer to be able to scan client registries ...
    (alt.computer.security)
  • RE: Lost my outlook contact... :(
    ... the network configuration is started from a web page located ... client computer, you will see a welcome page to invite you to start the ... local user profiles to the domain user profile. ... Before joining client computers to the network, ...
    (microsoft.public.windows.server.sbs)
  • Re: SMS 2.0 and SMS 2003 Running at same time in same domain.
    ... the clients are on the network. ... The operating system reported error 53: ... Possible cause: The client is offline. ... Verify that the client is connected to the network and that the SMS ...
    (microsoft.public.sms.setup)

Loading