# waitpid ____________________________________________________
#
# (waitpid is usually implemented via wait4 but not always)
# SYSCALL_DEFINE3(waitpid, pid_t, pid, int __user *, stat_addr, int, options)
#

@define _SYSCALL_WAITPID_NAME
%(
	name = "waitpid"
%)

@define _SYSCALL_WAITPID_ARGSTR
%(
	argstr = sprintf("%d, %p, %s", pid, status_uaddr, options_str)
%)

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

# dw_waitpid _____________________________________________________

probe dw_syscall.waitpid = kernel.function("sys_waitpid").call ?,
	kernel.function("sys32_waitpid").call ?
{
	@_SYSCALL_WAITPID_NAME
	pid = __int32($pid)
	status_uaddr = $stat_addr
	options = __int32($options)
	options_str = _wait4_opt_str(options)
	@_SYSCALL_WAITPID_ARGSTR
}
probe dw_syscall.waitpid.return = kernel.function("sys_waitpid").return ?,
	kernel.function("sys32_waitpid").return ?
{
	@_SYSCALL_WAITPID_NAME
	retstr = return_str(1, $return)
}

# nd_waitpid _____________________________________________________

probe nd_syscall.waitpid = kprobe.function("sys_waitpid") ?,
	kprobe.function("sys32_waitpid").call ?
{
	@_SYSCALL_WAITPID_NAME
	asmlinkage()
	pid = int_arg(1)
	status_uaddr = pointer_arg(2)
	options = int_arg(3)
	options_str = _wait4_opt_str(options)
	@_SYSCALL_WAITPID_ARGSTR
}
probe nd_syscall.waitpid.return = kprobe.function("sys_waitpid").return ?,
	kprobe.function("sys32_waitpid").return ?
{
	@_SYSCALL_WAITPID_NAME
	retstr = returnstr(1)
}
