# readlinkat ___________________________________________________
#
# long sys_readlinkat(int dfd, const char __user * path,
#		  char __user * buf,
#		  int bufsiz)
#

@define _SYSCALL_READLINKAT_NAME
%(
	name = "readlinkat"
%)

@define _SYSCALL_READLINKAT_ARGSTR
%(
	argstr = sprintf("%s, %s, %p, %d", dfd_str, path, buf_uaddr, bufsiz)
%)

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

# dw_readlinkat _____________________________________________________

probe dw_syscall.readlinkat = kernel.function("sys_readlinkat").call ?
{
	@__syscall_compat_gate(@const("__NR_readlinkat"),
			       @const("__NR_compat_readlinkat"))
	@_SYSCALL_READLINKAT_NAME
	dfd = __int32($dfd)
	dfd_str = _dfd_str(__int32($dfd))
	buf_uaddr = $buf
	bufsiz = __int32($bufsiz)
	path = user_string_quoted(@choose_defined($pathname, $path))
	@_SYSCALL_READLINKAT_ARGSTR
}

probe dw_syscall.readlinkat.return = kernel.function("sys_readlinkat").return ?
{
	@__syscall_compat_gate(@const("__NR_readlinkat"),
			       @const("__NR_compat_readlinkat"))
	@_SYSCALL_READLINKAT_NAME
	retstr = return_str(1, $return)
}

# nd_readlinkat _____________________________________________________

probe nd_syscall.readlinkat = kprobe.function("sys_readlinkat") ?
{
	@__syscall_compat_gate(@const("__NR_readlinkat"),
			       @const("__NR_compat_readlinkat"))
	@_SYSCALL_READLINKAT_NAME
	asmlinkage()
	dfd = int_arg(1)
	dfd_str = _dfd_str(dfd)
	path = user_string_quoted(pointer_arg(2))
	buf_uaddr = pointer_arg(3)
	bufsiz = int_arg(4)
	@_SYSCALL_READLINKAT_ARGSTR
}
probe nd_syscall.readlinkat.return = kprobe.function("sys_readlinkat").return ?
{
	@__syscall_compat_gate(@const("__NR_readlinkat"),
			       @const("__NR_compat_readlinkat"))
	@_SYSCALL_READLINKAT_NAME
	retstr = returnstr(1)
}
