# S390-specific system calls

%(arch == "s390" %?

# FIXME: the getresgid16/getresuid16 probes could be combined with
# their "generic" versions in tapset/syscalls.stp.

# getresgid __________________________________________________
# long sys32_getresgid16(u16 __user *rgid, u16 __user *egid, u16 __user *sgid)
#
probe syscall.getresgid16 = kernel.function("sys32_getresgid16") ?
{
	name = "getresgid"
	rgid_uaddr = @choose_defined($rgidp, $rgid)
	egid_uaddr = @choose_defined($egidp, $egid)
	sgid_uaddr = @choose_defined($sgidp, $sgid)
	argstr = sprintf("%p, %p, %p", @choose_defined($rgidp, $rgid),
			 @choose_defined($egidp, $egid),
			 @choose_defined($sgidp, $sgid))
}
probe syscall.getresgid16.return = kernel.function("sys32_getresgid16").return ?
{
	name = "getresgid"
	retstr = return_str(1, $return)
}
# getresuid __________________________________________________
# long sys32_getresuid16(u16 __user *ruid, u16 __user *euid, u16 __user *suid)
#
probe syscall.getresuid16 = kernel.function("sys32_getresuid16") ?
{
	name = "getresuid"
	ruid_uaddr = @choose_defined($ruidp, $ruid)
	euid_uaddr = @choose_defined($euidp, $euid)
	suid_uaddr = @choose_defined($suidp, $suid)
	argstr = sprintf("%p, %p, %p", @choose_defined($ruidp, $ruid),
			 @choose_defined($euidp, $euid),
			 @choose_defined($suidp, $suid))
}
probe syscall.getresuid16.return = kernel.function("sys32_getresuid16").return ?
{
	name = "getresuid"
	retstr = return_str(1, $return)
}

# ipc _________________________________________________
# long sys32_ipc(u32 call, int first, int second, int third, u32 ptr)
#
probe syscall.ipc = kernel.function("sys32_ipc") ?
{
	name = "ipc"
	argstr = sprintf("%d, %d, %d, %d, %p", $call, $first, $second, $third, $ptr)
}
probe syscall.ipc.return = kernel.function("sys_ipc").return ?
{
	name = "ipc"
	retstr = return_str(1, $return)
}

# In kernels < 2.6.33, mmap()/mmap2() was handled by arch-specific
# code.  In kernels >= 2.6.33, the arch-specific code just calls
# generic sys_mmap_pgoff().
%( kernel_v < "2.6.33" %?
# mmap _________________________________________________
# long old_mmap(struct mmap_arg_struct __user *arg)
# long old32_mmap(struct mmap_arg_struct_emu31 __user *arg)
#
probe syscall.mmap = __syscall.mmap ?, __syscall.mmap32 ?
{
	name = "mmap"
	argstr = sprintf("%p, %d, %s, %s, %d, %d", start, len,
			 _mprotect_prot_str(prot), _mmap_flags(flags),
			 fd, offset)
}
probe __syscall.mmap = kernel.function("old_mmap") ?,
		       kernel.function("SyS_s390_old_mmap") ?
{
	start = user_long(&@cast($arg, "mmap_arg_struct")->addr)
	len = user_long(&@cast($arg, "mmap_arg_struct")->len)
	prot = user_long(&@cast($arg, "mmap_arg_struct")->prot)
	flags = user_long(&@cast($arg, "mmap_arg_struct")->flags)
	fd = user_long(&@cast($arg, "mmap_arg_struct")->fd)
	offset = user_long(&@cast($arg, "mmap_arg_struct")->offset)
}
probe __syscall.mmap32 = kernel.function("old32_mmap")
{
	start = user_int(&@cast($arg, "mmap_arg_struct_emu31")->addr)
	len = user_int(&@cast($arg, "mmap_arg_struct_emu31")->len)
	prot = user_int(&@cast($arg, "mmap_arg_struct_emu31")->prot)
	flags = user_int(&@cast($arg, "mmap_arg_struct_emu31")->flags)
	fd = user_int(&@cast($arg, "mmap_arg_struct_emu31")->fd)
	offset = user_int(&@cast($arg, "mmap_arg_struct_emu31")->offset)
}

probe syscall.mmap.return = kernel.function("old_mmap").return ?,
                            kernel.function("old32_mmap").return ?,
                            kernel.function("SyS_s390_old_mmap").return ?
{
        name = "mmap"
        retstr = return_str(2, $return)
}


# mmap2 _________________________________________________
#
# long sys_mmap2(struct mmap_arg_struct __user  *arg)
# long sys32_mmap2(struct mmap_arg_struct_emu31 __user *arg)
#
probe syscall.mmap2 = __syscall.mmap2 ?, __syscall.mmap2_32 ?
{
        name = "mmap2"
	argstr = sprintf("%p, %d, %s, %s, %d, %d", start, length,
			 _mprotect_prot_str(prot), _mmap_flags(flags),
			 fd, pgoffset)
}
probe __syscall.mmap2 = kernel.function("sys_mmap2")
{
	start = user_long(&@cast($arg, "mmap_arg_struct")->addr)
	length = user_long(&@cast($arg, "mmap_arg_struct")->len)
	prot = user_long(&@cast($arg, "mmap_arg_struct")->prot)
	flags = user_long(&@cast($arg, "mmap_arg_struct")->flags)
	fd = user_long(&@cast($arg, "mmap_arg_struct")->fd)
	pgoffset = user_long(&@cast($arg, "mmap_arg_struct")->offset)
}
probe __syscall.mmap2_32 = kernel.function("sys32_mmap2")
{
	start = user_int(&@cast($arg, "mmap_arg_struct_emu31")->addr)
	length = user_int(&@cast($arg, "mmap_arg_struct_emu31")->len)
	prot = user_int(&@cast($arg, "mmap_arg_struct_emu31")->prot)
	flags = user_int(&@cast($arg, "mmap_arg_struct_emu31")->flags)
	fd = user_int(&@cast($arg, "mmap_arg_struct_emu31")->fd)
	pgoffset = user_int(&@cast($arg, "mmap_arg_struct_emu31")->offset)
}

probe syscall.mmap2.return = kernel.function("sys_mmap2").return ?,
                             kernel.function("sys32_mmap2").return ?
{
        name = "mmap2"
        retstr = return_str(2, $return)
}
%)

%( CONFIG_GENERIC_SIGALTSTACK == "n" || kernel_v < "3.8" %?
# sigaltstack ________________________________________________
# asmlinkage long
# sys_sigaltstack(const stack_t __user * uss, stack_t __user *uoss)
#
# NOTE: args vary between archs.
probe syscall.sigaltstack = kernel.function("sys_sigaltstack")
{
	name = "sigaltstack"
	uss_uaddr = $uss
	uoss_uaddr = $uoss
%(systemtap_v < "2.3" %?
	regs = %{ _stp_current_pt_regs() %}
%)
	argstr = sprintf("%p, %p", $uss, $uoss)
}
probe syscall.sigaltstack.return = kernel.function("sys_sigaltstack").return
{
	name = "sigaltstack"
	retstr = return_str(1, $return)
}
%)

# sys32_sigaltstack ________________________________________________
# asmlinkage long
# sys32_sigaltstack(const stack_t32 __user *uss, stack_t32 __user *uoss)
#
# NOTE: args vary between archs.
probe syscall.sys32_sigaltstack = kernel.function("sys32_sigaltstack") ?
{
	name = "sys32_sigaltstack"
	argstr = ""
}
probe syscall.sys32_sigaltstack.return = kernel.function("sys32_sigaltstack").return ?
{
	name = "sys32_sigaltstack"
	retstr = return_str(1, $return)
}

# sysctl _____________________________________________________
#
# long sys32_sysctl(struct __sysctl_args32 __user *args)
#
probe syscall.sysctl32 = kernel.function("sys32_sysctl") ?
{
	name = "sysctl"
	argstr = sprintf("%p", $args)
}
probe syscall.sysctl32.return = kernel.function("sys32_sysctl").return ?
{
	name = "sysctl"
	retstr = return_str(1, $return)
}

%)
