Hello,
Thanks for working on this!
Manolo de Medici, le mer. 18 mars 2026 21:29:11 +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 501ca0f6..50a8bb3c 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_name_processors(
> + set_name : processor_set_name_t;
> + out processors_list : processor_name_array_t);
I wouldn't put "_name" in the RPC name, other RPCs don't do that, e.g.
processor_set_info.
> diff --git a/kern/host.c b/kern/host.c
> index 26231b2b..53bc88c1 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_name_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)
> + return KERN_RESOURCE_SHORTAGE;
You need to unlock before returning an error
> +
> + tp = (processor_t *) addr;
> + queue_iterate(&pset->processors, p, processor_t, processors) {
> + tp[i++] = p;
> + }
But the processor_t could disappear, couldn't it?
> +
> + simple_unlock(&pset->lock);
> +
> + *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]);
We'd want to make these send rights while iterating with the lock, to be
sure the processor_t still exists. Once we unlock some may die, but
that's fine, the corresponding name can become dead.
Samuel