# inotify_rm_watch ___________________________________________
#
# long sys_inotify_rm_watch(int fd, u32 wd)
#

@define _SYSCALL_INOTIFY_RM_WATCH_NAME
%(
	name = "inotify_rm_watch"
%)

@define _SYSCALL_INOTIFY_RM_WATCH_ARGSTR
%(
	argstr = sprintf("%d, %d", fd, wd)
%)

@define _SYSCALL_INOTIFY_RM_WATCH_REGARGS
%(
	fd = int_arg(1)
	wd = int_arg(2)
%)

@define _SYSCALL_INOTIFY_RM_WATCH_REGARGS_STORE
%(
        if (@probewrite(fd))
          set_int_arg(1, fd)

	if (@probewrite(wd))
	  set_int_arg(2, wd)
%)

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

# dw_inotify_rm_watch _____________________________________________________

probe dw_syscall.inotify_rm_watch = kernel.function("sys_inotify_rm_watch").call ?
{
	@_SYSCALL_INOTIFY_RM_WATCH_NAME
	fd = __int32($fd)
	wd = __int32($wd)
	@_SYSCALL_INOTIFY_RM_WATCH_ARGSTR
}
probe dw_syscall.inotify_rm_watch.return = kernel.function("sys_inotify_rm_watch").return ?
{
	@_SYSCALL_INOTIFY_RM_WATCH_NAME
	@SYSC_RETVALSTR($return)
}

# nd_inotify_rm_watch _____________________________________________________

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

probe nd1_syscall.inotify_rm_watch = kprobe.function("sys_inotify_rm_watch") ?
{
	@_SYSCALL_INOTIFY_RM_WATCH_NAME
	asmlinkage()
	@_SYSCALL_INOTIFY_RM_WATCH_REGARGS
	@_SYSCALL_INOTIFY_RM_WATCH_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.inotify_rm_watch = kprobe.function(@arch_syscall_prefix "sys_inotify_rm_watch") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_INOTIFY_RM_WATCH_NAME
	@_SYSCALL_INOTIFY_RM_WATCH_REGARGS
	@_SYSCALL_INOTIFY_RM_WATCH_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_INOTIFY_RM_WATCH_REGARGS_STORE %)
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.inotify_rm_watch = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_inotify_rm_watch"), @const("__NR_compat_inotify_rm_watch"))
	@_SYSCALL_INOTIFY_RM_WATCH_NAME
	@_SYSCALL_INOTIFY_RM_WATCH_REGARGS
	@_SYSCALL_INOTIFY_RM_WATCH_ARGSTR
},
{
        %( @_IS_SREG_KERNEL %? @_SYSCALL_INOTIFY_RM_WATCH_REGARGS_STORE %)
}

probe nd_syscall.inotify_rm_watch.return = nd1_syscall.inotify_rm_watch.return!, nd2_syscall.inotify_rm_watch.return!, tp_syscall.inotify_rm_watch.return
  { }
  
probe nd1_syscall.inotify_rm_watch.return = kprobe.function("sys_inotify_rm_watch").return ?
{
	@_SYSCALL_INOTIFY_RM_WATCH_NAME
	@SYSC_RETVALSTR(returnval())
}

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