diff options
| author | Jorropo <jorropo.pgm@gmail.com> | 2026-03-04 10:01:11 +0100 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-04-06 10:01:22 -0700 |
| commit | ba402cd756a02cd80bcd76a2f7afc22ae2041c6c (patch) | |
| tree | 7ec950909238e2bfa126fd95e40875ad0699a99c | |
| parent | 6110cd6f83caa1f255189c209711c216d649c6d7 (diff) | |
| download | go-ba402cd756a02cd80bcd76a2f7afc22ae2041c6c.tar.xz | |
runtime: fix timespec definition on 32bits systems
The nsec field of timespec is a C long even when using
64bits time on 32bits systems.
This is because by timespec API if nsec never holds more than a
second worth of nanoseconds.
If it would theses would increment the sec field while the nsec
field would get the amount of nanoseconds modulus a second.
Fixes #77934
Change-Id: I9803998ba70123eb3b226379bd72b11cae972c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/751341
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
| -rw-r--r-- | src/runtime/defs_linux_386.go | 7 | ||||
| -rw-r--r-- | src/runtime/defs_linux_arm.go | 7 | ||||
| -rw-r--r-- | src/runtime/defs_linux_mipsx.go | 7 | ||||
| -rw-r--r-- | src/runtime/os_linux32.go | 10 |
4 files changed, 17 insertions, 14 deletions
diff --git a/src/runtime/defs_linux_386.go b/src/runtime/defs_linux_386.go index d1875954f3..3a8c201ff1 100644 --- a/src/runtime/defs_linux_386.go +++ b/src/runtime/defs_linux_386.go @@ -152,13 +152,14 @@ func (ts *timespec32) setNsec(ns int64) { type timespec struct { tv_sec int64 - tv_nsec int64 + tv_nsec int32 + _ [4]byte // the C ABI aligns int64 to 8 bytes } //go:nosplit func (ts *timespec) setNsec(ns int64) { - ts.tv_sec = int64(ns / 1e9) - ts.tv_nsec = int64(ns % 1e9) + ts.tv_sec = ns / 1e9 + ts.tv_nsec = int32(ns % 1e9) } type timeval struct { diff --git a/src/runtime/defs_linux_arm.go b/src/runtime/defs_linux_arm.go index 94577fc597..946f5bb230 100644 --- a/src/runtime/defs_linux_arm.go +++ b/src/runtime/defs_linux_arm.go @@ -111,13 +111,14 @@ func (ts *timespec32) setNsec(ns int64) { type timespec struct { tv_sec int64 - tv_nsec int64 + tv_nsec int32 + _ [4]byte // the C ABI aligns int64 to 8 bytes } //go:nosplit func (ts *timespec) setNsec(ns int64) { - ts.tv_sec = int64(ns / 1e9) - ts.tv_nsec = int64(ns % 1e9) + ts.tv_sec = ns / 1e9 + ts.tv_nsec = int32(ns % 1e9) } type stackt struct { diff --git a/src/runtime/defs_linux_mipsx.go b/src/runtime/defs_linux_mipsx.go index b8da4d00af..c14fa8498f 100644 --- a/src/runtime/defs_linux_mipsx.go +++ b/src/runtime/defs_linux_mipsx.go @@ -109,13 +109,14 @@ func (ts *timespec32) setNsec(ns int64) { type timespec struct { tv_sec int64 - tv_nsec int64 + tv_nsec int32 + _ [4]byte // the C ABI aligns int64 to 8 bytes } //go:nosplit func (ts *timespec) setNsec(ns int64) { - ts.tv_sec = int64(ns / 1e9) - ts.tv_nsec = int64(ns % 1e9) + ts.tv_sec = ns / 1e9 + ts.tv_nsec = int32(ns % 1e9) } type timeval struct { diff --git a/src/runtime/os_linux32.go b/src/runtime/os_linux32.go index 02cb18f32d..1ee1cdcaf9 100644 --- a/src/runtime/os_linux32.go +++ b/src/runtime/os_linux32.go @@ -31,7 +31,7 @@ func futex(addr unsafe.Pointer, op int32, val uint32, ts *timespec, addr2 unsafe var ts32 timespec32 var pts32 *timespec32 if ts != nil { - ts32.setNsec(ts.tv_sec*1e9 + ts.tv_nsec) + ts32.setNsec(ts.tv_sec*1e9 + int64(ts.tv_nsec)) pts32 = &ts32 } return futex_time32(addr, op, val, pts32, addr2, val3) @@ -53,14 +53,14 @@ func timer_settime(timerid int32, flags int32, new, old *itimerspec) int32 { var new32, old32 *itimerspec32 if new != nil { - newts.it_interval.setNsec(new.it_interval.tv_sec*1e9 + new.it_interval.tv_nsec) - newts.it_value.setNsec(new.it_value.tv_sec*1e9 + new.it_value.tv_nsec) + newts.it_interval.setNsec(new.it_interval.tv_sec*1e9 + int64(new.it_interval.tv_nsec)) + newts.it_value.setNsec(new.it_value.tv_sec*1e9 + int64(new.it_value.tv_nsec)) new32 = &newts } if old != nil { - oldts.it_interval.setNsec(old.it_interval.tv_sec*1e9 + old.it_interval.tv_nsec) - oldts.it_value.setNsec(old.it_value.tv_sec*1e9 + old.it_value.tv_nsec) + oldts.it_interval.setNsec(old.it_interval.tv_sec*1e9 + int64(old.it_interval.tv_nsec)) + oldts.it_value.setNsec(old.it_value.tv_sec*1e9 + int64(old.it_value.tv_nsec)) old32 = &oldts } |
