diff options
author | Ian Lance Taylor <iant@golang.org> | 2021-08-04 20:55:28 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2021-08-09 14:48:39 +0000 |
commit | 7aeaad5c86174f61b084d72d89fb02d7fc64391c (patch) | |
tree | 862487ba7d1fbf274b7a30b539e66922d2d2630c /src/runtime/cgo/gcc_traceback.c | |
parent | 507cc341ec2cb96b0199800245f222146f799266 (diff) | |
download | go-7aeaad5c86174f61b084d72d89fb02d7fc64391c.tar.gz go-7aeaad5c86174f61b084d72d89fb02d7fc64391c.zip |
runtime/cgo: when using msan explicitly unpoison cgoCallers
This avoids an incorrect msan uninitialized memory report when using
runtime.SetCgoTraceback when a signal occurs while the fifth argument
register is undefined. See the issue for more details.
Fixes #47543
Change-Id: I3d1b673e2c93471ccdae0171a99b88b5a6062840
Reviewed-on: https://go-review.googlesource.com/c/go/+/339902
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/cgo/gcc_traceback.c')
-rw-r--r-- | src/runtime/cgo/gcc_traceback.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/runtime/cgo/gcc_traceback.c b/src/runtime/cgo/gcc_traceback.c index d86331c583..6e9470c43c 100644 --- a/src/runtime/cgo/gcc_traceback.c +++ b/src/runtime/cgo/gcc_traceback.c @@ -7,6 +7,14 @@ #include <stdint.h> #include "libcgo.h" +#ifndef __has_feature +#define __has_feature(x) 0 +#endif + +#if __has_feature(memory_sanitizer) +#include <sanitizer/msan_interface.h> +#endif + // Call the user's traceback function and then call sigtramp. // The runtime signal handler will jump to this code. // We do it this way so that the user's traceback function will be called @@ -19,6 +27,18 @@ x_cgo_callers(uintptr_t sig, void *info, void *context, void (*cgoTraceback)(str arg.SigContext = (uintptr_t)(context); arg.Buf = cgoCallers; arg.Max = 32; // must match len(runtime.cgoCallers) + +#if __has_feature(memory_sanitizer) + // This function is called directly from the signal handler. + // The arguments are passed in registers, so whether msan + // considers cgoCallers to be initialized depends on whether + // it considers the appropriate register to be initialized. + // That can cause false reports in rare cases. + // Explicitly unpoison the memory to avoid that. + // See issue #47543 for more details. + __msan_unpoison(&arg, sizeof arg); +#endif + (*cgoTraceback)(&arg); sigtramp(sig, info, context); } |