Subject: Re: a (harmless) typo in cpu_getmcontext()?
To: Dmitri Nikulin <firstname.lastname@example.org>
From: Klaus Klein <email@example.com>
Date: 11/10/2004 23:36:54
On Wed, Nov 10, 2004 at 12:25:51AM +1100, Dmitri Nikulin wrote:
> What I wanted to ask was, if the old memset was 'broken' (since it set
> everything to '0', not 0) but the system worked anyway, is the memset
> even needed? Clearly it didn't do anything useful anyway (unless the
> next steps require everything to be the same, not necessarily zeroed),
> so why not dd it out entirely? This saves code space, generated code
> space, and a few CPU cycles. Surely this is the NetBSD Way.
The use of memset() in that place does have a purpose, actually.
NetBSD uses an mcontext_t storage layout conforming to the SVR4
ABI; however, it does not fill in all the structure's members.
Use of the mcontext storage passed to the function in question is
typically to be filled with the details of execution state of a
user process, and subsequently to be copied out, from the kernel,
to the memory space of that process.
Now, if you keep in mind that the mcontext object had been
allocated from kernel memory originally, those structure
members that were not filled in contain "garbage" from
previous uses of that memory, and leaking information from
kernel memory is a matter causing much concern. Blinding it
with '0' worked as well as 0 but was somewhat ... unconventional,
I hope this clarifies the issue (and the NetBSD Way) to some extent.