# shmat ______________________________________________________
#
# long sys_shmat(int shmid, char __user *shmaddr, int shmflg)
#

@define _SYSCALL_SHMAT_NAME
%(
	name = "shmat"
%)

@define _SYSCALL_SHMAT_ARGSTR
%(
	argstr = sprintf("%d, %p, %s", shmid, shmaddr_uaddr, shmflg_str)
%)

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

# dw_shmat _____________________________________________________

probe dw_syscall.shmat = kernel.function("sys_shmat").call ?
{
	@_SYSCALL_SHMAT_NAME
	shmid = $shmid
	shmaddr_uaddr = $shmaddr
	shmflg = $shmflg
	shmflg_str = _shmat_flags_str(shmflg)
	@_SYSCALL_SHMAT_ARGSTR
}
probe dw_syscall.shmat.return = kernel.function("sys_shmat").return ?
{
	@_SYSCALL_SHMAT_NAME
	retstr = return_str(1, $return)
}

# nd_shmat _____________________________________________________

probe nd_syscall.shmat = kprobe.function("sys_shmat") ?
{
	@_SYSCALL_SHMAT_NAME
	asmlinkage()
	shmid = int_arg(1)
	shmaddr_uaddr = pointer_arg(2)
	shmflg = int_arg(3)
	shmflg_str = _shmat_flags_str(shmflg)
	@_SYSCALL_SHMAT_ARGSTR
}
probe nd_syscall.shmat.return = kprobe.function("sys_shmat").return ?
{
	@_SYSCALL_SHMAT_NAME
	retstr = returnstr(1)
}

# compat_sys_shmat ________________________________________
#
# long compat_sys_shmat(int first, int second, compat_uptr_t third,
#			int version, void __user *uptr)
# COMPAT_SYSCALL_DEFINE3(shmat, int, shmid, compat_uptr_t, shmaddr,
#			 int, shmflg)
#

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

# dw_compat_sys_shmat _____________________________________________________

probe dw_syscall.compat_sys_shmat = kernel.function("compat_sys_shmat").call ?
{
	@_SYSCALL_SHMAT_NAME
%( systemtap_v < "2.3" %?
	first = @choose_defined($shmid, $first)
	second = @choose_defined($shmflg, $second)
	third = @choose_defined($third, 0)
	uptr_uaddr = @choose_defined($shmaddr, $uptr)
%)
	shmid = @choose_defined($shmid, $first)
	shmaddr_uaddr = @choose_defined($shmaddr, $uptr)
	shmflg = @choose_defined($shmflg, $second)
	shmflg_str = _shmat_flags_str(shmflg)
	@_SYSCALL_SHMAT_ARGSTR
}
probe dw_syscall.compat_sys_shmat.return = kernel.function("compat_sys_shmat").return ?
{
	@_SYSCALL_SHMAT_NAME
	retstr = return_str(1, $return)
}

# nd_compat_sys_shmat _____________________________________________________

probe nd_syscall.compat_sys_shmat = kprobe.function("compat_sys_shmat") ?
{
	@_SYSCALL_SHMAT_NAME

%( systemtap_v < "2.3" %?
	first = int_arg(1)
	second = int_arg(2)
	third = u32_arg(3)
	uptr_uaddr = pointer_arg(5)
%)
	shmid = int_arg(1)
%( kernel_v > "3.9" || CONFIG_ARCH_WANT_OLD_COMPAT_IPC == "y" %?
	shmflg = int_arg(3)
	shmaddr_uaddr = pointer_arg(2)
%:
	shmflg = int_arg(2)
	shmaddr_uaddr = pointer_arg(5)
%)
	shmflg_str = _shmat_flags_str(shmflg)
	@_SYSCALL_SHMAT_ARGSTR
}
probe nd_syscall.compat_sys_shmat.return = kprobe.function("compat_sys_shmat").return ?
{
	@_SYSCALL_SHMAT_NAME
	retstr = returnstr(1)
}
