-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/sys/unix: Sigset_t follows libc instead of kernel definition on Linux #55349
Comments
The runtime has https://github.com/golang/go/blob/d11c58eedbee29b4912dd50508b36ad15ebb739e/src/runtime/os_linux_generic.go and friends to deal with this. Maybe it makes sense to just lift that code into |
I'm not sure there is a good answer here. What should happen if the kernel changes the number of signals?. Arguably people calling |
I think that would only work if the kernel started to support a sigset_t smaller than the in kernel sigset_t at the same time. Otherwise user space would break, which is against Linux policy. From the sys/unix perspective this would mean making the struct larger and recompiling. |
Maybe we can copy what was done for Signalfd? I could add RtSigprocmask() like so: https://cs.opensource.google/go/x/sys/+/fb04ddd9:unix/syscall_linux.go;l=1944 We omit the size argument from the wrapper and pass the size ourselves. Passing NSIG/8 is kind of a hack but I guess it works well enough, and this avoids changing sigset_t. Maybe in addition export NSIG so that implementations of sigaddset can return an error if trying to set an unsupported signal? |
I don't see why userspace would break if the kernel increased the number of signals. As far as I know the reason that the size is passed to the system call is to permit the kernel to increase the signal count. The kernel would simply continue to accept the smaller size. |
I agree that if add I don't see a reason to export |
Yes, that's what I was trying to say. I suspect we're talking past each other with this
Yes, we need it for #55243.
This would be the first
Is it OK if I add |
According to POSIX It's fine to add |
Add a syscall wrapper for SYS_RT_SIGPROCMASK and export it as PthreadSigmask. The latter is defined by POSIX and can therefore be implemented by Darwin, etc. later on. Follow the approach used by Signalfd of passing _C__NSIG/8 as sigsetsize. This avoids exporting _C__NSIG and allows the syscall to work with the current definition of Sigset_t, which doesn't match the kernel definition of Sigset_t. Updates golang/go#55349
Change https://go.dev/cl/434555 mentions this issue: |
Add a syscall wrapper for SYS_RT_SIGPROCMASK and export it as PthreadSigmask. The latter is defined by POSIX and can therefore be implemented by Darwin, etc. later on. Follow the approach used by Signalfd of passing _C__NSIG/8 as sigsetsize. This avoids exporting _C__NSIG and allows the syscall to work with the current definition of Sigset_t, which doesn't match the kernel definition of Sigset_t. Updates golang/go#55349
Change https://go.dev/cl/435095 mentions this issue: |
I think the name |
I found it confusing too, but I believe it's the correct name. |
|
Okay, thanks. Then I guess |
Add a syscall wrapper for SYS_RT_SIGPROCMASK and export it as PthreadSigmask. The latter is defined by POSIX and can therefore be implemented by Darwin, etc. later on. Follow the approach used by Signalfd of passing _C__NSIG/8 as sigsetsize. This avoids exporting _C__NSIG and allows the syscall to work with the current definition of Sigset_t, which doesn't match the kernel definition of Sigset_t. Updates golang/go#55349 Change-Id: I49dc93366a7d316d820b0c25ecdef2ebb584634b Reviewed-on: https://go-review.googlesource.com/c/sys/+/435095 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
Change https://go.dev/cl/435775 mentions this issue: |
Sorry for sending another CL, I hadn't realised that the SIG_* constants used by PthreadSigmask use arch specific values. |
The recently added PthreadSigmask syscall expects a parameter how that specifies which action to perform on the thread's signal set. The value of this parameter differs between arches. Add the SIG_* constants to have a portable source. Updates golang/go#55349 Change-Id: I7cb42d7c2c42e9b3d22123e8de74960121d89313 Reviewed-on: https://go-review.googlesource.com/c/sys/+/435775 Reviewed-by: Benny Siegert <bsiegert@gmail.com> Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Thanks very much everyone! |
Sigset_t
inx/sys/unix
is defined as follows for amd64:In total, it has space for 1024 signals. However, Linux syscalls expect a
sigset_t
like so:This becomes a problem for syscalls that require
sizeof(sigset_t)
to be passed, for examplert_sigprocmask
:Passing
unsafe.Sizeof(unix.Sigset_t{})
will returnEINVAL
.This stackoverflow answer suggests that the discrepancy is due to glibc defining a larger than necessary
sigset_t
: https://unix.stackexchange.com/a/399356From my POV,
x/sys/unix
should follow the kernel layout, not the libc one. I think this hasn't been a problem so far since all existing users ofSigset_t
only take a pointer, so a larger than necessary structure is not a problem. Is there something that would break if we changed the definition?The text was updated successfully, but these errors were encountered: