# pwrite64 ___________________________________________________
#
# ssize_t sys_pwrite64(unsigned int fd,
#		  const char __user *buf,
#		  size_t count,
#		  loff_t pos)
#

@define _SYSCALL_PWRITE_NAME
%(
	name = "pwrite"
%)

@define _SYSCALL_PWRITE_ARGSTR
%(
	argstr = sprintf("%d, %s, %u, %d", fd, buf_str, count, offset)
%)

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

# dw_pwrite _____________________________________________________

probe dw_syscall.pwrite = kernel.function("sys_pwrite64").call
{
%( arch == "s390" %?
	@__syscall_gate(@const("__NR_pwrite64"))
%)
	@_SYSCALL_PWRITE_NAME
	fd = __int32($fd)
	buf_uaddr = $buf
	count = @__compat_ulong($count)
	buf_str = user_buffer_quoted(buf_uaddr, count, syscall_string_trunc)
	offset = $pos
	@_SYSCALL_PWRITE_ARGSTR
}
probe dw_syscall.pwrite.return = kernel.function("sys_pwrite64").return
{
%( arch == "s390" %?
	@__syscall_gate(@const("__NR_pwrite64"))
%)
	@_SYSCALL_PWRITE_NAME
	retstr = return_str(1, $return)
}

# nd_pwrite _____________________________________________________

probe nd_syscall.pwrite = kprobe.function("sys_pwrite64") ?
{
%( arch == "s390" %?
	@__syscall_gate(@const("__NR_pwrite64"))
%)
	@_SYSCALL_PWRITE_NAME
	asmlinkage()
	fd = int_arg(1)
	buf_uaddr = pointer_arg(2)
	count = ulong_arg(3)
	buf_str = user_buffer_quoted(buf_uaddr, count, syscall_string_trunc)
	offset = longlong_arg(4)
	@_SYSCALL_PWRITE_ARGSTR
}
probe nd_syscall.pwrite.return = kprobe.function("sys_pwrite64").return ?
{
%( arch == "s390" %?
	@__syscall_gate(@const("__NR_pwrite64"))
%)
	@_SYSCALL_PWRITE_NAME
	retstr = returnstr(1)
}

# long sys32_pwrite64(unsigned int fd, const char __user *ubuf,
#				size_t count, u32 poshi, u32 poslo)
# COMPAT_SYSCALL_DEFINE5(s390_pwrite64, unsigned int, fd,
#		         const char __user *, ubuf,
#		         compat_size_t, count, u32, high, u32, low)

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

# dw_pwrite32 _____________________________________________________

probe dw_syscall.pwrite32 =
%( arch == "s390" %?
	kernel.function("compat_sys_s390_pwrite64").call ?,
%)
	kernel.function("sys32_pwrite64").call ?
{
	@_SYSCALL_PWRITE_NAME
	fd = __int32($fd)
	count = @__compat_ulong($count)
	offset = ((@choose_defined($poshi, $high) << 32)
		  + __uint32(@choose_defined($poslo, $low)))
	buf_uaddr = @__pointer(@choose_defined($buf, $ubuf))
	buf_str = user_buffer_quoted(buf_uaddr, count, syscall_string_trunc)
	@_SYSCALL_PWRITE_ARGSTR
}
probe dw_syscall.pwrite32.return =
%( arch == "s390" %?
	kernel.function("compat_sys_s390_pwrite64").return ?,
%)
	kernel.function("sys32_pwrite64").return ?
{
	@_SYSCALL_PWRITE_NAME
	retstr = return_str(1, $return)
}

# nd_pwrite32 _____________________________________________________

probe nd_syscall.pwrite32 =
%( arch == "s390" %?
	kprobe.function("compat_sys_s390_pwrite64") ?,
%)
	kprobe.function("sys32_pwrite64") ?
{
	@_SYSCALL_PWRITE_NAME
	asmlinkage()
	fd = int_arg(1)
	buf_uaddr = pointer_arg(2)
	count = ulong_arg(3)
	buf_str = user_buffer_quoted(buf_uaddr, count, syscall_string_trunc)
	offset = (u32_arg(4) << 32) + u32_arg(5)
	@_SYSCALL_PWRITE_ARGSTR
}
probe nd_syscall.pwrite32.return =
%( arch == "s390" %?
	kprobe.function("compat_sys_s390_pwrite64").return ?,
%)
	kprobe.function("sys32_pwrite64").return ?
{
	@_SYSCALL_PWRITE_NAME
	retstr = returnstr(1)
}
