From owner-freebsd-hackers Thu Jul 12 19: 8:33 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from wantadilla.lemis.com (wantadilla.lemis.com [192.109.197.80]) by hub.freebsd.org (Postfix) with ESMTP id B6A8B37B401; Thu, 12 Jul 2001 19:08:24 -0700 (PDT) (envelope-from grog@lemis.com) Received: by wantadilla.lemis.com (Postfix, from userid 1004) id EA6816ACBC; Fri, 13 Jul 2001 11:38:22 +0930 (CST) Date: Fri, 13 Jul 2001 11:38:22 +0930 From: Greg Lehey To: y-carden@uniandes.edu.co Cc: FreeBSD Hackers Subject: Re: Some questions about kernel programming Message-ID: <20010713113822.V45037@wantadilla.lemis.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from y-carden@uniandes.edu.co on Thu, Jul 12, 2001 at 06:58:09AM -0500 Organization: The FreeBSD Project Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-418-838-708 WWW-Home-Page: http://www.FreeBSD.org/ X-PGP-Fingerprint: 6B 7B C3 8C 61 CD 54 AF 13 24 52 F8 6D A4 95 EF 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 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