# sendfile ___________________________________________________
#
# ssize_t sys_sendfile[64](int out_fd,
#		  int in_fd,
#		  off_t __user *offset,
#		  size_t count)
# SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd, loff_t __user *, offset,
#		 size_t, count)
# COMPAT_SYSCALL_DEFINE4(sendfile, int, out_fd, int, in_fd,
#		compat_off_t __user *, offset, compat_size_t, count)
# COMPAT_SYSCALL_DEFINE4(sendfile64, int, out_fd, int, in_fd,
#		compat_loff_t __user *, offset, compat_size_t, count)
#

@define _SYSCALL_SENDFILE_NAME
%(
	name = "sendfile"
%)

@define _SYSCALL_SENDFILE_ARGSTR
%(
	argstr = sprintf("%d, %d, %p, %u", out_fd, in_fd, offset_uaddr, count)
%)

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

# dw_sendfile _____________________________________________________

probe dw_syscall.sendfile = __syscall.sendfile ?,
	kernel.function("compat_sys_sendfile").call ?,
	kernel.function("compat_sys_sendfile64").call ?,
	kernel.function("sys32_sendfile").call ?
{
	@_SYSCALL_SENDFILE_NAME
	out_fd = __int32($out_fd)
	in_fd = __int32($in_fd)
	offset_uaddr = $offset
	count = @__compat_ulong($count)
	@_SYSCALL_SENDFILE_ARGSTR
}
probe __syscall.sendfile = kernel.function("sys_sendfile").call ?,
	kernel.function("sys_sendfile64").call ?
{
	@__syscall_gate2(@const("__NR_sendfile"), @const("__NR_sendfile64"))
}
probe dw_syscall.sendfile.return = __syscall.sendfile.return ?,
	kernel.function("compat_sys_sendfile").return ?,
	kernel.function("compat_sys_sendfile64").return ?,
	kernel.function("sys32_sendfile").return ?
{
	@_SYSCALL_SENDFILE_NAME
	retstr = return_str(1, $return)
}
probe __syscall.sendfile.return = kernel.function("sys_sendfile").return ?,
	kernel.function("sys_sendfile64").return ?
{
	@__syscall_gate2(@const("__NR_sendfile"), @const("__NR_sendfile64"))
}

# nd_sendfile _____________________________________________________

probe nd_syscall.sendfile = __nd_syscall.sendfile ?,
	kprobe.function("compat_sys_sendfile").call ?,
	kprobe.function("compat_sys_sendfile64").call ?,
	kprobe.function("sys32_sendfile").call ?
{
	@_SYSCALL_SENDFILE_NAME
	asmlinkage()
	out_fd = int_arg(1)
	in_fd = int_arg(2)
	offset_uaddr = pointer_arg(3)
	count = ulong_arg(4)
	@_SYSCALL_SENDFILE_ARGSTR
}
probe __nd_syscall.sendfile = kprobe.function("sys_sendfile").call ?,
	kprobe.function("sys_sendfile64").call ?
{
	@__syscall_gate2(@const("__NR_sendfile"), @const("__NR_sendfile64"))
}
probe nd_syscall.sendfile.return = __nd_syscall.sendfile.return ?,
	kprobe.function("compat_sys_sendfile").return ?,
	kprobe.function("compat_sys_sendfile64").return ?,
	kprobe.function("sys32_sendfile").return ?
{
	@_SYSCALL_SENDFILE_NAME
	retstr = returnstr(1)
}
probe __nd_syscall.sendfile.return = kprobe.function("sys_sendfile").return ?,
	kprobe.function("sys_sendfile64").return ?
{
	@__syscall_gate2(@const("__NR_sendfile"), @const("__NR_sendfile64"))
}
