<div dir="ltr">I don't see why not (It should go with r<span style="font-family:arial,sans-serif;font-size:13px">183651</span>). <div><br></div><div>--kcc </div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Mon, Jun 10, 2013 at 5:51 PM, Nathan Froyd <span dir="ltr"><<a href="mailto:froydnj@mozilla.com" target="_blank">froydnj@mozilla.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Kostya, Bill,<br>
<br>
Can this patch be backported to 3.3? It fixes a regression from 3.2.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Nathan<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
----- Original Message -----<br>
> Author: kcc<br>
> Date: Mon Jun 10 05:46:27 2013<br>
> New Revision: 183647<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=183647&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=183647&view=rev</a><br>
> Log:<br>
> [asan] fix the bug with memalign and malloc_usable_size<br>
> (<a href="http://code.google.com/p/address-sanitizer/issues/detail?id=193" target="_blank">http://code.google.com/p/address-sanitizer/issues/detail?id=193</a>);<br>
> also fix lint<br>
><br>
> Modified:<br>
> compiler-rt/trunk/lib/asan/asan_allocator2.cc<br>
> compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc<br>
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc<br>
><br>
> Modified: compiler-rt/trunk/lib/asan/asan_allocator2.cc<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator2.cc?rev=183647&r1=183646&r2=183647&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator2.cc?rev=183647&r1=183646&r2=183647&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/asan/asan_allocator2.cc (original)<br>
> +++ compiler-rt/trunk/lib/asan/asan_allocator2.cc Mon Jun 10 05:46:27<br>
> 2013<br>
> @@ -146,14 +146,15 @@ static uptr ComputeRZLog(uptr user_reque<br>
> // ChunkBase consists of ChunkHeader and other bytes that overlap<br>
> with user<br>
> // memory.<br>
><br>
> -// If a memory chunk is allocated by memalign and we had to increase<br>
> the<br>
> -// allocation size to achieve the proper alignment, then we store<br>
> this magic<br>
> +// If the left redzone is greater than the ChunkHeader size we store<br>
> a magic<br>
> // value in the first uptr word of the memory block and store the<br>
> address of<br>
> // ChunkBase in the next uptr.<br>
> -// M B ? ? ? L L L L L L H H U U U U U U<br>
> -// M -- magic value kMemalignMagic<br>
> +// M B L L L L L L L L L H H U U U U U U<br>
> +// | ^<br>
> +// ---------------------|<br>
> +// M -- magic value kAllocBegMagic<br>
> // B -- address of ChunkHeader pointing to the first 'H'<br>
> -static const uptr kMemalignMagic = 0xCC6E96B9;<br>
> +static const uptr kAllocBegMagic = 0xCC6E96B9;<br>
><br>
> struct ChunkHeader {<br>
> // 1-st 8 bytes.<br>
> @@ -276,10 +277,10 @@ struct QuarantineCallback {<br>
> RoundUpTo(m->UsedSize(), SHADOW_GRANULARITY),<br>
> kAsanHeapLeftRedzoneMagic);<br>
> void *p = reinterpret_cast<void *>(m->AllocBeg());<br>
> - if (m->from_memalign) {<br>
> - uptr *memalign_magic = reinterpret_cast<uptr *>(p);<br>
> - CHECK_EQ(memalign_magic[0], kMemalignMagic);<br>
> - CHECK_EQ(memalign_magic[1], reinterpret_cast<uptr>(m));<br>
> + if (p != m) {<br>
> + uptr *alloc_magic = reinterpret_cast<uptr *>(p);<br>
> + CHECK_EQ(alloc_magic[0], kAllocBegMagic);<br>
> + CHECK_EQ(alloc_magic[1], reinterpret_cast<uptr>(m));<br>
> }<br>
><br>
> // Statistics.<br>
> @@ -355,8 +356,6 @@ static void *Allocate(uptr size, uptr al<br>
> allocated = allocator.Allocate(cache, needed_size, 8, false);<br>
> }<br>
> uptr alloc_beg = reinterpret_cast<uptr>(allocated);<br>
> - // Clear the first allocated word (an old kMemalignMagic may still<br>
> be there).<br>
> - reinterpret_cast<uptr *>(alloc_beg)[0] = 0;<br>
> uptr alloc_end = alloc_beg + needed_size;<br>
> uptr beg_plus_redzone = alloc_beg + rz_size;<br>
> uptr user_beg = beg_plus_redzone;<br>
> @@ -373,11 +372,10 @@ static void *Allocate(uptr size, uptr al<br>
> CHECK_EQ(alloc_tid, m->alloc_tid); // Does alloc_tid fit into the<br>
> bitfield?<br>
> m->free_tid = kInvalidTid;<br>
> m->from_memalign = user_beg != beg_plus_redzone;<br>
> - if (m->from_memalign) {<br>
> - CHECK_LE(beg_plus_redzone + 2 * sizeof(uptr), user_beg);<br>
> - uptr *memalign_magic = reinterpret_cast<uptr *>(alloc_beg);<br>
> - memalign_magic[0] = kMemalignMagic;<br>
> - memalign_magic[1] = chunk_beg;<br>
> + if (alloc_beg != chunk_beg) {<br>
> + CHECK_LE(alloc_beg+ 2 * sizeof(uptr), chunk_beg);<br>
> + reinterpret_cast<uptr *>(alloc_beg)[0] = kAllocBegMagic;<br>
> + reinterpret_cast<uptr *>(alloc_beg)[1] = chunk_beg;<br>
> }<br>
> if (using_primary_allocator) {<br>
> CHECK(size);<br>
> @@ -533,31 +531,15 @@ static void *Reallocate(void *old_ptr, u<br>
> // Assumes alloc_beg == allocator.GetBlockBegin(alloc_beg).<br>
> static AsanChunk *GetAsanChunk(void *alloc_beg) {<br>
> if (!alloc_beg) return 0;<br>
> - uptr *memalign_magic = reinterpret_cast<uptr *>(alloc_beg);<br>
> - if (memalign_magic[0] == kMemalignMagic) {<br>
> - AsanChunk *m = reinterpret_cast<AsanChunk *>(memalign_magic[1]);<br>
> - CHECK(m->from_memalign);<br>
> - return m;<br>
> - }<br>
> if (!allocator.FromPrimary(alloc_beg)) {<br>
> uptr *meta = reinterpret_cast<uptr<br>
> *>(allocator.GetMetaData(alloc_beg));<br>
> AsanChunk *m = reinterpret_cast<AsanChunk *>(meta[1]);<br>
> return m;<br>
> }<br>
> - uptr actual_size =<br>
> - allocator.GetActuallyAllocatedSize(alloc_beg);<br>
> - CHECK_LE(actual_size, SizeClassMap::kMaxSize);<br>
> - // We know the actually allocted size, but we don't know the<br>
> redzone size.<br>
> - // Just try all possible redzone sizes.<br>
> - for (u32 rz_log = 0; rz_log < 8; rz_log++) {<br>
> - u32 rz_size = RZLog2Size(rz_log);<br>
> - uptr max_possible_size = actual_size - rz_size;<br>
> - if (ComputeRZLog(max_possible_size) != rz_log)<br>
> - continue;<br>
> - return reinterpret_cast<AsanChunk *>(<br>
> - reinterpret_cast<uptr>(alloc_beg) + rz_size -<br>
> kChunkHeaderSize);<br>
> - }<br>
> - return 0;<br>
> + uptr *alloc_magic = reinterpret_cast<uptr *>(alloc_beg);<br>
> + if (alloc_magic[0] == kAllocBegMagic)<br>
> + return reinterpret_cast<AsanChunk *>(alloc_magic[1]);<br>
> + return reinterpret_cast<AsanChunk *>(alloc_beg);<br>
> }<br>
><br>
> static AsanChunk *GetAsanChunkByAddr(uptr p) {<br>
><br>
> Modified: compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc?rev=183647&r1=183646&r2=183647&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc?rev=183647&r1=183646&r2=183647&view=diff</a><br>
> ==============================================================================<br>
> --- compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc (original)<br>
> +++ compiler-rt/trunk/lib/asan/tests/asan_noinst_test.cc Mon Jun 10<br>
> 05:46:27 2013<br>
> @@ -66,6 +66,7 @@ static void MallocStress(size_t n) {<br>
> size_t alignment = 1 << (my_rand_r(&seed) % 10 + 1);<br>
> char *ptr = (char*)__asan::asan_memalign(alignment, size,<br>
> &stack2,<br>
> __asan::FROM_MALLOC);<br>
> + EXPECT_EQ(size, __asan::asan_malloc_usable_size(ptr,<br>
> &stack2));<br>
> vec.push_back(ptr);<br>
> ptr[0] = 0;<br>
> ptr[size-1] = 0;<br>
><br>
> Modified:<br>
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc<br>
> URL:<br>
> <a href="http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc?rev=183647&r1=183646&r2=183647&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc?rev=183647&r1=183646&r2=183647&view=diff</a><br>
> ==============================================================================<br>
> ---<br>
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc<br>
> (original)<br>
> +++<br>
> compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc<br>
> Mon Jun 10 05:46:27 2013<br>
> @@ -179,8 +179,8 @@ static void ioctl_table_fill() {<br>
> _(0x00005315, READ, struct_cdrom_msf_sz); //<br>
> CDROMREADCOOKED<br>
> _(0x00005316, READ, struct_cdrom_msf_sz); // CDROMSEEK<br>
> // Conflicting request id.<br>
> - // _(0x00005382, NONE, 0); //<br>
> CDROMAUDIOBUFSIZ<br>
> - // _(0x00005382, WRITE, 2 * sizeof(int)); //<br>
> SCSI_IOCTL_GET_IDLUN<br>
> + // _(0x00005382, NONE, 0); //<br>
> CDROMAUDIOBUFSIZ<br>
> + // _(0x00005382, WRITE, 2 * sizeof(int)); //<br>
> SCSI_IOCTL_GET_IDLUN<br>
> _(0x00005383, NONE, 0); //<br>
> SCSI_IOCTL_TAGGED_ENABLE<br>
> _(0x00005384, NONE, 0); //<br>
> SCSI_IOCTL_TAGGED_DISABLE<br>
> _(0x00005385, READ, sizeof(int)); //<br>
> SCSI_IOCTL_PROBE_HOST<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
><br>
</div></div></blockquote></div><br></div>