github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/cpuid/cpuid.go (about) 1 // Copyright 2019 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 // Package cpuid provides basic functionality for creating and adjusting CPU 16 // feature sets. 17 // 18 // To use FeatureSets, one should start with an existing FeatureSet (either a 19 // known platform, or HostFeatureSet()) and then add, remove, and test for 20 // features as desired. 21 // 22 // For example: on x86, test for hardware extended state saving, and if 23 // we don't have it, don't expose AVX, which cannot be saved with fxsave. 24 // 25 // if !HostFeatureSet().HasFeature(X86FeatureXSAVE) { 26 // exposedFeatures.Remove(X86FeatureAVX) 27 // } 28 package cpuid 29 30 // Feature is a unique identifier for a particular cpu feature. We just use an 31 // int as a feature number on x86 and arm64. 32 // 33 // On x86, features are numbered according to "blocks". Each block is 32 bits, and 34 // feature bits from the same source (cpuid leaf/level) are in the same block. 35 // 36 // On arm64, features are numbered according to the ELF HWCAP definition. 37 // arch/arm64/include/uapi/asm/hwcap.h 38 type Feature int 39 40 // ErrIncompatible is returned by FeatureSet.HostCompatible if fs is not a 41 // subset of the host feature set. 42 type ErrIncompatible struct { 43 message string 44 } 45 46 // Error implements error. 47 func (e ErrIncompatible) Error() string { 48 return e.message 49 }