Hello,

[email protected], le ven. 15 août 2025 02:57:29 +0100, a ecrit:
> diff --git a/include/mach/gnumach.defs b/include/mach/gnumach.defs
> index f13e866b..f5b2f7f2 100644
> --- a/include/mach/gnumach.defs
> +++ b/include/mach/gnumach.defs
> @@ -223,3 +223,37 @@ simpleroutine thread_set_name(
>  routine thread_get_name(
>          thread : thread_t;
>          out name : kernel_debug_name_t);
> +
> +/*
> + *   Set a task virtual memory limit parameters
> + *
> + *   HOST_PORT must be the privileged host control port
> + *   if the caller desires to increase the current max limit.
> + *
> + *   On the other hand, if the max limit is being decreased, the
> + *   unprivileged host control port (as returned by mach_host_self())
> + *   can be provided.
> + *
> + *   Returns:
> + *     - KERN_SUCCESS
> + *     - KERN_INVALID_TASK
> + *     - KERN_INVALID_HOST
> + *     - KERN_INVALID_ARGUMENT
> + *         * when current_limit > max_limit
> + *        - KERN_NO_ACCESS
> + *         * attempt to increase max limit without providing
> + *           the privileged host control port.
> + */
> +routine vm_set_size_limit(
> +     host_port     : mach_port_t;
> +     map           : vm_task_t;
> +     current_limit : vm_size_t;
> +     max_limit     : vm_size_t);
> +
> +/*
> + *   Get a task virtual memory limit parameters
> + */
> +routine vm_get_size_limit(
> +             map           : vm_task_t;
> +     out     current_limit : vm_size_t;
> +     out     max_limit     : vm_size_t);

Please also document them along the other vm_* calls in doc/mach.texi

> diff --git a/vm/vm_map.c b/vm/vm_map.c
> index e1f8af9e..698dfa3c 100644
> --- a/vm/vm_map.c
> +++ b/vm/vm_map.c
> @@ -189,6 +189,7 @@ void vm_map_setup(
> @@ -786,11 +835,19 @@ kern_return_t vm_map_find_entry(
>       vm_size_t               size,
>       vm_offset_t             mask,
>       vm_object_t             object,
> -     vm_map_entry_t          *o_entry)       /* OUT */
> +     vm_map_entry_t          *o_entry,       /* OUT */
> +     vm_prot_t               protection,
> +     vm_prot_t               max_protection)

Please add their documentation in the comment above the function
definition.

Notably, that will explain why

> diff --git a/vm/vm_kern.c b/vm/vm_kern.c
> index 51223d98..918abe28 100644
> --- a/vm/vm_kern.c
> +++ b/vm/vm_kern.c
> @@ -108,7 +108,8 @@ projected_buffer_allocate(
>  
>       vm_map_lock(kernel_map);
>       kr = vm_map_find_entry(kernel_map, &addr, size, (vm_offset_t) 0,
> -                            VM_OBJECT_NULL, &k_entry);
> +                            VM_OBJECT_NULL, &k_entry,
> +                            VM_PROT_DEFAULT, VM_PROT_ALL);

we are doing this.

>       if (kr != KERN_SUCCESS) {
>         vm_map_unlock(kernel_map);
>         vm_object_deallocate(object);
> @@ -125,7 +126,8 @@ projected_buffer_allocate(
>  
>       vm_map_lock(map);
>       kr = vm_map_find_entry(map, &addr, size, (vm_offset_t) 0,
> -                            VM_OBJECT_NULL, &u_entry);
> +                            VM_OBJECT_NULL, &u_entry,
> +                            protection, protection);
>       if (kr != KERN_SUCCESS) {
>         vm_map_unlock(map);
>         vm_map_lock(kernel_map);
> @@ -144,6 +146,7 @@ projected_buffer_allocate(
>       u_entry->protection = protection;
>       u_entry->max_protection = protection;

Here, we want to remove setting u_entry->{,max_}protection, that's the
whole point of the additional parameter.

>       u_entry->inheritance = inheritance;
> +
>       vm_map_unlock(map);
>               *user_p = addr;
>  
> @@ -209,7 +212,8 @@ projected_buffer_map(
>  
>       vm_map_lock(map);
>       kr = vm_map_find_entry(map, &user_addr, size, (vm_offset_t) 0,
> -                            VM_OBJECT_NULL, &u_entry);
> +                            VM_OBJECT_NULL, &u_entry,
> +                            protection, protection);
>       if (kr != KERN_SUCCESS) {
>         vm_map_unlock(map);
>         return kr;
> @@ -226,6 +230,7 @@ projected_buffer_map(
>       u_entry->max_protection = protection;
>       u_entry->inheritance = inheritance;

And similarly here.

>       u_entry->wired_count = k_entry->wired_count;
> +
>       vm_map_unlock(map);
>               *user_p = user_addr;

Samuel

Reply via email to