From owner-freebsd-hackers@FreeBSD.ORG Mon Aug 3 22:01:51 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CF49D106566C for ; Mon, 3 Aug 2009 22:01:51 +0000 (UTC) (envelope-from des@des.no) Received: from tim.des.no (tim.des.no [194.63.250.121]) by mx1.freebsd.org (Postfix) with ESMTP id 90EAD8FC15 for ; Mon, 3 Aug 2009 22:01:51 +0000 (UTC) (envelope-from des@des.no) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id 98AA56D418; Mon, 3 Aug 2009 22:01:50 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id 6FD36844C4; Tue, 4 Aug 2009 00:01:50 +0200 (CEST) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Maslan References: <319cceca0908030119i3432a495ya60aa431dab0e1b1@mail.gmail.com> <864ospvvkv.fsf@ds4.des.no> <319cceca0908031043x6bfe5771wa73553dce922756a@mail.gmail.com> <86eirs65gb.fsf@ds4.des.no> <319cceca0908031425r3516de29q34807cdf2c7489ed@mail.gmail.com> Date: Tue, 04 Aug 2009 00:01:50 +0200 In-Reply-To: <319cceca0908031425r3516de29q34807cdf2c7489ed@mail.gmail.com> (Maslan's message of "Mon, 3 Aug 2009 21:25:27 +0000") Message-ID: <86k51k4kvl.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: FreeBSD Hackers Subject: Re: sosend() and mbuf X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Aug 2009 22:01:52 -0000 Maslan writes: > Now i got another problem, when I open a text file from this thread, > the kernel crashes, I'm sure that its the thread. If the kernel crashed, I assume you have a dump and a backtrace and can tell us *where* it crashed? One thing that springs to mind is that kern_open() will dereference td->td_proc, and AFAIK kthread_create() does not associate the thread with a process. > kthread_create((void *)thread_main, NULL, NULL, RFNOWAIT, 0, > "thread"); There is no kthread_create() in head. I assume you're working on 7? You shouldn't. The cast is incorrect. I assume you put it there to silence the warning telling you that your code was wrong. This will create a new thread in process 0, which is probably not what you want (although it should work). It would be better to create a separate process for your code and create the thread there. You can do both in a single function call using kproc_kthread_add(). You don't show the part of your code where you call sched_add() to actually start the thread. > void thread_main(){ There are at least two problems here: 1) thread_main() is supposed to take a void * argument, and 2) you disabled or ignored the compiler warnings that told you this was wrong. > f_close(fd); You didn't include the definition of f_close(), so I can't tell if there's anything wrong with it. > int f_open(char *filename, int *fd){ > struct thread *td =3D curthread; > int ret =3D kern_open(td, filename, UIO_SYSSPACE, O_RDONLY, FREAD); > if(!ret){ > *fd =3D td->td_retval[0]; > return 1; > } > return 0; > } This is overly complicated. There is no reason to conditionalize the assignment to *fd; just do it and return ret. FREAD is not a valid argument to kern_open(). Well, technically, it's with the expected range, but it doesn't do what you think it does. This doesn't really matter, though, because the mode argument is not used when opening an existing file. That's all the help I can give until you provide a stack trace from the crash and the complete code, not just selected excerpts. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no