From owner-freebsd-hackers Thu Oct 25 10:32:23 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from crufty.research.bell-labs.com (crufty.research.bell-labs.com [204.178.16.49]) by hub.freebsd.org (Postfix) with SMTP id 2C17F37B401 for ; Thu, 25 Oct 2001 10:32:13 -0700 (PDT) Received: from scummy.research.bell-labs.com ([135.104.2.10]) by crufty; Thu Oct 25 13:26:47 EDT 2001 Received: from aura.research.bell-labs.com (aura.research.bell-labs.com [135.104.46.10]) by scummy.research.bell-labs.com (8.11.4/8.11.4) with ESMTP id f9PHUrl02422 for ; Thu, 25 Oct 2001 13:30:53 -0400 (EDT) Received: (from sandeepj@localhost) by aura.research.bell-labs.com (8.9.1/8.9.1) id NAA25100 for hackers@freebsd.org; Thu, 25 Oct 2001 13:30:53 -0400 (EDT) Date: Thu, 25 Oct 2001 13:30:53 -0400 (EDT) Message-Id: <200110251730.NAA25100@aura.research.bell-labs.com> From: sandeepj@research.bell-labs.com (Sandeep Joshi) To: hackers@freebsd.org Subject: Weird kld module error (bad curproc?) 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 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