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

Add support for F_GETFD in order to support go1.22+ #84

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
20 changes: 20 additions & 0 deletions rvgo/fast/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,26 @@ func (inst *InstrumentedState) riscvStep() (outErr error) {
var out U64
var errCode U64
switch cmd {
case 0x1: // F_GETFD: get file descriptor flags
switch fd {
case 0: // stdin
out = toU64(0) // no flag set
case 1: // stdout
out = toU64(0) // no flag set
case 2: // stderr
out = toU64(0) // no flag set
case 3: // hint-read
out = toU64(0) // no flag set
case 4: // hint-write
out = toU64(0) // no flag set
case 5: // pre-image read
out = toU64(0) // no flag set
case 6: // pre-image write
out = toU64(0) // no flag set
default:
out = u64Mask()
errCode = toU64(0x4d) //EBADF
}
case 0x3: // F_GETFL: get file descriptor flags
switch fd {
case 0: // stdin
Expand Down
20 changes: 20 additions & 0 deletions rvgo/slow/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,26 @@ func Step(calldata []byte, po PreimageOracle) (stateHash common.Hash, outErr err
var out U64
var errCode U64
switch cmd.val() {
case 0x1: // F_GETFD: get file descriptor flags
switch fd.val() {
case 0: // stdin
out = toU64(0) // no flag set
case 1: // stdout
out = toU64(0) // no flag set
case 2: // stderr
out = toU64(0) // no flag set
case 3: // hint-read
out = toU64(0) // no flag set
case 4: // hint-write
out = toU64(0) // no flag set
case 5: // pre-image read
out = toU64(0) // no flag set
case 6: // pre-image write
out = toU64(0) // no flag set
default:
out = u64Mask()
errCode = toU64(0x4d) //EBADF
}
case 0x3: // F_GETFL: get file descriptor flags
switch fd.val() {
case 0: // stdin
Expand Down
11 changes: 10 additions & 1 deletion rvgo/test/syscall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,17 @@ func FuzzStateSyscallFcntl(f *testing.F) {
// Add 7 to fd to ensure fd > 6
testFcntl(t, fd+7, 3, pc, step, 0xFFFF_FFFF_FFFF_FFFF, 0x4d)

// Test F_GETFD
for _, fd := range []uint64{0, 1, 2, 3, 4, 5, 6} {
testFcntl(t, fd, 1, pc, step, 0, 0)
}

// Test F_GETFD for unsupported fds
// Add 7 to fd to ensure fd > 6
testFcntl(t, fd+7, 1, pc, step, 0xFFFF_FFFF_FFFF_FFFF, 0x4d)

// Test other commands
if cmd == 3 {
if cmd == 3 || cmd == 1 {
// Set arbitrary commands if cmd is F_GETFL
cmd = 4
}
Expand Down
36 changes: 36 additions & 0 deletions rvsol/src/RISCV.sol
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,42 @@ contract RISCV {
let out := 0
let errCode := 0
switch cmd
case 0x1 {
// F_GETFD: get file descriptor flags
switch fd
case 0 {
// stdin
out := toU64(0) // no flag set
}
case 1 {
// stdout
out := toU64(0) // no flag set
}
case 2 {
// stderr
out := toU64(0) // no flag set
}
case 3 {
// hint-read
out := toU64(0) // no flag set
}
case 4 {
// hint-write
out := toU64(0) // no flag set
}
case 5 {
// pre-image read
out := toU64(0) // no flag set
}
case 6 {
// pre-image write
out := toU64(0) // no flag set
}
default {
out := u64Mask()
errCode := toU64(0x4d) //EBADF
}
}
case 0x3 {
// F_GETFL: get file descriptor flags
switch fd
Expand Down
Loading