aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/sys_linux_amd64.s
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2015-09-29 21:24:13 -0700
committerIan Lance Taylor <iant@golang.org>2015-09-30 22:17:55 +0000
commit0c1f0549b893d9ddaab42a7765ba82234fbcc10d (patch)
tree6f0e6089d8bdac64096243e33ad7e773f17443a0 /src/runtime/sys_linux_amd64.s
parentb72a4a07c257f394f5a96dff29a4fc862601a41f (diff)
downloadgo-0c1f0549b893d9ddaab42a7765ba82234fbcc10d.tar.xz
runtime, runtime/cgo: support using msan on cgo code
The memory sanitizer (msan) is a nice compiler feature that can dynamically check for memory errors in C code. It's not useful for Go code, since Go is memory safe. But it is useful to be able to use the memory sanitizer on C code that is linked into a Go program via cgo. Without this change it does not work, as msan considers memory passed from Go to C as uninitialized. To make this work, change the runtime to call the C mmap function when using cgo. When using msan the mmap call will be intercepted and marked as returning initialized memory. Work around what appears to be an msan bug by calling malloc before we call mmap. Change-Id: I8ab7286d7595ae84782f68a98bef6d3688b946f9 Reviewed-on: https://go-review.googlesource.com/15170 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org>
Diffstat (limited to 'src/runtime/sys_linux_amd64.s')
-rw-r--r--src/runtime/sys_linux_amd64.s16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s
index 59c21c5b42..7ad704f306 100644
--- a/src/runtime/sys_linux_amd64.s
+++ b/src/runtime/sys_linux_amd64.s
@@ -239,7 +239,7 @@ TEXT runtime·sigreturn(SB),NOSPLIT,$0
SYSCALL
INT $3 // not reached
-TEXT runtime·mmap(SB),NOSPLIT,$0
+TEXT runtime·sysMmap(SB),NOSPLIT,$0
MOVQ addr+0(FP), DI
MOVQ n+8(FP), SI
MOVL prot+16(FP), DX
@@ -256,6 +256,20 @@ TEXT runtime·mmap(SB),NOSPLIT,$0
MOVQ AX, ret+32(FP)
RET
+// Call the function stored in _cgo_mmap using the GCC calling convention.
+// This must be called on the system stack.
+TEXT runtime·callCgoMmap(SB),NOSPLIT,$0
+ MOVQ addr+0(FP), DI
+ MOVQ n+8(FP), SI
+ MOVL prot+16(FP), DX
+ MOVL flags+20(FP), CX
+ MOVL fd+24(FP), R8
+ MOVL off+28(FP), R9
+ MOVQ _cgo_mmap(SB), AX
+ CALL AX
+ MOVQ AX, ret+32(FP)
+ RET
+
TEXT runtime·munmap(SB),NOSPLIT,$0
MOVQ addr+0(FP), DI
MOVQ n+8(FP), SI