# sched_yield ________________________________________________
# long sys_sched_yield(void)
#

@define _SYSCALL_SCHED_YIELD_NAME
%(
	name = "sched_yield"
%)

@define _SYSCALL_SCHED_YIELD_ARGSTR
%(
	argstr = ""
%)

probe syscall.sched_yield = dw_syscall.sched_yield !, nd_syscall.sched_yield {}
probe syscall.sched_yield.return = dw_syscall.sched_yield.return !,
                                   nd_syscall.sched_yield.return {}

# dw_sched_yield _____________________________________________________

probe dw_syscall.sched_yield = kernel.function("sys_sched_yield").call
{
	@_SYSCALL_SCHED_YIELD_NAME
	@_SYSCALL_SCHED_YIELD_ARGSTR
}
probe dw_syscall.sched_yield.return = kernel.function("sys_sched_yield").return
{
	@_SYSCALL_SCHED_YIELD_NAME
	@SYSC_RETVALSTR($return)
}

# nd_sched_yield _____________________________________________________

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

probe nd1_syscall.sched_yield = kprobe.function("sys_sched_yield")
{
	@_SYSCALL_SCHED_YIELD_NAME
	@_SYSCALL_SCHED_YIELD_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.sched_yield = kprobe.function(@arch_syscall0_prefix "sys_sched_yield") ?
{
	@_SYSCALL_SCHED_YIELD_NAME
	@_SYSCALL_SCHED_YIELD_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.sched_yield = kernel.trace("sys_enter") ?
{
	@__syscall_compat_gate(@const("__NR_sched_yield"), @const("__NR_compat_sched_yield"))
	@_SYSCALL_SCHED_YIELD_NAME
	@_SYSCALL_SCHED_YIELD_ARGSTR
}

probe nd_syscall.sched_yield.return = nd1_syscall.sched_yield.return!, nd2_syscall.sched_yield.return!, tp_syscall.sched_yield.return
  { }
  
probe nd1_syscall.sched_yield.return = kprobe.function("sys_sched_yield").return
{
	@_SYSCALL_SCHED_YIELD_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.sched_yield.return = kprobe.function(@arch_syscall0_prefix "sys_sched_yield").return ?
{
	@_SYSCALL_SCHED_YIELD_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.sched_yield.return = kernel.trace("sys_exit")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_sched_yield"), @const("__NR_compat_sched_yield"))
	@_SYSCALL_SCHED_YIELD_NAME
	@SYSC_RETVALSTR($ret)
}
