Date: Thu, 12 Jul 2001 21:28:09 -0500 From: Alfred Perlstein <bright@sneakerz.org> To: Greg Lehey <grog@FreeBSD.org> Cc: y-carden@uniandes.edu.co, FreeBSD Hackers <hackers@freebsd.org> Subject: Re: Some questions about kernel programming Message-ID: <20010712212809.F6664@sneakerz.org> In-Reply-To: <20010713113822.V45037@wantadilla.lemis.com>; from grog@FreeBSD.org on Fri, Jul 13, 2001 at 11:38:22AM %2B0930 References: <M2001071206580901828@Ayax.uniandes.edu.co> <20010713113822.V45037@wantadilla.lemis.com>
next in thread | previous in thread | raw e-mail | index | archive | help
* Greg Lehey <grog@FreeBSD.org> [010712 21:08] wrote: > 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. I also got this in private mail, hrmm.. > 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?" it actually exists, however the problem is that copyin and friends assume a seperate address space, I wonder if one could do some trick to alias the seperate address space on top of the kernel, that should allow copyin and friends to work on pointers into the kernel's address space. > > 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. You can't call kernel strlen on a userland address, you must do something like this: /* * return number of characters in a userland address string * or -1 if an illegal access occurs. */ int user_strlen(uaddr) char *uaddr; { int ret; ret = -1; do { ch = fubyte(uaddr); ret++; } while (ch != 0 && ch != -1); return (ch == -1 ? -1 : ret); } -- -Alfred Perlstein [alfred@freebsd.org] Ok, who wrote this damn function called '??'? And why do my programs keep crashing in it? 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?20010712212809.F6664>