From owner-freebsd-hackers@FreeBSD.ORG Mon Sep 28 17:19:09 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 BA0011065670 for ; Mon, 28 Sep 2009 17:19:09 +0000 (UTC) (envelope-from forensec@yahoo.de) Received: from web28503.mail.ukl.yahoo.com (web28503.mail.ukl.yahoo.com [87.248.110.182]) by mx1.freebsd.org (Postfix) with SMTP id 46F6F8FC13 for ; Mon, 28 Sep 2009 17:19:09 +0000 (UTC) Received: (qmail 71852 invoked by uid 60001); 28 Sep 2009 17:19:08 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1254158348; bh=+r4Khi3ETss0sCO07+MQOf05/q1kmAn4llG9obFfcuI=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=Q2ZMULq43teWKPTm4dM+7UyDosL60pzjg3zdjk3lrnspsJmzRPIWJSU4jrmsHzl7sWjkJYAzZy7I4OcaF5om1UhM9RDjXmrHm3DgYkHK00sceQo1C9r/hP/1wMS/j3bInhQzZm/T7CF5VBhB5/t60kNJSYmaPY9zzrKHudmyIkM= 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:Content-Transfer-Encoding; b=qcu9kCQnqcrtEMVoarW/Vel5L8+1/YnmOT9SOLi0FEfQ6QV256mflkOlMsnVvDS5KUO3oc7qef+WG0eauus66ArPFLIdj9W3MYmo6AC2dETztFVaxGyVWIjErV6joqTcmS7Qt9TzCWCV7D5avSsrQiIxhMq4mPucN2DWiNGCcFE=; Message-ID: <389605.70197.qm@web28503.mail.ukl.yahoo.com> X-YMail-OSG: c17Dvk8VM1lv4qUFS..9Ckjhy55YOg3LmRtdwwzRkghcVZts5sbhQphMMVuhbpZo3SpFByzVaYqP0Yqi_hVLKEcBx.N5riZkMY8SqneGlN.Wwj25VfVa7VmJ8vPRtwBSP2eRdih6mBJ9ODx6eAvHWkrkrvu2u_hj69DQ169tacdisJIJycJP_4VTfvdC5xq98NCtvvr0jBKjnd8uaosxkjaIPhbDBLJQwGWKHjB_ewtmyh48wFL634Oy9VX5f..K.7H1aPVd Received: from [78.53.192.36] by web28503.mail.ukl.yahoo.com via HTTP; Mon, 28 Sep 2009 10:19:08 PDT X-Mailer: YahooMailClassic/7.0.14 YahooMailWebService/0.7.347.3 Date: Mon, 28 Sep 2009 10:19:08 -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 Subject: Trouble with copyout, memcpy.... Plain-Text version =) 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 17:19:09 -0000 Hey list, I currently code a driver under Current 8.0 for Current 8.0. But there 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 ki_type; =A0 =A0 =A0 =A0 int=A0 =A0 =A0 ki_nchan; =A0 =A0 =A0 =A0 int=A0 =A0 =A0 ki_len_chanl; }; The above structure is used in my user-space app: int main(void) { =A0 =A0 =A0 =A0 struct daq_kitinfo *info; =A0 =A0 =A0 =A0 struct daq_kit kit;=20 =A0 =A0 =A0 =A0 int fd, size;=20 =A0 =A0 =A0 =A0 ... =A0 =A0 =A0 =A0 ... =A0 =A0 =A0 =A0 ... =A0 =A0 =A0 =A0 /*=20 =A0 =A0 =A0 =A0=A0=A0* At this point I'll try to alloc memory. Notice that= =20 =A0 =A0 =A0 =A0=A0=A0* the size i dependet from another struct entry. =A0 =A0 =A0 =A0=A0=A0*/ =A0 =A0 =A0 =A0 size =3D sizeof(*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* The next step is to call the drivers ioctl() interfa= ce =A0 =A0 =A0 =A0=A0=A0* (the reason for that is described below). =A0 =A0 =A0 =A0=A0=A0*/ =A0 =A0 =A0 =A0 if (ioctl(fd, DAQ_KITINFO, info)) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 printf("errno: %d\n", errno);=20 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=A0=A0exit(errno); =A0 =A0 =A0 =A0 } =A0 =A0 =A0 =A0=A0=A0printf("[ki_nchan] %d\n", info.ki_nchan); =A0 =A0 =A0 =A0=A0=A0... =A0 =A0 =A0 =A0=A0=A0... =A0 =A0 =A0 =A0=A0=A0return (0); } and inside the driver (put it simply): static int my_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int flags, =A0 =A0 struct thread *td) { =A0 =A0 =A0 =A0 struct daq_kitinfo *info; =A0 =A0 =A0 =A0 struct daq_kit =3D dev->si_drv1;=20 =A0 =A0 =A0 =A0 int size;=20 =A0 =A0 =A0 =A0 ... =A0 =A0 =A0 =A0 /* Do something useful e.g mutex'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 info =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=A0* Here I want to copy struct info from kernel to user-= space. =A0 =A0 =A0 =A0=A0=A0* If i use memcpy, the result is that the system hangs =A0 =A0 =A0 =A0=A0=A0* and I need to reboot the machine. OK, I thought =A0 =A0 =A0 =A0=A0=A0* copyout() should be able to do the job for me... =A0 =A0 =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 =A0 * Fuc[k-k] i still come inside this blo= ck. I always =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * get an EFAULT error.=20 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */ } I really don't know what I should do to let the driver working properly. The driver should grap some informations/attributes, and fill up the info structure, so we can copy the filled info struct to the user's app. I hope somebody can help me to resolve that problem. Ah, the corresponding 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) Thanks for attention and greatz from germany MG=0A=0A=0A