Date: Mon, 28 Sep 2009 09:24:40 -0700 (PDT) From: Leunam Elebek <forensec@yahoo.de> To: freebsd-hackers@freebsd.org Subject: Trouble with copyout, memcpy.... Message-ID: <112995.77056.qm@web28510.mail.ukl.yahoo.com>
next in thread | raw e-mail | index | archive | help
Hey list,I currently code a driver under Current 8.0 for Current 8.0.But th= ere are some problems with kernel/user-space interaction.I've the following= structure:struct daq_kitinfo {=A0 =A0 =A0 =A0 uint32_t ki_maxdata;=A0 =A0 = =A0 =A0 uint32_t ki_flags;=A0 =A0 =A0 =A0 uint32_t ki_rng_type;=A0 =A0 =A0 = =A0 int =A0 =A0 =A0 =A0 =A0 ki_type;=A0 =A0 =A0 =A0 int =A0 =A0 =A0 =A0 =A0= ki_nchan;=A0 =A0 =A0 =A0 int =A0 =A0 =A0 =A0 =A0 ki_len_chanl;};The above = structure is used in my user-space app:int main(void) {=A0 =A0 =A0 =A0 stru= ct daq_kitinfo *info;=A0 =A0 =A0 =A0 struct daq_kit kit; =A0 =A0 =A0 =A0 in= t fd, size; =A0 =A0 =A0 =A0 ...=A0 =A0 =A0 =A0 ...=A0 =A0 =A0 =A0 ...=A0 = =A0 =A0 =A0 /* =A0 =A0 =A0 =A0 =A0* At this point I'll try to alloc memory. Notice that =A0 =A0 =A0 =A0 =A0* the size i dependet = from another struct entry.=A0 =A0 =A0 =A0 =A0*/=A0 =A0 =A0 =A0 size =3D siz= eof(*info) * kit.k_nkits;=A0 =A0 =A0 =A0 info =3D malloc(size);=A0 =A0 =A0 = =A0 if (info =3D=3D NULL)=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 exit(ENOMEM);=A0 = =A0 =A0 =A0=A0=A0 =A0 =A0 =A0 /*=A0 =A0 =A0 =A0 =A0* The next step is to ca= ll the drivers ioctl() interface=A0 =A0 =A0 =A0 =A0* (the reason for that i= s described below).=A0 =A0 =A0 =A0 =A0*/=A0 =A0 =A0 =A0 if (ioctl(fd, DAQ_K= ITINFO, info)) {=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("errno: %d\n", errno= ); =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0exit(errno);=A0 =A0 =A0 =A0 }=A0 =A0 = =A0 =A0 =A0printf("[ki_nchan] %d\n", ki_nchan);=A0 =A0 =A0 =A0 =A0...=A0 = =A0 =A0 =A0 =A0...=A0 =A0 =A0 =A0 =A0return (0);}and inside the driver (put= it simply):static intmy_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flags,=A0 =A0 struct thread *td){=A0 =A0 =A0 =A0 struct daq_kitin= fo *info;=A0 =A0 =A0 =A0 struct daq_kit =3D dev->si_drv1; =A0 =A0 =A0 =A0 i= nt size; =A0 =A0 =A0 =A0 ...=A0 =A0 =A0 =A0 /* Do something useful e.g mute= x'ing... */=A0 =A0 =A0 =A0 ...=A0 =A0 =A0 =A0 /* The same as in user-space.= .. */=A0 =A0 =A0 =A0 size =3D sizeof(*info) * kit.k_nkits;=A0 =A0 =A0 =A0 i= nfo =3D malloc(sz, M_DAQ, M_NOWAIT | M_ZERO);=A0 =A0 =A0 =A0 if (info =3D= =3D NULL)=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ....=A0 =A0 =A0 =A0 /*=A0 =A0 =A0 = =A0 =A0* Here I want to copy struct info from kernel to user-space.=A0 =A0 = =A0 =A0 =A0* If i use memcpy, the result is that the system hangs=A0 =A0 = =A0 =A0 =A0* and I need to reboot the machine. OK, I thought=A0 =A0 =A0 =A0= =A0* copyout() should be able to do the job for me...=A0 =A0 =A0 =A0 =A0*/= =A0 =A0 =A0 =A0 =A0if (copyout(info, arg, sz))=A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0/*=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * Fuc[k-k] i still come inside this block. I alway= s=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * get an EFAULT error. =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 */}I really don't know what I should do to let the dri= ver workingproperly. The driver should grap some informations/attributes,an= d fill up the info structure, so we can copy the filled info structto the u= ser's app.I hope somebody can help me to resolve that problem.Ah, the corre= sponding ioctl is:#define GRP =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0'd'#define DAQ_KITINFO =A0 =A0 =A0 =A0_IOR(GRP, 3, struct daq_kitinfo)Th= anks for attention and greatz from germanyMG=0A=0A=0A
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?112995.77056.qm>