Commit Graph

89 Commits

Author SHA1 Message Date
Tobias Klauser
e5ecc2a674 unix: use Renameat2 to implement Renameat on linux/riscv64
On linux/riscv64, the renameat syscall no longer exists and has been
superseded by renameat2. Use Renameat2 to implement Renameat on
linux/riscv64.

Based on a patch by Ryan O'Leary.

Updates golang/go#27532

Change-Id: I7c60c7f824750408265f67397b8ac1fa7226f425
Reviewed-on: https://go-review.googlesource.com/c/157899
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-01-16 15:12:25 +00:00
Tobias Klauser
a457fd0364 unix: add Signalfd on linux
Also add the SFD_* constants and SignalfdSiginfo type.

Change-Id: I3415c212b85c9d5a940ba2bf70f43739a2630d78
Reviewed-on: https://go-review.googlesource.com/c/157897
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-15 15:29:22 +00:00
Sebastian Schmidt
2be5172556 unix: add ClockNanosleep and TIMER_ABSTIME
This adds the ClockNanosleep syscall and the TIMER_* constants;
currently only TIMER_ABSTIME for specifying an absolute timestamp.

Change-Id: Ic8d857eb92818529aadab569cd8646a19bb9c055
Reviewed-on: https://go-review.googlesource.com/c/157658
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2019-01-14 13:03:36 +00:00
Keith Randall
7c4c994c65 unix: remove raw syscall from Sendfile
Update golang/go#17490

Change-Id: Iaec54b8ffda1a24d4c8b5671185d570fb8683155
Reviewed-on: https://go-review.googlesource.com/c/154663
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-12-20 18:20:59 +00:00
Tobias Klauser
ad97f365e1 unix: avoid index out of range in Vmsplice with empty iovs
Passing an empty iovs []Iovec slice to Vmsplice leads to an index out of
range panic. Fix this by passing an nil unsafe.Pointer to the underlying
syscall in case of an empty slice.

Change-Id: If1844c1b2eb0833de598aed7e79b9fcf061f7975
Reviewed-on: https://go-review.googlesource.com/c/153317
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-12-08 17:50:41 +00:00
David Anderson
0cf1ed9e52 unix: add IoctlSetPointerInt
IoctlSetPointerInt is necessary for interacting with the PPP kernel
driver, which wants it passed as a pointer to int, rather than the
more conventional int cast as a pointer.

We can technically do this already with
IoctlSetInt(int(uintptr(unsafe.Pointer(&foo)))), but that's just
masking the operation we're trying to execute in the first place,
and relying on the internals of IoctlSetInt to do the right
inverse transformation.

Change-Id: I1e6a1dd6190c11f06c6f5393cd2cae453939878a
GitHub-Last-Rev: a88f56073d
GitHub-Pull-Request: golang/sys#25
Reviewed-on: https://go-review.googlesource.com/c/150321
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-11-21 00:28:34 +00:00
David Anderson
93218def8b unix: add sockaddr and defines for PPPoE sockets.
`sockaddr_pppox` is a packed struct, which godefs doesn't understand.
So, I had to do the byte packing by hand instead.

Change-Id: Ib92cf43f8ae0729a0af043c4241063911c95e6bf
GitHub-Last-Rev: 8982dec099
GitHub-Pull-Request: golang/sys#23
Reviewed-on: https://go-review.googlesource.com/c/149757
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2018-11-16 16:16:06 +00:00
Tobias Klauser
731415f00d unix: add kernel module load/unload syscalls on Linux
InitModule loads a kernel module from an ELF image. FinitModule loads a
kernel module from a file descriptor. DeleteModule unloads a kernel
module.

These syscalls require the CAP_SYS_MODULE capability.

See http://man7.org/linux/man-pages/man2/init_module.2.html and
http://man7.org/linux/man-pages/man2/delete_module.2.html for details.

Also drop deprecated syscalls related to kernel modules from the list
of unimplemented syscalls.

Change-Id: I131e17f02c5617640f5f4073982d2b27a6d78bbf
Reviewed-on: https://go-review.googlesource.com/c/144173
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-26 06:49:43 +00:00
Tobias Klauser
8469e31483 unix: export sizeof consts
Export the sizeof(Ptr|Short|Int|Long|LongLong) consts. This allows users
to get this information (e.g. for alignment purposes) without using cgo
or generating these constants themselves.

Change-Id: I8640482bf67b89c2f2b6e9a116ba7bc268f8135a
Reviewed-on: https://go-review.googlesource.com/c/139617
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-04 14:53:25 +00:00
Tobias Klauser
dad3d9fb7b unix: add ClockGetres on Linux
Change-Id: Id60c9310bad85e02ec81b04e7f304f058b680822
Reviewed-on: https://go-review.googlesource.com/138116
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-09-27 15:05:00 +00:00
Matt Layher
d47a0f3392 unix: implement Linux AF_XDP sockets
Provides access to the Linux AF_XDP socket family.  For more
information on AF_XDP, see:
https://www.kernel.org/doc/html/latest/networking/af_xdp.html.

Change-Id: I7efb82c4a67da3e15932e3c0d882f0bad7ba16ef
Reviewed-on: https://go-review.googlesource.com/136695
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2018-09-21 16:39:48 +00:00
Tobias Klauser
ee1b12c67a unix: add MemfdCreate on Linux
Add a wrapper for the memfd_create syscall on Linux. See
http://man7.org/linux/man-pages/man2/memfd_create.2.html for more
information.

Also add the corresponding MFD_* constants to be used in the flags
argument.

Change-Id: Ib30a007e15575a38ecf204601ffede9c913799b6
Reviewed-on: https://go-review.googlesource.com/135915
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-18 15:37:33 +00:00
Tobias Klauser
3249cb6984 unix: drop incorrect Fsetxattr size return value
Fsetxattr should just return an error (like Setxattr and like Fsetxattr
is already doing on FreeBSD).

Fix for CL 128176

Updates golang/go#26832

Change-Id: Id1c1315d9eb6952128e0c0ce44b19060e0403cc0
Reviewed-on: https://go-review.googlesource.com/128495
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-08-08 14:12:55 +00:00
Tobias Klauser
acbc56fc70 unix: add F*xattr on Linux
Add Fgetxattr, Flistxattr, Fremovexattr and Fsetxattr on Linux.

Updates golang/go#26832

Change-Id: Ia79915e91a928188c6c985ef301d5445f630b19c
Reviewed-on: https://go-review.googlesource.com/128176
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-08-07 16:23:57 +00:00
Tobias Klauser
2be389f392 unix: add Renameat2 on Linux
Renameat2 is Linux-specific and allows to pass an additional flags
argument to the renameat syscall. Also add the corresponding RENAME_*
flag mask values.

Change-Id: Ib4baa46fdd0b07ccd0988ac624862ce69d5c3ad5
Reviewed-on: https://go-review.googlesource.com/127763
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-06 19:25:00 +00:00
Ian Lance Taylor
bd9dbc187b unix: support Faccessat flags argument
The Linux kernel faccessat system call does not take a flags parameter.
The flag parameter to the C library faccessat function is implemented in C.
The unix.Faccessat function takes a flags parameter. In older releases
we have passed the flags parameter to the kernel, which ignored it.
In CL 119495 we started returning an error if any flags were set.
That seems clearly better than ignoring them, but it turns out that some
code was using the flags. The code was previously subtly broken.
Now it is obviously broken. That is better, but we can do better still:
we can implement the flags as the C library does. That is what this CL does.

Change-Id: I02d4bb981ebd39eb35e47c6e5281f85eaea68016
Reviewed-on: https://go-review.googlesource.com/126516
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-07-27 23:04:15 +00:00
Brad Fitzpatrick
e072cadbbd unix: document IoctlSetWinsize and IoctlSetTermios and fix pointer lifetime
Change-Id: I42e59149e58bd928d9beb2c6665ce186b377d2a1
Reviewed-on: https://go-review.googlesource.com/125640
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-07-24 21:28:12 +00:00
Alexander Menzhinsky
1b2967e3c2 unix: implement RFCOMM sockets on Linux
Add the SockaddrRFCOMM type and the ability to accept BTPROTO_L2CAP and BTPROTO_RFCOMM protocol sockets.

Fixes golang/go#22211

Change-Id: I580b526c5392b90663499af0f2ebe6f55b1f8154
Reviewed-on: https://go-review.googlesource.com/122457
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
2018-07-09 06:02:33 +00:00
Thanabodee Charoenpiriyakij
ad87a3a340 unix: check faccessat flags parameter on Linux
Currently Linux faccessat(2) syscall implementation doesn't support the
flags parameter. As per discuss in golang/go#25845, permit the same flags
as glibc [1].

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/faccessat.c;h=ea42b2303ff4b2d2d6548ea04376fb265f773436;hb=HEAD

Fixes golang/go#25845

Change-Id: I390ba14b2816283399472f3572967b19d0a36042
Reviewed-on: https://go-review.googlesource.com/119495
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-20 13:35:08 +00:00
Tobias Klauser
fc8bd948cf unix: don't use deprecated syscalls on linux/arm64
On linux/arm64 we used to manually define syscall numbers for some
deprecated syscalls. Most of them are unused by now anyhow. Convert the
remaining syscall wrappers using them to implement the respective
functionality using a non-deprecated syscall (in the same way glibc does
it):

- Implement EpollCreate using EpollCreate1 and additionally check
  that the passed size argument is larger than 0.
- Implement Futimesat and utimes using utimensat. Also change futimesat
  on the other geese to take a string instead of *byte and let the
  generated wrapper do the BytePtrFromString conversion.
- Return ENOSYS from Ustat. The ustat syscall has been deprecated for a
  long time in favor of fstatfs and statfs. Even glibc will deprecate
  ustat in the upcoming 2.28 release [1].

[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=NEWS;h=d51fa09544f03899b7ff5a80569db088c3c23c28;hb=HEAD#l90

Change-Id: I7ea38a3cd394b0875f17443b14e107fd9c70350d
Reviewed-on: https://go-review.googlesource.com/119655
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-19 16:09:47 +00:00
Jason A. Donenfeld
a2a45943ae unix: avoid extra syscall on send/recvmsg on Linux
By simply rearranging the logic, we avoid the overhead of a superfluous
call to getsockopt. For, if p is already non empty, there's no point
in having to check if we need to attach dummy payload. This has
performance benefits when using send/recvmsg for high speed
communications.

Change-Id: If47ab5322464aad8e6d2603a369e95327223211f
Reviewed-on: https://go-review.googlesource.com/108337
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-19 22:20:23 +00:00
Adam Sindelar
2f57af4873 unix: add wrapper around perf_event_open on Linux
This adds a wrapper around perf_event_open, exported constants and
two structs:
 - perf_event_attr, used to configure the syscall
 - perf_event_mmap_page to coordinate the kernel's mmap ring buffer

Change-Id: Ife7ded8344de9e3eb74441bd51ab9a04c81b4965
Reviewed-on: https://go-review.googlesource.com/105756
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-16 11:22:24 +00:00
Tobias Klauser
fcb792cfc2 unix: unify Getsockopt*
Move the common Getsockopt* implementations to syscall_unix.go instead
of duplicating them in syscall_bsd.go and syscall_linux.go. This also
makes all of them available on Solaris and adds GetsockoptByte on Linux.

Change-Id: Ibf49b27be46be579e63e3b3e2ebc1504e5228d5f
Reviewed-on: https://go-review.googlesource.com/104695
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-04-04 15:47:05 +00:00
Tobias Klauser
37707fdb30 unix: move gccgo redeclared *SyscallNoError functions to a separate file
Same as CL 34379, SyscallNoError and RawSyscallNoError are redeclared
for gccgo builds since CL 85756. Thus, move the declarations to a gc
specific file.

Updates golang/go#18312

Change-Id: Ia8f42b31e61a80530e5e90a44c0af32fd3452612
Reviewed-on: https://go-review.googlesource.com/91615
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-02-02 13:58:01 +00:00
Tobias Klauser
0346725895 unix: add godoc for Sockaddr* types
Add rudimentary godoc for all existing Sockaddr* types implementing the
Sockaddr interface.

Change-Id: Ida7d1e8756477b54fc773f4bc978002c3d4a376d
Reviewed-on: https://go-review.googlesource.com/89775
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-01-25 14:53:36 +00:00
Garret Kelly
ef802241c9 unix: add sockaddr_l2 definitions
The sockaddr_l2 address type is used with AF_BLUETOOTH sockets using the
BTPROTO_L2CAP protocol.

Change-Id: I263cfd3bb5920a8c1187ead6c2e0527276575d9f
Reviewed-on: https://go-review.googlesource.com/89475
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-01-25 08:08:17 +00:00
Tobias Klauser
af50095a40 unix: use ParseDirent from syscall
Just call syscall's implementation instead of duplicating ParseDirent
and the GOOS-specific private functions needed by it.

Change-Id: Icf49769390929463323608e093dd2a3d1c0ae4d3
Reviewed-on: https://go-review.googlesource.com/88475
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-01-22 08:19:59 +00:00
Tobias Klauser
fff93fa7cd unix: add Statx on Linux
statx(2) allows to get enhanced file status information (not currently
available through the existing stat syscalls), lightweight stat,
heavyweight stat. The Statx_t type used by Statx has consistent field
sizes on all arches (with year-2038-capable timestamps) and is closer to
the BSD implementation of Stat_t.

See http://man7.org/linux/man-pages/man2/statx.2.html for details. The
syscall was added in Linux kernel 4.11.

See https://github.com/tklauser/statx for an example of how this
function and types can be used to report stat(1)-like file status
information.

Change-Id: I9e9642b5b42a393f94fd532453888ce9ba4f0003
Reviewed-on: https://go-review.googlesource.com/87555
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-01-15 08:58:44 +00:00
Tobias Klauser
12d9d5b281 unix: add SchedGetaffinity and SchedSetaffinity on Linux
SchedGetaffinity and SchedSetaffinity are used to get and set a thread's
CPU affinity mask.

See http://man7.org/linux/man-pages/man2/sched_setaffinity.2.html for
details.

Also add a manual implementation of CpuSet_t and the corresponding
accessor functions (mimicking the CPU_* macros from sched.h).

Fixes golang/go#11243

Change-Id: Ia5abc0053cd06810b3b09ab65c27434f5323c1ad
Reviewed-on: https://go-review.googlesource.com/85915
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-01-05 20:31:47 +00:00
Tobias Klauser
28a7276518 unix: add SyscallNoError and RawSyscallNoError on Linux
Add the SyscallNoError and RawSyscallNoError wrapper functions which are
used for syscalls that don't return an error. Also convert all applicable
syscalls to use these wrappers.

Updates golang/go#22924

Change-Id: Ie143abc99de8d12d36b67ac278e08d7565f73ce0
Reviewed-on: https://go-review.googlesource.com/85756
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-01-03 16:03:02 +00:00
Tobias Klauser
53aa286056 unix: add GetsockoptString on Linux
Add a Getsockopt variant returning a string. This can e.g. be used to
retrieve a peer's SELinux or AppArmor labels using SO_PEERSEC.

Fixes golang/go#16374

Change-Id: Ia266bad1b0aef94ce19d378719ce1c1c976b4cc5
Reviewed-on: https://go-review.googlesource.com/83275
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-12-11 20:33:43 +00:00
Tobias Klauser
4ff8c001ce unix: add Fstatat on Linux for all GOOSes
Looks like it's enough to just add wrappers pointing to the
corresponding SYS_FSTATAT{,64} or SYS_NEWFSTATAT syscall. Add a test to
verify that assumption which checks that the returned stat data matches
what is returned by Stat/Lstat.

Also add the AT_NO_AUTOMOUNT constant which may be used for the flags
parmeter.

Fixes golang/go#14216

Change-Id: I73f27b483bd97d2dcf09d4b95a7957e75d194395
Reviewed-on: https://go-review.googlesource.com/79795
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-11-24 17:10:47 +00:00
Tobias Klauser
1e2299c37c unix: add PtracePokeUser
PtracePeekUser was already added in CL 38638, also add its "counterpart"
allowing to modify the tracee's user area.

Change-Id: Id84e85fe17b5cab7df5ecc83b6b7b8a39241241d
Reviewed-on: https://go-review.googlesource.com/76670
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-11-10 07:27:04 +00:00
Christopher Koch
164713f0df unix: remove unnecessary use of unsafe.Pointer.
Change-Id: I7ae67ce410ae2816c2f3e8ecb26e46265aa11d7f
Reviewed-on: https://go-review.googlesource.com/73771
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-10-26 20:47:33 +00:00
Tobias Klauser
9e4fff1f4d all: single space after period
Follow CL 20022 and consistently use single space after a period in
documentation.

Generated with:

$ perl -i -npe 's,^(\s*// .+[a-z]\.)  +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.)  +([A-Z])')

Change-Id: Ia29ad823668f060e81293e848a79fc4b4857d94b
Reviewed-on: https://go-review.googlesource.com/73530
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-10-25 20:39:07 +00:00
Tobias Klauser
686000749e unix: correct type for timeout argument to Select on linux/{arm64,mips64x}
Follow CL 70590 which did the same for syscall.

unix.Select uses SYS_PSELECT6 on arm64 and mipx64x, however this
syscall expects its 5th argument to be of type Timespec (with seconds
and nanoseconds) instead of type Timeval (with seconds and microseconds)
This leads to the timeout being too short by a factor of 1000.

This CL fixes this by adjusting the timeout argument accordingly,
similarly to how glibc does it for architectures where neither
SYS_SELECT nor SYS__NEWSELECT are available. It also makes Pselect
generaly available on linux.

Updates golang/go#22246

Change-Id: I69f8821a40c59ee469b8a986d784a4db8727ee9a
Reviewed-on: https://go-review.googlesource.com/70610
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-13 13:55:06 +00:00
Luca Bruno
bb24a47a89 unix: drop dummy byte for oob in unixgram SendmsgN
This commit relaxes SendmsgN behavior of introducing a dummy 1-byte
payload when sending ancillary-only messages.
The fake payload is not needed for SOCK_DGRAM type sockets, and actually
breaks interoperability with other fd-passing software (journald is one
known example). This introduces an additional check to avoid injecting
dummy payload in such case.

Backport of https://go.googlesource.com/go/+/93da0b6e66f24c4c307e0df37ceb102a33306174
Full reference at https:/golang.org/issue/6476#issue-51285243

Change-Id: I7cf00a1c7cde75fe62e00b98ccba6ac8469b0493
Reviewed-on: https://go-review.googlesource.com/60190
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-30 13:42:02 +00:00
Tobias Klauser
43e60d72a8 unix: unify memory functions on BSD
Make Madvice, Mlock, Mlockall, Mprotect, Msync, Munlock and Munlockall
available equally on all BSD flavors. NetBSD was previously lacking
SYS_MSYNC, so add it.

Reorder the //sys function prototype alphabetically and clean up already
implemented syscalls everywhere.

Also add tests for Mprotect, Msync and Madvice - now that they're
available on all unix platforms.

Fixes golang/go#18513

Change-Id: I0eb502d72c7e991f191fb96225ef04e8297d8b8d
Reviewed-on: https://go-review.googlesource.com/56172
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-17 23:46:08 +00:00
Kirill Smelkov
35ef4487ce unix: add Syncfs function on Linux
Syncfs is Linux-specific system call to synchronize to disk one
filesystem specified by fd to any of its files.

See http://man7.org/linux/man-pages/man2/syncfs.2.html for details.

Change-Id: Ia2ad6208c3fa0e9c40d5112ce938edd5d374131d
Reviewed-on: https://go-review.googlesource.com/51510
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-27 13:53:23 +00:00
Tobias Klauser
d6d53c0e54 unix: add Msync function on Linux
Add the Msync function on Linux. See
http://man7.org/linux/man-pages/man2/msync.2.html

Updates golang/go#8245

Change-Id: I964259bafc8d4fbca09961443f21c4278bf56706
Reviewed-on: https://go-review.googlesource.com/50891
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-07-25 13:53:26 +00:00
Tobias Klauser
cd2c276457 unix: add ioctl functions to get/set terminal window size on Linux
Add IoctlGetWinsize and IoctlSetWinsize to retreive and manipulate
Winsize structures on Linux, akin to the already existing implementation
on Solaris.

Also remove the named result parameter for IoctlSetInt and
IoctlSetTermios, as they add no additional use.

Change-Id: Id349d1d6a21d5c9a05943f4dcc3a275613ccf7b8
Reviewed-on: https://go-review.googlesource.com/49231
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-07-18 16:13:35 +00:00
Tobias Klauser
4cd6d1a821 unix: add Mkfifoat function on Linux
Add the Mkfifoat function on Linux, akin to the existing Mkfifo function
but taking an additional dirfd parameter. See
http://man7.org/linux/man-pages/man3/mkfifo.3.html

Originally requested in golang/go#14216

Also remove the named result parameter for Mkfifo, as they add no
additional use (suggested by Brad Fitzpatrick).

Change-Id: I7b759752abf3e1469d7f883a7f13313e3062aeb4
Reviewed-on: https://go-review.googlesource.com/48530
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-07-14 16:04:39 +00:00
Tobias Klauser
4ed4d404df unix: add ioctl functions for termios on Linux
Add IoctlGetTermios and IoctlGetTermios to retreive and manipulate
Termios structures on Linux, akin to the already existing implementation
or Solaris.

If desired, functions conforming to POSIX tcgetattr/tcsetattr could be
implemented on top of these.

Change-Id: I2a71061bad2e632c597b6f6184ad6374c46a43ee
Reviewed-on: https://go-review.googlesource.com/47330
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-06-30 17:12:05 +00:00
Tobias Klauser
c23410a886 unix: check Fchmodat flags parameter on Linux
Currently Linux' fchmodat(2) syscall implementation doesn't support the
flags parameter (though it might in future versions [1]). Fchmodat in
x/sys/unix takes the parameter and (wrongly) passes it on to the syscall
which will ignore it.

According to the POSIX.1-2008 manual page [2], AT_SYMLINK_NOFOLLOW is
the only valid value for the flags parameter and EOPNOTSUPP should be
returned in case changing the mode of a symbolic link is not supported
by the underlying system.  EINVAL should be returned for any other value
of the flags parameter.

  [1] https://patchwork.kernel.org/patch/9596301/
  [2] http://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html

Change the Fchmodat implementation accordingly and also add the
corresponding test.

Fixes golang/go#20130

Change-Id: I62e677e6674d3702eaf388af0ac3d7e623a35c24
Reviewed-on: https://go-review.googlesource.com/46474
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-06-23 14:22:15 +00:00
Tobias Klauser
0b25a408a5 unix: add Eventfd function on Linux
Add support for the eventfd2 syscall on Linux.

Use the eventfd2 syscall instead of eventfd, as the latter does not
provide a flags argument and glibc also maps its eventfd() function to
the eventfd2 syscall, see the Notes section in
http://man7.org/linux/man-pages/man2/eventfd.2.html

Also add the corresponding flags values EFD_CLOEXEC, EFD_NONBLOCK and
EFD_SEMAPHORE.

Change-Id: Ia8c99e68d5966ab5c7ebe7e45423943fd7d8214e
Reviewed-on: https://go-review.googlesource.com/45093
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-06-08 16:48:03 +00:00
Tobias Klauser
b90f89a1e7 unix: add missing xattr symlink syscall functions on Linux
Add support for the lgetxattr, llistxattr, lremovexattr and lsetxattr on
Linux, akin to the already existing getxattr, listxattr, removexattr and
setxattr syscalls.

These variants are identical to the already existing variants. except in
the case of a symbolic link where the extended attribute operation is
applied to the link itself rather than to the file that it refers to.
See:

  http://man7.org/linux/man-pages/man2/getxattr.2.html
  http://man7.org/linux/man-pages/man2/listxattr.2.html
  http://man7.org/linux/man-pages/man2/removexattr.2.html
  http://man7.org/linux/man-pages/man2/setxattr.2.html

Fixes golang/go#14116

Change-Id: I786953db8bf862566f54bdd745cc1feca5031be7
Reviewed-on: https://go-review.googlesource.com/44374
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-05-29 18:51:10 +00:00
Matt Layher
a55a760868 unix: add IoctlGetInt and IoctlSetInt on Linux
This CL adds basic integer get/set functions which wrap a generic
ioctl call.  The API is similar the one introduced for solaris/amd64
in CL 14587, but the request parameter has been changed to a uint
instead of an int.  This makes requests with a number larger than the
maximum signed 32-bit integer work on linux/386.

For consistency, the solaris/amd64 API has also been updated to make
use of a uint instead of an int for the request number.

Fixes golang/go#20474

Change-Id: Iaae1ee2e4bb4bfcc420dcec252fe53c8d90ce81d
Reviewed-on: https://go-review.googlesource.com/44009
Run-TryBot: Matt Layher <mdlayher@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-05-24 19:12:47 +00:00
Joe Richey joerichey@google.com
a2e06a18b0 unix: add bindings for keyutils syscalls
This CL adds support for the ADD_KEY, REQUESET_KEY, and KEYCTL syscalls.
These syscalls allow access to the kernel keyring facilities. In C code,
these syscalls are wrapped by the libkeyutils package. See:
	http://man7.org/linux/man-pages/man7/keyutils.7.html

The ADD_KEY and REQUEST_KEY calls are fairly straightforward, but the
KEYCTL syscall is a multiplexor for a number of key management
functions. See:
	http://man7.org/linux/man-pages/man3/keyctl.3.html

The Go bindings for the KEYCTL functions attempt to replicate what
libkeyutils does. This is done via generated helper functions.

Change-Id: If8c97d4ef5bce14c43dee3e6772ded42dc3c595a
Reviewed-on: https://go-review.googlesource.com/41415
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-05-18 22:39:15 +00:00
Derek McGowan
f845067cf7 unix: add Linux CopyFileRange syscall
Introduces the CopyFileRange syscall which first appears in Linux 4.5.
Allows copying file content between file descriptors within the kernel
without transferring data to user space. This syscall also allows the
kernel to take advantage of reflinking or other fast copy methods on
supported file systems.
http://man7.org/linux/man-pages/man2/copy_file_range.2.html

Change-Id: Id365f1e5d4d5ddf7159478e3a13084c9576ebd5c
Reviewed-on: https://go-review.googlesource.com/39992
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-05-12 18:10:32 +00:00
Chris Manghane
493114f682 unix: add GetsockoptTCPInfo
Change-Id: I190098a4a969a706c555e48d2ad938d41017601e
Reviewed-on: https://go-review.googlesource.com/39195
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-04-03 20:51:32 +00:00