From owner-freebsd-hackers@FreeBSD.ORG Mon Sep 28 16:51:23 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 79FEA106566B for ; Mon, 28 Sep 2009 16:51:23 +0000 (UTC) (envelope-from forensec@yahoo.de) Received: from web28510.mail.ukl.yahoo.com (web28510.mail.ukl.yahoo.com [87.248.110.189]) by mx1.freebsd.org (Postfix) with SMTP id 033358FC19 for ; Mon, 28 Sep 2009 16:51:22 +0000 (UTC) Received: (qmail 87708 invoked by uid 60001); 28 Sep 2009 16:24:41 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1254155081; bh=dfRmyb7ckDVCT3qzr2nZncaWIwPbxxKvm+UnFA1h9dg=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=X1pqxFw785TIp6uFoVif8jD+MkA3Dqp/bXuwP1963yshIagySxvCOmno3YK4KoLFslrMTBk5iVLdSZ8EzYhagYQ3tlV4G4Kvr2HS4JS76KnVezeasgjddRKQmcHp1S4sJWf2M+h65Upq8qFloC8TjZkHxcczAEvi4WySke7NqC0= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.de; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=1BzSOHNaPkNqZytt17ePN6K9OJPWSjyTUFN0w9fhPt3QBdXUsFrXJZDQLE3zfrwb7Zme2hczGk4JKMqj4an8YDDdET3ZaXb6g4QTaIcxaxHjIy8qjEZ/S5HHeWcXDAU6O5dSCARI5I4O6U6p4PJbatJO9F9/vR/w5hLDEpDveRk=; Message-ID: <112995.77056.qm@web28510.mail.ukl.yahoo.com> X-YMail-OSG: uCBKw48VM1nUvtjrEpQBVo_l5YSUxDXZBzjYzWMJt7mjP8DnQrV545E7 Received: from [78.53.192.36] by web28510.mail.ukl.yahoo.com via HTTP; Mon, 28 Sep 2009 09:24:40 PDT X-Mailer: YahooMailClassic/7.0.14 YahooMailWebService/0.7.347.3 Date: Mon, 28 Sep 2009 09:24:40 -0700 (PDT) From: Leunam Elebek To: freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Trouble with copyout, memcpy.... X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Sep 2009 16:51:23 -0000 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