From e0053f8b1c2c90da483ba228fbf671c12063266d Mon Sep 17 00:00:00 2001 From: Yao Zhang Date: Thu, 24 Sep 2015 08:42:10 -0400 Subject: [PATCH] runtime: restructured os1_linux.go, added mips64 support Linux/mips64 uses a different type of sigset. To deal with it, related functions in os1_linux.go is refactored to os1_linux_generic.go (used for non-mips64 architectures), and os1_linux_mips64x.go (only used in mips64{,le}), to avoid code copying. Change-Id: I5cadfccd86bfc4b30bf97e12607c3c614903ea4c Reviewed-on: https://go-review.googlesource.com/14991 Reviewed-by: Ian Lance Taylor --- src/runtime/os1_linux.go | 10 ++++------ src/runtime/os1_linux_generic.go | 27 +++++++++++++++++++++++++++ src/runtime/os1_linux_mips64x.go | 26 ++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 src/runtime/os1_linux_generic.go create mode 100644 src/runtime/os1_linux_mips64x.go diff --git a/src/runtime/os1_linux.go b/src/runtime/os1_linux.go index 6410801d8e..1d21d3b5aa 100644 --- a/src/runtime/os1_linux.go +++ b/src/runtime/os1_linux.go @@ -6,8 +6,6 @@ package runtime import "unsafe" -var sigset_all sigset = sigset{^uint32(0), ^uint32(0)} - // Linux futex. // // futexsleep(uint32 *addr, uint32 val) @@ -221,7 +219,7 @@ func minit() { nmask := *(*sigset)(unsafe.Pointer(&_g_.m.sigmask)) for i := range sigtable { if sigtable[i].flags&_SigUnblock != 0 { - nmask[(i-1)/32] &^= 1 << ((uint32(i) - 1) & 31) + sigdelset(&nmask, i) } } rtsigprocmask(_SIG_SETMASK, &nmask, nil, int32(unsafe.Sizeof(nmask))) @@ -281,7 +279,7 @@ func setsig(i int32, fn uintptr, restart bool) { if restart { sa.sa_flags |= _SA_RESTART } - sa.sa_mask = ^uint64(0) + sigfillset(&sa.sa_mask) // Although Linux manpage says "sa_restorer element is obsolete and // should not be used". x86_64 kernel requires it. Only use it on // x86. @@ -338,12 +336,12 @@ func signalstack(s *stack) { func updatesigmask(m sigmask) { var mask sigset - copy(mask[:], m[:]) + sigcopyset(&mask, m) rtsigprocmask(_SIG_SETMASK, &mask, nil, int32(unsafe.Sizeof(mask))) } func unblocksig(sig int32) { var mask sigset - mask[(sig-1)/32] |= 1 << ((uint32(sig) - 1) & 31) + sigaddset(&mask, int(sig)) rtsigprocmask(_SIG_UNBLOCK, &mask, nil, int32(unsafe.Sizeof(mask))) } diff --git a/src/runtime/os1_linux_generic.go b/src/runtime/os1_linux_generic.go new file mode 100644 index 0000000000..2c8b743aeb --- /dev/null +++ b/src/runtime/os1_linux_generic.go @@ -0,0 +1,27 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build !mips64 +// +build !mips64le +// +build linux + +package runtime + +var sigset_all = sigset{^uint32(0), ^uint32(0)} + +func sigaddset(mask *sigset, i int) { + (*mask)[(i-1)/32] |= 1 << ((uint32(i) - 1) & 31) +} + +func sigdelset(mask *sigset, i int) { + (*mask)[(i-1)/32] &^= 1 << ((uint32(i) - 1) & 31) +} + +func sigfillset(mask *uint64) { + *mask = ^uint64(0) +} + +func sigcopyset(mask *sigset, m sigmask) { + copy((*mask)[:], m[:]) +} diff --git a/src/runtime/os1_linux_mips64x.go b/src/runtime/os1_linux_mips64x.go new file mode 100644 index 0000000000..701e979102 --- /dev/null +++ b/src/runtime/os1_linux_mips64x.go @@ -0,0 +1,26 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build mips64 mips64le +// +build linux + +package runtime + +var sigset_all = sigset{^uint64(0), ^uint64(0)} + +func sigaddset(mask *sigset, i int) { + (*mask)[(i-1)/64] |= 1 << ((uint32(i) - 1) & 63) +} + +func sigdelset(mask *sigset, i int) { + (*mask)[(i-1)/64] &^= 1 << ((uint32(i) - 1) & 63) +} + +func sigfillset(mask *[2]uint64) { + (*mask)[0], (*mask)[1] = ^uint64(0), ^uint64(0) +} + +func sigcopyset(mask *sigset, m sigmask) { + (*mask)[0] = uint64(m[0]) | uint64(m[1])<<32 +}