Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 25 Oct 2001 13:30:53 -0400 (EDT)
From:      sandeepj@research.bell-labs.com (Sandeep Joshi)
To:        hackers@freebsd.org
Subject:   Weird kld module error (bad curproc?)
Message-ID:  <200110251730.NAA25100@aura.research.bell-labs.com>

next in thread | raw e-mail | index | archive | help
I am seeing strange behaviour with a kld module
which prints out the curproc->p_pid of the caller.

Here are the details :

Configuration :
---------------
  Uniprocessor kernel/Single i686 CPU
  4.3-RELEASE
  kernel config = GENERIC + {DUMMYNET, BREAK_TO_DEBUGGER}

Setup :
-------
(a) I have a kld module, which has a function "func1" 
    that can get called by a system call invoked by some 
    user-level process. (but func1 is _not_ a system call)

func1() does
{
    ..
    printf("%d\n", curproc->p_pid);
    ..
}


(b) This kld module also starts up a kernel thread
    using kthread_create.  Lets call this thing "K1"

(c) External to the module, there is a program which
    starts as proc P1 and then forks child processes 
    C1, C2, C3...Cn

    Each of these children ultimately call "func1"
    as follows

    P1 process                     |K1 was    |
    |                              |started by|
    ------------------             |kld module|
    |    |    |      |
    v    v    v      v
    C1   C2   C3    C4 processes
    |    |    |      |
    v    v    v      v
   All call func1() in the loadable module


Problem scenario
-----------------

Here's the problem..  

When C1 or C2 call "func1", the pid printed out by 
curproc->p_pid is correct.

BUT when any child process beyond the 2nd (e.g. C3, C4)
call "func1", the pid printed is actually "K1" (which
is the thread started by the loadable module!)

This is a consistent error.  If P1 starts only 2
children (C1 & C2) then the error does not occur.
If it starts more than 2, these effects are visible.

Tried the debugger?
-------------------
Yes, when I put a breakpoint in the ddb to match up
curproc with ps listings, I cannot recreate the effect 
since context switches get slowed down and C3 or C4 
never enter func1.  The few times I tried stopping in
ddb, it was always C1 on the stack.

I noticed that globals.h redefines curproc for 
KLD_MODULE to be
  #define curproc GLOBAL_RVALUE_NV(curproc, struct proc *)

Any clues ??

-Sandeep

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200110251730.NAA25100>