<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60815>60815</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[gwp-asan] handle error of `mprotect` properly.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hanfei1991
</td>
</tr>
</table>
<pre>
When we allocate memory with gwp-asan, we call `mprotect` in https://github.com/llvm/llvm-project/blob/2d6713b5b7a2d489b50221fb282c20fabba0ca39/compiler-rt/lib/gwp_asan/platform_specific/guarded_pool_allocator_posix.cpp#L78
This api will return -1 when reaching system vm map limit, and then crash. I think we can handle this error silently, free the allocated address and return `nullptr`, just like what tcmalloc does in https://github.com/google/tcmalloc/blob/5034f8cecdbe559bf24e0ae7f7eb7c10b873ac9e/tcmalloc/guarded_page_allocator.cc#L94
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUk0-LpDoUxT9N3ISSeK34Z-Gi32uEB285MMviJl413dGEJLZT337Q_lPQm2FWgje_cHLOPRijmVaijsl_mHzOcEuzC92M60imaNsiU264dz9nWvlOHK11GhPxhRYX7nw3aebT7i8YcWXw73FGo7WcVWLxwSXSiVWCm5XPKfnIyicGPYN-MmneVK7dwqC39u3zc_HBvRwQ9Mo6xaCHoaqLUklVIwzXplVSABSjggY0iBGVQqGxbBn02i3eWAqXcPDWHPi0-9u7uN5bTKMLyy160mY0-hhvGAYabt45e_t4nQs376L5lWvvGZT_1w0Tz0w8_ZhN5OgN3421PFDawsovBd8PcwKhns068XiPiRb-tvAFPbdmMekwBteBp-OgDhjnnP_H02zW13fDVj7jOlg6_kVOIbjAo7G0Jns_4DHQMXv4P3AchkAxnvd-SGGVWDdrfQqsEgf2ssXErXklvs-YeNLLyfPBUfxDJJNzkyUG_Sf0CESK8jo2mvSgSMpWjXAlgVSPNalaF0I1dYm6_QZ_GY0TPYzOtT4cbq88G7pyaMsWM-qKqq5kBW1dZXOnQY8NNmrUVOJYt9dG60bWsh7bklSjMtOBgFJAURVSVkWVC9AAVSnbEXUjh5ZdBS1obH4sWO7ClJkYN-oq0RQys6jIxnP_AVba-TlkAEcdQncupdqmyK7Cmpji45Zkkj2L81UA-fwZ5HuGbvxeBB-cp2DvebYF2_11J05tkUF_av8dAAD__3z9PRI">