Hi, I've been testing RLIMIT_DATA...
On Thu, Dec 19, 2024 at 10:36:49PM +0100, Luca wrote: > > I see that some limits (e.g. RLIMIT_DATA) are managed in glibc instead of > gnumach, maybe this could be a simpler way to add some minimal support? I > guess that one might overcome these limits by using directly the mach rpc or > hijacking glibc, but it could be enough for some use cases. > I failed to make it do anything. The only place where RLIMIT_DATA is read is in the Mach/Hurd specific `__hurd_set_brk` function. glibc-2.40/sysdeps/mach/hurd/brk.c: rlimit = _hurd_rlimits[RLIMIT_DATA].rlim_cur; [line 92] Which is called from __sbrk, and at that point I'm lost. Also, I cannot make it to fail with the attached test program.
#include <errno.h> #include <error.h> #include <limits.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <sys/mman.h> #include <sys/resource.h> #include <unistd.h> static const size_t M_1GB = (size_t) 1 * (size_t) 1024 * (size_t) 1024 * (size_t) 1024; static const size_t M_2GB = (size_t) 2 * M_1GB; static const size_t M_4GB = (size_t) 4 * M_1GB; static const size_t M_8GB = (size_t) 8 * M_1GB; int main(int argc, char **argv) { if (argc > 1 && argv[1][0] == 'l') { struct rlimit lims = { M_1GB / 4, M_1GB / 4 }; int err = setrlimit(RLIMIT_DATA, &lims); if (err == -1) { error(1, errno, "setrlimit failed"); } } void *addr1 = malloc(M_8GB); if (addr1 == NULL) { error(1, errno, "[addr1] mmap failed: errno=%u, ", errno); } void *addr2 = malloc(M_8GB); if (addr2 == NULL) { free(addr1); error(1, errno, "[addr2] mmap failed"); } free(addr1); free(addr2); return 0; }