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 <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2024-09-11 22:04:14 -07:00
parent e8e8c029c7
commit a31efe7045
2 changed files with 1 additions and 18 deletions
@@ -18,7 +18,6 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
"github.com/opencontainers/runc/libcontainer/configs" "github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runc/libcontainer/utils"
) )
// #cgo pkg-config: libseccomp // #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 // Read the next instruction. We have to use NativeEndian because
// seccomp_export_bpf outputs the program in *host* endian-ness. // seccomp_export_bpf outputs the program in *host* endian-ness.
var insn unix.SockFilter 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) { if errors.Is(err, io.EOF) {
// Parsing complete. // Parsing complete.
break break
-16
View File
@@ -1,13 +1,11 @@
package utils package utils
import ( import (
"encoding/binary"
"encoding/json" "encoding/json"
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"unsafe"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@@ -16,20 +14,6 @@ const (
exitSignalOffset = 128 exitSignalOffset = 128
) )
// NativeEndian is the native byte order of the host system.
var NativeEndian binary.ByteOrder
func init() {
// Copied from <golang.org/x/net/internal/socket/sys.go>.
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 // ExitStatus returns the correct exit status for a process based on if it
// was signaled or exited cleanly // was signaled or exited cleanly
func ExitStatus(status unix.WaitStatus) int { func ExitStatus(status unix.WaitStatus) int {