# preadv2 __________________________________________________
#
# SYSCALL_DEFINE6(preadv2, unsigned long, fd, const struct iovec __user *, vec,
#		unsigned long, vlen, unsigned long, pos_l, unsigned long, pos_h,
#		int, flags)
#COMPAT_SYSCALL_DEFINE6(preadv2, compat_ulong_t, fd,
#		const struct compat_iovec __user *,vec,
#		compat_ulong_t, vlen, u32, pos_low, u32, pos_high,
#		int, flags)

@define _SYSCALL_PREADV2_NAME
%(
	name = "preadv2"
%)

@define _SYSCALL_PREADV2_ARGSTR
%(
	argstr = sprintf("%d, %p, %d, 0x%x, %s", fd, vector_uaddr, count,
	                 offset, flags_str)
%)

@define _SYSCALL_PREADV2_REGARGS
%(
	fd = int_arg(1)
	vector_uaddr = pointer_arg(2)
	count = int_arg(3)
	offset = @__pos_from_hilo(ulong_arg(5), ulong_arg(4))
	flags = int_arg(6)
	flags_str = _preadv2_flags_str(flags)
%)

@define _SYSCALL_COMPAT_PREADV2_REGARGS
%(
	fd = int_arg(1)
	vector_uaddr = pointer_arg(2)
	count = int_arg(3)
	offset = (u32_arg(5) << 32) + u32_arg(4)
	flags = int_arg(6)
	flags_str = _preadv2_flags_str(flags)
%)

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

# dw_preadv2 _____________________________________________________

probe dw_syscall.preadv2 = __syscall.preadv2 ?, __syscall.compat_preadv2 ?
{
	@_SYSCALL_PREADV2_NAME
}
probe __syscall.preadv2 = kernel.function("sys_preadv2").call ?
{
	fd = __int32($fd)
	vector_uaddr = $vec
	count = __int32($vlen)
	offset = @__pos_from_hilo($pos_h, $pos_l)
	flags = $flags
	flags_str = _preadv2_flags_str(flags)
	@_SYSCALL_PREADV2_ARGSTR
}
probe __syscall.compat_preadv2 = kernel.function("compat_sys_preadv2").call ?
{
	fd = __int32($fd)
	vector_uaddr = $vec
	count = __int32($vlen)
	offset = ($pos_high << 32) + __uint32($pos_low)
	flags = $flags
	flags_str = _preadv2_flags_str(flags)
	@_SYSCALL_PREADV2_ARGSTR
}
probe dw_syscall.preadv2.return = kernel.function("sys_preadv2").return ?,
	kernel.function("compat_sys_preadv2").return ?
{
	@_SYSCALL_PREADV2_NAME
	@SYSC_RETVALSTR($return)
}

# nd_preadv2 _____________________________________________________

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

probe nd1_syscall.preadv2 = __nd1_syscall.preadv2 ?,
	__nd1_syscall.compat_preadv2 ?
{
	@_SYSCALL_PREADV2_NAME
}
probe __nd1_syscall.preadv2 = kprobe.function("sys_preadv2")
{
	asmlinkage()
	@_SYSCALL_PREADV2_REGARGS
	@_SYSCALL_PREADV2_ARGSTR
}
probe __nd1_syscall.compat_preadv2 = kprobe.function("compat_sys_preadv2")
{
	asmlinkage()
	@_SYSCALL_COMPAT_PREADV2_REGARGS
	@_SYSCALL_PREADV2_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.preadv2 = __nd2_syscall.preadv2 ?, 
	__nd2_syscall.compat_preadv2 ?
{
	@_SYSCALL_PREADV2_NAME
}
probe __nd2_syscall.preadv2 = kprobe.function(@arch_syscall_prefix "sys_preadv2")
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_PREADV2_REGARGS
	@_SYSCALL_PREADV2_ARGSTR
}
probe __nd2_syscall.compat_preadv2 = kprobe.function(@arch_syscall_prefix "compat_sys_preadv2")
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_COMPAT_PREADV2_REGARGS
	@_SYSCALL_PREADV2_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.preadv2 = __tp_syscall.preadv2 ?, 
	__tp_syscall.compat_preadv2 ?
{
	@_SYSCALL_PREADV2_NAME
}
probe __tp_syscall.preadv2 = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_gate(@const("__NR_preadv2"))
	@_SYSCALL_PREADV2_REGARGS
	@_SYSCALL_PREADV2_ARGSTR
}
probe __tp_syscall.compat_preadv2 = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__compat_syscall_gate(@const("__NR_compat_preadv2"))
	@_SYSCALL_COMPAT_PREADV2_REGARGS
	@_SYSCALL_PREADV2_ARGSTR
}

probe nd_syscall.preadv2.return = nd1_syscall.preadv2.return!, nd2_syscall.preadv2.return!, tp_syscall.preadv2.return
  { }
  
probe nd1_syscall.preadv2.return = kprobe.function("sys_preadv2").return ?,
	kprobe.function("compat_sys_preadv2").return ?
{
	@_SYSCALL_PREADV2_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.preadv2.return = kprobe.function(@arch_syscall_prefix "sys_preadv2").return ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_preadv2").return ?
{
	@_SYSCALL_PREADV2_NAME
	@SYSC_RETVALSTR(returnval())
}
 
/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.preadv2.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_preadv2"), @const("__NR_compat_preadv2"))
	@_SYSCALL_PREADV2_NAME
	@SYSC_RETVALSTR($ret)
}
