variable init

mdf at FreeBSD.org mdf at FreeBSD.org
Mon Aug 1 14:16:06 UTC 2011


On Mon, Aug 1, 2011 at 12:09 AM, Andrew Thompson <andy at fud.org.nz> wrote:
> Hi,
>
> Looking at,
>
> http://www.freebsd.org/cgi/query-pr.cgi?pr=159345
>
> The lock is a global variable, declared as
>
> static struct mtx       lagg_list_mtx;
>
> I would expect this to be zeroed memory, is this guaranteed?

It depends. :-)  The C standard mandates that this storage be zero.
However, seeing as we're the operating system, it's our job to do it.
For an application program the zero'd storage is zeroed by the loader.
 For the operating system, exactly when it's initialized is an
architectural decision.  I believe that the zeroed storage of FreeBSD
is cleared by the boot loader before it transfers control to the
operating system.  (For reference, on AIX the storage is cleared by
the virtual memory management code during bringup of the VMM leading
to interesting bugs when some variables used in early boot weren't
initialized).

Cheers,
matthew


More information about the freebsd-current mailing list