<p></p>
<p dir="auto">Well, the syscall cancellation itself seems to be working, it's the return value handling that is not implemented properly in the kernel:</p>
<pre><code>[gcc401 src]$ cat close2.c
#include <unistd.h>
int main() {
        dup2(0, 42);
        close(42);
        close(42);
        return 0;
}
[gcc401 src]$ ./strace -qq -eclose ./close2
close(3)                                = 0
close(42)                               = 0
close(42)                               = -1 EBADF (Bad file descriptor)
[gcc401 src]$ ./strace -qq -eclose -einject=close:error=enosys:when=2 ./close2
close(3)                                = 0
close(42./strace: Failed to tamper with process 2758428: unexpectedly got no error (return value 0x2a, error 0)
)                               = 42 (INJECTED)
close(42)                               = 0
[gcc401 src]$ ./strace -qq -eclose -einject=close:retval=9:when=2 ./close2
close(3)                                = 0
close(42./strace: Failed to tamper with process 2758433: unexpectedly got no error (return value 0x2a, error 0)
)                               = 42 (INJECTED)
close(42)                               = 0
[gcc401 src]$ ./strace -qq -esignal=none -eptrace ./strace -qq -eclose -einject=close:error=enosys:when=2 -o/dev/null ./close2
...
ptrace(PTRACE_GET_SYSCALL_INFO, 2758442, 88, {op=PTRACE_SYSCALL_INFO_ENTRY, arch=AUDIT_ARCH_LOONGARCH64, instruction_pointer=0x7ffff2fab930, stack_pointer=0x7ffffbb55fb0, entry={nr=__NR_close, args=[0x2a, 0x2a, 0, 0x7ffff303c538, 0, 0x7ffff305af90]}}) = 80
ptrace(PTRACE_GETREGSET, 2758442, NT_PRSTATUS, {iov_base={regs=[0, 0x12000054c, 0x7ffff307af90, 0x7ffffbb55fb0, 0x2a, 0x2a, 0, 0x7ffff303c538, 0, 0x7ffff305af90, 0x7ffffbb56140, 0x39, 0x7ffff3079200, 0x8, 0x1200084f0, 0x7ffff3061090, 0x1, 0x101010101010101, 0x7f7f7f7f7f7f7f7f, 0x10, 0x2, 0x7ac0000, 0, 0x7ffffbb56148, 0x1, 0, 0x120000530, 0x7ffff3077228, 0, 0x7ffffbb56158, 0x120007e38, 0], csr_era=0x7ffff2fab930, csr_badv=0x7ffff2fab9f0, reserved=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, iov_len=360}) = 0
ptrace(PTRACE_SETREGSET, 2758442, NT_PRSTATUS, {iov_base={regs=[0, 0x12000054c, 0x7ffff307af90, 0x7ffffbb55fb0, 0x2a, 0x2a, 0, 0x7ffff303c538, 0, 0x7ffff305af90, 0x7ffffbb56140, 0xffffffffffffffff, 0x7ffff3079200, 0x8, 0x1200084f0, 0x7ffff3061090, 0x1, 0x101010101010101, 0x7f7f7f7f7f7f7f7f, 0x10, 0x2, 0x7ac0000, 0, 0x7ffffbb56148, 0x1, 0, 0x120000530, 0x7ffff3077228, 0, 0x7ffffbb56158, 0x120007e38, 0], csr_era=0x7ffff2fab930, csr_badv=0x7ffff2fab9f0, reserved=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}, iov_len=360}) = 0
ptrace(PTRACE_SYSCALL, 2758442, NULL, 0) = 0
ptrace(PTRACE_GET_SYSCALL_INFO, 2758442, 88, {op=PTRACE_SYSCALL_INFO_EXIT, arch=AUDIT_ARCH_LOONGARCH64, instruction_pointer=0x7ffff2fab934, stack_pointer=0x7ffffbb55fb0, exit={rval=42, is_error=0}}) = 33
./strace: Failed to tamper with process 2758442: unexpectedly got no error (return value 0x2a, error 0)
...
</code></pre>
<p dir="auto">You can see from this example that in case of syscall cancellation the first syscall argument is returned unconditionally as the return value.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/strace/strace/pull/205#issuecomment-1007615226">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AOVBTR66UQL44MW3SNZ6W7TUU4TAVANCNFSM5KYUVD5Q">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub">Android</a>.
<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AOVBTR33ILSSKBXBQI73PBLUU4TAVA5CNFSM5KYUVD52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOHQHPZ6Q.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><strace/strace/pull/205/c1007615226</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/strace/strace/pull/205#issuecomment-1007615226",
"url": "https://github.com/strace/strace/pull/205#issuecomment-1007615226",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>