gitlab.com/Raven-IO/raven-delve@v1.22.4/pkg/proc/amd64util/xsave_amd64.go (about)

     1  package amd64util
     2  
     3  import (
     4  	"sync"
     5  )
     6  
     7  var xstateMaxSize int
     8  var loadXstateMaxSizeOnce sync.Once
     9  
    10  func cpuid(axIn, cxIn uint32) (axOut, bxOut, cxOut, dxOut uint32)
    11  
    12  func AMD64XstateMaxSize() int {
    13  	loadXstateMaxSizeOnce.Do(func() {
    14  		// See Intel 64 and IA-32 Architecture Software Developer's Manual, Vol. 1
    15  		// chapter 13.2 and Vol. 2A CPUID instruction for a description of all the
    16  		// magic constants.
    17  
    18  		_, _, cx, _ := cpuid(0x01, 0x00)
    19  
    20  		if cx&(1<<26) == 0 { // Vol. 2A, Table 3-10, XSAVE enabled bit check
    21  			// XSAVE not supported by this processor
    22  			xstateMaxSize = _XSTATE_MAX_KNOWN_SIZE
    23  			return
    24  		}
    25  
    26  		_, _, cx, _ = cpuid(0x0d, 0x00) // processor extended state enumeration main leaf
    27  		xstateMaxSize = int(cx)
    28  	})
    29  	return xstateMaxSize
    30  }