github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/gohacks/linkname_go113_unsafe.go (about) 1 // Copyright 2023 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 //go:build go1.13 16 17 // //go:linkname directives type-checked by checklinkname. Any other 18 // non-linkname assumptions outside the Go 1 compatibility guarantee should 19 // have an accompanied vet check or version guard build tag. 20 21 // Package gohacks contains utilities for subverting the Go compiler. 22 package gohacks 23 24 import ( 25 "unsafe" 26 ) 27 28 // Note that go:linkname silently doesn't work if the local name is exported, 29 // necessitating an indirection for exported functions. 30 31 // Memmove is runtime.memmove, exported for SeqAtomicLoad/SeqAtomicTryLoad<T>. 32 // 33 //go:nosplit 34 func Memmove(to, from unsafe.Pointer, n uintptr) { 35 memmove(to, from, n) 36 } 37 38 //go:linkname memmove runtime.memmove 39 //go:noescape 40 func memmove(to, from unsafe.Pointer, n uintptr) 41 42 // Nanotime is runtime.nanotime. 43 // 44 //go:nosplit 45 func Nanotime() int64 { 46 return nanotime() 47 } 48 49 //go:linkname nanotime runtime.nanotime 50 //go:noescape 51 func nanotime() int64