# acct _______________________________________________________
# long sys_acct(const char __user *name)

@define _SYSCALL_ACCT_NAME
%(
	name = "acct"
%)

@define _SYSCALL_ACCT_ARGSTR
%(
	argstr = filename
%)

@define _SYSCALL_ACCT_REGARGS
%(
	filename = user_string_quoted(pointer_arg(1))
%)

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

# dw_acct _____________________________________________________

probe dw_syscall.acct = kernel.function("sys_acct").call ?
{
	@_SYSCALL_ACCT_NAME
	filename = user_string_quoted($name)
	@_SYSCALL_ACCT_ARGSTR
}
probe dw_syscall.acct.return = kernel.function("sys_acct").return ?
{
	@_SYSCALL_ACCT_NAME
	@SYSC_RETVALSTR($return)
}

# nd_acct _____________________________________________________

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

probe nd1_syscall.acct = kprobe.function("sys_acct") ?
{
	@_SYSCALL_ACCT_NAME
	asmlinkage()
	@_SYSCALL_ACCT_REGARGS
	@_SYSCALL_ACCT_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.acct = kprobe.function(@arch_syscall_prefix "sys_acct") ?
{
	__set_syscall_pt_regs(pointer_arg(1))
	@_SYSCALL_ACCT_NAME
	@_SYSCALL_ACCT_REGARGS
	@_SYSCALL_ACCT_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.acct = kernel.trace("sys_enter")
{
	__set_syscall_pt_regs($regs)
	@__syscall_compat_gate(@const("__NR_acct"), @const("__NR_compat_acct"))
	@_SYSCALL_ACCT_NAME
	@_SYSCALL_ACCT_REGARGS
	@_SYSCALL_ACCT_ARGSTR
}

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

probe nd1_syscall.acct.return = kprobe.function("sys_acct").return ?
{
	@_SYSCALL_ACCT_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.acct.return = kprobe.function(@arch_syscall_prefix "sys_acct").return ?
{
	@_SYSCALL_ACCT_NAME
	@SYSC_RETVALSTR(returnval())
}

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

