]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix syscall.NewCallback to return all bits for uintptr values
authorAlex Brainman <alex.brainman@gmail.com>
Fri, 25 Jan 2019 07:56:22 +0000 (18:56 +1100)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Tue, 26 Feb 2019 20:22:39 +0000 (20:22 +0000)
syscall.NewCallback mistakenly used MOVL even for windows/amd64,
which only returned the lower 32 bits regardless of the architecture.
This was due to a copy and paste after porting from windows/386.
The code now uses MOVQ, which will return all the available bits.

Also adjust TestReturnAfterStackGrowInCallback to ensure we never
regress.

Fixes #29331

Change-Id: I4f5c8021c33f234c2bb7baa9ef7a6b4870172509
Reviewed-on: https://go-review.googlesource.com/c/159579
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
src/runtime/sys_windows_amd64.s
src/runtime/syscall_windows_test.go

index 612f0a474d18f504ecba889197a0ef0669e295af..43a26497ad8a79751678e3c4873404fb0054df80 100644 (file)
@@ -351,7 +351,7 @@ TEXT runtime·callbackasm1(SB),NOSPLIT,$0
        ADDQ    $64, SP
        POPFQ
 
-       MOVL    -8(CX)(DX*1), AX  // return value
+       MOVQ    -8(CX)(DX*1), AX  // return value
        POPQ    -8(CX)(DX*1)      // restore bytes just after the args
        RET
 
index 3ad651297677481ca15b296ac48c7ce24e5e94f3..5335c12f0f7b8a8f4bc163daa2d019a79c620cf7 100644 (file)
@@ -655,12 +655,16 @@ uintptr_t cfunc(callback f, uintptr_t n) {
                r   uintptr
                err syscall.Errno
        }
+       want := result{
+               // Make it large enough to test issue #29331.
+               r:   (^uintptr(0)) >> 24,
+               err: 333,
+       }
        c := make(chan result)
        go func() {
-               r, _, err := proc.Call(cb, 100)
+               r, _, err := proc.Call(cb, want.r)
                c <- result{r, err.(syscall.Errno)}
        }()
-       want := result{r: 100, err: 333}
        if got := <-c; got != want {
                t.Errorf("got %d want %d", got, want)
        }