From owner-freebsd-hackers Thu Jul 12 19:28:13 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from sneakerz.org (sneakerz.org [216.33.66.254]) by hub.freebsd.org (Postfix) with ESMTP id 01B1337B405; Thu, 12 Jul 2001 19:28:10 -0700 (PDT) (envelope-from bright@sneakerz.org) Received: by sneakerz.org (Postfix, from userid 1092) id 92FFF5D01F; Thu, 12 Jul 2001 21:28:09 -0500 (CDT) Date: Thu, 12 Jul 2001 21:28:09 -0500 From: Alfred Perlstein To: Greg Lehey Cc: y-carden@uniandes.edu.co, FreeBSD Hackers Subject: Re: Some questions about kernel programming Message-ID: <20010712212809.F6664@sneakerz.org> References: <20010713113822.V45037@wantadilla.lemis.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i In-Reply-To: <20010713113822.V45037@wantadilla.lemis.com>; from grog@FreeBSD.org on Fri, Jul 13, 2001 at 11:38:22AM +0930 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG * Greg Lehey [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