On Fri, 27 May 2022 23:02:46 +0200
Rubén Llorente <port...@use.startmail.com> wrote:

> I have also shamelessly copied the mechanism sort uses for rising its
> RDATA_LIMIT and tests so far look good. Still I have to figure out how
> to do the same thing with the stack size.
> 
> Also, how portable are setrlimit and getrlimit? Eventually we should get
> this patch submitted upstream.

Not portable: other Unix clones have setrlimit, but the meaning of
RDATA_LIMIT is different.  In some systems, RDATA_LIMIT only limits
sbrk(2), so one can bypass the limit by using anonymous mmap(2) to
allocate memory.  OpenBSD is more strict, because our RDATA_LIMIT
counts both sbrk(2) and anonymous mmap(2).

malloc(3) probably uses anonymous mmap(2), so those other systems
allow malloc(3) to take gigabytes of memory from anonymous mmap(2)
while ignoring RDATA_LIMIT.

For stack size, I'm not sure.  If you are on the main thread, try
RLIMIT_STACK.  If you are on another thread, try
pthread_attr_setstacksize(3).

Reply via email to