# getpgrp ____________________________________________________
# long sys_getpgrp(void)

@define _SYSCALL_GETPGRP_NAME
%(
	name = "getpgrp"
%)

@define _SYSCALL_GETPGRP_ARGSTR
%(
	argstr = ""
%)

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

# dw_getpgrp _____________________________________________________

probe dw_syscall.getpgrp = kernel.function("sys_getpgrp").call ?
{
	@_SYSCALL_GETPGRP_NAME
	@_SYSCALL_GETPGRP_ARGSTR
}
probe dw_syscall.getpgrp.return = kernel.function("sys_getpgrp").return ?
{
	@_SYSCALL_GETPGRP_NAME
	@SYSC_RETVALSTR($return)
}

# nd_getpgrp _____________________________________________________

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

probe nd1_syscall.getpgrp = kprobe.function("sys_getpgrp") ?
{
	@_SYSCALL_GETPGRP_NAME
	@_SYSCALL_GETPGRP_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.getpgrp = kprobe.function(@arch_syscall0_prefix "sys_getpgrp") ?
{
	@_SYSCALL_GETPGRP_NAME
	@_SYSCALL_GETPGRP_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.getpgrp = kernel.trace("sys_enter") ?
{
	@__syscall_compat_gate(@const("__NR_getpgrp"), @const("__NR_compat_getpgrp"))
	@_SYSCALL_GETPGRP_NAME
	@_SYSCALL_GETPGRP_ARGSTR
}

probe nd_syscall.getpgrp.return = nd1_syscall.getpgrp.return!, nd2_syscall.getpgrp.return!, tp_syscall.getpgrp.return
  { }
  
probe nd1_syscall.getpgrp.return = kprobe.function("sys_getpgrp").return ?
{
	@_SYSCALL_GETPGRP_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.getpgrp.return = kprobe.function(@arch_syscall0_prefix "sys_getpgrp").return ?
{
	@_SYSCALL_GETPGRP_NAME
	@SYSC_RETVALSTR(returnval())
}

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