1
0
mirror of https://github.com/golang/go synced 2024-11-18 07:54:55 -07:00
go/misc/cgo/testsanitizers/msan3.go
Ian Lance Taylor 8f3f2ccac0 runtime: mark cgo callback results as written for msan
This is a fix for the -msan option when using cgo callbacks.  A cgo
callback works by writing out C code that puts a struct on the stack and
passes the address of that struct into Go.  The result parameters are
fields of the struct.  The Go code will write to the result parameters,
but the Go code thinks it is just writing into the Go stack, and
therefore won't call msanwrite.  This CL adds a call to msanwrite in the
cgo callback code so that the C knows that results were written.

Change-Id: I80438dbd4561502bdee97fad3f02893a06880ee1
Reviewed-on: https://go-review.googlesource.com/16611
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-11-11 05:58:19 +00:00

33 lines
533 B
Go

// Copyright 2015 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
/*
extern int *GoFn(void);
// Yes, you can have definitions if you use //export, as long as they are weak.
int f(void) __attribute__ ((weak));
int f() {
int *p = GoFn();
if (*p != 12345)
return 0;
return 1;
}
*/
import "C"
//export GoFn
func GoFn() *C.int {
i := C.int(12345)
return &i
}
func main() {
if r := C.f(); r != 1 {
panic(r)
}
}