motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit d7c770fb7f071543c21d91dc2d01f01df81f0cf6 (tree)
parent 353c59e6d5f32203ade301c609e20c1fa954f73d
Author: Vincent Rischmann <vincent@rischmann.fr>
Date:   Sun, 10 Oct 2021 15:10:02 +0200

os: fix getrlimit/setrlimit test for MIPS

This test can fail due to a fix in musl for 32 bit MIPS, where musl changes limits greater than -1UL/2 to RLIM_INFINITY.
See http://git.musl-libc.org/cgit/musl/commit/src/misc/getrlimit.c?id=8258014fd1e34e942a549c88c7e022a00445c352

Depending on the system where the test is run getrlimit can return
RLIM_INFINITY for example if RLIMIT_MEMLOCK is bigger than ~2GiB.

If that happens, the setrlimit call will fail with PermissionDenied.

Diffstat:
Mlib/std/os/test.zig | 14+++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lib/std/os/test.zig b/lib/std/os/test.zig @@ -693,7 +693,19 @@ test "getrlimit and setrlimit" { inline for (std.meta.fields(os.rlimit_resource)) |field| { const resource = @intToEnum(os.rlimit_resource, field.value); const limit = try os.getrlimit(resource); - try os.setrlimit(resource, limit); + + // On 32 bit MIPS musl includes a fix which changes limits greater than -1UL/2 to RLIM_INFINITY. + // See http://git.musl-libc.org/cgit/musl/commit/src/misc/getrlimit.c?id=8258014fd1e34e942a549c88c7e022a00445c352 + // + // This happens for example if RLIMIT_MEMLOCK is bigger than ~2GiB. + // In that case the following the limit would be RLIM_INFINITY and the following setrlimit fails with EPERM. + if (comptime builtin.cpu.arch.isMIPS() and builtin.link_libc) { + if (limit.cur != os.linux.RLIM.INFINITY) { + try os.setrlimit(resource, limit); + } + } else { + try os.setrlimit(resource, limit); + } } }