-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67479d4
commit 13f28cd
Showing
8 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module go_wasm | ||
|
||
go 1.18 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// export | ||
package helper | ||
|
||
//export wasm_load_bpf_object | ||
func WasmLoadBpfObject(int32, int32) int64 | ||
|
||
//export wasm_attach_bpf_program | ||
func WasmAttachBpfProgram(int64, int32, int32) int32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"go_wasm/helper" | ||
"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))) | ||
helper.WasmAttachBpfProgram(objPtr, CString{}.new("path_rmdir").toWasmPtr(), 0) | ||
for { | ||
time.Sleep(10 * time.Second) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters