Rémi Bernon (@rbernon) commented about server/async.c:
count = min( count, capacity );
i = 0;
if ((ptr = set_reply_data_size( count * sizeof(*ptr) )))
{
LIST_FOR_EACH_ENTRY_SAFE( async, next_async, &canceled_list, struct async, canceled_entry )
{
if (i++ < capacity)
{
if (!async->wait_handle)
async->wait_handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 );
*ptr++ = async->wait_handle;
}
list_remove( &async->canceled_entry );
}
reply->handles_size = count * sizeof(*ptr);
}
I think this could be reordered and you would not really need a list: Call `set_reply_data_size` first, and pass the pointer to cancel_async, which would allocate the wait handles if necessary and fill the array directly.
Another option for wait handle allocation is to move it to async creation unconditionally, which would be better for allocation failure handling, but that might be a waste of handles, so idk.