atomicbitops_arm64.go raw

   1  // Copyright 2022 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 atomicbitops
  19  
  20  import (
  21  	"runtime"
  22  
  23  	"golang.org/x/sys/cpu"
  24  	"gvisor.dev/gvisor/pkg/cpuid"
  25  )
  26  
  27  var arm64HasATOMICS bool
  28  
  29  func init() {
  30  	// The gvisor cpuid package only works on Linux.
  31  	// For all other operating systems, use Go's x/sys/cpu package
  32  	// to get the one bit we care about here.
  33  	//
  34  	// See https://github.com/google/gvisor/issues/7849.
  35  	if runtime.GOOS == "linux" {
  36  		arm64HasATOMICS = cpuid.HostFeatureSet().HasFeature(cpuid.ARM64FeatureATOMICS)
  37  	} else {
  38  		arm64HasATOMICS = cpu.ARM64.HasATOMICS
  39  	}
  40  }
  41