1
0
mirror of https://github.com/golang/go synced 2024-11-16 23:04:44 -07:00

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
This commit is contained in:
ioworker0 2023-04-24 14:30:07 +08:00 committed by GitHub
parent 6bbbc5dc70
commit 35e7f8e5cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}