# sigaltstack ________________________________________________
#
# In kernel 3.8, CONFIG_GENERIC_SIGALTSTACK was added by
# kernel commit 6bf9adfc90370b695cb111116e15fdc0e1906270.
#
# Then, in kernel 3.9, all architectures were switched to using the
# generic sigaltstack by kernel commit
# d64008a8f30e0b381b292788ec6f3ee509b3bb40, which also removed the
# CONFIG_GENERIC_SIGALTSTACK config variable.
#
# Thus the following preprocessor test.
%( CONFIG_GENERIC_SIGALTSTACK == "y" || kernel_v >= "3.9" %?

# SYSCALL_DEFINE2(sigaltstack,const stack_t __user *,uss, stack_t __user *,uoss)
# COMPAT_SYSCALL_DEFINE2(sigaltstack,
#			const compat_stack_t __user *, uss_ptr,
#			compat_stack_t __user *, uoss_ptr)
#

@define _SYSCALL_SIGALTSTACK_NAME
%(
	name = "sigaltstack"
%)

@define _SYSCALL_SIGALTSTACK_ARGSTR
%(
	argstr = sprintf("%s, %p", uss_str, uoss_uaddr)
%)

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

# dw_sigaltstack _____________________________________________________

probe dw_syscall.sigaltstack = kernel.function("sys_sigaltstack").call,
	kernel.function("compat_sys_sigaltstack").call ?
{
	@_SYSCALL_SIGALTSTACK_NAME
	uss_uaddr = @__pointer(@choose_defined($uss, $uss_ptr))
	uss_str = (@__compat_task ? _stp_compat_sigaltstack_u(uss_uaddr)
	          : _stp_sigaltstack_u(uss_uaddr))
	uoss_uaddr = @__pointer(@choose_defined($uoss, $uoss_ptr))
	@_SYSCALL_SIGALTSTACK_ARGSTR
}
probe dw_syscall.sigaltstack.return = kernel.function("sys_sigaltstack").return,
	kernel.function("compat_sys_sigaltstack").return ?
{
	@_SYSCALL_SIGALTSTACK_NAME
	retstr = return_str(1, $return)
}

# nd_sigaltstack _____________________________________________________

probe nd_syscall.sigaltstack = kprobe.function("sys_sigaltstack"),
	kprobe.function("compat_sys_sigaltstack") ?
{
	@_SYSCALL_SIGALTSTACK_NAME
	asmlinkage()
	uss_uaddr = pointer_arg(1)
	uss_str = (@__compat_task ? _stp_compat_sigaltstack_u(uss_uaddr)
	          : _stp_sigaltstack_u(uss_uaddr))
	uoss_uaddr = pointer_arg(2)
	@_SYSCALL_SIGALTSTACK_ARGSTR
}
probe nd_syscall.sigaltstack.return = kprobe.function("sys_sigaltstack").return,
	kprobe.function("compat_sys_sigaltstack").return ?
{
	@_SYSCALL_SIGALTSTACK_NAME
	retstr = returnstr(1)
}
%)
