Matt Bailey wrote:
> I'm trying to use ddi_copyin to copy a string from a user application to a 
> psuedo driver in kernel space.
> 
> How do I copy data and print it out?  Anyone know of any resources I can look 
> at with an example?
> 
> Here's the ioctl code:
> 
> char *strPtr, *string;
> ...
>                 case STR_COPY:
>                         ddi_copyin((char *)arg, strPtr, sizeof (char*), mode);
>                         strcpy(string, strPtr); // EXPLODES HERE
>                       break;

Did you kmem_alloc(9F) space for strPtr ?  Also I'm pretty sure that you 
don't want sizeof (char *) as the 3rd argument to ddi_copyin but the 
actual size.

Are you 100% sure it is the strcpy that is causing the panic and not the 
ddi_copyin ?  Also what is mode set to ?

As for actually printing it out, I tend to use cmn_err with CE_NOTE if I 
really want to do that rather than just stopping in the function with 
mdb and displaying the data.

In general it is normal to define a struct that is shared between user 
and kernel space and in that struct you would have size information for 
any variable size data.  Note that you need to be careful about using 
generic types like size_t or uint_t if you do this, always be explicit, 
eg uint32_t or uint64_t so that you reduce the likely hood of problems 
with 32 bit app and 64 bit kernel.


-- 
Darren J Moffat
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to