# sync _______________________________________________________
#
# sys_sync(void)
#

@define _SYSCALL_SYNC_NAME
%(
	name = "sync"
%)

@define _SYSCALL_SYNC_ARGSTR
%(
	argstr = ""
%)

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

# dw_sync _____________________________________________________

probe dw_syscall.sync = kernel.function("sys_sync").call
{
	@_SYSCALL_SYNC_NAME
	@_SYSCALL_SYNC_ARGSTR
}
probe dw_syscall.sync.return = kernel.function("sys_sync").return
{
	@_SYSCALL_SYNC_NAME
	@SYSC_RETVALSTR($return)
}

# nd_sync _____________________________________________________

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

probe nd1_syscall.sync = kprobe.function("sys_sync")
{
	@_SYSCALL_SYNC_NAME
	@_SYSCALL_SYNC_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.sync = kprobe.function(@arch_syscall0_prefix "sys_sync") ?
{
	@_SYSCALL_SYNC_NAME
	@_SYSCALL_SYNC_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.sync = kernel.trace("sys_enter") ?
{
	@__syscall_compat_gate(@const("__NR_sync"), @const("__NR_compat_sync"))
	@_SYSCALL_SYNC_NAME
	@_SYSCALL_SYNC_ARGSTR
}

probe nd_syscall.sync.return = nd1_syscall.sync.return!, nd2_syscall.sync.return!, tp_syscall.sync.return
  { }

probe nd1_syscall.sync.return = kprobe.function("sys_sync").return
{
	@_SYSCALL_SYNC_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.sync.return = kprobe.function(@arch_syscall0_prefix "sys_sync").return ?
{
	@_SYSCALL_SYNC_NAME
	@SYSC_RETVALSTR(returnval())
}

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