]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix misaligned 64-bit atomic
authorDmitriy Vyukov <dvyukov@google.com>
Sun, 10 Mar 2013 16:46:11 +0000 (20:46 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Sun, 10 Mar 2013 16:46:11 +0000 (20:46 +0400)
Fixes #4869.
Fixes #5007.
Update #5005.

R=golang-dev, 0xe2.0x9a.0x9b, bradfitz
CC=golang-dev
https://golang.org/cl/7534044

src/pkg/runtime/mgc0.c
src/pkg/runtime/parfor.c
src/pkg/runtime/runtime.h

index 010f9cd9615795497c5061b152c9fb37a6475d2a..6ec9706f49a092f782271a53cd8574d8ea9268ef 100644 (file)
@@ -1757,6 +1757,8 @@ runtime·gc(int32 force)
        // a problem in the past.
        if((((uintptr)&work.empty) & 7) != 0)
                runtime·throw("runtime: gc work buffer is misaligned");
+       if((((uintptr)&work.full) & 7) != 0)
+               runtime·throw("runtime: gc work buffer is misaligned");
 
        // The gc is turned off (via enablegc) until
        // the bootstrap has completed.
index aa5537d0201354b9a48f11e199c6dda774ba9bbe..a4468c2afc3b121b322e6376a0df5a97c9ada41c 100644 (file)
@@ -46,6 +46,7 @@ void
 runtime·parforsetup(ParFor *desc, uint32 nthr, uint32 n, void *ctx, bool wait, void (*body)(ParFor*, uint32))
 {
        uint32 i, begin, end;
+       uint64 *pos;
 
        if(desc == nil || nthr == 0 || nthr > desc->nthrmax || body == nil) {
                runtime·printf("desc=%p nthr=%d count=%d body=%p\n", desc, nthr, n, body);
@@ -67,7 +68,10 @@ runtime·parforsetup(ParFor *desc, uint32 nthr, uint32 n, void *ctx, bool wait,
        for(i=0; i<nthr; i++) {
                begin = (uint64)n*i / nthr;
                end = (uint64)n*(i+1) / nthr;
-               desc->thr[i].pos = (uint64)begin | (((uint64)end)<<32);
+               pos = &desc->thr[i].pos;
+               if(((uintptr)pos & 7) != 0)
+                       runtime·throw("parforsetup: pos is not aligned");
+               *pos = (uint64)begin | (((uint64)end)<<32);
        }
 }
 
index 8ae6e6a6c909d88487bb4a913b00a25e409d39a1..d9afd5b7967e63204ec128747e1568cc15b17b4d 100644 (file)
@@ -483,6 +483,7 @@ struct ParFor
        bool wait;                      // if true, wait while all threads finish processing,
                                        // otherwise parfor may return while other threads are still working
        ParForThread *thr;              // array of thread descriptors
+       uint32 pad;                     // to align ParForThread.pos for 64-bit atomic operations
        // stats
        uint64 nsteal;
        uint64 nstealcnt;