User Mode: There are several ways.
1) The most common / flexible way is to use DeviceIOControl for communication between user mode and kernel mode, including memory transfer.
This has been a long time (six years? XP timeframe) since I wrote my latest kernel driver, so this is an overview of the process, not the exact code. However, your user mode program should be able to get a handle to your "device" or an open instance of your driver working on something using CreateFile and specifying its name, for example \\.\YourNameHere . Use this handle to communicate with it (the first parameter is DeviceIOControl .)
Four options that interest you:
__in_opt LPVOID lpInBuffer, __in DWORD nInBufferSize, __out_opt LPVOID lpOutBuffer, __in DWORD nOutBufferSize, __out_opt LPDWORD lpBytesReturned,
Using this data, you can provide data to the driver (using the lpInBuffer and nInBufferSize ), which determines how large it is - whether this data or how to interpret it depends on your driver) mode mode can return data through lpOutBuffer (a pointer to the memory you they have already been assigned in user mode - this is not the pointer that the driver installs!), its size in bytes in nOutBufferSize (again, you know this, since you allocate this buffer in user mode), and then the driver will tell you how much of this buffer actually s completed by lpBytesReturned .
This Wikipedia article describes the general concept of ioctl functions , an example of which is DeviceIOControl.
Note. You said: "I'm trying to exchange memory between user space and kernel space in windows." This is not exactly shared memory - it is not memory that both user mode and kernel mode are reading or writing at the same time, for example. This is the memory where, when the DeviceIOControl function is called, the kernel mode has access to your memory allocated in user mode, for which you pass its pointers (although it is a little more complicated from memory, but it is an effect.) That is. it only "shares" when you call this method.
2) Another alternative is to use ReadFile and WriteFile if you need a simple data transfer and the kernel driver accepts it. This does not allow you to have two-way communication, as DeviceIOControl does (where you give the driver data, and it gives you something with an error code), but it is simple, and you are probably already familiar with these APIs.
Kernel mode side: Are you writing a kernel driver? If so, this article contains information about the implementation of the IOCTL side in kernel mode . This series of articles also describes how user mode can use ReadFile and WriteFile for communication if you choose these methods.