From 8e9fff1a3a189a348d338f6cb059b12939cf76bc Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Fri, 12 Mar 2021 13:11:36 -0800 Subject: [PATCH] unix: add CloseRange The close_range(2) syscall is available since Linux kernel v5.9, with additional functionality of CLOSE_RANGE_CLOEXEC since v5.11. No tests are required since this is a bare syscall. Change-Id: I410470e3713e2005cc7acf24d1347938fe05ef63 Reviewed-on: https://go-review.googlesource.com/c/sys/+/301409 Run-TryBot: Ian Lance Taylor TryBot-Result: Go Bot Reviewed-by: Ian Lance Taylor Trust: Emmanuel Odeke --- unix/linux/types.go | 7 +++++++ unix/syscall_linux.go | 1 + unix/zsyscall_linux.go | 10 ++++++++++ unix/ztypes_linux.go | 5 +++++ 4 files changed, 23 insertions(+) diff --git a/unix/linux/types.go b/unix/linux/types.go index ef138cf5..321cb8f6 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -84,6 +84,7 @@ struct termios2 { #include #include #include +#include #include #include #include @@ -3648,3 +3649,9 @@ type ( HIDRawReportDescriptor C.struct_hidraw_report_descriptor HIDRawDevInfo C.struct_hidraw_devinfo ) + +// close_range +const ( + CLOSE_RANGE_UNSHARE = C.CLOSE_RANGE_UNSHARE + CLOSE_RANGE_CLOEXEC = C.CLOSE_RANGE_CLOEXEC +) diff --git a/unix/syscall_linux.go b/unix/syscall_linux.go index 0a48548e..44ea96e3 100644 --- a/unix/syscall_linux.go +++ b/unix/syscall_linux.go @@ -1877,6 +1877,7 @@ func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err e //sys ClockGettime(clockid int32, time *Timespec) (err error) //sys ClockNanosleep(clockid int32, flags int, request *Timespec, remain *Timespec) (err error) //sys Close(fd int) (err error) +//sys CloseRange(first uint, last uint, flags uint) (err error) //sys CopyFileRange(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) //sys DeleteModule(name string, flags int) (err error) //sys Dup(oldfd int) (fd int, err error) diff --git a/unix/zsyscall_linux.go b/unix/zsyscall_linux.go index 3ee26f4a..7305cc91 100644 --- a/unix/zsyscall_linux.go +++ b/unix/zsyscall_linux.go @@ -532,6 +532,16 @@ func Close(fd int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT +func CloseRange(first uint, last uint, flags uint) (err error) { + _, _, e1 := Syscall(SYS_CLOSE_RANGE, uintptr(first), uintptr(last), uintptr(flags)) + if e1 != 0 { + err = errnoErr(e1) + } + return +} + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + func CopyFileRange(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) { r0, _, e1 := Syscall6(SYS_COPY_FILE_RANGE, uintptr(rfd), uintptr(unsafe.Pointer(roff)), uintptr(wfd), uintptr(unsafe.Pointer(woff)), uintptr(len), uintptr(flags)) n = int(r0) diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index d3a18713..33ca5034 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -3709,3 +3709,8 @@ type ( Product int16 } ) + +const ( + CLOSE_RANGE_UNSHARE = 0x2 + CLOSE_RANGE_CLOEXEC = 0x4 +)