]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: increase stack frame during cgo call on windows/amd64
authorAlex Brainman <alex.brainman@gmail.com>
Mon, 3 Sep 2012 02:12:51 +0000 (12:12 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Mon, 3 Sep 2012 02:12:51 +0000 (12:12 +1000)
Fixes #3945.

R=golang-dev, minux.ma
CC=golang-dev, vcc.163
https://golang.org/cl/6490056

misc/cgo/test/cgo_test.go
misc/cgo/test/issue3945.go [new file with mode: 0644]
src/pkg/runtime/asm_amd64.s

index 1aa21cb65bccc0a423829b88d2e331929e8f6954..c3c35b53c2fd7dd9e2b5e4720277e698a3e99c51 100644 (file)
@@ -29,5 +29,6 @@ func TestSetEnv(t *testing.T)              { testSetEnv(t) }
 func TestHelpers(t *testing.T)             { testHelpers(t) }
 func TestLibgcc(t *testing.T)              { testLibgcc(t) }
 func Test1635(t *testing.T)                { test1635(t) }
+func TestPrintf(t *testing.T)              { testPrintf(t) }
 
 func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
diff --git a/misc/cgo/test/issue3945.go b/misc/cgo/test/issue3945.go
new file mode 100644 (file)
index 0000000..331cd0b
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2012 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+// Test that cgo reserves enough stack space during cgo call.
+// See http://golang.org/issue/3945 for details.
+
+// #include <stdio.h>
+//
+// void say() {
+//    printf("%s from C\n", "hello");
+// }
+//
+import "C"
+
+import "testing"
+
+func testPrintf(t *testing.T) {
+       C.say()
+}
index 08133f02d2d2015d7807054a9839bd5814471ea2..216c89c29f230be1731fd8980b0ae883e68c5db1 100644 (file)
@@ -489,19 +489,21 @@ TEXT runtime·asmcgocall(SB),7,$0
        MOVQ    (g_sched+gobuf_sp)(SI), SP
 
        // Now on a scheduling stack (a pthread-created stack).
-       SUBQ    $48, SP
+       // Make sure we have enough room for 4 stack-backed fast-call
+       // registers as per windows amd64 calling convention.
+       SUBQ    $64, SP
        ANDQ    $~15, SP        // alignment for gcc ABI
-       MOVQ    DI, 32(SP)      // save g
-       MOVQ    DX, 24(SP)      // save SP
+       MOVQ    DI, 48(SP)      // save g
+       MOVQ    DX, 40(SP)      // save SP
        MOVQ    BX, DI          // DI = first argument in AMD64 ABI
        MOVQ    BX, CX          // CX = first argument in Win64
        CALL    AX
 
        // Restore registers, g, stack pointer.
        get_tls(CX)
-       MOVQ    32(SP), DI
+       MOVQ    48(SP), DI
        MOVQ    DI, g(CX)
-       MOVQ    24(SP), SP
+       MOVQ    40(SP), SP
        RET
 
 // cgocallback(void (*fn)(void*), void *frame, uintptr framesize)