From c02aa463db0c5867a4ae1adfc2f98c436cb751b0 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 8 Jan 2016 16:56:02 -0800 Subject: runtime: fix arm/arm64/ppc64/mips64 to dropm when necessary Fixes #13881. Change-Id: Idff77db381640184ddd2b65022133bb226168800 Reviewed-on: https://go-review.googlesource.com/18449 Reviewed-by: David Crawshaw Run-TryBot: Ian Lance Taylor --- src/runtime/testdata/testprogcgo/dropm.go | 57 ++++++++++++++++++++++++++ src/runtime/testdata/testprogcgo/dropm_stub.go | 11 +++++ 2 files changed, 68 insertions(+) create mode 100644 src/runtime/testdata/testprogcgo/dropm.go create mode 100644 src/runtime/testdata/testprogcgo/dropm_stub.go (limited to 'src/runtime/testdata') diff --git a/src/runtime/testdata/testprogcgo/dropm.go b/src/runtime/testdata/testprogcgo/dropm.go new file mode 100644 index 0000000000..80ccdcc608 --- /dev/null +++ b/src/runtime/testdata/testprogcgo/dropm.go @@ -0,0 +1,57 @@ +// Copyright 2016 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. + +// Test that a sequence of callbacks from C to Go get the same m. +// This failed to be true on arm and arm64, which was the root cause +// of issue 13881. + +package main + +/* +#include +#include + +extern void GoCheckM(); + +static void* thread(void* arg __attribute__ ((unused))) { + GoCheckM(); + return NULL; +} + +static void CheckM() { + pthread_t tid; + pthread_create(&tid, NULL, thread, NULL); + pthread_join(tid, NULL); + pthread_create(&tid, NULL, thread, NULL); + pthread_join(tid, NULL); +} +*/ +import "C" + +import ( + "fmt" + "os" +) + +func init() { + register("EnsureDropM", EnsureDropM) +} + +var savedM uintptr + +//export GoCheckM +func GoCheckM() { + m := runtime_getm_for_test() + if savedM == 0 { + savedM = m + } else if savedM != m { + fmt.Printf("m == %x want %x\n", m, savedM) + os.Exit(1) + } +} + +func EnsureDropM() { + C.CheckM() + fmt.Println("OK") +} diff --git a/src/runtime/testdata/testprogcgo/dropm_stub.go b/src/runtime/testdata/testprogcgo/dropm_stub.go new file mode 100644 index 0000000000..4c3f46ade4 --- /dev/null +++ b/src/runtime/testdata/testprogcgo/dropm_stub.go @@ -0,0 +1,11 @@ +// Copyright 2016 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 main + +import _ "unsafe" // for go:linkname + +// Defined in the runtime package. +//go:linkname runtime_getm_for_test runtime.getm +func runtime_getm_for_test() uintptr -- cgit v1.3