Skip to content

Commit 3cf1aaf

Browse files
orangecmsJorropo
authored andcommitted
runtime: use futexes with 64-bit time on Linux
Linux introduced new syscalls to fix the year 2038 issue. To still be able to use the old ones, the Kconfig option COMPAT_32BIT_TIME would be necessary. Use the new syscall with 64-bit values for futex by default. Define _ENOSYS for detecting if it's not available. Add a fallback to use the older syscall in case the new one is not available, since Go runs on Linux from 2.6.32 on, per https://go.dev/wiki/MinimumRequirements. Updates #75133 Change-Id: I65daff0a3d06b55440ff05d8f5a9aa1c07eb201d GitHub-Last-Rev: 96dd1bd GitHub-Pull-Request: #75306 Reviewed-on: https://go-review.googlesource.com/c/go/+/701615 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 0ab038a commit 3cf1aaf

19 files changed

+186
-22
lines changed

src/runtime/defs2_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const (
4848
EINTR = C.EINTR
4949
EAGAIN = C.EAGAIN
5050
ENOMEM = C.ENOMEM
51+
ENOSYS = C.ENOSYS
5152

5253
PROT_NONE = C.PROT_NONE
5354
PROT_READ = C.PROT_READ

src/runtime/defs_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const (
3737
EINTR = C.EINTR
3838
EAGAIN = C.EAGAIN
3939
ENOMEM = C.ENOMEM
40+
ENOSYS = C.ENOSYS
4041

4142
PROT_NONE = C.PROT_NONE
4243
PROT_READ = C.PROT_READ

src/runtime/defs_linux_386.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const (
99
_EINTR = 0x4
1010
_EAGAIN = 0xb
1111
_ENOMEM = 0xc
12+
_ENOSYS = 0x26
1213

1314
_PROT_NONE = 0x0
1415
_PROT_READ = 0x1
@@ -136,16 +137,30 @@ type fpstate struct {
136137
anon0 [48]byte
137138
}
138139

139-
type timespec struct {
140+
// The timespec structs and types are defined in Linux in
141+
// include/uapi/linux/time_types.h and include/uapi/asm-generic/posix_types.h.
142+
type timespec32 struct {
140143
tv_sec int32
141144
tv_nsec int32
142145
}
143146

144147
//go:nosplit
145-
func (ts *timespec) setNsec(ns int64) {
148+
func (ts *timespec32) setNsec(ns int64) {
146149
ts.tv_sec = timediv(ns, 1e9, &ts.tv_nsec)
147150
}
148151

152+
type timespec struct {
153+
tv_sec int64
154+
tv_nsec int64
155+
}
156+
157+
//go:nosplit
158+
func (ts *timespec) setNsec(ns int64) {
159+
var newNS int32
160+
ts.tv_sec = int64(timediv(ns, 1e9, &newNS))
161+
ts.tv_nsec = int64(newNS)
162+
}
163+
149164
type timeval struct {
150165
tv_sec int32
151166
tv_usec int32
@@ -223,8 +238,8 @@ type ucontext struct {
223238
}
224239

225240
type itimerspec struct {
226-
it_interval timespec
227-
it_value timespec
241+
it_interval timespec32
242+
it_value timespec32
228243
}
229244

230245
type itimerval struct {

src/runtime/defs_linux_amd64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const (
99
_EINTR = 0x4
1010
_EAGAIN = 0xb
1111
_ENOMEM = 0xc
12+
_ENOSYS = 0x26
1213

1314
_PROT_NONE = 0x0
1415
_PROT_READ = 0x1

src/runtime/defs_linux_arm.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const (
1111
_EINTR = 0x4
1212
_ENOMEM = 0xc
1313
_EAGAIN = 0xb
14+
_ENOSYS = 0x26
1415

1516
_PROT_NONE = 0
1617
_PROT_READ = 0x1
@@ -95,16 +96,30 @@ const (
9596
_SOCK_DGRAM = 0x2
9697
)
9798

98-
type timespec struct {
99+
// The timespec structs and types are defined in Linux in
100+
// include/uapi/linux/time_types.h and include/uapi/asm-generic/posix_types.h.
101+
type timespec32 struct {
99102
tv_sec int32
100103
tv_nsec int32
101104
}
102105

103106
//go:nosplit
104-
func (ts *timespec) setNsec(ns int64) {
107+
func (ts *timespec32) setNsec(ns int64) {
105108
ts.tv_sec = timediv(ns, 1e9, &ts.tv_nsec)
106109
}
107110

111+
type timespec struct {
112+
tv_sec int64
113+
tv_nsec int64
114+
}
115+
116+
//go:nosplit
117+
func (ts *timespec) setNsec(ns int64) {
118+
var newNS int32
119+
ts.tv_sec = int64(timediv(ns, 1e9, &newNS))
120+
ts.tv_nsec = int64(newNS)
121+
}
122+
108123
type stackt struct {
109124
ss_sp *byte
110125
ss_flags int32
@@ -155,8 +170,8 @@ func (tv *timeval) set_usec(x int32) {
155170
}
156171

157172
type itimerspec struct {
158-
it_interval timespec
159-
it_value timespec
173+
it_interval timespec32
174+
it_value timespec32
160175
}
161176

162177
type itimerval struct {

src/runtime/defs_linux_arm64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const (
99
_EINTR = 0x4
1010
_EAGAIN = 0xb
1111
_ENOMEM = 0xc
12+
_ENOSYS = 0x26
1213

1314
_PROT_NONE = 0x0
1415
_PROT_READ = 0x1

src/runtime/defs_linux_loong64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const (
1010
_EINTR = 0x4
1111
_EAGAIN = 0xb
1212
_ENOMEM = 0xc
13+
_ENOSYS = 0x26
1314

1415
_PROT_NONE = 0x0
1516
_PROT_READ = 0x1

src/runtime/defs_linux_mips64x.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
_EINTR = 0x4
1313
_EAGAIN = 0xb
1414
_ENOMEM = 0xc
15+
_ENOSYS = 0x26
1516

1617
_PROT_NONE = 0x0
1718
_PROT_READ = 0x1

src/runtime/defs_linux_mipsx.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
_EINTR = 0x4
1313
_EAGAIN = 0xb
1414
_ENOMEM = 0xc
15+
_ENOSYS = 0x26
1516

1617
_PROT_NONE = 0x0
1718
_PROT_READ = 0x1
@@ -93,16 +94,30 @@ const (
9394
_SIGEV_THREAD_ID = 0x4
9495
)
9596

96-
type timespec struct {
97+
// The timespec structs and types are defined in Linux in
98+
// include/uapi/linux/time_types.h and include/uapi/asm-generic/posix_types.h.
99+
type timespec32 struct {
97100
tv_sec int32
98101
tv_nsec int32
99102
}
100103

101104
//go:nosplit
102-
func (ts *timespec) setNsec(ns int64) {
105+
func (ts *timespec32) setNsec(ns int64) {
103106
ts.tv_sec = timediv(ns, 1e9, &ts.tv_nsec)
104107
}
105108

109+
type timespec struct {
110+
tv_sec int64
111+
tv_nsec int64
112+
}
113+
114+
//go:nosplit
115+
func (ts *timespec) setNsec(ns int64) {
116+
var newNS int32
117+
ts.tv_sec = int64(timediv(ns, 1e9, &newNS))
118+
ts.tv_nsec = int64(newNS)
119+
}
120+
106121
type timeval struct {
107122
tv_sec int32
108123
tv_usec int32
@@ -138,8 +153,8 @@ type siginfo struct {
138153
}
139154

140155
type itimerspec struct {
141-
it_interval timespec
142-
it_value timespec
156+
it_interval timespec32
157+
it_value timespec32
143158
}
144159

145160
type itimerval struct {

src/runtime/defs_linux_ppc64.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const (
99
_EINTR = 0x4
1010
_EAGAIN = 0xb
1111
_ENOMEM = 0xc
12+
_ENOSYS = 0x26
1213

1314
_PROT_NONE = 0x0
1415
_PROT_READ = 0x1

0 commit comments

Comments
 (0)