Blame SOURCES/rhbz1643997.0016-tapset-bpf-context.stp-add-execname-triage-other-fun.patch

583230
From deb88d0b1fef10177ab197b066f434c720253f8d Mon Sep 17 00:00:00 2001
583230
From: Serhei Makarov <smakarov@redhat.com>
583230
Date: Tue, 30 Oct 2018 17:29:46 -0400
583230
Subject: [PATCH 16/32] tapset/bpf/context.stp :: add execname(), triage other
583230
 functions
583230
583230
* tapset/bpf/context.stp: Notes on other functions that could be added.
583230
(execname): New tapset function.
583230
583230
* tapset/linux/context.stp: Move pexecname() to a more logical location.
583230
---
583230
 tapset/bpf/context.stp   | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
583230
 tapset/linux/context.stp | 30 +++++++++++-----------
583230
 2 files changed, 81 insertions(+), 15 deletions(-)
583230
583230
diff --git a/tapset/bpf/context.stp b/tapset/bpf/context.stp
583230
index 45dcd4d71..55e0f871b 100644
583230
--- a/tapset/bpf/context.stp
583230
+++ b/tapset/bpf/context.stp
583230
@@ -6,6 +6,34 @@
583230
 // Public License (GPL); either version 2, or (at your option) any
583230
 // later version.
583230
 
583230
+/**
583230
+ * sfunction execname - Returns the execname of a target process (or group of processes)
583230
+ *
583230
+ * Description: Returns the execname of a target process (or group of processes).
583230
+ */
583230
+function execname:string ()
583230
+%{ /* bpf */ /* pure */ /* unprivileged */ /* stable */
583230
+  /* buf = bpf_stk_alloc(BPF_MAXSTRINGLEN);
583230
+     buf[0] = 0x0; // guarantee NUL byte
583230
+     rc = get_current_comm(buf, BPF_MAXSTRINGLEN); */
583230
+  alloc, $buf, BPF_MAXSTRINGLEN;
583230
+  0x62, $buf, -, -, 0x0; /* stw [$buf+0], 0x0 -- guarantee NUL byte */
583230
+  call, $rc, get_current_comm, $buf, BPF_MAXSTRINGLEN;
583230
+
583230
+  /* if (rc < 0) return err_msg;
583230
+     return buf; */
583230
+  0xa5, $rc, 0, _err, -; /* jlt $rc, 0, _err */
583230
+  0xbf, $$, $buf, -, -; /* mov $$, $buf */
583230
+  0x05, -, -, _done, -; /* ja _done */
583230
+
583230
+  label, _err;
583230
+  0xbf, $$, "<unknown>", -, -; /* mov $$, <unknown> */
583230
+
583230
+  label, _done;
583230
+%}
583230
+
583230
+// TODO: pexecname ()
583230
+
583230
 /**
583230
  * sfunction pid - Returns the ID of a thread group
583230
  * 
583230
@@ -20,6 +48,8 @@ function pid:long ()
583230
    0x77, $$, 0, 0, 32   /* rshk $$, 32 */
583230
 %}
583230
 
583230
+// TODO: ns_pid:long ()
583230
+
583230
 /**
583230
  * sfunction tid - Returns the thread ID of a target process
583230
  * 
583230
@@ -33,6 +63,14 @@ function tid:long ()
583230
    0xbc, $$, 0, 0, 0    /* movwx $$, r0 */
583230
 %}
583230
 
583230
+// TODO: ns_tid:long ()
583230
+// TODO: ppid:long ()
583230
+// TODO: ns_ppid:long ()
583230
+// TODO: pgrp:long ()
583230
+// TODO: ns_pgrp:long ()
583230
+// TODO: sid:long ()
583230
+// TODO: ns_sid:long ()
583230
+
583230
 /**
583230
  * sfunction gid - Returns the group ID of a target process
583230
  * 
583230
@@ -46,6 +84,10 @@ function gid:long ()
583230
    0x77, $$, 0, 0, 32	/* rshk $$, 32 */
583230
 %}
583230
 
583230
+// TODO: ns_gid:long ()
583230
+// TODO: egid:long ()
583230
+// TODO: ns_egid:long ()
583230
+
583230
 /**
583230
  * sfunction uid - Returns the user ID of a target process
583230
  *
583230
@@ -58,6 +100,12 @@ function uid:long ()
583230
    0xbc, $$, 0, 0, 0	/* movwx $$, r0 */
583230
 %}
583230
 
583230
+// TODO: ns_uid:long ()
583230
+// TODO: euid:long ()
583230
+// TODO: ns_euid:long ()
583230
+// XXX: is_myproc () is only relevant for unprivileged use of eBPF (still theoretical).
583230
+
583230
+// TODO: Old systemtap-compat scripts should not be running on eBPF backend in the first place?
583230
 /**
583230
  * sfunction cpuid - Returns the current cpu number
583230
  * 
583230
@@ -82,3 +130,21 @@ function cpu:long ()
583230
    0x85, 0, 0, 0, 8;	/* call BPF_FUNC_get_smp_processor_id */
583230
    0xbf, $$, 0, 0, 0	/* movx $$, r0 */
583230
 %}
583230
+
583230
+// TODO: registers_valid:long ()
583230
+// TODO: user_mode:long ()
583230
+// TODO: is_return:long ()
583230
+// TODO: target:long ()
583230
+// TODO: module_name:string ()
583230
+// XXX: module_size:string () -- not clear if this should refer to the entire .bo or to just the current eBPF routine.
583230
+// TODO: stp_pid:long ()
583230
+// XXX: remote_id:long (), remote_uri:string() -- pending an evaluation of remote eBPF execution.
583230
+// XXX: stack_size() -- not clear if this should be the eBPF stack size or the kernel stack size.
583230
+// XXX: stack_used(),stack_unused() probably a fairly ill-defined idea with the eBPF stack.
583230
+// TODO: Other context functions for info about things like eBPF maps.
583230
+
583230
+// TODO: addr:long ()
583230
+// TODO: uaddr:long ()
583230
+// XXX: cmdline_args:string(n:long, m:long, delim:string) -- requires string concatenation & loops.
583230
+// TODO: cmdline_arg:string(n:long)
583230
+// XXX: cmdline_string:string() -- requires string concatenation & loops.
583230
diff --git a/tapset/linux/context.stp b/tapset/linux/context.stp
583230
index 2bd405186..46b1f6b32 100644
583230
--- a/tapset/linux/context.stp
583230
+++ b/tapset/linux/context.stp
583230
@@ -19,6 +19,21 @@ function execname:string ()
583230
 	strlcpy (STAP_RETVALUE, current->comm, MAXSTRINGLEN);
583230
 %}
583230
 
583230
+/**
583230
+ * sfunction pexecname - Returns the execname of a target process's parent process
583230
+ *
583230
+ * Description: This function returns the execname of a target
583230
+ * process's parent procces.
583230
+ */
583230
+function pexecname:string ()
583230
+%{ /* pure */ /* unprivileged */ /* stable */
583230
+#if defined(STAPCONF_REAL_PARENT)
583230
+	strlcpy (STAP_RETVALUE, current->real_parent->comm, MAXSTRINGLEN);
583230
+#else
583230
+	strlcpy (STAP_RETVALUE, current->parent->comm, MAXSTRINGLEN);
583230
+#endif
583230
+%}
583230
+
583230
 /**
583230
  * sfunction pid - Returns the ID of a target process
583230
  *
583230
@@ -153,21 +168,6 @@ function ns_sid:long ()
583230
   else STAP_RETURN (rc);
583230
 %}
583230
 
583230
-/**
583230
- * sfunction pexecname - Returns the execname of a target process's parent process
583230
- *
583230
- * Description: This function returns the execname of a target
583230
- * process's parent procces.
583230
- */
583230
-function pexecname:string ()
583230
-%{ /* pure */ /* unprivileged */ /* stable */
583230
-#if defined(STAPCONF_REAL_PARENT)
583230
-	strlcpy (STAP_RETVALUE, current->real_parent->comm, MAXSTRINGLEN);
583230
-#else
583230
-	strlcpy (STAP_RETVALUE, current->parent->comm, MAXSTRINGLEN);
583230
-#endif
583230
-%}
583230
-
583230
 /**
583230
  * sfunction gid - Returns the group ID of a target process
583230
  *
583230
-- 
583230
2.14.5
583230