Bug 485924

Summary: No support for pidfd_send_signal system call
Product: [Developer tools] valgrind Reporter: k04jg02
Component: memcheckAssignee: Julian Seward <jseward>
Status: CONFIRMED ---    
Severity: normal CC: mark, milasudril
Priority: NOR    
Version First Reported In: 3.22.0   
Target Milestone: ---   
Platform: Ubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description k04jg02 2024-04-21 20:42:49 UTC
SUMMARY
If you call pidfd_send_signal and then run valgrind on your executable you get this message on x86-64:

==822833== For lists of detected and suppressed errors, rerun with: -s
==822833== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
--822834-- WARNING: unhandled amd64-linux syscall: 424
--822834-- You may be able to write your own handler.
--822834-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--822834-- Nevertheless we consider this a bug.  Please report
--822834-- it at http://valgrind.org/support/bug_reports.html.
Comment 1 k04jg02 2024-04-21 20:44:06 UTC
Note that my libc was not new enough to have a wrapper for this syscall, if yours isn't as well you will want this to reproduce:

```
#include <sys/syscall.h>

#ifndef SYS_pidfd_send_signal
#define SYS_pidfd_send_signal 424
#endif

int pidfd_send_signal(int pidfd, int sig, siginfo_t* info, unsigned int flags)
{
    return syscall(SYS_pidfd_send_signal, pidfd, sig, info, flags);
}
```
Comment 2 Mark Wielaard 2024-04-23 16:33:48 UTC
There was a preliminary implementation posted to the mailinglist:
https://sourceforge.net/p/valgrind/mailman/message/52515225/
Comment 3 Mark Wielaard 2024-04-23 16:48:35 UTC
So the only tricky part is that we want to mimic this part of the (generic) PRE(sys_kill):

   /* If we're sending SIGKILL, check to see if the target is one of            
      our threads and handle it specially. */                                   
   if (ARG2 == VKI_SIGKILL && ML_(do_sigkill)(ARG1, -1))                        
      SET_STATUS_Success(0);                                                    

In the pidfd_send_signal case ARG2 is the signo, just like the kill syscall.
But ARG1 is a pidfd and do_sigkill wants an pid (tid).
So we have to somehow translate the pidfd to a pid number.

It isn't immediately clear how to do that.
Comment 4 milasudril 2026-01-18 15:57:11 UTC
Any work on this