github.com/google/capslock@v0.2.3-0.20240517042941-dac19fc347c0/testpkgs/uselinkname/uselinkname.go (about) 1 // Copyright 2023 Google LLC 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file or at 5 // https://developers.google.com/open-source/licenses/bsd 6 7 // Package uselinkname is for testing go:linkname. 8 package uselinkname 9 10 import ( 11 "syscall" 12 13 _ "unsafe" // To allow go:linkname. 14 ) 15 16 // Foo calls the Go runtime's internal random-number generator, using go:linkname. 17 func Foo() uint64 { 18 return runtime_fastrand64() 19 } 20 21 //go:linkname runtime_fastrand64 runtime.fastrand64 22 func runtime_fastrand64() uint64 23 24 // CallExplicitlyCategorizedFunction calls a function which uses linkname. 25 // Functions using linkname which are not explicitly categorized should have 26 // the arbitrary-execution capability, but Getpagesize has been categorized as 27 // having the system-calls capability. 28 func CallExplicitlyCategorizedFunction() int { 29 return syscall.Getpagesize() + 1 30 }