<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 6, 2017 at 2:42 PM, Jonas Devlieghere <span dir="ltr"><<a href="mailto:jdevlieghere@apple.com" target="_blank">jdevlieghere@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class="gmail-"><blockquote type="cite"><div>On Sep 6, 2017, at 9:14 PM, Kostya Serebryany <<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>> wrote:</div><br class="gmail-m_-1091325060882693480Apple-interchange-newline"><div><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 6, 2017 at 8:43 AM, Jonas Devlieghere via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
Is it possible to change the value of ASan's allocator_may_return_null at runtime or somehow disable this check temporarily? If I install an LLVM bad_alloc_error_handler, ASan's allocator wrapper detects this first and terminates the process instead of returning 0, preventing the custom handler from being called.<br></blockquote><div><br></div>Is this question related to "r312582 - Revert "[Decompression] Fail gracefully when out of memory”"? </div></div></div></div></blockquote><div><br></div></span><div>It is! Though even if we don't need it, I’d still be interested to know whether this is possible. </div></div></div></blockquote><div><br></div><div>I'm not sure what you are asking for, exactly. </div><div>Here is how it works: </div><div><br></div><div>% clang++ -fsanitize=address  ~/llvm/projects/compiler-rt/test/asan/TestCases/allocator_returns_null.cc<br></div><div><br></div><div>% ./a.out malloc<br></div><div><div>==2503==WARNING: AddressSanitizer failed to allocate 0x10000000001 bytes</div></div><div><div>==2503==AddressSanitizer's allocator is terminating the process instead of returning 0</div><div>==2503==If you don't like this behavior set allocator_may_return_null=1</div></div><div><br></div><div>% ASAN_OPTIONS=allocator_may_return_null=1 ./a.out malloc<br></div><div><div>==2513==WARNING: AddressSanitizer failed to allocate 0x10000000001 bytes</div><div>errno: 12</div><div>x: 0</div></div><div><br></div><div>So you can change the value of allocator_may_return_null at startup. </div><div>There is no way to change this while the process is running. </div><div><br></div><div>You can set allocator_may_return_null per binary using __asan_default_options</div><div>(see llvm/projects/compiler-rt/include/sanitizer/asan_interface.h)</div><div>but unless absolutely necessary I'd try to avoid this. Lots of things may go wrong. </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><div>If the answer is no, I wonder how useful error handler is (which isn't currently used, at least not upstream). </div></div></div></blockquote><div><br></div><div>Imho, an error handler that tries to recover from OOM is a very dangerous thing and should be avoided. </div><div>This essentially introduces a very fragile code to the least tests path. </div><div><br></div><div>--kcc </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div><span class="gmail-"><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Thanks,<br>
Jonas<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div></div>
</div></blockquote></span></div><br></div></blockquote></div><br></div></div>