# perf_event_open ____________________________________________
#
# SYSCALL_DEFINE5(perf_event_open,
#		struct perf_event_attr __user *, attr_uptr,
#		pid_t, pid, int, cpu, int, group_fd, unsigned long, flags)

@define _SYSCALL_PERF_EVENT_OPEN_NAME
%(
	name = "perf_event_open"
%)

@define _SYSCALL_PERF_EVENT_OPEN_ARGSTR
%(
	argstr = sprintf("%p, %d, %d, %d, %s", attr_uaddr, pid, cpu, group_fd, flags_str)
%)

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

# dw_perf_event_open _____________________________________________________

probe dw_syscall.perf_event_open = kernel.function("sys_perf_event_open").call ?
{
	@_SYSCALL_PERF_EVENT_OPEN_NAME
	attr_uaddr = $attr_uptr
	pid = __int32($pid)
	cpu = __int32($cpu)
	group_fd = __int32($group_fd)
	flags = @__compat_ulong($flags)
	flags_str = _perf_event_open_flags_str(flags)
	@_SYSCALL_PERF_EVENT_OPEN_ARGSTR
}
probe dw_syscall.perf_event_open.return =
	kernel.function("sys_perf_event_open").return ?
{
	@_SYSCALL_PERF_EVENT_OPEN_NAME
	retstr = return_str(1, $return)
}

# nd_perf_event_open _____________________________________________________

probe nd_syscall.perf_event_open = kprobe.function("sys_perf_event_open") ?
{
	@_SYSCALL_PERF_EVENT_OPEN_NAME
	asmlinkage()
	attr_uaddr = pointer_arg(1)
	pid = int_arg(2)
	cpu = int_arg(3)
	group_fd = int_arg(4)
	flags = ulong_arg(5)
	flags_str = _perf_event_open_flags_str(flags)
	@_SYSCALL_PERF_EVENT_OPEN_ARGSTR
}
probe nd_syscall.perf_event_open.return =
	kprobe.function("sys_perf_event_open").return ?
{
	@_SYSCALL_PERF_EVENT_OPEN_NAME
	retstr = returnstr(1)
}
