//processor.
// </tapsetdescription>
-/**
- * sfunction print_regs - Print a register dump
- *
- * Description: This function prints a register dump. Does nothing if no registers are available for the probe point.
- */
-function print_regs ()
-%{
- if ((c->probe_flags & _STP_PROBE_STATE_USER_MODE) && CONTEXT->uregs) {
- _stp_print_regs (CONTEXT->uregs);
- } else if (CONTEXT->kregs) {
- _stp_print_regs (CONTEXT->kregs);
- }
-%}
-
-/**
- * sfunction execname - Returns the execname of a target process (or group of processes)
- *
- * Description: Returns the execname of a target process (or group of processes).
- */
-function execname:string ()
-%{ /* pure */ /* unprivileged */
- strlcpy (STAP_RETVALUE, current->comm, MAXSTRINGLEN);
-%}
-
-/**
- * sfunction pid - Returns the ID of a target process
- *
- * Description: This function returns the ID of a target process.
- */
-function pid:long ()
-%{ /* pure */ /* unprivileged */
- STAP_RETVALUE = current->tgid;
-%}
-
-/**
- * sfunction tid - Returns the thread ID of a target process
- *
- * Description: This function returns the thread ID of the target process.
- */
-function tid:long ()
-%{ /* pure */ /* unprivileged */
- STAP_RETVALUE = current->pid;
-%}
-
-/**
- * sfunction ppid - Returns the process ID of a target process's parent process
- *
- * Description: This function return the process ID of the target proccess's parent process.
- */
-function ppid:long()
-%{ /* pure */ /* unprivileged */
-#if defined(STAPCONF_REAL_PARENT)
- STAP_RETVALUE = current->real_parent->tgid;
-#else
- STAP_RETVALUE = current->parent->tgid;
-#endif
-%}
-
-/**
- * sfunction pgrp - Returns the process group ID of the current process
- *
- * Description: This function returns the process group ID of the
- * current process.
- */
-function pgrp:long ()
-%{ /* pure */ /* unprivileged */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
- struct signal_struct *ss = kread( &(current->signal) );
- STAP_RETVALUE = kread ( &(ss->pgrp) );
- CATCH_DEREF_FAULT();
-#else
- STAP_RETVALUE = task_pgrp_nr_ns(current, &init_pid_ns);
-#endif
-%}
-
-/**
- * sfunction sid - Returns the session ID of the current process
- *
- * Description: The session ID of a process is the process group ID
- * of the session leader. Session ID is stored in the signal_struct
- * since Kernel 2.6.0.
- */
-function sid:long ()
-%{ /* pure */ /* unprivileged */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
- struct signal_struct *ss = kread( &(current->signal) );
- STAP_RETVALUE = kread ( &(ss->session) );
- CATCH_DEREF_FAULT();
-#else
- STAP_RETVALUE = task_session_nr_ns(current, &init_pid_ns);
-#endif
-%}
-
-/**
- * sfunction pexecname - Returns the execname of a target process's parent process
- *
- * Description: This function returns the execname of a target
- * process's parent procces.
- */
-function pexecname:string ()
-%{ /* pure */ /* unprivileged */
-#if defined(STAPCONF_REAL_PARENT)
- strlcpy (STAP_RETVALUE, current->real_parent->comm, MAXSTRINGLEN);
-#else
- strlcpy (STAP_RETVALUE, current->parent->comm, MAXSTRINGLEN);
-#endif
-%}
-
-/**
- * sfunction gid - Returns the group ID of a target process
- *
- * Description: This function returns the group ID of a target process.
- */
-function gid:long ()
-%{ /* pure */ /* unprivileged */
-#ifdef STAPCONF_TASK_UID
- STAP_RETVALUE = current->gid;
-#else
- STAP_RETVALUE = current_gid();
-#endif
-%}
-
-/**
- * sfunction egid - Returns the effective gid of a target process
- *
- * Description: This function returns the effective gid of a target process
- */
-function egid:long ()
-%{ /* pure */ /* unprivileged */
-#ifdef STAPCONF_TASK_UID
- STAP_RETVALUE = current->egid;
-#else
- STAP_RETVALUE = current_egid();
-#endif
-%}
-
-/**
- * sfunction uid - Returns the user ID of a target process
- *
- * Description: This function returns the user ID of the target process.
- */
-function uid:long ()
-%{ /* pure */ /* unprivileged */
-#ifdef STAPCONF_TASK_UID
- STAP_RETVALUE = current->uid;
-#else
- STAP_RETVALUE = current_uid();
-#endif
-%}
-
-/**
- * sfunction euid - Return the effective uid of a target process
- *
- * Description: Returns the effective user ID of the target process.
- */
-function euid:long ()
-%{ /* pure */ /* unprivileged */
-#ifdef STAPCONF_TASK_UID
- STAP_RETVALUE = current->euid;
-#else
- STAP_RETVALUE = current_euid();
-#endif
-%}
-
-
-/**
- * sfunction is_myproc - Determines if the current probe point has occurred in the user's own process
- *
- * Description: This function returns 1 if the current probe
- * point has occurred in the user's own process.
- */
-function is_myproc:long ()
-%{ /* pure */ /* unprivileged */
- STAP_RETVALUE = is_myproc();
-%}
-
-
-%( systemtap_v <= "1.4" %?
-/**
- * sfunction cpuid - Returns the current cpu number
- *
- * Description: This function returns the current cpu number.
- * Deprecated in SystemTap 1.4 and removed in SystemTap 1.5.
- */
-function cpuid:long ()
-%{ /* pure */
- STAP_RETVALUE = smp_processor_id();
-%}
-%)
-
-/**
- * sfunction cpu - Returns the current cpu number
- *
- * Description: This function returns the current cpu number.
- */
-function cpu:long ()
-%{ /* pure */ /* unprivileged */
- STAP_RETVALUE = smp_processor_id();
-%}
-
/**
* sfunction pp - Returns the active probe point
*
strlcpy (STAP_RETVALUE, CONTEXT->probe_point, MAXSTRINGLEN);
%}
-/**
- * sfunction registers_valid - Determines validity of register() and u_register() in current context
- *
- * Description: This function returns 1 if register() and u_register()
- * can be used in the current context, or 0 otherwise.
- * For example, registers_valid() returns 0
- * when called from a begin or end probe.
- */
-function registers_valid:long ()
-%{ /* pure */ /* unprivileged */
- STAP_RETVALUE = ((c->probe_flags & _STP_PROBE_STATE_USER_MODE)
- ? (CONTEXT->uregs != NULL)
- : (CONTEXT->kregs != NULL));
-%}
-
-/**
- * sfunction user_mode - Determines if probe point occurs in user-mode
- *
- * Return 1 if the probe point occurred in user-mode.
- */
-function user_mode:long ()
-%{ /* pure */ /* unprivileged */
- STAP_RETVALUE = (CONTEXT->probe_flags
- & _STP_PROBE_STATE_USER_MODE) ? 1 : 0;
-%}
-
-/**
- * sfunction is_return - Whether the current probe context is a return probe
- *
- * Description: Returns 1 if the current probe context is a return probe,
- * returns 0 otherwise.
- */
-function is_return:long ()
-%{ /* pure */
- if (CONTEXT->probe_type == _STP_PROBE_HANDLER_KRETPROBE
- || CONTEXT->probe_type == _STP_PROBE_HANDLER_URETPROBE)
- STAP_RETVALUE = 1;
- else
- STAP_RETVALUE = 0;
-%}
-
-/**
- * sfunction target - Return the process ID of the target process
- *
- * Description: This function returns the process ID of the target
- * process. This is useful in conjunction with the -x PID or
- * -c CMD command-line options to stap. An example of its use is
- * to create scripts that filter on a specific process.
- *
- * -x <pid>
- * target() returns the pid specified by -x
- *
- * -c <command>
- * target() returns the pid for the executed command specified by -c
- */
-function target:long ()
-%{ /* pure */ /* unprivileged */
- STAP_RETVALUE = _stp_target;
-%}
-
-/**
- * sfunction module_name - The module name of the current script
- *
- * Description: This function returns the name of the stap module.
- * Either generated randomly (stap_[0-9a-f]+_[0-9a-f]+)
- * or set by stap -m <module_name>.
- */
-function module_name:string ()
-%{ /* pure */ /* unprivileged */
- strlcpy(STAP_RETVALUE, THIS_MODULE->name, MAXSTRINGLEN);
-%}
-
-/**
- * sfunction stp_pid - The process id of the stapio process
- *
- * Description: This function returns the process id of the
- * stapio process that launched this script. There could be
- * other SystemTap scripts and stapio processes running on
- * the system.
- */
-function stp_pid:long ()
-%{ /* pure */
- STAP_RETVALUE = _stp_pid;
-%}
-
-
-/**
- * sfunction remote_id - The index of this instance in a remote execution.
- *
- * Description: This function returns a number 0..N, which is the unique
- * index of this particular script execution from a swarm of
- * "stap --remote A --remote B ..." runs, and is the same number
- * "stap --remote-prefix" would print. The function returns -1 if the
- * script was not launched with "stap --remote", or if the remote
- * staprun/stapsh are older than version 1.7.
- */
-function remote_id:long () {
- return %{ /* pure */ /* unprivileged */ _stp_remote_id %}
-}
-
-
-/**
- * sfunction remote_uri - The name of this instance in a remote execution.
- *
- * Description: This function returns the remote host used to invoke
- * this particular script execution from a swarm of "stap --remote" runs.
- * It may not be unique among the swarm.
- * The function returns an empty string if the script was not launched with
- * "stap --remote".
- */
-function remote_uri:string () {
- return %{ /* string */ /* pure */ /* unprivileged */ _stp_remote_uri %}
-}
-
-
-/**
- * sfunction stack_size - Return the size of the kernel stack
- *
- * Description: This function returns the size of the kernel stack.
- */
-function stack_size:long ()
-%{ /* pure */
- STAP_RETVALUE = THREAD_SIZE;
-%}
-
-/**
- * sfunction stack_used - Returns the amount of kernel stack used
- *
- * Description: This function determines how many bytes are
- * currently used in the kernel stack.
- */
-function stack_used:long ()
-%{ /* pure */
- char a;
- STAP_RETVALUE = THREAD_SIZE - ((long)&a & (THREAD_SIZE-1));
-%}
-
-/**
- * sfunction stack_unused - Returns the amount of kernel stack currently available
- *
- * Description: This function determines how many bytes are
- * currently available in the kernel stack.
- */
-function stack_unused:long ()
-%{ /* pure */
- char a;
- STAP_RETVALUE = (long)&a & (THREAD_SIZE-1);
-%}
-
-/**
- * sfunction addr - Address of the current probe point.
- *
- * Description: Returns the instruction pointer from the current probe's
- * register state. Not all probe types have registers though, in which case
- * zero is returned. The returned address is suitable for use with functions
- * like symname() and symdata().
- */
-function addr:long ()
-%{ /* pure */
- if (CONTEXT->probe_flags & _STP_PROBE_STATE_USER_MODE) {
- STAP_RETVALUE = (intptr_t)(CONTEXT->uregs ? REG_IP(CONTEXT->uregs) : 0);
- } else {
- STAP_RETVALUE = (intptr_t)(CONTEXT->kregs ? REG_IP(CONTEXT->kregs) : 0);
- }
-%}
-
-/**
- * sfunction uaddr - User space address of current running task
- *
- * Description: Returns the address in userspace that the current
- * task was at when the probe occurred. When the current running task
- * isn't a user space thread, or the address cannot be found, zero
- * is returned. Can be used to see where the current task is combined
- * with usymname() or usymdata(). Often the task will be in the VDSO
- * where it entered the kernel.
- */
-function uaddr:long ()
-%{ /* pure */ /* myproc-unprivileged */
- struct pt_regs *uregs;
-
- if (CONTEXT->probe_flags & _STP_PROBE_STATE_USER_MODE)
- uregs = CONTEXT->uregs;
- else
- uregs = _stp_current_pt_regs();
-
- if (uregs)
- STAP_RETVALUE = (int64_t) REG_IP(uregs);
- else
- STAP_RETVALUE = 0;
-%}
-
-
/**
* sfunction probe_type - The low level probe handler type of the current probe.
*
break;
}
%}
-
-/**
- * sfunction cmdline_args - Fetch command line arguments from current process
- * @n: First argument to get (zero is the command itself)
- * @m: Last argument to get (or minus one for all arguments after n)
- * @delim: String to use to delimit arguments when more than one.
- *
- * Description: Returns arguments from the current process starting
- * with argument number n, up to argument m. If there are less than n
- * arguments, or the arguments cannot be retrieved from the current
- * process, the empty string is returned. If m is smaller than n then
- * all arguments starting from argument n are returned. Argument zero
- * is traditionally the command itself.
- */
-function cmdline_args:string(n:long, m:long, delim:string)
-{
- args = "";
- mm = @cast(task_current(), "task_struct", "kernel<linux/sched.h>")->mm;
- if (mm)
- {
- arg_start = @cast(mm, "mm_struct", "kernel<linux/sched.h>")->arg_start;
- arg_end = @cast(mm, "mm_struct", "kernel<linux/sched.h>")->arg_end;
- if (arg_start != 0 && arg_end != 0)
- {
- nr = 0;
- len = arg_end - arg_start;
- arg = user_string2(arg_start, "");
- while (len > 0)
- {
- if (nr == n)
- args = arg;
- else if (nr > n)
- {
- if (arg == "")
- args .= delim . "\"\""
- else
- args .= delim . arg;
- }
-
- arg_len = strlen(arg);
- arg_start += arg_len + 1;
- len -= arg_len + 1;
- if (len > 0 && nr != m)
- arg = user_string2(arg_start, "");
- else
- arg = "";
- nr++;
- }
- }
- }
- return args;
-}
-
-/**
- * sfunction cmdline_arg - Fetch a command line argument
- * @n: Argument to get (zero is the command itself)
- *
- * Description: Returns argument the requested argument from the
- * current process or the empty string when there are not that many
- * arguments or there is a problem retrieving the argument. Argument
- * zero is traditionally the command itself.
- */
-function cmdline_arg:string(n:long)
-{
- return cmdline_args(n, n, "");
-}
-
-/**
- * sfunction cmdline_str - Fetch all command line arguments from current process
- *
- * Description: Returns all arguments from the current process
- * delimited by spaces. Returns the empty string when the arguments
- * cannot be retrieved.
- */
-function cmdline_str:string()
-{
- return cmdline_args(0, -1, " ");
-}
--- /dev/null
+// context-envvar tapset
+// Copyright (C) 2012 Red Hat, Inc.
+//
+// This file is part of systemtap, and is free software. You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+
+// NB: functionally equivalent to linux/context-envvar.stp
+
+%{
+#include <stdlib.h>
+%}
+
+function env_var:string(name:string)
+%{ /* pure */
+ // XXX getenv may not be reentrant!
+ const char* env = getenv(STAP_ARG_name);
+ if (env)
+ strlcpy (STAP_RETVALUE, env, MAXSTRINGLEN);
+ else
+ STAP_RETVALUE[0] = '\0';
+
+%}
--- /dev/null
+// context tapset
+// Copyright (C) 2012 Red Hat, Inc.
+//
+// This file is part of systemtap, and is free software. You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+
+// NB: functionally equivalent to linux/context.stp
+
+%{
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+%}
+
+// TODO function print_regs ()
+
+// TODO function execname:string ()
+
+function pid:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = getpid();
+%}
+
+function tid:long ()
+%{ /* pure */ /* unprivileged */
+ /* NB: no glibc wrapper available */
+ STAP_RETVALUE = syscall(SYS_gettid);
+%}
+
+function ppid:long()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = getppid();
+%}
+
+function pgrp:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = getpgrp();
+%}
+
+function sid:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = getsid(0);
+%}
+
+// TODO function pexecname:string ()
+
+function gid:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = getgid();
+%}
+
+function egid:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = getegid();
+%}
+
+function uid:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = getuid();
+%}
+
+function euid:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = geteuid();
+%}
+
+
+// TODO function is_myproc:long ()
+// NB: dyninst by nature is myproc-only, *except if you're root*
+
+// TODO function cpu:long ()
+
+// TODO function registers_valid:long ()
+
+function user_mode:long ()
+{
+ return 1;
+}
+
+// TODO function is_return:long ()
+
+// TODO function target:long ()
+
+// TODO function module_name:string ()
+
+// TODO function stp_pid:long ()
+
+// TODO function remote_id:long ()
+
+// TODO function remote_uri:string ()
+
+// TODO function stack_size:long ()
+
+// TODO function stack_used:long ()
+
+// TODO function stack_unused:long ()
+
+// TODO function addr:long ()
+
+// TODO function uaddr:long ()
+
+// TODO function cmdline_args:string(n:long, m:long, delim:string)
+
+// TODO function cmdline_arg:string(n:long)
+
+// TODO function cmdline_str:string()
--- /dev/null
+/* ctime.stp - Convert seconds to human readable date string.
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ */
+
+/* NB: functionally equivalent to linux/ctime.stp
+ * This means unlike normal userspace ctime(), this version
+ * returns time in UTC, without a final newline.
+ */
+
+%{
+#include <string.h>
+#include <time.h>
+%}
+
+function ctime:string(epochsecs:long)
+%{ /* pure */
+ struct tm gmt;
+ char buf[26];
+
+ const time_t t = STAP_ARG_epochsecs;
+
+ if (gmtime_r(&t, &gmt) && asctime_r(&gmt, buf)) {
+ char* newline = strchr(buf, '\n');
+ if (newline)
+ *newline = '\0';
+ strlcpy (STAP_RETVALUE, buf, MAXSTRINGLEN);
+ } else
+ STAP_RETVALUE[0] = '\0';
+%}
--- /dev/null
+// NB: functionally equivalent to linux/endian.stp
+
+%{
+#include <endian.h>
+%}
+
+function big_endian2:long (val:long) %{ /* pure */
+ STAP_RETVALUE = htobe16((uint16_t)STAP_ARG_val);
+%}
+
+function big_endian4:long (val:long) %{ /* pure */
+ STAP_RETVALUE = htobe32((uint32_t)STAP_ARG_val);
+%}
+
+function big_endian8:long (val:long) %{ /* pure */
+ STAP_RETVALUE = htobe64((uint64_t)STAP_ARG_val);
+%}
+
+function little_endian2:long (val:long) %{ /* pure */
+ STAP_RETVALUE = htole16((uint16_t)STAP_ARG_val);
+%}
+
+function little_endian4:long (val:long) %{ /* pure */
+ STAP_RETVALUE = htole32((uint32_t)STAP_ARG_val);
+%}
+
+function little_endian8:long (val:long) %{ /* pure */
+ STAP_RETVALUE = htole64((uint64_t)STAP_ARG_val);
+%}
--- /dev/null
+// Copyright (C) 2012 Red Hat Inc.
+//
+// This file is part of systemtap, and is free software. You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+//
+
+// NB: functionally equivalent to linux/guru-delay.stp
+
+%{
+#include <time.h>
+%}
+
+function mdelay(ms:long)
+{
+ udelay(ms * 1000);
+}
+
+function udelay(us:long)
+%{ /* guru */
+ struct timespec ts = {
+ STAP_ARG_us / 1000000,
+ STAP_ARG_us % 1000000,
+ };
+ nanosleep(&ts, NULL);
+ // XXX spin on EINTR?
+%}
--- /dev/null
+/* Some functions from libc <arpa/inet.h> */
+
+/* NB: functionally equivalent to linux/inet.stp
+ * ... but we have the advantage of using (mostly) direct equivalents!
+ */
+
+%{
+#include <arpa/inet.h>
+#include <endian.h>
+%}
+
+function htonll:long (x:long)
+%{
+ /* pure */ STAP_RETVALUE = htobe64 ((uint64_t) STAP_ARG_x);
+%}
+
+function htonl:long (x:long)
+%{
+ /* pure */ STAP_RETVALUE = htonl ((uint32_t) STAP_ARG_x);
+%}
+
+function htons:long (x:long)
+%{
+ /* pure */ STAP_RETVALUE = htons ((uint16_t) STAP_ARG_x);
+%}
+
+function ntohll:long (x:long)
+%{
+ /* pure */ STAP_RETVALUE = be64toh ((uint64_t) STAP_ARG_x);
+%}
+
+function ntohl:long (x:long)
+%{
+ /* pure */ STAP_RETVALUE = ntohl ((uint32_t) STAP_ARG_x);
+%}
+
+function ntohs:long (x:long)
+%{
+ /* pure */ STAP_RETVALUE = ntohs ((uint16_t) STAP_ARG_x);
+%}
--- /dev/null
+// timestamp tapset -- gettimeofday variants
+// Copyright (C) 2012 Red Hat, Inc.
+//
+// This file is part of systemtap, and is free software. You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+
+// NB: functionally equivalent to linux/timestamp_gtod.stp
+
+%{
+#include <sys/time.h>
+%}
+
+function gettimeofday_ns:long () {
+ return gettimeofday_us() * 1000; // XXX available resolution isn't this high!
+}
+
+function gettimeofday_us:long () %{ /* pure */ /* unprivileged */
+ struct timeval tv;
+ if (gettimeofday(&tv, NULL) == 0)
+ STAP_RETVALUE = (uint64_t)tv.tv_sec * 1000000 + tv.tv_usec;
+%}
+
+function gettimeofday_ms:long () {
+ return gettimeofday_us() / 1000;
+}
+
+function gettimeofday_s:long () {
+ return gettimeofday_us() / 1000000;
+}
--- /dev/null
+// context tapset
+// Copyright (C) 2005-2011 Red Hat Inc.
+// Copyright (C) 2006 Intel Corporation.
+//
+// This file is part of systemtap, and is free software. You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+// <tapsetdescription>
+// Context functions provide additional information about where an event occurred. These functions can
+//provide information such as a backtrace to where the event occurred and the current register values for the
+//processor.
+// </tapsetdescription>
+
+/**
+ * sfunction print_regs - Print a register dump
+ *
+ * Description: This function prints a register dump. Does nothing if no registers are available for the probe point.
+ */
+function print_regs ()
+%{
+ if ((c->probe_flags & _STP_PROBE_STATE_USER_MODE) && CONTEXT->uregs) {
+ _stp_print_regs (CONTEXT->uregs);
+ } else if (CONTEXT->kregs) {
+ _stp_print_regs (CONTEXT->kregs);
+ }
+%}
+
+/**
+ * sfunction execname - Returns the execname of a target process (or group of processes)
+ *
+ * Description: Returns the execname of a target process (or group of processes).
+ */
+function execname:string ()
+%{ /* pure */ /* unprivileged */
+ strlcpy (STAP_RETVALUE, current->comm, MAXSTRINGLEN);
+%}
+
+/**
+ * sfunction pid - Returns the ID of a target process
+ *
+ * Description: This function returns the ID of a target process.
+ */
+function pid:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = current->tgid;
+%}
+
+/**
+ * sfunction tid - Returns the thread ID of a target process
+ *
+ * Description: This function returns the thread ID of the target process.
+ */
+function tid:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = current->pid;
+%}
+
+/**
+ * sfunction ppid - Returns the process ID of a target process's parent process
+ *
+ * Description: This function return the process ID of the target proccess's parent process.
+ */
+function ppid:long()
+%{ /* pure */ /* unprivileged */
+#if defined(STAPCONF_REAL_PARENT)
+ STAP_RETVALUE = current->real_parent->tgid;
+#else
+ STAP_RETVALUE = current->parent->tgid;
+#endif
+%}
+
+/**
+ * sfunction pgrp - Returns the process group ID of the current process
+ *
+ * Description: This function returns the process group ID of the
+ * current process.
+ */
+function pgrp:long ()
+%{ /* pure */ /* unprivileged */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
+ struct signal_struct *ss = kread( &(current->signal) );
+ STAP_RETVALUE = kread ( &(ss->pgrp) );
+ CATCH_DEREF_FAULT();
+#else
+ STAP_RETVALUE = task_pgrp_nr_ns(current, &init_pid_ns);
+#endif
+%}
+
+/**
+ * sfunction sid - Returns the session ID of the current process
+ *
+ * Description: The session ID of a process is the process group ID
+ * of the session leader. Session ID is stored in the signal_struct
+ * since Kernel 2.6.0.
+ */
+function sid:long ()
+%{ /* pure */ /* unprivileged */
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
+ struct signal_struct *ss = kread( &(current->signal) );
+ STAP_RETVALUE = kread ( &(ss->session) );
+ CATCH_DEREF_FAULT();
+#else
+ STAP_RETVALUE = task_session_nr_ns(current, &init_pid_ns);
+#endif
+%}
+
+/**
+ * sfunction pexecname - Returns the execname of a target process's parent process
+ *
+ * Description: This function returns the execname of a target
+ * process's parent procces.
+ */
+function pexecname:string ()
+%{ /* pure */ /* unprivileged */
+#if defined(STAPCONF_REAL_PARENT)
+ strlcpy (STAP_RETVALUE, current->real_parent->comm, MAXSTRINGLEN);
+#else
+ strlcpy (STAP_RETVALUE, current->parent->comm, MAXSTRINGLEN);
+#endif
+%}
+
+/**
+ * sfunction gid - Returns the group ID of a target process
+ *
+ * Description: This function returns the group ID of a target process.
+ */
+function gid:long ()
+%{ /* pure */ /* unprivileged */
+#ifdef STAPCONF_TASK_UID
+ STAP_RETVALUE = current->gid;
+#else
+ STAP_RETVALUE = current_gid();
+#endif
+%}
+
+/**
+ * sfunction egid - Returns the effective gid of a target process
+ *
+ * Description: This function returns the effective gid of a target process
+ */
+function egid:long ()
+%{ /* pure */ /* unprivileged */
+#ifdef STAPCONF_TASK_UID
+ STAP_RETVALUE = current->egid;
+#else
+ STAP_RETVALUE = current_egid();
+#endif
+%}
+
+/**
+ * sfunction uid - Returns the user ID of a target process
+ *
+ * Description: This function returns the user ID of the target process.
+ */
+function uid:long ()
+%{ /* pure */ /* unprivileged */
+#ifdef STAPCONF_TASK_UID
+ STAP_RETVALUE = current->uid;
+#else
+ STAP_RETVALUE = current_uid();
+#endif
+%}
+
+/**
+ * sfunction euid - Return the effective uid of a target process
+ *
+ * Description: Returns the effective user ID of the target process.
+ */
+function euid:long ()
+%{ /* pure */ /* unprivileged */
+#ifdef STAPCONF_TASK_UID
+ STAP_RETVALUE = current->euid;
+#else
+ STAP_RETVALUE = current_euid();
+#endif
+%}
+
+
+/**
+ * sfunction is_myproc - Determines if the current probe point has occurred in the user's own process
+ *
+ * Description: This function returns 1 if the current probe
+ * point has occurred in the user's own process.
+ */
+function is_myproc:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = is_myproc();
+%}
+
+
+%( systemtap_v <= "1.4" %?
+/**
+ * sfunction cpuid - Returns the current cpu number
+ *
+ * Description: This function returns the current cpu number.
+ * Deprecated in SystemTap 1.4 and removed in SystemTap 1.5.
+ */
+function cpuid:long ()
+%{ /* pure */
+ STAP_RETVALUE = smp_processor_id();
+%}
+%)
+
+/**
+ * sfunction cpu - Returns the current cpu number
+ *
+ * Description: This function returns the current cpu number.
+ */
+function cpu:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = smp_processor_id();
+%}
+
+/**
+ * sfunction registers_valid - Determines validity of register() and u_register() in current context
+ *
+ * Description: This function returns 1 if register() and u_register()
+ * can be used in the current context, or 0 otherwise.
+ * For example, registers_valid() returns 0
+ * when called from a begin or end probe.
+ */
+function registers_valid:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = ((c->probe_flags & _STP_PROBE_STATE_USER_MODE)
+ ? (CONTEXT->uregs != NULL)
+ : (CONTEXT->kregs != NULL));
+%}
+
+/**
+ * sfunction user_mode - Determines if probe point occurs in user-mode
+ *
+ * Return 1 if the probe point occurred in user-mode.
+ */
+function user_mode:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = (CONTEXT->probe_flags
+ & _STP_PROBE_STATE_USER_MODE) ? 1 : 0;
+%}
+
+/**
+ * sfunction is_return - Whether the current probe context is a return probe
+ *
+ * Description: Returns 1 if the current probe context is a return probe,
+ * returns 0 otherwise.
+ */
+function is_return:long ()
+%{ /* pure */
+ if (CONTEXT->probe_type == _STP_PROBE_HANDLER_KRETPROBE
+ || CONTEXT->probe_type == _STP_PROBE_HANDLER_URETPROBE)
+ STAP_RETVALUE = 1;
+ else
+ STAP_RETVALUE = 0;
+%}
+
+/**
+ * sfunction target - Return the process ID of the target process
+ *
+ * Description: This function returns the process ID of the target
+ * process. This is useful in conjunction with the -x PID or
+ * -c CMD command-line options to stap. An example of its use is
+ * to create scripts that filter on a specific process.
+ *
+ * -x <pid>
+ * target() returns the pid specified by -x
+ *
+ * -c <command>
+ * target() returns the pid for the executed command specified by -c
+ */
+function target:long ()
+%{ /* pure */ /* unprivileged */
+ STAP_RETVALUE = _stp_target;
+%}
+
+/**
+ * sfunction module_name - The module name of the current script
+ *
+ * Description: This function returns the name of the stap module.
+ * Either generated randomly (stap_[0-9a-f]+_[0-9a-f]+)
+ * or set by stap -m <module_name>.
+ */
+function module_name:string ()
+%{ /* pure */ /* unprivileged */
+ strlcpy(STAP_RETVALUE, THIS_MODULE->name, MAXSTRINGLEN);
+%}
+
+/**
+ * sfunction stp_pid - The process id of the stapio process
+ *
+ * Description: This function returns the process id of the
+ * stapio process that launched this script. There could be
+ * other SystemTap scripts and stapio processes running on
+ * the system.
+ */
+function stp_pid:long ()
+%{ /* pure */
+ STAP_RETVALUE = _stp_pid;
+%}
+
+
+/**
+ * sfunction remote_id - The index of this instance in a remote execution.
+ *
+ * Description: This function returns a number 0..N, which is the unique
+ * index of this particular script execution from a swarm of
+ * "stap --remote A --remote B ..." runs, and is the same number
+ * "stap --remote-prefix" would print. The function returns -1 if the
+ * script was not launched with "stap --remote", or if the remote
+ * staprun/stapsh are older than version 1.7.
+ */
+function remote_id:long () {
+ return %{ /* pure */ /* unprivileged */ _stp_remote_id %}
+}
+
+
+/**
+ * sfunction remote_uri - The name of this instance in a remote execution.
+ *
+ * Description: This function returns the remote host used to invoke
+ * this particular script execution from a swarm of "stap --remote" runs.
+ * It may not be unique among the swarm.
+ * The function returns an empty string if the script was not launched with
+ * "stap --remote".
+ */
+function remote_uri:string () {
+ return %{ /* string */ /* pure */ /* unprivileged */ _stp_remote_uri %}
+}
+
+
+/**
+ * sfunction stack_size - Return the size of the kernel stack
+ *
+ * Description: This function returns the size of the kernel stack.
+ */
+function stack_size:long ()
+%{ /* pure */
+ STAP_RETVALUE = THREAD_SIZE;
+%}
+
+/**
+ * sfunction stack_used - Returns the amount of kernel stack used
+ *
+ * Description: This function determines how many bytes are
+ * currently used in the kernel stack.
+ */
+function stack_used:long ()
+%{ /* pure */
+ char a;
+ STAP_RETVALUE = THREAD_SIZE - ((long)&a & (THREAD_SIZE-1));
+%}
+
+/**
+ * sfunction stack_unused - Returns the amount of kernel stack currently available
+ *
+ * Description: This function determines how many bytes are
+ * currently available in the kernel stack.
+ */
+function stack_unused:long ()
+%{ /* pure */
+ char a;
+ STAP_RETVALUE = (long)&a & (THREAD_SIZE-1);
+%}
+
+/**
+ * sfunction addr - Address of the current probe point.
+ *
+ * Description: Returns the instruction pointer from the current probe's
+ * register state. Not all probe types have registers though, in which case
+ * zero is returned. The returned address is suitable for use with functions
+ * like symname() and symdata().
+ */
+function addr:long ()
+%{ /* pure */
+ if (CONTEXT->probe_flags & _STP_PROBE_STATE_USER_MODE) {
+ STAP_RETVALUE = (intptr_t)(CONTEXT->uregs ? REG_IP(CONTEXT->uregs) : 0);
+ } else {
+ STAP_RETVALUE = (intptr_t)(CONTEXT->kregs ? REG_IP(CONTEXT->kregs) : 0);
+ }
+%}
+
+/**
+ * sfunction uaddr - User space address of current running task
+ *
+ * Description: Returns the address in userspace that the current
+ * task was at when the probe occurred. When the current running task
+ * isn't a user space thread, or the address cannot be found, zero
+ * is returned. Can be used to see where the current task is combined
+ * with usymname() or usymdata(). Often the task will be in the VDSO
+ * where it entered the kernel.
+ */
+function uaddr:long ()
+%{ /* pure */ /* myproc-unprivileged */
+ struct pt_regs *uregs;
+
+ if (CONTEXT->probe_flags & _STP_PROBE_STATE_USER_MODE)
+ uregs = CONTEXT->uregs;
+ else
+ uregs = _stp_current_pt_regs();
+
+ if (uregs)
+ STAP_RETVALUE = (int64_t) REG_IP(uregs);
+ else
+ STAP_RETVALUE = 0;
+%}
+
+
+/**
+ * sfunction cmdline_args - Fetch command line arguments from current process
+ * @n: First argument to get (zero is the command itself)
+ * @m: Last argument to get (or minus one for all arguments after n)
+ * @delim: String to use to delimit arguments when more than one.
+ *
+ * Description: Returns arguments from the current process starting
+ * with argument number n, up to argument m. If there are less than n
+ * arguments, or the arguments cannot be retrieved from the current
+ * process, the empty string is returned. If m is smaller than n then
+ * all arguments starting from argument n are returned. Argument zero
+ * is traditionally the command itself.
+ */
+function cmdline_args:string(n:long, m:long, delim:string)
+{
+ args = "";
+ mm = @cast(task_current(), "task_struct", "kernel<linux/sched.h>")->mm;
+ if (mm)
+ {
+ arg_start = @cast(mm, "mm_struct", "kernel<linux/sched.h>")->arg_start;
+ arg_end = @cast(mm, "mm_struct", "kernel<linux/sched.h>")->arg_end;
+ if (arg_start != 0 && arg_end != 0)
+ {
+ nr = 0;
+ len = arg_end - arg_start;
+ arg = user_string2(arg_start, "");
+ while (len > 0)
+ {
+ if (nr == n)
+ args = arg;
+ else if (nr > n)
+ {
+ if (arg == "")
+ args .= delim . "\"\""
+ else
+ args .= delim . arg;
+ }
+
+ arg_len = strlen(arg);
+ arg_start += arg_len + 1;
+ len -= arg_len + 1;
+ if (len > 0 && nr != m)
+ arg = user_string2(arg_start, "");
+ else
+ arg = "";
+ nr++;
+ }
+ }
+ }
+ return args;
+}
+
+/**
+ * sfunction cmdline_arg - Fetch a command line argument
+ * @n: Argument to get (zero is the command itself)
+ *
+ * Description: Returns argument the requested argument from the
+ * current process or the empty string when there are not that many
+ * arguments or there is a problem retrieving the argument. Argument
+ * zero is traditionally the command itself.
+ */
+function cmdline_arg:string(n:long)
+{
+ return cmdline_args(n, n, "");
+}
+
+/**
+ * sfunction cmdline_str - Fetch all command line arguments from current process
+ *
+ * Description: Returns all arguments from the current process
+ * delimited by spaces. Returns the empty string when the arguments
+ * cannot be retrieved.
+ */
+function cmdline_str:string()
+{
+ return cmdline_args(0, -1, " ");
+}
--- /dev/null
+// logging tapset
+// Copyright (C) 2005-2011 Red Hat Inc.
+//
+// This file is part of systemtap, and is free software. You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+
+
+/**
+ * sfunction ftrace - Send a message to the ftrace ring-buffer
+ *
+ * @msg: The formatted message string
+ *
+ * Description: If the ftrace ring-buffer is configured & available,
+ * see /debugfs/tracing/trace for the message. Otherwise, the
+ * message may be quietly dropped. An implicit end-of-line is added.
+ */
+function ftrace (msg:string) %{
+#ifdef STAPCONF_TRACE_PRINTK
+ static char *fmt = "%s\n";
+ trace_printk (fmt, STAP_ARG_msg);
+
+ /* The "fmt" is designed to be non __builtin_constant_p(), so as
+ to defeat trace_printk -> __trace_bprintk optimization. That's
+ because bprintk doesn't save the incoming strings, only their
+ addresses. */
+#endif
+%}
+
+
+
+/**
+ * sfunction printk - Send a message to the kernel trace buffer
+ *
+ * @level: an integer for the severity level (0=KERN_EMERG ... 7=KERN_DEBUG)
+ * @msg: The formatted message string
+ *
+ * Description: Print a line of text to the kernel dmesg/console with the
+ * given severity. An implicit end-of-line is added. This function may
+ * not be safely called from all kernel probe contexts, so is restricted
+ * to guru mode only.
+ */
+function printk (level:long,msg:string) %{ /* guru */
+ printk (STAP_ARG_level == 0 ? KERN_EMERG "%s\n":
+ STAP_ARG_level == 1 ? KERN_ALERT "%s\n":
+ STAP_ARG_level == 2 ? KERN_CRIT "%s\n":
+ STAP_ARG_level == 3 ? KERN_ERR "%s\n":
+ STAP_ARG_level == 4 ? KERN_WARNING "%s\n":
+ STAP_ARG_level == 5 ? KERN_NOTICE "%s\n":
+ STAP_ARG_level == 6 ? KERN_INFO "%s\n":
+ STAP_ARG_level == 7 ? KERN_DEBUG "%s\n":
+#ifdef KERN_DEFAULT
+ KERN_DEFAULT "%s\n"
+#else
+ KERN_INFO "%s\n"
+#endif
+ , STAP_ARG_msg);
+%}
function stp_print_binary(n:long, arg1:long, arg2:long, arg3:long, arg4:long) %{
_stp_print_binary (STAP_ARG_n, STAP_ARG_arg1, STAP_ARG_arg2, STAP_ARG_arg3, STAP_ARG_arg4);
%}
-
-
-/**
- * sfunction ftrace - Send a message to the ftrace ring-buffer
- *
- * @msg: The formatted message string
- *
- * Description: If the ftrace ring-buffer is configured & available,
- * see /debugfs/tracing/trace for the message. Otherwise, the
- * message may be quietly dropped. An implicit end-of-line is added.
- */
-function ftrace (msg:string) %{
-#ifdef STAPCONF_TRACE_PRINTK
- static char *fmt = "%s\n";
- trace_printk (fmt, STAP_ARG_msg);
-
- /* The "fmt" is designed to be non __builtin_constant_p(), so as
- to defeat trace_printk -> __trace_bprintk optimization. That's
- because bprintk doesn't save the incoming strings, only their
- addresses. */
-#endif
-%}
-
-
-
-/**
- * sfunction printk - Send a message to the kernel trace buffer
- *
- * @level: an integer for the severity level (0=KERN_EMERG ... 7=KERN_DEBUG)
- * @msg: The formatted message string
- *
- * Description: Print a line of text to the kernel dmesg/console with the
- * given severity. An implicit end-of-line is added. This function may
- * not be safely called from all kernel probe contexts, so is restricted
- * to guru mode only.
- */
-function printk (level:long,msg:string) %{ /* guru */
- printk (STAP_ARG_level == 0 ? KERN_EMERG "%s\n":
- STAP_ARG_level == 1 ? KERN_ALERT "%s\n":
- STAP_ARG_level == 2 ? KERN_CRIT "%s\n":
- STAP_ARG_level == 3 ? KERN_ERR "%s\n":
- STAP_ARG_level == 4 ? KERN_WARNING "%s\n":
- STAP_ARG_level == 5 ? KERN_NOTICE "%s\n":
- STAP_ARG_level == 6 ? KERN_INFO "%s\n":
- STAP_ARG_level == 7 ? KERN_DEBUG "%s\n":
-#ifdef KERN_DEFAULT
- KERN_DEFAULT "%s\n"
-#else
- KERN_INFO "%s\n"
-#endif
- , STAP_ARG_msg);
-%}