diff options
author | Ian Lance Taylor <iant@golang.org> | 2017-06-06 15:08:59 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2017-06-06 23:26:55 +0000 |
commit | f425f549573e5017861216d62ccb22ee37b68004 (patch) | |
tree | a5dc94df90194f08092676258a4079650564b4f5 /src/runtime/sys_linux_amd64.s | |
parent | 557f6a13beb9e2da58d439d228e7f8f838c61159 (diff) | |
download | go-f425f549573e5017861216d62ccb22ee37b68004.tar.gz go-f425f549573e5017861216d62ccb22ee37b68004.zip |
runtime: intercept munmap as we do mmap
For cgo programs on linux-amd64 we call the C function mmap.
This supports programs such as the C memory sanitizer that need to
intercept all calls to mmap. It turns out that there are programs that
intercept both mmap and munmap, or that at least expect that if they
intercept mmap, they also intercept munmap. So, if we permit mmap
to be intercepted, also permit munmap to be intercepted.
No test, as it requires two odd things: a C program that intercepts
mmap and munmap, and a Go program that calls munmap.
Change-Id: Iec33f47d59f70dbb7463fd12d30728c24cd4face
Reviewed-on: https://go-review.googlesource.com/45016
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Diffstat (limited to 'src/runtime/sys_linux_amd64.s')
-rw-r--r-- | src/runtime/sys_linux_amd64.s | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s index bf539aa0da..e0dc3e1264 100644 --- a/src/runtime/sys_linux_amd64.s +++ b/src/runtime/sys_linux_amd64.s @@ -393,7 +393,7 @@ TEXT runtime·callCgoMmap(SB),NOSPLIT,$16 MOVQ AX, ret+32(FP) RET -TEXT runtime·munmap(SB),NOSPLIT,$0 +TEXT runtime·sysMunmap(SB),NOSPLIT,$0 MOVQ addr+0(FP), DI MOVQ n+8(FP), SI MOVQ $11, AX // munmap @@ -403,6 +403,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 |