Просмотр исходного кода

Added more comments regarding 64-bit alignment issue

Rod Hynes 9 лет назад
Родитель
Сommit
6c70356fd3

+ 3 - 5
psiphon/common/throttled.go

@@ -57,11 +57,9 @@ type RateLimits struct {
 // The underlying rate limiter uses the token bucket algorithm to
 // calculate delay times for read and write operations.
 type ThrottledConn struct {
-	// https://golang.org/src/sync/atomic/doc.go#L50
-	// On both ARM and x86-32, it is the caller's responsibility to arrange for 64-bit
-	// alignment of 64-bit words accessed atomically. The first word in a global
-	// variable or in an allocated struct or slice can be relied upon to be
-	// 64-bit aligned.
+	// Note: 64-bit ints used with atomic operations are at placed
+	// at the start of struct to ensure 64-bit alignment.
+	// (https://golang.org/pkg/sync/atomic/#pkg-note-BUG)
 	unlimitedReadBytes  int64
 	unlimitedWriteBytes int64
 	limitingReads       int32

+ 3 - 0
psiphon/server/dns.go

@@ -41,6 +41,9 @@ const (
 // "/etc/resolv.conf" on platforms where it is available; and
 // otherwise using a default value.
 type DNSResolver struct {
+	// Note: 64-bit ints used with atomic operations are at placed
+	// at the start of struct to ensure 64-bit alignment.
+	// (https://golang.org/pkg/sync/atomic/#pkg-note-BUG)
 	lastReloadTime int64
 	common.ReloadableFile
 	isReloading int32

+ 3 - 0
psiphon/server/meek.go

@@ -443,6 +443,9 @@ func (server *MeekServer) terminateConnection(
 }
 
 type meekSession struct {
+	// Note: 64-bit ints used with atomic operations are at placed
+	// at the start of struct to ensure 64-bit alignment.
+	// (https://golang.org/pkg/sync/atomic/#pkg-note-BUG)
 	lastActivity        int64
 	clientConn          *meekConn
 	meekProtocolVersion int

+ 3 - 0
psiphon/server/net.go

@@ -160,6 +160,9 @@ func (entry *LRUConnsEntry) Touch() {
 // either a successful read or write.
 //
 type ActivityMonitoredConn struct {
+	// Note: 64-bit ints used with atomic operations are at placed
+	// at the start of struct to ensure 64-bit alignment.
+	// (https://golang.org/pkg/sync/atomic/#pkg-note-BUG)
 	startTime            int64
 	lastReadActivityTime int64
 	net.Conn

+ 3 - 0
psiphon/server/tunnelServer.go

@@ -551,6 +551,9 @@ type sshClient struct {
 }
 
 type trafficState struct {
+	// Note: 64-bit ints used with atomic operations are at placed
+	// at the start of struct to ensure 64-bit alignment.
+	// (https://golang.org/pkg/sync/atomic/#pkg-note-BUG)
 	bytesUp                        int64
 	bytesDown                      int64
 	concurrentPortForwardCount     int64

+ 3 - 0
psiphon/server/udp.go

@@ -268,6 +268,9 @@ func (mux *udpPortForwardMultiplexer) removePortForward(connID uint16) {
 }
 
 type udpPortForward struct {
+	// Note: 64-bit ints used with atomic operations are at placed
+	// at the start of struct to ensure 64-bit alignment.
+	// (https://golang.org/pkg/sync/atomic/#pkg-note-BUG)
 	bytesUp      int64
 	bytesDown    int64
 	connID       uint16

+ 4 - 1
psiphon/serverApi.go

@@ -44,8 +44,11 @@ import (
 // offer the Psiphon API through a web service; newer servers offer the Psiphon
 // API through SSH requests made directly through the tunnel's SSH client.
 type ServerContext struct {
-	sessionId                string
+	// Note: 64-bit ints used with atomic operations are at placed
+	// at the start of struct to ensure 64-bit alignment.
+	// (https://golang.org/pkg/sync/atomic/#pkg-note-BUG)
 	tunnelNumber             int64
+	sessionId                string
 	tunnel                   *Tunnel
 	psiphonHttpsClient       *http.Client
 	statsRegexps             *transferstats.Regexps