github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/pkg/sentry/platform/ptrace/ptrace_arm64_unsafe.go (about) 1 // Copyright 2020 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 arm64 16 // +build arm64 17 18 package ptrace 19 20 import ( 21 "unsafe" 22 23 "github.com/MerlinKodo/gvisor/pkg/abi/linux" 24 "golang.org/x/sys/unix" 25 ) 26 27 // getTLS gets the thread local storage register. 28 func (t *thread) getTLS(tls *uint64) error { 29 iovec := unix.Iovec{ 30 Base: (*byte)(unsafe.Pointer(tls)), 31 Len: uint64(unsafe.Sizeof(*tls)), 32 } 33 _, _, errno := unix.RawSyscall6( 34 unix.SYS_PTRACE, 35 unix.PTRACE_GETREGSET, 36 uintptr(t.tid), 37 linux.NT_ARM_TLS, 38 uintptr(unsafe.Pointer(&iovec)), 39 0, 0) 40 if errno != 0 { 41 return errno 42 } 43 return nil 44 } 45 46 // setTLS sets the thread local storage register. 47 func (t *thread) setTLS(tls *uint64) error { 48 iovec := unix.Iovec{ 49 Base: (*byte)(unsafe.Pointer(tls)), 50 Len: uint64(unsafe.Sizeof(*tls)), 51 } 52 _, _, errno := unix.RawSyscall6( 53 unix.SYS_PTRACE, 54 unix.PTRACE_SETREGSET, 55 uintptr(t.tid), 56 linux.NT_ARM_TLS, 57 uintptr(unsafe.Pointer(&iovec)), 58 0, 0) 59 if errno != 0 { 60 return errno 61 } 62 return nil 63 }