Skip to content

Commit 7c2e69f

Browse files
authored
Merge pull request #4399 from kolyshkin/endian
libct/seccomp/patchbpf: use binary.NativeEndian
2 parents e8e8c02 + a31efe7 commit 7c2e69f

File tree

2 files changed

+1
-18
lines changed

2 files changed

+1
-18
lines changed

libcontainer/seccomp/patchbpf/enosys_linux.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"golang.org/x/sys/unix"
1919

2020
"github.com/opencontainers/runc/libcontainer/configs"
21-
"github.com/opencontainers/runc/libcontainer/utils"
2221
)
2322

2423
// #cgo pkg-config: libseccomp
@@ -110,7 +109,7 @@ func parseProgram(rdr io.Reader) ([]bpf.RawInstruction, error) {
110109
// Read the next instruction. We have to use NativeEndian because
111110
// seccomp_export_bpf outputs the program in *host* endian-ness.
112111
var insn unix.SockFilter
113-
if err := binary.Read(rdr, utils.NativeEndian, &insn); err != nil {
112+
if err := binary.Read(rdr, binary.NativeEndian, &insn); err != nil {
114113
if errors.Is(err, io.EOF) {
115114
// Parsing complete.
116115
break

libcontainer/utils/utils.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package utils
22

33
import (
4-
"encoding/binary"
54
"encoding/json"
65
"io"
76
"os"
87
"path/filepath"
98
"strings"
10-
"unsafe"
119

1210
"golang.org/x/sys/unix"
1311
)
@@ -16,20 +14,6 @@ const (
1614
exitSignalOffset = 128
1715
)
1816

19-
// NativeEndian is the native byte order of the host system.
20-
var NativeEndian binary.ByteOrder
21-
22-
func init() {
23-
// Copied from <golang.org/x/net/internal/socket/sys.go>.
24-
i := uint32(1)
25-
b := (*[4]byte)(unsafe.Pointer(&i))
26-
if b[0] == 1 {
27-
NativeEndian = binary.LittleEndian
28-
} else {
29-
NativeEndian = binary.BigEndian
30-
}
31-
}
32-
3317
// ExitStatus returns the correct exit status for a process based on if it
3418
// was signaled or exited cleanly
3519
func ExitStatus(status unix.WaitStatus) int {

0 commit comments

Comments
 (0)