# sched_get_priority_max _____________________________________
#
# asmlinkage long
# sys_sched_get_priority_max(int policy)
#

@define _SYSCALL_SCHED_GET_PRIORITY_MAX_NAME
%(
	name = "sched_get_priority_max"
%)

@define _SYSCALL_SCHED_GET_PRIORITY_MAX_ARGSTR
%(
	argstr = policy_str
%)

@define _SYSCALL_SCHED_GET_PRIORITY_MAX_REGARGS
%(
	policy = int_arg(1)
	policy_str = _sched_policy_str(policy)
%)

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

# dw_sched_get_priority_max _____________________________________________________

probe dw_syscall.sched_get_priority_max = kernel.function("sys_sched_get_priority_max").call
{
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_NAME
	policy = __int32($policy)
	policy_str = _sched_policy_str(policy)
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_ARGSTR
}
probe dw_syscall.sched_get_priority_max.return = kernel.function("sys_sched_get_priority_max").return
{
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_NAME
	@SYSC_RETVALSTR($return)
}

# nd_sched_get_priority_max _____________________________________________________

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

probe nd1_syscall.sched_get_priority_max = kprobe.function("sys_sched_get_priority_max") ?
{
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_NAME
	asmlinkage()
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_REGARGS
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.sched_get_priority_max = kprobe.function(@arch_syscall_prefix "sys_sched_get_priority_max") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_NAME
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_REGARGS
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.sched_get_priority_max = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_sched_get_priority_max"), @const("__NR_compat_sched_get_priority_max"))
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_NAME
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_REGARGS
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_ARGSTR
}

probe nd_syscall.sched_get_priority_max.return = nd1_syscall.sched_get_priority_max.return!, nd2_syscall.sched_get_priority_max.return!, tp_syscall.sched_get_priority_max.return
  { }
  
probe nd1_syscall.sched_get_priority_max.return = kprobe.function("sys_sched_get_priority_max").return ?
{
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.sched_get_priority_max.return = kprobe.function(@arch_syscall_prefix "sys_sched_get_priority_max").return ?
{
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_NAME
	@SYSC_RETVALSTR(returnval())
}
 
/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.sched_get_priority_max.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_sched_get_priority_max"), @const("__NR_compat_sched_get_priority_max"))
	@_SYSCALL_SCHED_GET_PRIORITY_MAX_NAME
	@SYSC_RETVALSTR($ret)
}
