Permalink
Browse files

Add bpf.VmEndianness variable

This allows the user of the bpf.Vm to control what endianness the
VM should use.
  • Loading branch information...
1 parent 3da985c commit 0c0cd2628b36f2b053b7cc1ec04b76aab4c5189c @mvo5 committed Jun 2, 2017
Showing with 6 additions and 2 deletions.
  1. +6 −2 bpf/vm_instructions.go
View
@@ -134,6 +134,10 @@ func inBounds(inLen int, offset int, size int) bool {
return offset+size <= inLen
}
+// VmEndianness controlls what byte order the bpf.VM is using.
+// The default is binary.BigEndian
+var VmEndianness binary.ByteOrder = binary.BigEndian
+
func loadCommon(in []byte, offset int, size int) (uint32, bool) {
if !inBounds(len(in), offset, size) {
return 0, false
@@ -143,9 +147,9 @@ func loadCommon(in []byte, offset int, size int) (uint32, bool) {
case 1:
return uint32(in[offset]), true
case 2:
- return uint32(binary.BigEndian.Uint16(in[offset : offset+size])), true
+ return uint32(VmEndianness.Uint16(in[offset : offset+size])), true
case 4:
- return uint32(binary.BigEndian.Uint32(in[offset : offset+size])), true
+ return uint32(VmEndianness.Uint32(in[offset : offset+size])), true
default:
panic(fmt.Sprintf("invalid load size: %d", size))
}

0 comments on commit 0c0cd26

Please sign in to comment.