Manolo de Medici, le mar. 24 mars 2026 21:40:37 +0000, a ecrit:
> This call allows to get the list of unprivileged processor ports
> belonging to a processor set.
> ---
>  include/mach/mach_host.defs |  7 +++++++
>  kern/host.c                 | 40 +++++++++++++++++++++++++++++++++++++
>  2 files changed, 47 insertions(+)
> 
> diff --git a/include/mach/mach_host.defs b/include/mach/mach_host.defs
> index 372f3859..e9aa1603 100644
> --- a/include/mach/mach_host.defs
> +++ b/include/mach/mach_host.defs
> @@ -393,3 +393,10 @@ routine  host_get_kernel_version(
>  routine      host_get_uptime64(
>               host            : host_t;
>       out     uptime          : time_value64_t);
> +
> +/*
> + *   Get list of processors in processor set
> + */
> +routine processor_set_processors(
> +             set_name        : processor_set_name_t;
> +     out     processors_list : processor_name_array_t);
> diff --git a/kern/host.c b/kern/host.c
> index e7219e1c..c9ebd069 100644
> --- a/kern/host.c
> +++ b/kern/host.c
> @@ -387,3 +387,43 @@ host_processor_set_priv(
>       pset_reference(*pset);
>       return KERN_SUCCESS;
>  }
> +
> +kern_return_t processor_set_processors(
> +     const processor_set_t   pset,
> +     processor_name_array_t  *processor_list,
> +     natural_t               *countp)
> +{
> +     unsigned                count, i = 0;
> +     vm_offset_t             addr;
> +     processor_t             p;
> +     processor_t             *tp;
> +
> +     if (pset == PROCESSOR_SET_NULL)
> +             return KERN_INVALID_ARGUMENT;
> +
> +     simple_lock(&pset->lock);
> +
> +     count = pset->processor_count;
> +
> +     addr = kalloc((vm_size_t) (count * sizeof(mach_port_t)));
> +     if (addr == 0) {
> +             simple_unlock(&pset->lock);
> +             return KERN_RESOURCE_SHORTAGE;
> +     }
> +
> +     tp = (processor_t *) addr;
> +     queue_iterate(&pset->processors, p, processor_t, processors) {
> +             tp[i++] = p;
> +     }
> +
> +     *countp = count;
> +     *processor_list = (mach_port_t *) addr;
> +
> +     /* do the conversion that Mig should handle */
> +     for (i = 0; i < count; i++)
> +             ((mach_port_t *) tp)[i] =
> +                     (mach_port_t)convert_processor_name_to_port(tp[i]);

Now, better directly fold this loop with the previous one, and directly
make tp a (mach_port_t *) and write

                tp[i++] = (mach_port_t)convert_processor_name_to_port(p);

(and you can directly assign *processor_list = tp).

Samuel

> +
> +     simple_unlock(&pset->lock);
> +     return KERN_SUCCESS;
> +}
> -- 
> 2.53.0
> 
> 

-- 
Samuel
<r> make
<r> oops
<m> make clean

Reply via email to