From owner-freebsd-hackers@FreeBSD.ORG Sat Jun 4 00:58:41 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 32D7316A41C for ; Sat, 4 Jun 2005 00:58:41 +0000 (GMT) (envelope-from julian@elischer.org) Received: from bigwoop.vicor-nb.com (bigwoop.vicor-nb.com [208.206.78.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0592643D49 for ; Sat, 4 Jun 2005 00:58:40 +0000 (GMT) (envelope-from julian@elischer.org) Received: from [208.206.78.97] (julian.vicor-nb.com [208.206.78.97]) by bigwoop.vicor-nb.com (Postfix) with ESMTP id CC9247A403; Fri, 3 Jun 2005 17:58:40 -0700 (PDT) Message-ID: <42A0FCC0.6010805@elischer.org> Date: Fri, 03 Jun 2005 17:58:40 -0700 From: Julian Elischer User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.7) Gecko/20050423 X-Accept-Language: en, hu MIME-Version: 1.0 To: shiner chen References: <20050603034129.34801.qmail@web15510.mail.cnb.yahoo.com> In-Reply-To: <20050603034129.34801.qmail@web15510.mail.cnb.yahoo.com> Content-Type: text/plain; charset=GB2312 Content-Transfer-Encoding: 8bit Cc: freebsd-hackers@freebsd.org Subject: Re: a error about the kern_sendit 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: Sat, 04 Jun 2005 00:58:41 -0000 shiner chen wrote: > i wrote a function to send the data of my a data structure in my kld by socket in kernel, the function as follow: > the arg 1 is file descriptor of socket. the arg 2 is the address of data structure. the arg 3 is the length of data structure and it is 20 bytes . > > the error return by kern_sendit is EFAULT(14), i check the address of data structure ,but it is right! > why ? who can tell me. thanks!! > > int loadinfo_send(int so_fd, struct thread *td, > char *snd_buf, unsigned int uBufLen) > { > int st = 0; > > /* read */ > struct iovec aiov; > struct msghdr msg; > > msg.msg_name = 0; > msg.msg_namelen = 0; > msg.msg_iov = &aiov; > msg.msg_iovlen = 1; > msg.msg_control = 0; > msg.msg_flags = 0; > > /* do actual send operation now */ > aiov.iov_base = snd_buf ; > aiov.iov_len = uBufLen; > ///////// there is error//////////////////////// I think that aio is expected to be the address of a userspace buffer. kern_sendit() is expecting to get the address info from the msg and passes it to so->so_proto->pr_usrreqs->pru_sosend() without there having ever been any work in making it a kernel address. an example of xxx->sosend() is sosend(). sosend uses uiomove() to bring the data in from user space unless you have set the UIO_SYSSPACE value for uio->uio_segflg. Since the uio is added in kern_sendit() you do not have the oportunity to change this. possibly this is what keta_kern_sendit() does but you do not show this function so I can not tell this. I'm also dubious whether you can use an int fd at that point.. are you runnin on behalf of a specific process of which you know the fd for the socket you want? For in-kernel use of a socket yuo should look at either the nfs code or the ng_ksocket code.. Not sure if this helps... > /*st = kern_sendit(td, so_fd,&msg,0,0);*/ > > st = keta_kern_sendit(td, control_so,&msg,0,0); > if( st!=0 ){ > if ( st == EAGAIN ){ > loadinfo_msleep(1); > } > else{ > log(LOG_DEBUG,"in loadinfo_send, send error(%d)!\n",st); > return st; > } > } > log(LOG_DEBUG,"send successfully !\n"); > return st; > } > > > > --------------------------------- > DO YOU YAHOO!? > 雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱 > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" >