github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/fs/proc/cpuinfo.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 package proc 16 17 import ( 18 "bytes" 19 20 "github.com/SagerNet/gvisor/pkg/context" 21 "github.com/SagerNet/gvisor/pkg/sentry/fs" 22 "github.com/SagerNet/gvisor/pkg/sentry/kernel" 23 ) 24 25 // LINT.IfChange 26 27 func newCPUInfo(ctx context.Context, msrc *fs.MountSource) *fs.Inode { 28 k := kernel.KernelFromContext(ctx) 29 features := k.FeatureSet() 30 if features == nil { 31 // Kernel is always initialized with a FeatureSet. 32 panic("cpuinfo read with nil FeatureSet") 33 } 34 var buf bytes.Buffer 35 for i, max := uint(0), k.ApplicationCores(); i < max; i++ { 36 features.WriteCPUInfoTo(i, &buf) 37 } 38 return newStaticProcInode(ctx, msrc, buf.Bytes()) 39 } 40 41 // LINT.ThenChange(../../fsimpl/proc/tasks_files.go)