Browse Source

Updated license

tags/v1.0.0
maze 1 year ago
parent
commit
d786f5ddf5
11 changed files with 119 additions and 24 deletions
  1. +25
    -18
      LICENSE
  2. +4
    -0
      assembler.go
  3. +13
    -4
      cmd/bpfasm/main.go
  4. +4
    -0
      parse.go
  5. +5
    -0
      vm.go
  6. +5
    -0
      vm_alu_test.go
  7. +4
    -0
      vm_debug.go
  8. +50
    -0
      vm_extension_test.go
  9. +2
    -1
      vm_jump_test.go
  10. +2
    -1
      vm_scratch_test.go
  11. +5
    -0
      vm_test.go

+ 25
- 18
LICENSE View File

@@ -1,21 +1,28 @@
MIT License
Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
Copyright (c) 2009 The Go Authors. All rights reserved.

Copyright (c) <year> <copyright holders>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 4
- 0
assembler.go View File

@@ -1,5 +1,9 @@
//go:generate antlr -package parser -Dlanguage=Go -visitor parser/BPF.g4

// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package bpf

import (


+ 13
- 4
cmd/bpfasm/main.go View File

@@ -1,3 +1,7 @@
// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

/*
Package bpfasm implements a basic BPF assembler.

@@ -41,11 +45,16 @@ func main() {
os.Exit(2)
}

raw, err := bpf.Assemble(string(b))
program, err := bpf.Assemble(string(b))
if err != nil {
fmt.Fprintln(os.Stderr, "error assembling", flag.Arg(0)+":", err)
os.Exit(2)
}
raw, err := program.Assemble()
if err != nil {
fmt.Fprintln(os.Stderr, "error assembling instructions", flag.Arg(0)+":", err)
os.Exit(2)
}

if !*outASM && !*outCode && *outFile == "" {
*outFile = flag.Arg(0) + ".bin"
@@ -68,8 +77,8 @@ func main() {
fmt.Fprintf(output, "{ %#02x, %2d, %2d, %#08x },\n", instruction.Op, instruction.Jt, instruction.Jf, instruction.K)
}
} else if *outASM {
for _, instruction := range raw {
fmt.Fprintln(output, instruction.Disassemble())
for _, instruction := range program {
fmt.Fprintln(output, instruction)
}
} else {
for _, instruction := range raw {
@@ -77,6 +86,6 @@ func main() {
}
}

//assembled := unsafe.Pointer(&raw[0])
//assembled := unsafe.Pointer(&program[0])

}

+ 4
- 0
parse.go View File

@@ -1,3 +1,7 @@
// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package bpf

import (


+ 5
- 0
vm.go View File

@@ -1,3 +1,8 @@
// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Copyright (c) 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package bpf

import (


+ 5
- 0
vm_alu_test.go View File

@@ -1,3 +1,8 @@
// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Copyright 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package bpf_test

import (


+ 4
- 0
vm_debug.go View File

@@ -1,3 +1,7 @@
// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package bpf

import (


+ 50
- 0
vm_extension_test.go View File

@@ -0,0 +1,50 @@
// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Copyright (c) 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package bpf_test

import (
"testing"

"golang.org/x/net/bpf"
)

func TestVMLoadExtensionNotImplemented(t *testing.T) {
_, _, err := testVM(t, []bpf.Instruction{
bpf.LoadExtension{
Num: 100,
},
bpf.RetA{},
})
if errStr(err) != "extension 100 not implemented" {
t.Fatalf("unexpected error: %v", err)
}
}

func TestVMLoadExtensionExtLen(t *testing.T) {
vm, done, err := testVM(t, []bpf.Instruction{
bpf.LoadExtension{
Num: bpf.ExtLen,
},
bpf.RetA{},
})
if err != nil {
t.Fatalf("failed to load BPF program: %v", err)
}
defer done()

out, err := vm.Run([]byte{
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0, 1, 2, 3,
})
if err != nil {
t.Fatalf("unexpected error while running program: %v", err)
}
if want, got := 4, out; want != got {
t.Fatalf("unexpected number of output bytes:\n- want: %d\n- got: %d",
want, got)
}
}

+ 2
- 1
vm_jump_test.go View File

@@ -1,4 +1,5 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Copyright (c) 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.



+ 2
- 1
vm_scratch_test.go View File

@@ -1,4 +1,5 @@
// Copyright 2016 The Go Authors. All rights reserved.
// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Copyright (c) 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.



+ 5
- 0
vm_test.go View File

@@ -1,3 +1,8 @@
// Copyright (c) 2019 Wijnand Modderman-Lenstra. All rights reserved.
// Copyright (c) 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package bpf_test

import (


Loading…
Cancel
Save