# sched_rr_get_interval ______________________________________
#
# long sys_sched_rr_get_interval(pid_t pid, struct timespec __user *interval)
#

@define _SYSCALL_SCHED_RR_GET_INTERVAL_NAME
%(
	name = "sched_rr_get_interval"
%)

@define _SYSCALL_SCHED_RR_GET_INTERVAL_ARGSTR
%(
	argstr = sprintf("%d, %p", pid, tp_uaddr)
%)

@define _SYSCALL_SCHED_RR_GET_INTERVAL_REGARGS
%(
	pid = int_arg(1)
	tp_uaddr = pointer_arg(2)
%)

@define _SYSCALL_SCHED_RR_GET_INTERVAL_REGARGS_STORE
%(
        if (@probewrite(pid))
          set_int_arg(1, pid)

	if (@probewrite(tp_uaddr))
	  set_pointer_arg(2, tp_uaddr)
%)

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

# dw_sched_rr_get_interval _____________________________________________________

probe dw_syscall.sched_rr_get_interval = __syscall.sched_rr_get_interval,
	kernel.function("compat_sys_sched_rr_get_interval").call ?,
	kernel.function("sys32_sched_rr_get_interval").call ?
{
	@_SYSCALL_SCHED_RR_GET_INTERVAL_NAME
	pid = __int32($pid)
	tp_uaddr = @__pointer($interval)
	@_SYSCALL_SCHED_RR_GET_INTERVAL_ARGSTR
}
probe __syscall.sched_rr_get_interval =
	kernel.function("sys_sched_rr_get_interval").call
{
	@__syscall_gate(@const("__NR_sched_rr_get_interval"))
}
probe dw_syscall.sched_rr_get_interval.return =
	__syscall.sched_rr_get_interval.return,
	kernel.function("compat_sys_sched_rr_get_interval").return ?,
	kernel.function("sys32_sched_rr_get_interval").return ?
{
	@_SYSCALL_SCHED_RR_GET_INTERVAL_NAME
	@SYSC_RETVALSTR($return)
}
probe __syscall.sched_rr_get_interval.return =
	kernel.function("sys_sched_rr_get_interval").return
{
	@__syscall_gate(@const("__NR_sched_rr_get_interval"))
}

# nd_sched_rr_get_interval _____________________________________________________

probe nd_syscall.sched_rr_get_interval = nd1_syscall.sched_rr_get_interval!, nd2_syscall.sched_rr_get_interval!, tp_syscall.sched_rr_get_interval
  { }

probe nd1_syscall.sched_rr_get_interval = __nd1_syscall.sched_rr_get_interval,
	kprobe.function("compat_sys_sched_rr_get_interval").call ?,
	kprobe.function("sys32_sched_rr_get_interval").call ?
{
	@_SYSCALL_SCHED_RR_GET_INTERVAL_NAME
	asmlinkage()
	@_SYSCALL_SCHED_RR_GET_INTERVAL_REGARGS
	@_SYSCALL_SCHED_RR_GET_INTERVAL_ARGSTR
}
probe __nd1_syscall.sched_rr_get_interval =
	kprobe.function("sys_sched_rr_get_interval").call
{
	@__syscall_gate(@const("__NR_sched_rr_get_interval"))
}

/* kernel 4.17+ */
probe nd2_syscall.sched_rr_get_interval =
	kprobe.function(@arch_syscall_prefix "sys_sched_rr_get_interval") ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_sched_rr_get_interval") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_SCHED_RR_GET_INTERVAL_NAME
	@_SYSCALL_SCHED_RR_GET_INTERVAL_REGARGS
	@_SYSCALL_SCHED_RR_GET_INTERVAL_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_SCHED_RR_GET_INTERVAL_REGARGS_STORE %)
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.sched_rr_get_interval = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_sched_rr_get_interval"), @const("__NR_compat_sched_rr_get_interval"))
	@_SYSCALL_SCHED_RR_GET_INTERVAL_NAME
	@_SYSCALL_SCHED_RR_GET_INTERVAL_REGARGS
	@_SYSCALL_SCHED_RR_GET_INTERVAL_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_SCHED_RR_GET_INTERVAL_REGARGS_STORE %)
}

probe nd_syscall.sched_rr_get_interval.return = nd1_syscall.sched_rr_get_interval.return!, nd2_syscall.sched_rr_get_interval.return!, tp_syscall.sched_rr_get_interval.return
  { }
  
probe nd1_syscall.sched_rr_get_interval.return =
	__nd1_syscall.sched_rr_get_interval.return,
	kprobe.function("compat_sys_sched_rr_get_interval").return ?,
	kprobe.function("sys32_sched_rr_get_interval").return ?
{
	@_SYSCALL_SCHED_RR_GET_INTERVAL_NAME
	@SYSC_RETVALSTR(returnval())
}
probe __nd1_syscall.sched_rr_get_interval.return =
	kprobe.function("sys_sched_rr_get_interval").return
{
	@__syscall_gate(@const("__NR_sched_rr_get_interval"))
}

/* kernel 4.17+ */
probe nd2_syscall.sched_rr_get_interval.return =
	kprobe.function(@arch_syscall_prefix "sys_sched_rr_get_interval").return ?,
	kprobe.function(@arch_syscall_prefix "compat_sys_sched_rr_get_interval").return ?
{
	@_SYSCALL_SCHED_RR_GET_INTERVAL_NAME
	@SYSC_RETVALSTR(returnval())
}
 
/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.sched_rr_get_interval.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_sched_rr_get_interval"), @const("__NR_compat_sched_rr_get_interval"))
	@_SYSCALL_SCHED_RR_GET_INTERVAL_NAME
	@SYSC_RETVALSTR($ret)
}
