# rt_sigqueueinfo ____________________________________________
#
# long sys_rt_sigqueueinfo(int pid, int sig, siginfo_t __user *uinfo)
#

@define _SYSCALL_RT_SIGQUEUEINFO_NAME
%(
	name = "rt_sigqueueinfo"
%)

@define _SYSCALL_RT_SIGQUEUEINFO_ARGSTR
%(
	argstr = sprintf("%d, %s, %s", pid, sig_name, siginfo_str)
%)

@define _SYSCALL_RT_SIGQUEUEINFO_REGARGS
%(
	pid = int_arg(1)
	sig = int_arg(2)
	sig_name = _signal_name(sig)
	uinfo_uaddr = pointer_arg(3)
	siginfo_str = (@__compat_task ? _stp_compat_siginfo_u(uinfo_uaddr)
	               : _stp_siginfo_u(uinfo_uaddr))
%)

@define _SYSCALL_RT_SIGQUEUEINFO_REGARGS_STORE
%(
        if (@probewrite(pid))
          set_int_arg(1, pid)

	if (@probewrite(sig))
	  set_int_arg(2, sig)

	if (@probewrite(uinfo_uaddr))
	  set_pointer_arg(3, uinfo_uaddr)
%)


probe syscall.rt_sigqueueinfo = dw_syscall.rt_sigqueueinfo !,
                                nd_syscall.rt_sigqueueinfo ? {}
probe syscall.rt_sigqueueinfo.return = dw_syscall.rt_sigqueueinfo.return !,
                                       nd_syscall.rt_sigqueueinfo.return ? {}

# dw_rt_sigqueueinfo _____________________________________________________

probe dw_syscall.rt_sigqueueinfo =
	__syscall.rt_sigqueueinfo ?,
	kernel.function("sys32_rt_sigqueueinfo").call ?,
	kernel.function("compat_sys_rt_sigqueueinfo").call ?
{
	@_SYSCALL_RT_SIGQUEUEINFO_NAME
	pid = __int32($pid)
	sig = __int32($sig)
	sig_name = _signal_name(sig)
	uinfo_uaddr = $uinfo
	siginfo_str = (@__compat_task ? _stp_compat_siginfo_u($uinfo)
	               : _stp_siginfo_u($uinfo))
	@_SYSCALL_RT_SIGQUEUEINFO_ARGSTR
}
probe __syscall.rt_sigqueueinfo = kernel.function("sys_rt_sigqueueinfo").call
{
	@__syscall_gate(@const("__NR_rt_sigqueueinfo"))
}
probe dw_syscall.rt_sigqueueinfo.return =
	__syscall.rt_sigqueueinfo.return ?,
	kernel.function("sys32_rt_sigqueueinfo").return ?,
	kernel.function("compat_sys_rt_sigqueueinfo").return ?
{
	@_SYSCALL_RT_SIGQUEUEINFO_NAME
	@SYSC_RETVALSTR($return)
}
probe __syscall.rt_sigqueueinfo.return =
	kernel.function("sys_rt_sigqueueinfo").return
{
	@__syscall_gate(@const("__NR_rt_sigqueueinfo"))
}

# nd_rt_sigqueueinfo _____________________________________________________

probe nd_syscall.rt_sigqueueinfo = nd1_syscall.rt_sigqueueinfo!, nd2_syscall.rt_sigqueueinfo!, tp_syscall.rt_sigqueueinfo
  { }

probe nd1_syscall.rt_sigqueueinfo =
	__nd1_syscall.rt_sigqueueinfo ?,
	kprobe.function("sys32_rt_sigqueueinfo") ?,
	kprobe.function("compat_sys_rt_sigqueueinfo") ?
{
	@_SYSCALL_RT_SIGQUEUEINFO_NAME
	asmlinkage()
	@_SYSCALL_RT_SIGQUEUEINFO_REGARGS
	@_SYSCALL_RT_SIGQUEUEINFO_ARGSTR
}
probe __nd1_syscall.rt_sigqueueinfo = kprobe.function("sys_rt_sigqueueinfo")
{
	@__syscall_gate(@const("__NR_rt_sigqueueinfo"))
}

/* kernel 4.17+ */
probe nd2_syscall.rt_sigqueueinfo =
	kprobe.function(@arch_syscall_prefix "sys_rt_sigqueueinfo") ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_rt_sigqueueinfo") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_RT_SIGQUEUEINFO_NAME
	@_SYSCALL_RT_SIGQUEUEINFO_REGARGS
	@_SYSCALL_RT_SIGQUEUEINFO_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_RT_SIGQUEUEINFO_REGARGS_STORE %)
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.rt_sigqueueinfo = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_rt_sigqueueinfo"), @const("__NR_compat_rt_sigqueueinfo"))
	@_SYSCALL_RT_SIGQUEUEINFO_NAME
	@_SYSCALL_RT_SIGQUEUEINFO_REGARGS
	@_SYSCALL_RT_SIGQUEUEINFO_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_RT_SIGQUEUEINFO_REGARGS_STORE %)
}

probe nd_syscall.rt_sigqueueinfo.return = nd1_syscall.rt_sigqueueinfo.return!, nd2_syscall.rt_sigqueueinfo.return!, tp_syscall.rt_sigqueueinfo.return
  { }
  
probe nd1_syscall.rt_sigqueueinfo.return =
	__nd1_syscall.rt_sigqueueinfo.return ?,
	kprobe.function("sys32_rt_sigqueueinfo").return ?,
	kprobe.function("compat_sys_rt_sigqueueinfo").return ?
{
	@_SYSCALL_RT_SIGQUEUEINFO_NAME
	@SYSC_RETVALSTR(returnval())
}
probe __nd1_syscall.rt_sigqueueinfo.return =
	kprobe.function("sys_rt_sigqueueinfo").return
{
	@__syscall_gate(@const("__NR_rt_sigqueueinfo"))
}

/* kernel 4.17+ */
probe nd2_syscall.rt_sigqueueinfo.return =
	kprobe.function(@arch_syscall_prefix "sys_rt_sigqueueinfo").return ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_rt_sigqueueinfo").return ?
{
	@_SYSCALL_RT_SIGQUEUEINFO_NAME
	@SYSC_RETVALSTR(returnval())
}
 
/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.rt_sigqueueinfo.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_rt_sigqueueinfo"), @const("__NR_compat_rt_sigqueueinfo"))
	@_SYSCALL_RT_SIGQUEUEINFO_NAME
	@SYSC_RETVALSTR($ret)
}
