Debian Codegraph @

src/runtime/set_vma_name_linux.go

raw
1 // Copyright 2025 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build linux
6
7 package runtime
8
9 import (
10 "internal/runtime/atomic"
11 "internal/runtime/syscall/linux"
12 "unsafe"
13 )
14
15 var prSetVMAUnsupported atomic.Bool
16
17 func setVMANameSupported() bool {
18 return !prSetVMAUnsupported.Load()
19 }
20
21 // setVMAName calls prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, start, len, name)
22 func setVMAName(start unsafe.Pointer, length uintptr, name string) {
23 if debug.decoratemappings == 0 || !setVMANameSupported() {
24 return
25 }
26
27 var sysName [80]byte
28 n := copy(sysName[:], " Go: ")
29 copy(sysName[n:79], name) // leave final byte zero
30
31 _, _, err := linux.Syscall6(linux.SYS_PRCTL, linux.PR_SET_VMA, linux.PR_SET_VMA_ANON_NAME, uintptr(start), length, uintptr(unsafe.Pointer(&sysName[0])), 0)
32 if err == _EINVAL {
33 prSetVMAUnsupported.Store(true)
34 }
35 // ignore other errors
36 }