Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Jul 2001 11:38:22 +0930
From:      Greg Lehey <grog@FreeBSD.org>
To:        y-carden@uniandes.edu.co
Cc:        FreeBSD Hackers <hackers@freebsd.org>
Subject:   Re: Some questions about kernel programming
Message-ID:  <20010713113822.V45037@wantadilla.lemis.com>
In-Reply-To: <M2001071206580901828@Ayax.uniandes.edu.co>; from y-carden@uniandes.edu.co on Thu, Jul 12, 2001 at 06:58:09AM -0500
References:  <M2001071206580901828@Ayax.uniandes.edu.co>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thursday, 12 July 2001 at  6:58:09 -0500, y-carden@uniandes.edu.co wrote:
> Dear Friends
>
> I have some questions about kernel programming:

You'd be better off sending mail like this to -hackers.  I've followed
up there.

> 1. Why I can call some system calls functions into the kernel but
>    another not?, for example: I can call printf(), but I can't call
>    socket().

You can't call system calls from the kernel.  printf() is a library
call in userland; there's a different, but similar printf() in the
kernel.

> 2. Into kernel I can call the socket "low level" functions
>    that this system calls invoke  sosocket(), soconnect(), etc.
>    but, How I do replace the send() system call? Perhaps, Can I call
>    write() into kernel with same parameters?
>    For example :
>    /* res =  send(skt, buf, buflen, 0); */
>    res =  write (skt, buf, buflen);

write() doesn't exist in the kernel.  The simple answer is "you're
going to have to read what the send() syscall does and emulate it".
First, though, you need to answer the question "why do I want to do
this in the kernel?"

> 3. How I can copy a pointer string ( character array ) from user space to
>    kernel space using copyin() without the following problem (I can't
>    pass the length the explicitly from user land):
>
> struct	MySystemCall_args {
> 	char *	address;
> };
>
> int MySystemCall( p,uap)
>   struct proc *p;
>   register struct  MySystemCall_args *uap;
> {
>   char *the_address;
>
>   printf(" ---> uap->address : %s\n", uap->address );
>   printf(" ---> (strlen (uap->address) * sizeof(char)) : %d \n",
> 	(strlen (uap->address) * sizeof(char)) );
>   copyin(uap->address, the_address, (strlen (uap->address) * sizeof(char))
> );
>   printf("the_address: %s \n", the_address );
>   printf("strlen (the_address): %d \n", strlen (the_address) );
>
> When this code run in mode kernel:
>   ---> uap->address : 127.0.0.1
>   ---> (strlen (uap->address) * sizeof(char)) : 9
>   the_address : 127.0.0.1\M-"\M-Y\M-GX\M-p+\M-@@\M-_\M-*\M-@
>   strlen (the_address): 20
>
> This crash the kernel later...

You've forgotten the terminating \0.  Add one to the length.

Greg
--
When replying to this message, please copy the original recipients.
If you don't, I may ignore the reply.
For more information, see http://www.lemis.com/questions.html
See complete headers for address and phone numbers

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




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