Signal implement SYS_rt_sigtimedwait syscall 137#201
Open
doanbaotrung wants to merge 1 commit into
Open
Conversation
5b89e41 to
0e0f9a3
Compare
There was a problem hiding this comment.
1 issue found and verified against the latest diff
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/syscall/signal.c">
<violation number="1" location="src/syscall/signal.c:1419">
P2: The saturation check uses `>` instead of `>=`, so a guest-supplied timespec with tv_sec == INT64_MAX/1000000000 and a large tv_nsec can make `tv_sec * 1000000000LL + tv_nsec` exceed INT64_MAX, causing signed overflow (UB) rather than saturating to INT64_MAX.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| if (lts.tv_sec > (INT64_MAX / 1000000000LL)) | ||
| remaining_ns = INT64_MAX; | ||
| else | ||
| remaining_ns = lts.tv_sec * 1000000000LL + lts.tv_nsec; |
There was a problem hiding this comment.
P2: The saturation check uses > instead of >=, so a guest-supplied timespec with tv_sec == INT64_MAX/1000000000 and a large tv_nsec can make tv_sec * 1000000000LL + tv_nsec exceed INT64_MAX, causing signed overflow (UB) rather than saturating to INT64_MAX.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/syscall/signal.c, line 1419:
<comment>The saturation check uses `>` instead of `>=`, so a guest-supplied timespec with tv_sec == INT64_MAX/1000000000 and a large tv_nsec can make `tv_sec * 1000000000LL + tv_nsec` exceed INT64_MAX, causing signed overflow (UB) rather than saturating to INT64_MAX.</comment>
<file context>
@@ -1332,7 +1332,162 @@ int64_t signal_rt_sigpending(guest_t *g, uint64_t set_gva, uint64_t sigsetsize)
+ if (lts.tv_sec > (INT64_MAX / 1000000000LL))
+ remaining_ns = INT64_MAX;
+ else
+ remaining_ns = lts.tv_sec * 1000000000LL + lts.tv_nsec;
+ }
+
</file context>
72bafea to
6b3cf43
Compare
Add rt_sigtimedwait so that sigwait(3), sigwaitinfo(3), and
sigtimedwait(3) work inside the guest. All three are thin wrappers
over this syscall in musl and glibc; returning -ENOSYS breaks any
application that uses a dedicated signal-management thread.
abi.h:
Define SYS_rt_sigtimedwait = 137, which sits between
rt_sigpending (136) and rt_sigqueueinfo (138) in the aarch64
Linux syscall table.
signal.c:
sigtimedwait_try_dequeue() - acquires sig_lock and dequeues one
signal matching the caller's mask. Thread-directed (private)
set is drained before the shared set, mirroring Linux
dequeue_signal() priority. Reuses signal_rt_dequeue_locked()
and signal_standard_peek_locked() from signal_deliver().
signal_rt_sigtimedwait() - reads and validates the guest mask
and optional timeout, then polls in 1 ms sleep chunks (same
pattern as interruptible_sleep_ns in time.c) until:
- a matching signal is consumed -> return signum
- timeout expires -> return -EAGAIN
- exit_group requested -> return -EINTR
- unblocked non-waited signal -> return -EINTR
SIGKILL/SIGSTOP are silently removed from the wait mask,
matching Linux do_sigtimedwait behavior.
NULL timeout_gva blocks indefinitely; {0,0} polls once.
info_gva = 0 skips the siginfo_t write (sigwait(3) path).
signal.h: declare signal_rt_sigtimedwait.
dispatch.tbl: register sc_rt_sigtimedwait with guest-ptr flag.
syscall.c: SC_FORWARD x0..x3 -> set, info, timeout, sigsetsize.
Fix sysprog21#196
6b3cf43 to
0e6c431
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add rt_sigtimedwait so that sigwait(3), sigwaitinfo(3), and sigtimedwait(3) work inside the guest. All three are thin wrappers over this syscall in musl and glibc; returning -ENOSYS breaks any application that uses a dedicated signal-management thread.
abi.h:
Define SYS_rt_sigtimedwait = 137, which sits between
rt_sigpending (136) and rt_sigqueueinfo (138) in the aarch64
Linux syscall table.
signal.c:
sigtimedwait_try_dequeue() - acquires sig_lock and dequeues one
signal matching the caller's mask. Thread-directed (private)
set is drained before the shared set, mirroring Linux
dequeue_signal() priority. Reuses signal_rt_dequeue_locked()
and signal_standard_peek_locked() from signal_deliver().
signal_rt_sigtimedwait() - reads and validates the guest mask
and optional timeout, then polls in 1 ms sleep chunks (same
pattern as interruptible_sleep_ns in time.c) until:
- a matching signal is consumed -> return signum
- timeout expires -> return -EAGAIN
- exit_group requested -> return -EINTR
- unblocked non-waited signal -> return -EINTR
SIGKILL/SIGSTOP are silently removed from the wait mask,
matching Linux do_sigtimedwait behavior.
NULL timeout_gva blocks indefinitely; {0,0} polls once.
info_gva = 0 skips the siginfo_t write (sigwait(3) path).
signal.h: declare signal_rt_sigtimedwait.
dispatch.tbl: register sc_rt_sigtimedwait with guest-ptr flag.
syscall.c: SC_FORWARD x0..x3 -> set, info, timeout, sigsetsize.
Fix #196
Summary by cubic
Implements
SYS_rt_sigtimedwait(137) sosigwait(3),sigwaitinfo(3), andsigtimedwait(3)work inside the guest. Adds the aarch64 ABI constant and wires the syscall through dispatch.SYS_rt_sigtimedwait = 137, registerssc_rt_sigtimedwait, and forwards args insyscall.c.siginfo_twrite; timeout supports block forever, poll once{0,0}, or bounded wait in 1 ms chunks.SIGKILL/SIGSTOP. Returns signum on success,-EAGAINon timeout,-EINTRon exit-group or unrelated unblocked signal.tests/test-sigtimedwait.cand a Makefile target (links-lpthread) covering sigwait, sigwaitinfo, poll-once, short timeout, and cross-thread delivery.scripts/check-syscall-coverage.pyto maprt_sigtimedwaittosigwait,sigwaitinfo, andsigtimedwait.Written for commit 0e6c431. Summary will update on new commits.