# fstatat ____________________________________________________
# sys32_fstatat64(unsigned int dfd, char __user *filename, struct stat64_emu31 __user* statbuf, int flag)
# long sys_newfstatat(int dfd, char __user *filename, struct stat __user *statbuf, int flag)
# long sys_fstatat64(int dfd, char __user *filename, struct stat64 __user *statbuf, int flag)
# long compat_sys_newfstatat(unsigned int dfd, char __user *filename, struct compat_stat __user *statbuf, int flag)

@define _SYSCALL_FSTATAT_NAME
%(
	name = "fstatat"
%)

@define _SYSCALL_FSTATAT_ARGSTR
%(
	argstr = sprintf("%s, %s, %p, %s", dirfd_str, path, buf_uaddr, flags_str)
%)

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

# dw_fstatat _____________________________________________________

probe dw_syscall.fstatat = kernel.function("sys_fstatat64").call ?,
                        kernel.function("sys_newfstatat").call ?,
                        kernel.function("compat_sys_newfstatat").call ?,
                        kernel.function("sys32_fstatat64").call ?,
%( arch == "s390" %?
                        kernel.function("compat_sys_s390_fstatat64").call ?,
%)
                        kernel.function("sys32_fstatat").call ?
{
	@_SYSCALL_FSTATAT_NAME
	dirfd = __int32($dfd)
	dirfd_str = _dfd_str(__int32($dfd))
	path = user_string_quoted($filename)
	buf_uaddr = $statbuf
	flags = __int32($flag)
	flags_str = _at_flag_str(__int32($flag))
	@_SYSCALL_FSTATAT_ARGSTR
}
probe dw_syscall.fstatat.return = kernel.function("sys_fstatat64").return ?,
	kernel.function("sys_newfstatat").return ?,
	kernel.function("compat_sys_newfstatat").return ?,
	kernel.function("sys32_fstatat64").return ?,
%( arch == "s390" %?
	kernel.function("compat_sys_s390_fstatat64").return ?,
%)
	kernel.function("sys32_fstatat").return ?
{
	@_SYSCALL_FSTATAT_NAME
	retstr = return_str(1, $return)
}

# nd_fstatat _____________________________________________________

probe nd_syscall.fstatat = kprobe.function("sys_fstatat64") ?,
                           kprobe.function("sys_newfstatat") ?,
                           kprobe.function("compat_sys_newfstatat") ?,
                           kprobe.function("sys32_fstatat64") ?,
%( arch == "s390" %?
                           kprobe.function("compat_sys_s390_fstatat64") ?,
%)
			   kprobe.function("sys32_fstatat") ?
{
	@_SYSCALL_FSTATAT_NAME
	asmlinkage()
	dirfd = int_arg(1)
	dirfd_str = _dfd_str(dirfd)
	path = user_string_quoted(pointer_arg(2))
	buf_uaddr = pointer_arg(3)
	flags = int_arg(4)
	flags_str = _at_flag_str(flags)
	@_SYSCALL_FSTATAT_ARGSTR
}
probe nd_syscall.fstatat.return = kprobe.function("sys_fstatat64").return ?,
	kprobe.function("sys_newfstatat").return ?,
	kprobe.function("compat_sys_newfstatat").return ?,
	kprobe.function("sys32_fstatat64").return ?,
%( arch == "s390" %?
	kprobe.function("compat_sys_s390_fstatat64").return ?,
%)
	kprobe.function("sys32_fstatat").return ?
{
	@_SYSCALL_FSTATAT_NAME
	retstr = returnstr(1)
}
