aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/mem_linux.go
diff options
context:
space:
mode:
authorioworker0 <ioworker0@gmail.com>2023-04-24 06:37:52 +0000
committerGopher Robot <gobot@golang.org>2023-04-26 04:06:08 +0000
commitada0eec8277449ecd6383c86bc2e5fe7e7058fc7 (patch)
tree2a6b4dabb1427c617cabd0920ed3f75925376835 /src/runtime/mem_linux.go
parent3c59639b902fada0a2e5a6a35bafd10fc9183b89 (diff)
downloadgo-ada0eec8277449ecd6383c86bc2e5fe7e7058fc7.tar.xz
runtime: add a alignment check
The Linux implementation requires that the address addr be page-aligned, and allows length to be zero. See Linux notes: https://man7.org/linux/man-pages/man2/madvise.2.html Change-Id: Ic49960c32991ef12f23de2de76e9689567c82d03 GitHub-Last-Rev: 35e7f8e5cc0b045043a88d9f304ef5bb1e9c1ab2 GitHub-Pull-Request: golang/go#59793 Reviewed-on: https://go-review.googlesource.com/c/go/+/488015 Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/mem_linux.go')
-rw-r--r--src/runtime/mem_linux.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/runtime/mem_linux.go b/src/runtime/mem_linux.go
index 31815fb421..b456f7f2ff 100644
--- a/src/runtime/mem_linux.go
+++ b/src/runtime/mem_linux.go
@@ -92,6 +92,11 @@ func sysHugePageOS(v unsafe.Pointer, n uintptr) {
}
func sysNoHugePageOS(v unsafe.Pointer, n uintptr) {
+ if uintptr(v)&(physPageSize-1) != 0 {
+ // The Linux implementation requires that the address
+ // addr be page-aligned, and allows length to be zero.
+ throw("unaligned sysNoHugePageOS")
+ }
madvise(v, n, _MADV_NOHUGEPAGE)
}