problem while passing string literal to wince driver
hi,
While i pass a string literal directly to an exported dll function,
which internally passes this string to a windowsce stream interface
driver(through IOCTL),the driver gets hung on strcpy.
If i pass a char array initialized with the same string literal, it
works fine
Eg:
in Application,
somFunc("String literal"); // somFunc(char[]) works fine;
in Dll,
EXPORT void someFunc(char* string)
{
DeviceIoControl(....);
}
in Driver dll,
// this fn is called from IOCTL entry point
someFuncInDriver(char* string)
{
strcpy(tempString, string); --- hangs
}
can someone give me exact reason for this problem in wince ???
TIA,
Gomas
Re: problem while passing string literal to wince driver
Well, the app calling DeviceIoControl is in one process address space, and
the device driver is being hosted in another process address space
(device.exe). Can't do that (virtual memory system w/process address
protection, right?).
You should just pass the bytes. With pointer, you can use
MapPtrToProcess/GetCallerProcess to map the app's slot 0-based pointer to an
app-slot pointer that can then be safely dereferenced in device.exe.
--
Michael Salamone [eMVP]
Entrek Software, Inc.
[url]www.entrek.com[/url]
"gomas" <gomas_vincy@yahoo.com> wrote in message
news:28575a5c.0401280344.30f8becf@posting.google.com...[color=blue]
> hi,
>
> While i pass a string literal directly to an exported dll function,
> which internally passes this string to a windowsce stream interface
> driver(through IOCTL),the driver gets hung on strcpy.
>
> If i pass a char array initialized with the same string literal, it
> works fine
>
> Eg:
> in Application,
>
> somFunc("String literal"); // somFunc(char[]) works fine;
>
> in Dll,
>
> EXPORT void someFunc(char* string)
> {
> DeviceIoControl(....);
> }
>
> in Driver dll,
>
> // this fn is called from IOCTL entry point
>
> someFuncInDriver(char* string)
> {
> strcpy(tempString, string); --- hangs
> }
>
>
> can someone give me exact reason for this problem in wince ???
>
> TIA,
>
> Gomas[/color]
Re: problem while passing string literal to wince driver
Well maybe Michael is write but maybe not as they are both Dlls and you
didn't specify. You also didn't show the actual call to DeviceIoControl as
that can make a world of a difference. If the string pointer is passed as
the input buffer pointer then the OS will automatically handle mapping the
pointer. However if the string pointer is "embedded" within a structure
whose pointer is passed to DeviceIoControl then the driver will need to call
MapCallerPtr() to safely validate the caller has permission to access the
provided pointer and to map it appropriately for use in the driver.
NOTE:
MapCallerPtr is preferred to MapPtrToProcess as MapPtrToProcess will
effectively be a NOP for a pre-mapped pointer allowing a caller to forge a
pointer to another process space it should not have access to.
MapCallerPtr() validates that the caller actually has permissions to access
the data the pointer points to and then does the mapping. Practice Safe
Computing!
--
Steve Maillet (eMVP)
Entelechy Consulting
smaillet_AT_EntelechyConsulting_DOT_com