authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-03 16:45:55-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-12-03 16:45:55-08:00
log36b6e95aa3638fa8449526f68e46bc86d4b22e5c
tree5c1041e8ca7a6ddca8161e27a6ba36e10ed3380c
parentbb75f5d29709c7593dfe7269f70515919ff25c74
parentd7c770fb7f071543c21d91dc2d01f01df81f0cf6
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #9927 from vrischmann/fix-rlimit-resource

Fix rlimit_resource for MIPS and SPARC

4 files changed, 179 insertions(+), 44 deletions(-)

lib/std/os/linux.zig+46-43
......@@ -4197,65 +4197,68 @@ pub const ifreq = extern struct {
41974197};
41984198
41994199// doc comments copied from musl
4200pub const rlimit_resource = enum(c_int) {
4201 /// Per-process CPU limit, in seconds.
4202 CPU,
4200pub const rlimit_resource = if (native_arch.isMIPS() or native_arch.isSPARC())
4201 arch_bits.rlimit_resource
4202else
4203 enum(c_int) {
4204 /// Per-process CPU limit, in seconds.
4205 CPU,
42034206
4204 /// Largest file that can be created, in bytes.
4205 FSIZE,
4207 /// Largest file that can be created, in bytes.
4208 FSIZE,
42064209
4207 /// Maximum size of data segment, in bytes.
4208 DATA,
4210 /// Maximum size of data segment, in bytes.
4211 DATA,
42094212
4210 /// Maximum size of stack segment, in bytes.
4211 STACK,
4213 /// Maximum size of stack segment, in bytes.
4214 STACK,
42124215
4213 /// Largest core file that can be created, in bytes.
4214 CORE,
4216 /// Largest core file that can be created, in bytes.
4217 CORE,
42154218
4216 /// Largest resident set size, in bytes.
4217 /// This affects swapping; processes that are exceeding their
4218 /// resident set size will be more likely to have physical memory
4219 /// taken from them.
4220 RSS,
4219 /// Largest resident set size, in bytes.
4220 /// This affects swapping; processes that are exceeding their
4221 /// resident set size will be more likely to have physical memory
4222 /// taken from them.
4223 RSS,
42214224
4222 /// Number of processes.
4223 NPROC,
4225 /// Number of processes.
4226 NPROC,
42244227
4225 /// Number of open files.
4226 NOFILE,
4228 /// Number of open files.
4229 NOFILE,
42274230
4228 /// Locked-in-memory address space.
4229 MEMLOCK,
4231 /// Locked-in-memory address space.
4232 MEMLOCK,
42304233
4231 /// Address space limit.
4232 AS,
4234 /// Address space limit.
4235 AS,
42334236
4234 /// Maximum number of file locks.
4235 LOCKS,
4237 /// Maximum number of file locks.
4238 LOCKS,
42364239
4237 /// Maximum number of pending signals.
4238 SIGPENDING,
4240 /// Maximum number of pending signals.
4241 SIGPENDING,
42394242
4240 /// Maximum bytes in POSIX message queues.
4241 MSGQUEUE,
4243 /// Maximum bytes in POSIX message queues.
4244 MSGQUEUE,
42424245
4243 /// Maximum nice priority allowed to raise to.
4244 /// Nice levels 19 .. -20 correspond to 0 .. 39
4245 /// values of this resource limit.
4246 NICE,
4246 /// Maximum nice priority allowed to raise to.
4247 /// Nice levels 19 .. -20 correspond to 0 .. 39
4248 /// values of this resource limit.
4249 NICE,
42474250
4248 /// Maximum realtime priority allowed for non-priviledged
4249 /// processes.
4250 RTPRIO,
4251 /// Maximum realtime priority allowed for non-priviledged
4252 /// processes.
4253 RTPRIO,
42514254
4252 /// Maximum CPU time in µs that a process scheduled under a real-time
4253 /// scheduling policy may consume without making a blocking system
4254 /// call before being forcibly descheduled.
4255 RTTIME,
4255 /// Maximum CPU time in µs that a process scheduled under a real-time
4256 /// scheduling policy may consume without making a blocking system
4257 /// call before being forcibly descheduled.
4258 RTTIME,
42564259
4257 _,
4258};
4260 _,
4261 };
42594262
42604263pub const rlim_t = u64;
42614264
lib/std/os/linux/mips.zig+60
......@@ -769,3 +769,63 @@ pub const timezone = extern struct {
769769};
770770
771771pub const Elf_Symndx = u32;
772
773pub const rlimit_resource = enum(c_int) {
774 /// Per-process CPU limit, in seconds.
775 CPU,
776
777 /// Largest file that can be created, in bytes.
778 FSIZE,
779
780 /// Maximum size of data segment, in bytes.
781 DATA,
782
783 /// Maximum size of stack segment, in bytes.
784 STACK,
785
786 /// Largest core file that can be created, in bytes.
787 CORE,
788
789 /// Number of open files.
790 NOFILE,
791
792 /// Address space limit.
793 AS,
794
795 /// Largest resident set size, in bytes.
796 /// This affects swapping; processes that are exceeding their
797 /// resident set size will be more likely to have physical memory
798 /// taken from them.
799 RSS,
800
801 /// Number of processes.
802 NPROC,
803
804 /// Locked-in-memory address space.
805 MEMLOCK,
806
807 /// Maximum number of file locks.
808 LOCKS,
809
810 /// Maximum number of pending signals.
811 SIGPENDING,
812
813 /// Maximum bytes in POSIX message queues.
814 MSGQUEUE,
815
816 /// Maximum nice priority allowed to raise to.
817 /// Nice levels 19 .. -20 correspond to 0 .. 39
818 /// values of this resource limit.
819 NICE,
820
821 /// Maximum realtime priority allowed for non-priviledged
822 /// processes.
823 RTPRIO,
824
825 /// Maximum CPU time in µs that a process scheduled under a real-time
826 /// scheduling policy may consume without making a blocking system
827 /// call before being forcibly descheduled.
828 RTTIME,
829
830 _,
831};
lib/std/os/linux/sparc64.zig+60
......@@ -828,3 +828,63 @@ pub const ucontext_t = extern struct {
828828 stack: stack_t,
829829 sigmask: sigset_t,
830830};
831
832pub const rlimit_resource = enum(c_int) {
833 /// Per-process CPU limit, in seconds.
834 CPU,
835
836 /// Largest file that can be created, in bytes.
837 FSIZE,
838
839 /// Maximum size of data segment, in bytes.
840 DATA,
841
842 /// Maximum size of stack segment, in bytes.
843 STACK,
844
845 /// Largest core file that can be created, in bytes.
846 CORE,
847
848 /// Largest resident set size, in bytes.
849 /// This affects swapping; processes that are exceeding their
850 /// resident set size will be more likely to have physical memory
851 /// taken from them.
852 RSS,
853
854 /// Number of open files.
855 NOFILE,
856
857 /// Number of processes.
858 NPROC,
859
860 /// Locked-in-memory address space.
861 MEMLOCK,
862
863 /// Address space limit.
864 AS,
865
866 /// Maximum number of file locks.
867 LOCKS,
868
869 /// Maximum number of pending signals.
870 SIGPENDING,
871
872 /// Maximum bytes in POSIX message queues.
873 MSGQUEUE,
874
875 /// Maximum nice priority allowed to raise to.
876 /// Nice levels 19 .. -20 correspond to 0 .. 39
877 /// values of this resource limit.
878 NICE,
879
880 /// Maximum realtime priority allowed for non-priviledged
881 /// processes.
882 RTPRIO,
883
884 /// Maximum CPU time in µs that a process scheduled under a real-time
885 /// scheduling policy may consume without making a blocking system
886 /// call before being forcibly descheduled.
887 RTTIME,
888
889 _,
890};
lib/std/os/test.zig+13-1
......@@ -694,7 +694,19 @@ test "getrlimit and setrlimit" {
694694 inline for (std.meta.fields(os.rlimit_resource)) |field| {
695695 const resource = @intToEnum(os.rlimit_resource, field.value);
696696 const limit = try os.getrlimit(resource);
697 try os.setrlimit(resource, limit);
697
698 // On 32 bit MIPS musl includes a fix which changes limits greater than -1UL/2 to RLIM_INFINITY.
699 // See http://git.musl-libc.org/cgit/musl/commit/src/misc/getrlimit.c?id=8258014fd1e34e942a549c88c7e022a00445c352
700 //
701 // This happens for example if RLIMIT_MEMLOCK is bigger than ~2GiB.
702 // In that case the following the limit would be RLIM_INFINITY and the following setrlimit fails with EPERM.
703 if (comptime builtin.cpu.arch.isMIPS() and builtin.link_libc) {
704 if (limit.cur != os.linux.RLIM.INFINITY) {
705 try os.setrlimit(resource, limit);
706 }
707 } else {
708 try os.setrlimit(resource, limit);
709 }
698710 }
699711}
700712