]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add msan support on freebsd/amd64
authorDmitri Goutnik <dgoutnik@gmail.com>
Wed, 8 Jun 2022 15:52:19 +0000 (10:52 -0500)
committerDmitri Goutnik <dgoutnik@gmail.com>
Fri, 14 Oct 2022 12:48:03 +0000 (12:48 +0000)
Adjust build constraints and change the runtime to call the C mmap function
when using cgo.

R=go1.20

For #53298

Change-Id: If9c3306dc16a8645d1bb9be0343e0472d6c4783f
Reviewed-on: https://go-review.googlesource.com/c/go/+/411274
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/cgo/gcc_mmap.c
src/runtime/cgo/mmap.go
src/runtime/cgo_mmap.go
src/runtime/mmap.go
src/runtime/msan/msan.go
src/runtime/sys_freebsd_amd64.s

index 698a7e3cd243e2c17bb6588f1e897933c852c583..83d857f0d155e220230295219b8f188410c276ac 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build linux,amd64 linux,arm64 linux,ppc64le
+// +build linux,amd64 linux,arm64 linux,ppc64le freebsd,amd64
 
 #include <errno.h>
 #include <stdint.h>
index eae0a9e7cc859d2339fd48bed0b299e991ca564b..2f7e83bcb7357ee40159d787dc908927609711e8 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build (linux && amd64) || (linux && arm64)
+//go:build (linux && amd64) || (linux && arm64) || (freebsd && amd64)
 
 package cgo
 
index 4cb3e65f14ddd4d3b4ec58fc13f0d8366853e7f9..30660f77844fbe83867f76888c7514ad0026ebd2 100644 (file)
@@ -4,7 +4,7 @@
 
 // Support for memory sanitizer. See runtime/cgo/mmap.go.
 
-//go:build (linux && amd64) || (linux && arm64)
+//go:build (linux && amd64) || (linux && arm64) || (freebsd && amd64)
 
 package runtime
 
index 3280a62e8dd9e43806c12dfeefc22af261205493..f0183f61cfad82953d0f7c0163556822c7583ae6 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build !aix && !darwin && !js && (!linux || !amd64) && (!linux || !arm64) && !openbsd && !plan9 && !solaris && !windows
+//go:build !aix && !darwin && !js && (!linux || !amd64) && (!linux || !arm64) && (!freebsd || !amd64) && !openbsd && !plan9 && !solaris && !windows
 
 package runtime
 
index f1bf4e1065cf96c2fc40c8a51afb3f29c252e8d0..4e41f8528d02a1d2d5141208f4edd1013ed1068b 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-//go:build msan && linux && (amd64 || arm64)
+//go:build msan && ((linux && (amd64 || arm64)) || (freebsd && amd64))
 
 package msan
 
index 35311398daf898d6d96986b9ae1fda77f52303a0..c266d73ea28fdd641d8a12a41c26926f3c9d2d17 100644 (file)
@@ -385,7 +385,7 @@ sigtrampnog:
        MOVQ    _cgo_callers(SB), AX
        JMP     AX
 
-TEXT runtime·mmap(SB),NOSPLIT,$0
+TEXT runtime·sysMmap(SB),NOSPLIT,$0
        MOVQ    addr+0(FP), DI          // arg 1 addr
        MOVQ    n+8(FP), SI             // arg 2 len
        MOVL    prot+16(FP), DX         // arg 3 prot
@@ -403,7 +403,25 @@ ok:
        MOVQ    $0, err+40(FP)
        RET
 
-TEXT runtime·munmap(SB),NOSPLIT,$0
+// 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,$16
+       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
+       MOVQ    SP, BX
+       ANDQ    $~15, SP        // alignment as per amd64 psABI
+       MOVQ    BX, 0(SP)
+       CALL    AX
+       MOVQ    0(SP), SP
+       MOVQ    AX, ret+32(FP)
+       RET
+
+TEXT runtime·sysMunmap(SB),NOSPLIT,$0
        MOVQ    addr+0(FP), DI          // arg 1 addr
        MOVQ    n+8(FP), SI             // arg 2 len
        MOVL    $SYS_munmap, AX
@@ -412,6 +430,19 @@ TEXT runtime·munmap(SB),NOSPLIT,$0
        MOVL    $0xf1, 0xf1  // crash
        RET
 
+// Call the function stored in _cgo_munmap using the GCC calling convention.
+// This must be called on the system stack.
+TEXT runtime·callCgoMunmap(SB),NOSPLIT,$16-16
+       MOVQ    addr+0(FP), DI
+       MOVQ    n+8(FP), SI
+       MOVQ    _cgo_munmap(SB), AX
+       MOVQ    SP, BX
+       ANDQ    $~15, SP        // alignment as per amd64 psABI
+       MOVQ    BX, 0(SP)
+       CALL    AX
+       MOVQ    0(SP), SP
+       RET
+
 TEXT runtime·madvise(SB),NOSPLIT,$0
        MOVQ    addr+0(FP), DI
        MOVQ    n+8(FP), SI