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_arm64.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_arm64.go')
| -rw-r--r-- | src/syscall/syscall_linux_arm64.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/syscall/syscall_linux_arm64.go b/src/syscall/syscall_linux_arm64.go index f42686262a..42984ba2ed 100644 --- a/src/syscall/syscall_linux_arm64.go +++ b/src/syscall/syscall_linux_arm64.go @@ -36,7 +36,7 @@ func Fstatat(fd int, path string, stat *Stat_t, flags int) error { //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) //sys Setfsgid(gid int) (err error) //sys Setfsuid(uid int) (err error) -//sysnb setrlimit(resource int, rlim *Rlimit) (err error) +//sysnb setrlimit1(resource int, rlim *Rlimit) (err error) //sys Shutdown(fd int, how int) (err error) //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) @@ -148,13 +148,23 @@ func Getrlimit(resource int, rlim *Rlimit) error { return getrlimit(resource, rlim) } -// Setrlimit prefers the prlimit64 system call. See issue 38604. -func Setrlimit(resource int, rlim *Rlimit) error { +// setrlimit prefers the prlimit64 system call. See issue 38604. +func setrlimit(resource int, rlim *Rlimit) error { err := prlimit(0, resource, rlim, nil) if err != ENOSYS { return err } - return setrlimit(resource, rlim) + return setrlimit1(resource, rlim) +} + +//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 + } + _, _, errno = RawSyscall(SYS_SETRLIMIT, uintptr(resource), uintptr(unsafe.Pointer(rlim)), 0) + return errno } func (r *PtraceRegs) PC() uint64 { return r.Pc } |
