setrlimit for RLIMIT_DATA fails for values < 418301149184

Hello!

On arm64 macOS Monterey 12.3, calling the setrlimit C function for the RLIMIT_DATA resource to set the rlim_cur field of the rlimit struct fails (i.e., EINVAL [Invalid argument]) for values less than 418301149184. For values greater than or equal to 418301149184, it succeeds. Does anyone know why this is?

I think it's a bug, but I suppose it could be an undocumented change in behavior as well.

I created a reproducer if anyone would like to try it (this forum will only let me attach files with certain extensions, hence the .txt extensions):

To build:

$ mv Makefile.txt Makefile
$ mv set-rlimit-data.c.txt set-rlimit-data.c
$ make

Here's running it with a value less than 418301149184 which fails:

$ ./set-rlimit-data 30000000
getrlimit RLIMIT_DATA rlim_cur: 9223372036854775807
getrlimit RLIMIT_DATA rlim_max: 9223372036854775807
setrlimit RLIMIT_DATA rlim_cur: 30000000
setrlimit RLIMIT_DATA rlim_max: 9223372036854775807
set-rlimit-data: setrlimit failed: Invalid argument
$ echo $?
1

And here's running it with a value of 418301149184 which succeeds:

$ ./set-rlimit-data 418301149184
getrlimit RLIMIT_DATA rlim_cur: 9223372036854775807
getrlimit RLIMIT_DATA rlim_max: 9223372036854775807
setrlimit RLIMIT_DATA rlim_cur: 418301149184
setrlimit RLIMIT_DATA rlim_max: 9223372036854775807
$ echo $?
0

You can also see this problem with the ulimit built-in of /bin/sh (but note that the units of the ulimit -d option argument are KB, not B):

$ /bin/sh -c 'ulimit -d 30000 /usr/bin/true'
/bin/sh: line 0: ulimit: data seg size: cannot modify limit: Invalid argument
$ echo $?
1

The setrlimit(2) man page does not say anything about values less than 418301149184 being invalid.

I submitted this yesterday as a feedback to Apple, and it has been assigned the FB9963813 identifier.

Thank you!

P.S. I wish Apple had a public issue tracker so that I could have a public URL to link to when referring to an issue! The next best thing, as far as I can tell, is to post to this forum and reference the post. If there's a better way to reference issues, I would love to hear about it!

There is this if you want to use it: http://openradar.appspot.com/faq It's just a copy of the radars people send to apple.

I am having the same issue after upgrading to Monterey 12.7.1 It worked on 12.7.0 and also works on Big Sur 11.7.10. I also tested on Sonoma 14.1.1 and it fails there too. I used the above program to test.

setrlimit for RLIMIT_DATA fails for values &lt; 418301149184
 
 
Q