]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make Playground timestamps change when the stream fd changes
authorBryan C. Mills <bcmills@google.com>
Fri, 6 Apr 2018 20:19:30 +0000 (16:19 -0400)
committerBryan C. Mills <bcmills@google.com>
Wed, 11 Apr 2018 18:12:02 +0000 (18:12 +0000)
The process reading the output of the binary may read stderr and
stdout separately, and may interleave reads from the two streams
arbitrarily. Because we explicitly serialize writes on the writer
side, we can reuse a timestamp within a single stream without losing
information; however, if we use the same timestamp for write on both
streams, the reader can't tell how to interleave them.

This change ensures that every time we change between the two fds, we
also bump the timestamp. That way, writes within a stream continue to
show the same timestamp, but a sorted merge of the contents of the two
streams always interleaves them in the correct order.

This still requires a corresponding change to the Playground parser to
actually reconstruct the correct interleaving. It currently merges the
two streams without reordering them; it should instead buffer them
separately and perform a sorted merge. (See
https://golang.org/cl/105496.)

Updates golang/go#24615.
Updates golang/go#24659.

Change-Id: Id789dfcc02eb4247906c9ddad38dac50cf829979
Reviewed-on: https://go-review.googlesource.com/105235
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Yury Smolsky <yury@smolsky.by>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/os_nacl.go
src/runtime/sys_nacl_amd64p32.s

index d03cb8faf2fdc7c8e64e072f16476639648fd57d..7b8a7d548ea6a635c99b6adcc96cdbaff43248d0 100644 (file)
@@ -289,6 +289,15 @@ type gsignalStack struct{}
 
 var writelock uint32 // test-and-set spin lock for write
 
+// lastfaketime stores the last faketime value written to fd 1 or 2.
+var lastfaketime int64
+
+// lastfaketimefd stores the fd to which lastfaketime was written.
+//
+// Subsequent writes to the same fd may use the same timestamp,
+// but the timestamp must increase if the fd changes.
+var lastfaketimefd int32
+
 /*
 An attempt at IRT. Doesn't work. See end of sys_nacl_amd64.s.
 
index ff4c2e7bb5f8feb22369374d4a830473326ed8e3..4c4d509576cb047adeb4d0f80ba7a95370a2d90c 100644 (file)
@@ -89,6 +89,22 @@ playback:
        CMPL BX, $0
        JNE playback
 
+       MOVQ runtime·lastfaketime(SB), CX
+       MOVL runtime·lastfaketimefd(SB), BX
+       CMPL DI, BX
+       JE samefd
+
+       // If the current fd doesn't match the fd of the previous write,
+       // ensure that the timestamp is strictly greater. That way, we can
+       // recover the original order even if we read the fds separately.
+       INCQ CX
+       MOVL DI, runtime·lastfaketimefd(SB)
+
+samefd:
+       CMPQ AX, CX
+       CMOVQLT CX, AX
+       MOVQ AX, runtime·lastfaketime(SB)
+
        // Playback header: 0 0 P B <8-byte time> <4-byte data length>
        MOVL $(('B'<<24) | ('P'<<16)), 0(SP)
        BSWAPQ AX