Commit 51f14a9f authored by Rémy Oudompheng's avatar Rémy Oudompheng

runtime: fix erroneous overflow protection on netbsd/openbsd semasleep.

On NetBSD tv_sec is already an int64 so no need for a test.

On OpenBSD, semasleep expects a Unix time as argument,
and 1<<30 is in 2004.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7810044
parent b89a2bcf
...@@ -65,7 +65,6 @@ int32 ...@@ -65,7 +65,6 @@ int32
runtime·semasleep(int64 ns) runtime·semasleep(int64 ns)
{ {
Timespec ts; Timespec ts;
int64 secs;
// spin-mutex lock // spin-mutex lock
while(runtime·xchg(&m->waitsemalock, 1)) while(runtime·xchg(&m->waitsemalock, 1))
...@@ -94,11 +93,7 @@ runtime·semasleep(int64 ns) ...@@ -94,11 +93,7 @@ runtime·semasleep(int64 ns)
runtime·lwp_park(nil, 0, &m->waitsemacount, nil); runtime·lwp_park(nil, 0, &m->waitsemacount, nil);
} else { } else {
ns += runtime·nanotime(); ns += runtime·nanotime();
secs = ns/1000000000LL; ts.tv_sec = ns/1000000000LL;
// Avoid overflow
if(secs > 1LL<<30)
secs = 1LL<<30;
ts.tv_sec = secs;
ts.tv_nsec = ns%1000000000LL; ts.tv_nsec = ns%1000000000LL;
// TODO(jsing) - potential deadlock! // TODO(jsing) - potential deadlock!
// See above for details. // See above for details.
......
...@@ -79,8 +79,8 @@ runtime·semasleep(int64 ns) ...@@ -79,8 +79,8 @@ runtime·semasleep(int64 ns)
ns += runtime·nanotime(); ns += runtime·nanotime();
secs = ns/1000000000LL; secs = ns/1000000000LL;
// Avoid overflow // Avoid overflow
if(secs > 1LL<<30) if(secs >= 1LL<<31)
secs = 1LL<<30; secs = (1LL<<31) - 1;
ts.tv_sec = secs; ts.tv_sec = secs;
ts.tv_nsec = ns%1000000000LL; ts.tv_nsec = ns%1000000000LL;
runtime·thrsleep(&m->waitsemacount, CLOCK_REALTIME, &ts, &m->waitsemalock, nil); runtime·thrsleep(&m->waitsemacount, CLOCK_REALTIME, &ts, &m->waitsemalock, nil);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment