Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 03 Jun 2005 17:58:40 -0700
From:      Julian Elischer <julian@elischer.org>
To:        shiner chen <shiner_chen@yahoo.com.cn>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: a error about the kern_sendit
Message-ID:  <42A0FCC0.6010805@elischer.org>
In-Reply-To: <20050603034129.34801.qmail@web15510.mail.cnb.yahoo.com>
References:  <20050603034129.34801.qmail@web15510.mail.cnb.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help


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"
> 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?42A0FCC0.6010805>