Re: Hidden read of indeterminate memory
From: glen herrmannsfeldt (gah_at_ugcs.caltech.edu)
Date: 12/21/03
- Next message: Sander: "2 style questions"
- Previous message: Ben Pfaff: "Re: Hidden read of indeterminate memory"
- In reply to: pete: "Re: Hidden read of indeterminate memory"
- Next in thread: Ben Pfaff: "Re: Hidden read of indeterminate memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 21 Dec 2003 07:48:01 GMT
pete wrote:
(snip)
> According to:
> 1 the definition of undefined behavior
> 2 the fact that uninitialized objects have indeterminate value
> I don't think that a program is required to reserve storage
> for an uninitialized object,
> unless the address is of the object is taken.
Maybe not.
One I did hear about, and posted in another, unrelated, thread,
was a system that initially mapped the same page of real memory
to all allocated virtual memory, and marked that page read only.
When it was actually written to, a new, read/write page is
allocated, the page tables are changed, and the data is written
into that page.
The unexpected effect came when someone wanted to test the
speed of memory access, minimizing the effect of a cache.
The test program malloc()'ed a large region of memory and
continually accessed it. It was enough larger than the cache
that it was expected all access to go to real memory.
As it didn't seem to matter what the data was, nothing was
ever written to the memory. Well, only one real page was
allocated, small enough to fit in the cache, and so the cache
speed was measured.
It might be possible on some systems to initially map such
pages so that they couldn't be read, and have undesirable
side effects. It doesn't seem much harder, though, to map
to a single page, assuming that a paging system is in use.
There are unexpected effects that can occur when memory is
read without first being written. Because of the cases where
this could happen, unintentionally, in real programs, systems
should make sure that the effects aren't too bad.
Padding bytes of structures, for example, are normally not
written, yet one could reasonably expect to be able to copy
a structure with memcpy().
-- glen
- Next message: Sander: "2 style questions"
- Previous message: Ben Pfaff: "Re: Hidden read of indeterminate memory"
- In reply to: pete: "Re: Hidden read of indeterminate memory"
- Next in thread: Ben Pfaff: "Re: Hidden read of indeterminate memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|