Hello,

Diego Nieto Cid, le sam. 28 juin 2025 23:31:45 +0100, a ecrit:
> I was updating this patch and I've gut a doubt with what to do with the
> result of vm_map_find_entry_anywhere in case of a failure to enforce the
> limit.
> 
> I end up with code like below:
> 
>       if (anywhere) {
>               entry = vm_map_find_entry_anywhere(map, size, mask, FALSE, 
> &start);
> 
>               if (entry == NULL) {
>                       RETURN(KERN_NO_SPACE);
>               }
> 
>               end = start + size;
>               *address = start;
>               next_entry = entry->vme_next;
>       } else {
>               ...     
>               vm_map_lock(map);
>               ...
>       }
> 
> followed by the call to vm_map_enforce_limit:
> 
>       /*
>        *      If the allocation has protection equal to VM_PROT_NONE,
>        *      don't check for limits as the map's size_none field is
>        *      not yet incremented.
>        */
>       if (max_protection != VM_PROT_NONE) {
>               if ((result = vm_map_enforce_limit(map, size, "vm_map_enter")) 
> != KERN_SUCCESS)
>                       RETURN(result);
>       }
> 
> it requires the map locked which is the case as if anywhere is TRUE
> vm_map_find_entry_anywhere call will lock the map and otherwise the
> map is locked in the else case of the if in the first snippet.
> 
> My doubt is what to do the non NULL entry in case result, returned
> by the enforcer function, is not KERN_SUCCESS. Wouldn't I be leaking
> a vm_map_entry_t?

No, vm_map_find_entry_anywhere only returns an existing entry, which
vm_map_find_entry tries to extend, and if that is not possible,
vm_map_find_entry will allocate a new entry itself.

Samuel

Reply via email to