Re: [PATCH v3] Implement "info proc mappings" for NetBSD

Simon Marchi
2020-04-11T21:53:47Z

On 2020-04-11 5:28 p.m., Kamil Rytarowski wrote:
> On 11.04.2020 23:05, Simon Marchi wrote:
>> On 2020-04-06 5:37 a.m., Kamil Rytarowski wrote:
>>> @@ -39,3 +42,148 @@ nbsd_nat_target::pid_to_exec_file (int pid)
>>> return NULL;
>>> return buf;
>>> }
>>> +
>>> +/* Retrieve all the memory regions in the specified process. */
>>> +
>>> +static gdb::unique_xmalloc_ptr<struct kinfo_vmentry[]>
>>> +nbsd_kinfo_get_vmmap (pid_t pid, size_t *size)
>>> +{
>>> + int mib[5] = {CTL_VM, VM_PROC, VM_PROC_MAP, pid,
>>> + sizeof (struct kinfo_vmentry)};
>>> +
>>> + size_t length = 0;
>>> + if (sysctl (mib, ARRAY_SIZE (mib), NULL, &length, NULL, 0))
>>> + {
>>> + *size = 0;
>>> + return NULL;
>>> + }
>>> +
>>> + /* Prereserve more space. */
>>> + length = length * 5 / 3;
>>
>> Why is this needed?
>>
>
> This length is volatile and can be larger on the 2nd sysctl(3) call. We
> can call this function against a running process that can enlarge its
> usage of address space in this time window.

Ok, then please make the comment explain that. We can see that the expression
increases length, but as a reader I have no idea why.

Simon