From a31efe70454d29330e0e7a105352dcf88ad5fbf3 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 11 Sep 2024 22:04:14 -0700 Subject: [PATCH] libct/seccomp/patchbpf: use binary.NativeEndian It is available since Go 1.21 and is defined during compile time (i.e. based on GOARCH during build). Signed-off-by: Kir Kolyshkin --- libcontainer/seccomp/patchbpf/enosys_linux.go | 3 +-- libcontainer/utils/utils.go | 16 ---------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/libcontainer/seccomp/patchbpf/enosys_linux.go b/libcontainer/seccomp/patchbpf/enosys_linux.go index f829bf7ae2f..86de3137855 100644 --- a/libcontainer/seccomp/patchbpf/enosys_linux.go +++ b/libcontainer/seccomp/patchbpf/enosys_linux.go @@ -18,7 +18,6 @@ import ( "golang.org/x/sys/unix" "github.com/opencontainers/runc/libcontainer/configs" - "github.com/opencontainers/runc/libcontainer/utils" ) // #cgo pkg-config: libseccomp @@ -110,7 +109,7 @@ func parseProgram(rdr io.Reader) ([]bpf.RawInstruction, error) { // Read the next instruction. We have to use NativeEndian because // seccomp_export_bpf outputs the program in *host* endian-ness. var insn unix.SockFilter - if err := binary.Read(rdr, utils.NativeEndian, &insn); err != nil { + if err := binary.Read(rdr, binary.NativeEndian, &insn); err != nil { if errors.Is(err, io.EOF) { // Parsing complete. break diff --git a/libcontainer/utils/utils.go b/libcontainer/utils/utils.go index 1b523d8ac54..793783929fb 100644 --- a/libcontainer/utils/utils.go +++ b/libcontainer/utils/utils.go @@ -1,13 +1,11 @@ package utils import ( - "encoding/binary" "encoding/json" "io" "os" "path/filepath" "strings" - "unsafe" "golang.org/x/sys/unix" ) @@ -16,20 +14,6 @@ const ( exitSignalOffset = 128 ) -// NativeEndian is the native byte order of the host system. -var NativeEndian binary.ByteOrder - -func init() { - // Copied from . - i := uint32(1) - b := (*[4]byte)(unsafe.Pointer(&i)) - if b[0] == 1 { - NativeEndian = binary.LittleEndian - } else { - NativeEndian = binary.BigEndian - } -} - // ExitStatus returns the correct exit status for a process based on if it // was signaled or exited cleanly func ExitStatus(status unix.WaitStatus) int {