Date: Wed, 11 Mar 2009 16:38:30 +0200 From: Kostik Belousov <kostikbel@gmail.com> To: pluknet <pluknet@gmail.com> Cc: freebsd-hackers@freebsd.org Subject: Re: Non-existing p_vmspace. When is it possible? Message-ID: <20090311143830.GJ41617@deviant.kiev.zoral.com.ua> In-Reply-To: <a31046fc0903110638x52d9b6cbt4d39656c0be61442@mail.gmail.com> References: <a31046fc0903110606r7c398ef1ud2921e7c30658fe6@mail.gmail.com> <a31046fc0903110638x52d9b6cbt4d39656c0be61442@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--jlzMyYUOO8BCbMOc
Content-Type: text/plain; charset=koi8-r
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Wed, Mar 11, 2009 at 04:38:39PM +0300, pluknet wrote:
> Hi.
>=20
> 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.
>=20
> 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.
>=20
> Currently I additionally explicitly check on P_SYSTEM and PRS_NEW,
> then p->p_vmspace against NULL.
>=20
> So I'd wish to understand if a time-window between
> 1) placing a new process to proclist
> =9Aand
> 2) attaching vmspace to this process
> is possible at all, and then in what cases.
>=20
> 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.
>=20
> So an additional check on p_vmspace !=3D NULL is not need.
> Am I right?
The canonical sequence of doing this is, assuming p is a held pointer
to a process:
vm =3D vmspace_acquire_ref(p);
if (vm =3D=3D NULL) {
PRELE(p);
return ?;
}
use vm;
vmspace_free(vm);
Look around the tree for the vmspace_acquire_ref usage.
--jlzMyYUOO8BCbMOc
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)
iEYEARECAAYFAkm3zOUACgkQC3+MBN1Mb4hfJACfWipoAwAy+EovspIQAF/z+Z+e
iGQAn3VAiyQVG0d58CX1rgKdgmCQAC6f
=d3Nx
-----END PGP SIGNATURE-----
--jlzMyYUOO8BCbMOc--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090311143830.GJ41617>
