From: Arsalan Ahmad on
Hi,

I am writing a driver which takes in the call to DeviceIoControl() some
structure like below:

stuct someStruct
{
char *in_ptr;
int in_ptr_len;
int num;
char *out_ptr;
int out_ptr_len;
}

where ptr points to some memory. Problem is that DeviceIoControl() just
seems to take a pointer to a buffer (in_ptr and out_ptr), so if now I passed
address of an object of someStruct type, the how can I access data pointed
to by ptr member from inside my driver?

Also is it possible that i allocate memory pointed to by out_ptr in my
driver and still I can access the memory from my application that opens that
driver?

I am using Pocker PC 2003.

Thanks,

Arsalan

Thanks,

Arsalan


From: Tim Roberts on
"Arsalan Ahmad" <arsal__(a)hotmail.com> wrote:
>
>I am writing a driver which takes in the call to DeviceIoControl() some
>structure like below:
>
>stuct someStruct
>{
> char *in_ptr;
> int in_ptr_len;
> int num;
> char *out_ptr;
> int out_ptr_len;
>}
>
>where ptr points to some memory. Problem is that DeviceIoControl() just
>seems to take a pointer to a buffer (in_ptr and out_ptr), so if now I passed
>address of an object of someStruct type, the how can I access data pointed
>to by ptr member from inside my driver?

In the CE environments, user-mode addresses can be accessed from kernel
mode just as regular pointers. You should just be able to dereference it.

However, since DeviceIoControl already has an input and an output
parameter, why don't you just use them, instead of defining your own
structure?

>Also is it possible that i allocate memory pointed to by out_ptr in my
>driver and still I can access the memory from my application that opens that
>driver?

It depends on the setup. Some CE systems run full-time in kernel mode. In
such an environment, your kernel address would still be valid in user mode.
If your isn't that way, then you can't do this.
--
- Tim Roberts, timr(a)probo.com
Providenza & Boekelheide, Inc.
From: Maxim S. Shatskih on
Try using the huge self-relative buffer, which will use offsets instead of
pointers.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim(a)storagecraft.com
http://www.storagecraft.com

"Arsalan Ahmad" <arsal__(a)hotmail.com> wrote in message
news:%23sNyvef6FHA.2600(a)tk2msftngp13.phx.gbl...
> Hi,
>
> I am writing a driver which takes in the call to DeviceIoControl() some
> structure like below:
>
> stuct someStruct
> {
> char *in_ptr;
> int in_ptr_len;
> int num;
> char *out_ptr;
> int out_ptr_len;
> }
>
> where ptr points to some memory. Problem is that DeviceIoControl() just
> seems to take a pointer to a buffer (in_ptr and out_ptr), so if now I passed
> address of an object of someStruct type, the how can I access data pointed
> to by ptr member from inside my driver?
>
> Also is it possible that i allocate memory pointed to by out_ptr in my
> driver and still I can access the memory from my application that opens that
> driver?
>
> I am using Pocker PC 2003.
>
> Thanks,
>
> Arsalan
>
> Thanks,
>
> Arsalan
>
>

From: Vladimir Zinin on

Hi,


> I am writing a driver which takes in the call to DeviceIoControl() some
> structure like below:
>
> stuct someStruct
> {
> char *in_ptr;
> int in_ptr_len;
> int num;
> char *out_ptr;
> int out_ptr_len;
> }
>
> where ptr points to some memory. Problem is that DeviceIoControl() just
> seems to take a pointer to a buffer (in_ptr and out_ptr), so if now I
passed
> address of an object of someStruct type, the how can I access data
pointed
> to by ptr member from inside my driver?


Use the undocumented functions:
LPVOID MapPtrToProcess(LPVOID lpv, HANDLE hProc);
HANDLE GetCallerProcess(void);

For example:

struct someStruct *pss = ...;
char *in_ptr = (char*)MapPtrToProcess(pss->in_ptr, GetCallerProcess());

>
> Also is it possible that i allocate memory pointed to by out_ptr in my
> driver and still I can access the memory from my application that opens that
> driver?
>

You can do this on WM2003. But this is not good idea.
The best way is to allocate out_ptr buffer in an user process.


--
Best regards,
Vladimir Zinin
mailto:vzinin(a)gmail.com


From: Pavel A. on

"Vladimir Zinin" <vzinin(a)gmail.com> wrote in message news:%23IBZ3C46FHA.2608(a)tk2msftngp13.phx.gbl...
>
> Use the undocumented functions:
> LPVOID MapPtrToProcess(LPVOID lpv, HANDLE hProc);
> HANDLE GetCallerProcess(void);

Why undocumented? these functions are official APIs of WinCE,
and are very well documented.

Regards,
--PA