github.com/dylandreimerink/gobpfld@v0.6.1-0.20220205171531-e79c330ad608/kernelsupport/arch.go (about) 1 package kernelsupport 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 // ArchSupport is a flagset which describes on which architectures eBPF is supported 9 type ArchSupport uint64 10 11 const ( 12 // KFeatArchx86_64 means the kernel has eBPF support on the x86_64 architecture 13 KFeatArchx86_64 ArchSupport = 1 << iota 14 // KFeatArchARM64 means the kernel has eBPF support on the ARM64 architecture 15 KFeatArchARM64 16 // KFeatArchs390 means the kernel has eBPF support on the s390 architecture 17 KFeatArchs390 18 // KFeatArchPP64 means the kernel has eBPF support on the PowerPC64 architecture 19 KFeatArchPP64 20 // KFeatArchSparc64 means the kernel has eBPF support on the Sparc64 architecture 21 KFeatArchSparc64 22 // KFeatArchMIPS means the kernel has eBPF support on the MIPS architecture 23 KFeatArchMIPS 24 // KFeatArchARM32 means the kernel has eBPF support on the ARM32 architecture 25 KFeatArchARM32 26 // KFeatArchx86 means the kernel has eBPF support on the x86_32 architecture 27 KFeatArchx86 28 // KFeatArchRiscVRV64G means the kernel has eBPF support on the RISC-V RV64G architecture 29 KFeatArchRiscVRV64G 30 // KFeatArchRiscVRV32G means the kernel has eBPF support on the RISC-V RV32G architecture 31 KFeatArchRiscVRV32G 32 33 // An end marker for enumeration, not an actual feature flag 34 kFeatArchMax //nolint:revive // leading k is used to stay consistent with exported vars 35 ) 36 37 // Has returns true if 'as' has all the specified flags 38 func (as ArchSupport) Has(flags ArchSupport) bool { 39 return as&flags == flags 40 } 41 42 var archSupportToString = map[ArchSupport]string{ 43 KFeatArchx86_64: "x86_64", 44 KFeatArchARM64: "ARM64", 45 KFeatArchs390: "s309", 46 KFeatArchPP64: "PowerPC64", 47 KFeatArchSparc64: "Sparc64", 48 KFeatArchMIPS: "MIPS", 49 KFeatArchARM32: "ARM32", 50 KFeatArchx86: "x86_32", 51 KFeatArchRiscVRV64G: "RISC-V RV64G", 52 KFeatArchRiscVRV32G: "RISC-V RV32G", 53 } 54 55 func (as ArchSupport) String() string { 56 var archs []string 57 for i := ArchSupport(1); i < kFeatArchMax; i = i << 1 { 58 // If this flag is set 59 if as&i > 0 { 60 archStr := archSupportToString[i] 61 if archStr == "" { 62 archStr = fmt.Sprintf("missing arch str(%d)", i) 63 } 64 archs = append(archs, archStr) 65 } 66 } 67 68 if len(archs) == 0 { 69 return "No support" 70 } 71 72 if len(archs) == 1 { 73 return archs[0] 74 } 75 76 return strings.Join(archs, ", ") 77 }