-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] New architecture: wasm #1552
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build !wasm | ||
|
||
package internal | ||
|
||
import "os" | ||
|
||
func Getpagesize() int { | ||
return os.Getpagesize() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why isn't this logic in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did some reading on this last week, apparently ENOSYS is returned by much of the tinygo syscall package for wasm. This would be a good sentinel to conclude that a syscall can't be made and we need to fall back to a sane default. We can make things on the Windows side behave similarly, so high-level logic only needs to check for ENOSYS. cc @lmb |
||
} else { | ||
dotAllowed = objNameAllowsDot() == nil | ||
} | ||
|
||
switch { | ||
case char >= 'A' && char <= 'Z': | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know much about tinygo, but some Googling reveals that it implements a subset of the Go "os" package, and it looks like it implements os.Getpagesize() as well for the arches it targets. Why is it hardcoded here? This is the crux of the PR but isn't mentioned anywhere.
In any case, I'd like this to go into the respective stdlib, either in Google's implementation or tinygo if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the following error if I try to use os.Getpagesize:
According to https://pkg.go.dev/github.com/tinygo-org/tinygo/src/os#Getpagesize, it was added in tinygo 0.24.0 and I use 0.30.0, but it still does not work.
Issue: tinygo-org/tinygo#1285
I agree it should ideally be fixed in tinygo or Go... I could try to make a PR there. But I would like to have a workaround in cilium/ebpf meanwhile. Btw,
syscall.Getpagesize()
works, presumably thanks to tinygo-org/tinygo#2856; could that be an option to use that in cilium/ebpf as a workaround?In tinygo-org/tinygo#1285, they suggest to return -1... That would not work for cilium/ebpf when used in
unix.Mmap
but we wouldn't call those methods from wasm context. And forinternal.NewBufferedSectionReader(n=-1)
, it seems the implementation would use a buffer of 16 bytes when given a negative number, so that would work (but might be slow).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we merge a workaround, there's no guarantee you will get around to making that upstream contribution. 😉 I really don't want to hardcode non-bpf-related platform constants, that's definitely the runtime/stdlib's responsibility.
Underlyingly,
os.Getpagesize()
simply callssyscall.Getpagesize()
(https://cs.opensource.google/go/go/+/refs/tags/go1.23.0:src/os/types.go;l=13), so sounds like a trivial fix in tinygo? Might be a good exercise to understand the underlying tech a bit better.I prefer to make only the absolute minimum changes to the lib to force us to address issues in the underlying layers. This is good for the health of the platform and potentially enables more software to run correctly out-of-the-box.