On Wed, Mar 11, 2009 at 04:38:39PM +0300, pluknet wrote: > Hi. > > I perform in FOREACH_PROC_IN_SYSTEM(), where I conditionally > look at p_vmspace internals. I'd like to know the safe way to > reference p_vmspace fields without potential null-dereference. > > I see an example in vm_pageout_oom(), where making access to > p->p_vmspace fields is done without additional checks. > Nevertheless I want to further catch on how it works. > > Currently I additionally explicitly check on P_SYSTEM and PRS_NEW, > then p->p_vmspace against NULL. > > So I'd wish to understand if a time-window between > 1) placing a new process to proclist > and > 2) attaching vmspace to this process > is possible at all, and then in what cases. > > I see in fork1() that a new process' (named p2 here) state is set to > PRS_NEW just before LIST_INSERT_HEAD(&allproc, p2, p_list) and then > (after vmspace is already attached in vm_forkproc()) is set to PRS_NORMAL. > > So an additional check on p_vmspace != NULL is not need. > Am I right?
The canonical sequence of doing this is, assuming p is a held pointer to a process: vm = vmspace_acquire_ref(p); if (vm == NULL) { PRELE(p); return ?; } use vm; vmspace_free(vm); Look around the tree for the vmspace_acquire_ref usage.
pgpRBITRednxy.pgp
Description: PGP signature