Skip to content
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

Fix for running op-program #16

Merged
merged 6 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions docs/golang.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ SYS_sched_getaffinity 123
# program advises kernel how to use memory, can be no-op
SYS_madvise 233

# NOOP - To not support, but needed to run op-program
# May need more investigation
# -----------------------
# file memory mapping
SYS_munmap 215

# interprocess communication
SYS_pipe2 59

SYS_epoll_create1 20
SYS_epoll_ctl 21
SYS_readlinkat 78
SYS_newfstatat 79
SYS_newuname 160
SYS_getrandom 278

# To not support
# -----------------------
Expand All @@ -153,12 +168,6 @@ SYS_close 57
SYS_openat 56
SYS_faccessat 48

# file memory mapping
SYS_munmap 215

# interprocess communication
SYS_pipe2 59

# send a signal to another process
SYS_kill 129

Expand Down
10 changes: 10 additions & 0 deletions rvgo/fast/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ func PatchVM(f *elf.File, vmState *VMState) error {
"runtime.main.func1", // patch out: main.func() { newm(sysmon, ....) }
"runtime.deductSweepCredit", // uses floating point nums and interacts with gc we disabled
"runtime.(*gcControllerState).commit",
// these prometheus packages rely on concurrent background things. We cannot run those.
"github.com/prometheus/client_golang/prometheus.init",
"github.com/prometheus/client_golang/prometheus.init.0",
"github.com/prometheus/procfs.init",
"github.com/prometheus/common/model.init",
"github.com/prometheus/client_model/go.init",
"github.com/prometheus/client_model/go.init.0",
"github.com/prometheus/client_model/go.init.1",
// skip flag pkg init, we need to debug arg-processing more to see why this fails
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious to know what the failure is. Does the program crash during pkg init?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, these lines are copied from Cannon 😅
So I have no idea about the details..

"flag.init",
// We need to patch this out, we don't pass float64nan because we don't support floats
"runtime.check":
// RISCV patch: ret (pseudo instruction)
Expand Down
24 changes: 24 additions & 0 deletions rvgo/fast/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,30 @@ func (inst *InstrumentedState) riscvStep() (outErr error) {
case 233: // madvise - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 20: // epoll_create1 - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 21: // epoll_ctl - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 59: // pipe2 - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 78: // readlinkat - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 79: // newfstatat - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 160: // newuname - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 215: // munmap - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 278: // getrandom - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 261: // prlimit64 -- unsupported, we have getrlimit, is prlimit64 even called?
revertWithCode(0xf001ca11, fmt.Errorf("unsupported system call: %d", a7))
case 422: // futex - not supported, for now
Expand Down
24 changes: 24 additions & 0 deletions rvgo/slow/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,30 @@ func Step(calldata []byte, po PreimageOracle) (stateHash common.Hash, outErr err
case 233: // madvise - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 20: // epoll_create1 - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 21: // epoll_ctl - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 59: // pipe2 - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 78: // readlinkat - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 79: // newfstatat - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 160: // newuname - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 215: // munmap - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 278: // getrandom - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
case 261: // prlimit64 -- unsupported, we have getrlimit, is prlimit64 even called?
revertWithCode(0xf001ca11, fmt.Errorf("unsupported system call: %d", a7))
case 422: // futex - not supported, for now
Expand Down
24 changes: 24 additions & 0 deletions rvsol/src/RISCV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,30 @@ contract RISCV {
} case 233 { // madvise - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
} case 20 { // epoll_create1 - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
} case 21 { // epoll_ctl - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
} case 59 { // pipe2 - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
} case 78 { // readlinkat - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
} case 79 { // newfstatat - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
} case 160 { // newuname - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
} case 215 { // munmap - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
} case 278 { // getrandom - ignored
setRegister(toU64(10), toU64(0))
setRegister(toU64(11), toU64(0))
} case 261 { // prlimit64 -- unsupported, we have getrlimit, is prlimit64 even called?
revertWithCode(0xf001ca11) // unsupported system call
} case 422 { // futex - not supported, for now
Expand Down
4 changes: 2 additions & 2 deletions tests/go-tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ bin:
mkdir bin

bin/simple:
cd simple && GOOS=linux GOARCH=riscv64 GOROOT=$(LATEST_GOROOT) go build -o ../bin/simple .
cd simple && GOOS=linux GOARCH=riscv64 GOROOT=$(LATEST_GOROOT) go build -gcflags="all=-d=softfloat" -o ../bin/simple .

bin/simple.dump: bin/simple
riscv64-linux-gnu-objdump -D --disassemble --disassembler-options=no-aliases --wide --source -m riscv:rv64 -EL bin/simple > bin/simple.dump

bin/minimal:
cd minimal && GOOS=linux GOARCH=riscv64 GOROOT=$(LATEST_GOROOT) go build -o ../bin/minimal .
cd minimal && GOOS=linux GOARCH=riscv64 GOROOT=$(LATEST_GOROOT) go build -gcflags="all=-d=softfloat" -o ../bin/minimal .

bin/minimal.dump: bin/minimal
riscv64-linux-gnu-objdump -D --disassemble --disassembler-options=no-aliases --wide --source -m riscv:rv64 -EL bin/minimal > bin/minimal.dump
Expand Down
Loading