Skip to content

socket: return EAGAIN for non-blocking recv - #1680

Open
Henglie wants to merge 1 commit into
qilingframework:devfrom
Henglie:fix/recv-nonblocking-eagain
Open

Henglie wants to merge 1 commit into
qilingframework:devfrom
Henglie:fix/recv-nonblocking-eagain

Conversation

@Henglie

@Henglie Henglie commented Nov 14, 2026 •

Copy link
Copy Markdown

Summary

ql_syscall_recv let BlockingIOError escape the syscall handler when a guest called recv on a non-blocking socket with no data pending. The guest emulation was then aborted instead of receiving -EAGAIN, which is what a real kernel returns.

This PR catches that condition in the syscall wrapper and returns -EAGAIN, and adds a regression test.

Fixes #1373.

Test

Added tests/test_socket.py::SocketTest::test_recv_on_nonblocking_socket_returns_eagain:

  • creates a non-blocking socket pair
  • registers one end as guest fd 3
  • calls ql_syscall_recv with no data queued

Before the fix the test fails with the reported BlockingIOError. After the fix it passes with the return value -EAGAIN.

Local run (Windows 11, CPython 3.11.9, Unicorn 2.1.3):

python -m unittest -v test_socket test_shellcode
Ran 9 tests in 4.273s
OK

The test module is also imported from tests/test_posix.py, so it runs as part of the Linux test suite.

Not verified

  • No full guest HTTP daemon or rootfs integration run; the regression test exercises the syscall handler directly.
  • Only recv is covered here. recvfrom/recvmsg were not changed.

Related: open PR #1676 also touches errno handling in socket.py. This change is independent, but a trivial import rebase may be needed if #1676 merges first.

Checklist

Which kind of PR do you create?

  • This PR only contains minor fixes.
  • This PR contains major feature update.
  • This PR introduces a new function/api for Qiling Framework.

Coding convention?

  • The new code conforms to Qiling Framework naming convention.
  • The imports are arranged properly.
  • Essential comments are added. (No comment added: the three-line handler is self-explanatory.)
  • The reference of the new code is pointed out.

Extra tests?

  • No extra tests are needed for this PR.
  • I have added enough tests for this PR.
  • Tests will be added after some discussion and review.

Changelog?

  • This PR doesn't need to update Changelog. (ChangeLog is organized by release.)
  • Changelog will be updated after some proper review.
  • Changelog has been updated in my PR.

Target branch?

  • The target branch is dev branch.

One last thing

A guest recv on a non-blocking socket raised BlockingIOError out of the
syscall handler and aborted emulation. Translate that condition to
-EAGAIN, as a real kernel does, and add a regression test.

Fixes qilingframework#1373
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant