#! stap -p4
#
# Arch-specific probes that all/most arches support.
#

# Newer kernel's syscall.mmap2 tests are in syscalls-detailed.stp.
%( kernel_v < "2.6.33" %?
%( arch != "i386" %?
probe syscall.mmap
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %d, %d, %d, %d, %d\n", start, len, prot, flags, fd,
	       offset)
}
probe syscall.mmap.return
{
	printf("%s, %s\n", name, retstr)
}
%)

probe syscall.mmap2 ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %d, %d, %d, %d, %d", start, length, prot, flags,
	       fd, pgoffset)
}
probe syscall.mmap2.return ?
{
	printf("%s, %s\n", name, retstr)
}
%)

probe syscall.sys32_sigaltstack ?
{
	printf("%s, %s\n", name, argstr)
}
probe syscall.sys32_sigaltstack.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sysctl ?, syscall.sysctl32 ?
{
	printf("%s, %d, %s\n", name, args, argstr)
}
probe syscall.sysctl.return ?, syscall.sysctl32.return ?
{
	printf("%s, %s\n", name, retstr)
}

#
# i386-specific probes
#

%( arch == "i386" %?
probe syscall.get_thread_area
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %s", u_info_uaddr, u_info_str)
}
probe syscall.get_thread_area.return
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.iopl
{
	printf("%s, %s\n", name, argstr)
	printf("%d\n", level)
}
probe syscall.iopl.return
{
	printf("%s, %s\n", name, retstr)
}

%( systemtap_v <= "2.7" %?
probe syscall.ipc ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %d, %d, %d, %p, %d", call, first, second, third,
	       ptr_uaddr, fifth)
}
probe syscall.ipc.return ?
{
	printf("%s, %s\n", name, retstr)
}
%)

# syscall.mmap2 is above

probe syscall.set_thread_area
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %s\n", u_info_uaddr, u_info_str)
}
probe syscall.set_thread_area.return
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.set_zone_reclaim ?
{
	name = "set_zone_reclaim"
	printf("%d, %d, %d", node, zone, state)
}
probe syscall.set_zone_reclaim.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.vm86 ?, syscall.vm86old ?
{
	printf("%s, %s\n", name, argstr)
}
probe syscall.vm86.return ?, syscall.vm86old.return ?
{
	printf("%s, %s\n", name, retstr)
}
%)

#
# ia64-specific probes
#

%( arch == "ia64" %?
# syscall.mmap is above

# syscall.mmap2 is above

# syscall.sysctl32 is above
%)

#
# powerpc-specific probes
#

%( arch == "powerpc" %?
probe syscall.sys64_time ?
{
	printf("%s, %s\n", name, argstr)
}
probe syscall.sys64_time.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.ppc64_personality
{
	printf("%s, %s\n", name, argstr)
	printf("%d\n", persona)
}
probe syscall.ppc64_personality.return
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.ppc_rtas ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p\n", uargs_uaddr)
}
probe syscall.ppc_rtas.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.ppc64_sys32_stime ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p\n", t_uaddr)
}
probe syscall.ppc64_sys32_stime.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_ptrace ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %p, %p, %p", request, pid, addr, data)
}
probe syscall.sys32_ptrace.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_sysinfo ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p\n", info_uaddr)
}
probe syscall.sys32_sysinfo.return ?
{
	printf("%s, %s\n", name, retstr)
}

# Notice no convenience variables like i386 version.  'ptr' is of a
# different type.
probe syscall.ipc ?
{
	printf("%s, %s\n", name, argstr)
}
probe syscall.ipc.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_sigreturn ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %p, %p, %p, %p, %p\n", r3, r4, r5, r6, r7, r8)
}
probe syscall.sys32_sigreturn.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_adjtimex ?
{
	printf("%s, %s\n", name, argstr)
}
probe syscall.sys32_adjtimex.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_getdents = kernel.function("sys32_getdents") ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %p, %d\n", fd, dirp_uaddr, count)
}
probe syscall.sys32_getdents.return = kernel.function("sys32_getdents").return ?
{
	printf("%s, %s\n", name, retstr)
}

# syscall.sysctl32 is above
#probe syscall.compat_sysctl ?
#{
#	printf("%s, %s\n", name, argstr)
#}
#probe syscall.compat_sysctl.return ?
#{
#	printf("%s, %s\n", name, retstr)
#}

probe syscall.sys32_sched_setparam ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %p\n", pid, param_uaddr)
}
probe syscall.sys32_sched_setparam.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_sched_rr_get_interval ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %p\n", pid, interval_uaddr)
}
probe syscall.sys32_sched_rr_get_interval.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_rt_sigpending ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %d\n", set_uaddr, sigsetsize)
}
probe syscall.sys32_rt_sigpending.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_rt_sigtimedwait ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %p, %p, %p\n", uthese_uaddr, uinfo_uaddr,
	       uts_uaddr, sigsetsize)
}
probe syscall.sys32_rt_sigtimedwait.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_rt_sigqueueinfo ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %d, %p\n", pid, sig, uinfo_uaddr)
}
probe syscall.sys32_rt_sigqueueinfo.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_sendfile64 ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %d, %p, %d", out_fd, in_fd, offset_uaddr, count)
}
probe syscall.sys32_sendfile64.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.ppc32_timer_create ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %p, %p\n", which_clock, timer_event_spec, created_timer_id)
}
probe syscall.ppc32_timer_create.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.compat_timer_settime ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %d, %p, %p\n", timer_id, flags, new_setting_uaddr,
	       old_setting_uaddr)
}
probe syscall.compat_timer_settime.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.compat_timer_gettime ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %p\n", timer_id, setting_uaddr)
}
probe syscall.compat_timer_gettime.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.compat_clock_settime ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %p\n", which_clock, tp_uaddr)
}
probe syscall.compat_clock_settime.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_swapcontext ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %p, %d, %d, %d, %d, %p\n", old_ctx_uaddr,
	       new_ctx_uaddr, r5, r6, r7, r8, regs)
}
probe syscall.sys32_swapcontext.return = kernel.function("sys32_swapcontext").return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.sys32_utimes ?
{
	printf("%s, %s\n", name, argstr)
	argstr = sprintf("%p(%s), %p\n", filename_uaddr, path, tvp_uaddr)
}
probe syscall.sys32_utimes.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.compat_mbind ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %d, %d, %p, %d, %d\n", start_uaddr, len, policy,
	       nodemask_uaddr, maxnode, flags)
}
probe syscall.compat_mbind.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.compat_get_mempolicy ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %p, %d, %d, %d\n", policy_uaddr, nmask_uaddr,
	       maxnode, addr, flags)
}
probe syscall.compat_get_mempolicy.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.compat_set_mempolicy ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %p, %d\n", policy, nodemask_uaddr, maxnode)
}
probe syscall.compat_set_mempolicy.return ?
{
	printf("%s, %s\n", name, retstr)
}

# syscall.mmap is above

# syscall.mmap2 is above

probe syscall.ppc64_sys_stime ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p\n", t_uaddr)
}
probe syscall.ppc64_sys_stime.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.ppc64_newuname ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p\n", name_uaddr)
}
probe syscall.ppc64_newuname.return ?
{
	printf("%s, %s\n", name, retstr)
}
%)

#
# s390-specific probes
#

%( arch == "s390" %?
probe syscall.getresgid16 ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %p, %p\n", rgid_uaddr, egid_uaddr, sgid_uaddr)
}
probe syscall.getresgid16.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.getresuid16 ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p, %p, %p\n", ruid_uaddr, euid_uaddr, suid_uaddr)
}
probe syscall.getresuid16.return ?
{
	printf("%s, %s\n", name, retstr)
}

%( systemtap_v < "2.7" %?
probe syscall.ipc ?
{
	printf("%s, %s\n", name, argstr)
}
probe syscall.ipc.return ?
{
	printf("%s, %s\n", name, retstr)
}
%)

# syscall.mmap is above

# syscall.mmap2 is above

# syscall.sysctl32 is above
%)

#
# x86_64-specific probes
#

%( arch == "x86_64" %?
probe syscall.arch_prctl
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %s, %d\n", code, code_str, addr)
}
probe syscall.arch_prctl.return
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.iopl
{
	printf("%s, %s\n", name, argstr)
	printf("%d\n", level)
}
probe syscall.iopl.return
{
	printf("%s, %s\n", name, retstr)
}

# syscall.sysctl32 is above

# Newer kernel's syscall.mmap2 tests are in syscalls-detailed.stp.
%( kernel_v < "2.6.33" %?
# syscall.mmap is above, but we want to make sure syscall.mmap32
# matches syscall.mmap
probe syscall.mmap, syscall.mmap32
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %d, %d, %d, %d, %d\n", start, len, prot, flags, fd,
	       offset)
}
probe syscall.mmap.return, syscall.mmap32.return
{
	printf("%s, %s\n", name, retstr)
}
%)

# syscall.mmap2 is above

probe syscall.vm86_warning ?
{
	printf("%s, %s\n", name, argstr)
}
probe syscall.vm86_warning.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.pipe32 ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %s, %p, %d, %d\n", flags, flag_str, fildes_uaddr, pipe0,
	       pipe1)
}
probe syscall.pipe32.return ?
{
	printf("%s, %s\n", name, retstr)
}
%)

probe syscall.compat_ftruncate64 ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %d\n", fd, length)
}
probe syscall.compat_ftruncate64.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.compat_truncate64 ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p (%s), %d\n", path_uaddr, path, length)
}
probe syscall.compat_truncate64.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.compat_readahead ?
{
	printf("%s, %s\n", name, argstr)
	printf("%d, %d, %u", fd, offset, count)
}
probe syscall.compat_readahead.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.get_thread_area ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p\n", u_info_uaddr)
}
probe syscall.get_thread_area.return ?
{
	printf("%s, %s\n", name, retstr)
}

probe syscall.set_thread_area ?
{
	printf("%s, %s\n", name, argstr)
	printf("%p\n", u_info_uaddr)
}
probe syscall.set_thread_area.return ?
{
	printf("%s, %s\n", name, retstr)
}
