diff --git a/btf/btf.go b/btf/btf.go index 671f680b2..20bed62c6 100644 --- a/btf/btf.go +++ b/btf/btf.go @@ -632,8 +632,16 @@ func (s *Spec) TypeByName(name string, typ interface{}) error { wanted = typPtr.Elem().Type() } - if !wanted.AssignableTo(typeInterface) { - return fmt.Errorf("%T does not satisfy Type interface", typ) + switch wanted { + case reflect.TypeOf((**Datasec)(nil)).Elem(): + // Those types are already assignable to Type. No need to call + // AssignableTo. Avoid it when possible to workaround + // limitation in tinygo: + // https://github.com/tinygo-org/tinygo/issues/4277 + default: + if !wanted.AssignableTo(typeInterface) { + return fmt.Errorf("%T does not satisfy Type interface", typ) + } } types, err := s.AnyTypesByName(name) diff --git a/internal/endian_le.go b/internal/endian_le.go index 6dcd916d5..d833ea764 100644 --- a/internal/endian_le.go +++ b/internal/endian_le.go @@ -1,4 +1,4 @@ -//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || ppc64le || riscv64 +//go:build 386 || amd64 || amd64p32 || arm || arm64 || loong64 || mipsle || mips64le || mips64p32le || ppc64le || riscv64 || wasm package internal diff --git a/internal/io.go b/internal/io.go index 1eaf4775a..3e5ddd30a 100644 --- a/internal/io.go +++ b/internal/io.go @@ -28,7 +28,7 @@ func NewBufferedSectionReader(ra io.ReaderAt, off, n int64) *bufio.Reader { // of 4096. Allow arches with larger pages to allocate more, but don't // allocate a fixed 4k buffer if we only need to read a small segment. buf := n - if ps := int64(os.Getpagesize()); n > ps { + if ps := int64(Getpagesize()); n > ps { buf = ps } diff --git a/internal/page_others.go b/internal/page_others.go new file mode 100644 index 000000000..64bd38e75 --- /dev/null +++ b/internal/page_others.go @@ -0,0 +1,9 @@ +//go:build !wasm + +package internal + +import "os" + +func Getpagesize() int { + return os.Getpagesize() +} diff --git a/internal/page_wasm.go b/internal/page_wasm.go new file mode 100644 index 000000000..3c3da9c0e --- /dev/null +++ b/internal/page_wasm.go @@ -0,0 +1,8 @@ +//go:build wasm + +package internal + +func Getpagesize() int { + // A WebAssembly page has a constant size of 65,536 bytes, i.e., 64KiB + return 64 * 1024 +} diff --git a/map.go b/map.go index d0ea05d4a..3adb624b3 100644 --- a/map.go +++ b/map.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "math/rand" - "os" "path/filepath" "reflect" "slices" @@ -507,7 +506,7 @@ func handleMapCreateError(attr sys.MapCreateAttr, spec *MapSpec, err error) erro // BPF_MAP_TYPE_RINGBUF's max_entries must be a power-of-2 multiple of kernel's page size. if errors.Is(err, unix.EINVAL) && (attr.MapType == sys.BPF_MAP_TYPE_RINGBUF || attr.MapType == sys.BPF_MAP_TYPE_USER_RINGBUF) { - pageSize := uint32(os.Getpagesize()) + pageSize := uint32(internal.Getpagesize()) maxEntries := attr.MaxEntries if maxEntries%pageSize != 0 || !internal.IsPow(maxEntries) { return fmt.Errorf("map create: %w (ring map size %d not a multiple of page size %d)", err, maxEntries, pageSize) @@ -950,7 +949,7 @@ func (m *Map) nextKey(key interface{}, nextKeyOut sys.Pointer) error { } var mmapProtectedPage = sync.OnceValues(func() ([]byte, error) { - return unix.Mmap(-1, 0, os.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_SHARED) + return unix.Mmap(-1, 0, internal.Getpagesize(), unix.PROT_NONE, unix.MAP_ANON|unix.MAP_SHARED) }) // guessNonExistentKey attempts to perform a map lookup that returns ENOENT. diff --git a/syscalls.go b/syscalls.go index 0766e7dd6..62a61cae1 100644 --- a/syscalls.go +++ b/syscalls.go @@ -27,7 +27,14 @@ var ( // invalidBPFObjNameChar returns true if char may not appear in // a BPF object name. func invalidBPFObjNameChar(char rune) bool { - dotAllowed := objNameAllowsDot() == nil + var dotAllowed bool + if runtime.GOOS == "js" { + // In Javascript environments, BPF objects are not going to be + // loaded to a kernel, so we can use dots without testing. + dotAllowed = true + } else { + dotAllowed = objNameAllowsDot() == nil + } switch { case char >= 'A' && char <= 'Z':