# getgid _____________________________________________________
# long sys_getgid(void)
# long sys32_getgid16(void)
#

@define _SYSCALL_GETGID_NAME
%(
	name = "getgid"
%)

@define _SYSCALL_GETGID_ARGSTR
%(
	argstr = ""
%)

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

# dw_getgid _____________________________________________________

probe dw_syscall.getgid = kernel.function("sys_getgid16").call ?,
                       kernel.function("sys32_getgid16").call ?,
%( arch == "s390" %?
                       kernel.function("compat_sys_s390_getgid16").call ?,
%)
                       kernel.function("sys_getgid").call
{
	@_SYSCALL_GETGID_NAME
	@_SYSCALL_GETGID_ARGSTR
}
probe dw_syscall.getgid.return = kernel.function("sys_getgid16").return ?,
	kernel.function("sys32_getgid16").return ?,
%( arch == "s390" %?
	kernel.function("compat_sys_s390_getgid16").return ?,
%)
	kernel.function("sys_getgid").return
{
	@_SYSCALL_GETGID_NAME
	@SYSC_RETVALSTR($return)
}

# nd_getgid _____________________________________________________

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

probe nd1_syscall.getgid = kprobe.function("sys_getgid16") ?,
                           kprobe.function("sys32_getgid16") ?,
%( arch == "s390" %?
                           kprobe.function("compat_sys_s390_getgid16") ?,
%)
                           kprobe.function("sys_getgid")
{
	@_SYSCALL_GETGID_NAME
	@_SYSCALL_GETGID_ARGSTR
}

/* kernel 4.17+ */
probe nd2_syscall.getgid = kprobe.function(@arch_syscall0_prefix "sys_getgid") ?,
                           kprobe.function(@arch_syscall0_prefix "sys_getgid16") ?
{
	@_SYSCALL_GETGID_NAME
	@_SYSCALL_GETGID_ARGSTR
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.getgid = __tp_syscall.getgid, __tp_syscall.getgid16
{
	@_SYSCALL_GETGID_NAME
	@_SYSCALL_GETGID_ARGSTR
}
probe __tp_syscall.getgid = kernel.trace("sys_enter")
{
	@__syscall_compat_gate(@const("__NR_getgid"), @const("__NR_compat_getgid32"))
}
probe __tp_syscall.getgid16 = kernel.trace("sys_enter")
{
	@__compat_syscall_gate(@const("__NR_compat_getgid"))
}

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

probe nd1_syscall.getgid.return = kprobe.function("sys_getgid16").return ?,
	kprobe.function("sys32_getgid16").return ?,
%( arch == "s390" %?
	kprobe.function("compat_sys_s390_getgid16").return ?,
%)
	kprobe.function("sys_getgid").return
{
	@_SYSCALL_GETGID_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 4.17+ */
probe nd2_syscall.getgid.return =
	kprobe.function(@arch_syscall0_prefix "sys_getgid").return ?,
	kprobe.function(@arch_syscall0_prefix "sys_getgid16").return ?
{
	@_SYSCALL_GETGID_NAME
	@SYSC_RETVALSTR(returnval())
}

/* kernel 3.5+, but undesirable because it affects all syscalls */
probe tp_syscall.getgid.return = __tp_syscall.getgid.return, __tp_syscall.getgid16.return
{
	__set_syscall_pt_regs($regs)
	@_SYSCALL_GETGID_NAME
	@SYSC_RETVALSTR($ret)
}
probe __tp_syscall.getgid.return = kernel.trace("sys_exit")
{
	@__syscall_compat_gate(@const("__NR_getgid"), @const("__NR_compat_getgid32"))
}
probe __tp_syscall.getgid16.return = kernel.trace("sys_exit")
{
	@__compat_syscall_gate(@const("__NR_compat_getgid"))
}
