Date: Tue, 04 Aug 2009 00:01:50 +0200 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: Maslan <maslanbsd@gmail.com> Cc: FreeBSD Hackers <freebsd-hackers@freebsd.org> Subject: Re: sosend() and mbuf Message-ID: <86k51k4kvl.fsf@ds4.des.no> In-Reply-To: <319cceca0908031425r3516de29q34807cdf2c7489ed@mail.gmail.com> (Maslan's message of "Mon, 3 Aug 2009 21:25:27 %2B0000") References: <319cceca0908030119i3432a495ya60aa431dab0e1b1@mail.gmail.com> <864ospvvkv.fsf@ds4.des.no> <319cceca0908031043x6bfe5771wa73553dce922756a@mail.gmail.com> <86eirs65gb.fsf@ds4.des.no> <319cceca0908031425r3516de29q34807cdf2c7489ed@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Maslan <maslanbsd@gmail.com> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86k51k4kvl.fsf>