Here's the example I was working from
http://www.filibeto.org/~aduritz/truetrue/solaris10/device-driver-html/faatl.html#ffdqq
Kernel Code:

                case DDI_MODEL_NONE:
                        if (ddi_copyin((void *)arg, &new_len;, sizeof (size_t),
                            mode) != 0)
                                return (EFAULT);
                        break;


User Code:

static void
set_size(const char *dev, size_t sz)
{
        int fd;

        if ((fd = open(dev, O_RDWR)) < 0) {
                perror("open");
                exit(3);
        }

        if (ioctl(fd, QOTDIOCSSZ, &sz;) < 0) {
                perror("QOTDIOCSSZ");
                exit(4);
        }

        (void) close(fd);
}

I am able to ge this to work by declaring a size32_t in the kernel code,
looks like size_t is 64 bit in kernel space by default.

So I was trying to change this to copy strings instead.  Thanks for the
advice, I will try out some of the suggestions, but I figured this would
provide better context to my question.

-Matt

On 8/9/07, Darren J Moffat <[EMAIL PROTECTED]> wrote:
>
> 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