Skip to content

Commit

Permalink
Add support for F_GETFD in order to support go1.22+
Browse files Browse the repository at this point in the history
  • Loading branch information
mininny committed Oct 6, 2024
1 parent 25feabf commit 09810ae
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
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
9 changes: 9 additions & 0 deletions rvgo/test/syscall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,15 @@ 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 {
// Set arbitrary commands if cmd is F_GETFL
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

0 comments on commit 09810ae

Please sign in to comment.