<div class="gmail_quote">On 17 June 2011 09:14, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com">kcc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Maybe the fallback code should just use a function call. Much simpler for documentation purposes. </blockquote><div><br>Sounds good.<br> <br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote"><div class="im"></div><div>On 32-bit, the shadow region is:</div><div><span style="font-family:arial, sans-serif;font-size:13px"><table style="border-collapse:separate;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204)">
<tbody><tr><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
<tt style="font-family:Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;font-size:12px;max-width:66em">[0x28000000, 0x3fffffff]</tt></td><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
<tt style="font-family:Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;font-size:12px;max-width:66em">HighShadow</tt></td></tr><tr><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
<tt style="font-family:Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;font-size:12px;max-width:66em">[0x24000000, 0x27ffffff]</tt></td><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
<tt style="font-family:Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;font-size:12px;max-width:66em">ShadowGap</tt></td></tr><tr><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
<tt style="font-family:Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;font-size:12px;max-width:66em">[0x20000000, 0x23ffffff]</tt></td><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
<tt style="font-family:Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;font-size:12px;max-width:66em">LowShadow</tt></td></tr></tbody></table></span></div>
<div><br></div><div>This is 0.5G total. So, I mmap all these three shadow subregions and 'mprotect' the ShadowGap. </div><div>This is done at startup. If the mmap fails, an assert will fire. </div></div></blockquote>
<div><br><br>I see. On embedded platforms that won't work with all cases. Most implementations have fragmented memory, memory mapped I/O, secure zones, etc. Depending on what you're trying to do, mmap will work but writing to memory won't.<br>
<br>On ARM world, SoC designers can come up with any number of configurations, which makes a generic implementation impossible. You'll need some kind of tablegen to define writeable regions and how to map between memory and shadow. Manufacturers generally provide this information when you buy the kit.<br>
<br>But again, most OSes should take care of that for you, so that's only relevant for bare-metal applications.<br><br><br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="gmail_quote"><div><br></div><div>
On 64-bit, the shadow looks like this: </div><div><span style="font-family:arial, sans-serif;font-size:13px"><table style="border-collapse:separate;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204)">
<tbody><tr><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
<tt style="font-family:Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;font-size:12px;max-width:66em">[0x0000140000000000, 0x00001fffffffffff]</tt></td><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
HighShadow</td></tr><tr><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
<tt style="font-family:Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;font-size:12px;max-width:66em">[0x0000120000000000, 0x000013ffffffffff]</tt></td><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
ShadowGap</td></tr><tr><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
<tt style="font-family:Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Lucida Console', monospace;font-size:12px;max-width:66em">[0x0000100000000000, 0x000011ffffffffff]</tt></td><td style="font-size:13px;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;border-left-width:1px;border-top-style:solid;border-right-style:solid;border-bottom-style:solid;border-left-style:solid;border-top-color:rgb(204, 204, 204);border-right-color:rgb(204, 204, 204);border-bottom-color:rgb(204, 204, 204);border-left-color:rgb(204, 204, 204);padding-top:5px;padding-right:5px;padding-bottom:5px;padding-left:5px">
LowShadow</td></tr></tbody></table></span></div><div><br></div><div>This is quite a lot, I can not mmap/mprotect this thing. </div><div>So, I basically *hope* that it won't be used by anyone but the ASAN run time (of course, there are asserts here and there to check it). </div>
<div>When some part of the shadow region is being written to (when we poison memory), SEGV happens and the SEGV handler mmaps the required region. </div></div></blockquote><div><br>Ok, if you allocate big enough regions you shouldn't need to SEGV that often.<br>
<br>
<br></div></div>-- <br>cheers,<br>--renato<br><br><a href="http://systemcall.org/" target="_blank">http://systemcall.org/</a><br><br>Reclaim your digital rights, eliminate DRM, learn more at <a href="http://www.defectivebydesign.org/what_is_drm" target="_blank">http://www.defectivebydesign.org/what_is_drm</a><br>