github.com/MerlinKodo/gvisor@v0.0.0-20231110090155-957f62ecf90e/pkg/sentry/syscalls/linux/sys_tls_amd64.go (about) 1 // Copyright 2018 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 amd64 16 // +build amd64 17 18 package linux 19 20 import ( 21 "github.com/MerlinKodo/gvisor/pkg/abi/linux" 22 "github.com/MerlinKodo/gvisor/pkg/errors/linuxerr" 23 "github.com/MerlinKodo/gvisor/pkg/marshal/primitive" 24 "github.com/MerlinKodo/gvisor/pkg/sentry/arch" 25 "github.com/MerlinKodo/gvisor/pkg/sentry/kernel" 26 ) 27 28 // ArchPrctl implements linux syscall arch_prctl(2). 29 // It sets architecture-specific process or thread state for t. 30 func ArchPrctl(t *kernel.Task, sysno uintptr, args arch.SyscallArguments) (uintptr, *kernel.SyscallControl, error) { 31 switch args[0].Int() { 32 case linux.ARCH_GET_FS: 33 addr := args[1].Pointer() 34 fsbase := t.Arch().TLS() 35 switch t.Arch().Width() { 36 case 8: 37 if _, err := primitive.CopyUint64Out(t, addr, uint64(fsbase)); err != nil { 38 return 0, nil, err 39 } 40 default: 41 return 0, nil, linuxerr.ENOSYS 42 } 43 case linux.ARCH_SET_FS: 44 fsbase := args[1].Uint64() 45 if !t.Arch().SetTLS(uintptr(fsbase)) { 46 return 0, nil, linuxerr.EPERM 47 } 48 case linux.ARCH_GET_GS, linux.ARCH_SET_GS: 49 t.Kernel().EmitUnimplementedEvent(t, sysno) 50 fallthrough 51 default: 52 return 0, nil, linuxerr.EINVAL 53 } 54 55 return 0, nil, nil 56 }