Prev: RegDBRestore API Documentation
Next: How to determine if it's a CD or DVD in drive & RW possibly?
From: Micky on 28 Nov 2007 04:20 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? Thanks, Micky
From: Pops on 28 Nov 2007 06:46 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
From: Don Burn on 28 Nov 2007 07:04 The standard way to do this is to use what is known as an inverted call. Namely the application sends a bunch of IOCTL requests to the driver, where they are pended until the driver needs to call the app, the driver then completes the request which returns it and the data to the application. See http://www.osronline.com/article.cfm?id=94 for details. LPC's are not documented (and the web documents you find are wrong). Use the inverted call this is what most drivers, including a lot of Microsoft's use. -- Don Burn (MVP, Windows DDK) Windows 2k/XP/2k3 Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr Remove StopSpam to reply "Micky" <mkaufmannn(a)hotmail.com.(nospam)> wrote in message news:7A9F75A6-801F-47DC-8216-6750AB2C2323(a)microsoft.com... > 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? > > Thanks, > > Micky
|
Pages: 1 Prev: RegDBRestore API Documentation Next: How to determine if it's a CD or DVD in drive & RW possibly? |