[compiler-rt] [sanitizer-common] Improve mach_vm_region_recurse error handling (PR #158670)
Mariusz Borsa via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 17:09:30 PDT 2025
================
@@ -1265,17 +1265,34 @@ uptr FindAvailableMemoryRange(uptr size, uptr alignment, uptr left_padding,
kr = mach_vm_region_recurse(mach_task_self(), &address, &vmsize, &depth,
(vm_region_info_t)&vminfo, &count);
- // There are cases where going beyond the processes' max vm does
- // not return KERN_INVALID_ADDRESS so we check for going beyond that
- // max address as well.
- if (kr == KERN_INVALID_ADDRESS || address > max_vm_address) {
+ if (kr == KERN_SUCCESS) {
+ // There are cases where going beyond the processes' max vm does
+ // not return KERN_INVALID_ADDRESS so we check for going beyond that
+ // max address as well.
+ if (address > max_vm_address) {
+ address = max_vm_address;
+ kr = -1; // break after this iteration.
+ }
+
+ if (max_occupied_addr)
+ *max_occupied_addr = address + vmsize;
+ } else if (kr == KERN_INVALID_ADDRESS) {
// No more regions beyond "address", consider the gap at the end of VM.
address = max_vm_address;
- vmsize = 0;
- kr = -1; // break after this iteration.
+
+ // We will break after this iteration anyway since kr != KERN_SUCCESS
+ } else if (kr == KERN_DENIED) {
----------------
wrotki wrote:
I knew I saw it somewhere but only found it now, in Dan's comments to your other PR:
https://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code
https://github.com/llvm/llvm-project/pull/158670
More information about the llvm-commits
mailing list