diff options
| author | Ian Lance Taylor <iant@golang.org> | 2023-03-13 20:59:14 -0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@google.com> | 2023-03-15 17:21:30 +0000 |
| commit | f5eef58e4381259cbd84b3f2074c79607fb5c821 (patch) | |
| tree | 1405152029a813b5e8efa81c1cd10212a6eb12a0 /src/syscall/syscall_linux_arm.go | |
| parent | 491153a71ab2bae3fe9a586489320573448511ab (diff) | |
| download | go-f5eef58e4381259cbd84b3f2074c79607fb5c821.tar.xz | |
syscall: restore original NOFILE rlimit in child process
If we increased the NOFILE rlimit when starting the program,
restore the original rlimit when forking a child process.
For #46279
Change-Id: Ia5d2af9ef435e5932965c15eec2e428d2130d230
Reviewed-on: https://go-review.googlesource.com/c/go/+/476097
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/syscall/syscall_linux_arm.go')
| -rw-r--r-- | src/syscall/syscall_linux_arm.go | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/syscall/syscall_linux_arm.go b/src/syscall/syscall_linux_arm.go index f4740af586..600ec3552d 100644 --- a/src/syscall/syscall_linux_arm.go +++ b/src/syscall/syscall_linux_arm.go @@ -159,9 +159,9 @@ func Getrlimit(resource int, rlim *Rlimit) (err error) { return } -//sysnb setrlimit(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT +//sysnb setrlimit1(resource int, rlim *rlimit32) (err error) = SYS_SETRLIMIT -func Setrlimit(resource int, rlim *Rlimit) (err error) { +func setrlimit(resource int, rlim *Rlimit) (err error) { err = prlimit(0, resource, rlim, nil) if err != ENOSYS { return err @@ -183,7 +183,34 @@ func Setrlimit(resource int, rlim *Rlimit) (err error) { return EINVAL } - return setrlimit(resource, &rl) + return setrlimit1(resource, &rl) +} + +//go:nosplit +func rawSetrlimit(resource int, rlim *Rlimit) Errno { + _, _, errno := RawSyscall6(SYS_PRLIMIT64, 0, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0, 0, 0) + if errno != ENOSYS { + return errno + } + + rl := rlimit32{} + if rlim.Cur == rlimInf64 { + rl.Cur = rlimInf32 + } else if rlim.Cur < uint64(rlimInf32) { + rl.Cur = uint32(rlim.Cur) + } else { + return EINVAL + } + if rlim.Max == rlimInf64 { + rl.Max = rlimInf32 + } else if rlim.Max < uint64(rlimInf32) { + rl.Max = uint32(rlim.Max) + } else { + return EINVAL + } + + _, _, errno = RawSyscall(SYS_SETRLIMIT, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0) + return errno } func (r *PtraceRegs) PC() uint64 { return uint64(r.Uregs[15]) } |
