jedisct1/libuv — comment on commit 6e280b341b9f5feb38157d8ddb340c21610685dd
File: src/unix/openbsd.c line 68
By jedisct1:

Hi Ben,

KERN_ARGMAX is the max number of arguments, not the maximum overall size required to store them all.

Growing the buffer until everything fits is the approach in every piece of code using this interface in OpenBSD, including the kvm library.

The sysctl() call requires a buffer large enough to store the list of pointers to each arguments, immediately followed by the arguments themselves.

This interface sucks, but I'm not sure that we can do anything better. That said, the kernel enforces a hard limit of 256 Kb, so more than this amount of memory can never be temporary wasted.