sosend() and mbuf

Dag-Erling Smørgrav des at des.no
Mon Aug 3 22:01:52 UTC 2009


Maslan <maslanbsd at 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 = curthread;
> 	int ret = kern_open(td, filename, UIO_SYSSPACE, O_RDONLY, FREAD);
> 	if(!ret){
> 		*fd = 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
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-hackers mailing list