Skip to content

Commit

Permalink
update logo
Browse files Browse the repository at this point in the history
  • Loading branch information
Littlefisher619 authored and qq906907952 committed Feb 19, 2023
1 parent 67479d4 commit 13f28cd
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 3 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

# 📦 Wasm-bpf: Wasm library and toolchain for eBPF

![logo](test/asserts/logo.png)

[![Actions Status](https://github.com/eunomia-bpf/wasm-bpf/workflows/Ubuntu/badge.svg)](https://github.com/eunomia-bpf/wasm-bpf/actions)
[![CodeFactor](https://www.codefactor.io/repository/github/eunomia-bpf/wasm-bpf/badge)](https://www.codefactor.io/repository/github/eunomia-bpf/wasm-bpf)
[![DeepSource](https://deepsource.io/gh/eunomia-bpf/wasm-bpf.svg/?label=active+issues&show_trend=true&token=rcSI3J1-gpwLIgZWtKZC-N6C)](https://deepsource.io/gh/eunomia-bpf/wasm-bpf/?ref=repository-badge)
Expand Down
7 changes: 7 additions & 0 deletions examples/lsm/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.PHONY: all

ARCH ?= $(shell uname -m | sed 's/x86_64/x86/' | sed 's/aarch64/arm64/' | sed 's/ppc64le/powerpc/' | sed 's/mips.*/mips/')
TINYGO ?= $(shell which tinygo)
VMLINUX := ../../third_party/vmlinux/$(ARCH)/vmlinux.h
BPF_HEADERS := ../../third_party/
# Use our own libbpf API headers and Linux UAPI headers distributed with
Expand Down Expand Up @@ -34,6 +35,7 @@ all: $(APP).wasm $(APP).bpf.o
.PHONY: clean
clean:
rm -rf *.o *.json *.wasm *.skel.h
cd go_wasm/ && rm -rf *.o *.json *.wasm *.skel.h

# Build BPF code
%.bpf.o: %.bpf.c $(wildcard %.h) $(VMLINUX)
Expand All @@ -60,6 +62,11 @@ WASI_CFLAGS = -O2 --sysroot=/opt/wasi-sdk/share/wasi-sysroot -Wl,--allow-undefin
$(APP).wasm: $(APP).c $(APP).skel.h
$(WASI_CLANG) $(WASI_CFLAGS) -o $@ $<

$(APP)_go_wasm: $(APP).bpf.o
cp ./$(APP).bpf.o go-lsm
cd go-lsm && $(TINYGO) build -target wasi -o $(APP).go.wasm main.go


TEST_TIME := 3
.PHONY: test
test:
Expand Down
5 changes: 5 additions & 0 deletions examples/lsm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ CONFIG_DEBUG_INFO_BTF=y
CONFIG_BPF_LSM=y
CONFIG_LSM="[other LSMs],bpf"
```

go wasm example(need tinygo):
```sh
make lsm_go_wasm # will output to go_wasm/lsm.go.wasm
```
3 changes: 3 additions & 0 deletions examples/lsm/go-lsm/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module go_wasm

go 1.18
8 changes: 8 additions & 0 deletions examples/lsm/go-lsm/helper/helper.go
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
36 changes: 36 additions & 0 deletions examples/lsm/go-lsm/main.go
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)
}

}
1 change: 1 addition & 0 deletions src/wasm-bpf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ static int attach_cgroup(struct bpf_program *prog, const char *path) {
path);
return -1;
}
close(fd);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion third_party/bpftool
Submodule bpftool updated 1 files
+1 −89 src/gen.c

0 comments on commit 13f28cd

Please sign in to comment.