-
-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathmain.go
More file actions
39 lines (31 loc) · 750 Bytes
/
main.go
File metadata and controls
39 lines (31 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"bytes"
_ "embed"
"fmt"
helper "github.com/eunomia-bpf/wasm-bpf/wasm-sdk/go_sdk"
"time"
"unsafe"
)
type CString struct {
s []byte
}
func (c CString) new(s string) *CString {
c.s = bytes.Join([][]byte{[]byte(s), {0}}, nil)
return &c
}
func (c *CString) toWasmPtr() int32 {
return int32(uintptr(unsafe.Pointer(&(c.s[0]))))
}
//go:embed lsm.bpf.o
var obj []byte
func main() {
var bpfObj int32 = int32(uintptr(unsafe.Pointer(&obj[0])))
objPtr := helper.WasmLoadBpfObject(bpfObj, int32(len(obj)))
fmt.Println("objptr=", objPtr)
attachResult := helper.WasmAttachBpfProgram(objPtr, CString{}.new("path_rmdir").toWasmPtr(), 0)
fmt.Println("attachResult=", attachResult)
for {
time.Sleep(10 * time.Second)
}
}