Skip to content

Commit

Permalink
Merge pull request #4399 from kolyshkin/endian
Browse files Browse the repository at this point in the history
libct/seccomp/patchbpf: use binary.NativeEndian
  • Loading branch information
AkihiroSuda committed Sep 12, 2024
2 parents e8e8c02 + a31efe7 commit 7c2e69f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 18 deletions.
3 changes: 1 addition & 2 deletions libcontainer/seccomp/patchbpf/enosys_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions libcontainer/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package utils

import (
"encoding/binary"
"encoding/json"
"io"
"os"
"path/filepath"
"strings"
"unsafe"

"golang.org/x/sys/unix"
)
Expand All @@ -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 <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
// was signaled or exited cleanly
func ExitStatus(status unix.WaitStatus) int {
Expand Down

0 comments on commit 7c2e69f

Please sign in to comment.