]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix erroneous overflow protection on netbsd/openbsd semasleep.
authorRémy Oudompheng <oudomphe@phare.normalesup.org>
Tue, 19 Mar 2013 06:08:26 +0000 (07:08 +0100)
committerRémy Oudompheng <oudomphe@phare.normalesup.org>
Tue, 19 Mar 2013 06:08:26 +0000 (07:08 +0100)
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

src/pkg/runtime/os_netbsd.c
src/pkg/runtime/os_openbsd.c

index 6cf57d65645eea014e6ecf9cc45673afd6cded3b..d4b874f4c24da180372ca46fecee25bd5632bb27 100644 (file)
@@ -65,7 +65,6 @@ int32
 runtime·semasleep(int64 ns)
 {
        Timespec ts;
-       int64 secs;
 
        // spin-mutex lock
        while(runtime·xchg(&m->waitsemalock, 1))
@@ -94,11 +93,7 @@ runtime·semasleep(int64 ns)
                                runtime·lwp_park(nil, 0, &m->waitsemacount, nil);
                        } else {
                                ns += runtime·nanotime();
-                               secs = ns/1000000000LL;
-                               // Avoid overflow
-                               if(secs > 1LL<<30)
-                                       secs = 1LL<<30;
-                               ts.tv_sec = secs;
+                               ts.tv_sec = ns/1000000000LL;
                                ts.tv_nsec = ns%1000000000LL;
                                // TODO(jsing) - potential deadlock!
                                // See above for details.
index c3f562e0a2214a2915460dbbe3b8c688b8786814..2c34f0ef999e5008dccf1202426f98025edfb5fa 100644 (file)
@@ -79,8 +79,8 @@ runtime·semasleep(int64 ns)
                                ns += runtime·nanotime();
                                secs = ns/1000000000LL;
                                // Avoid overflow
-                               if(secs > 1LL<<30)
-                                       secs = 1LL<<30;
+                               if(secs >= 1LL<<31)
+                                       secs = (1LL<<31) - 1;
                                ts.tv_sec = secs;
                                ts.tv_nsec = ns%1000000000LL;
                                runtime·thrsleep(&m->waitsemacount, CLOCK_REALTIME, &ts, &m->waitsemalock, nil);