summaryrefslogtreecommitdiffstats
path: root/runtime/staprun
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/staprun')
-rw-r--r--runtime/staprun/common.c25
-rw-r--r--runtime/staprun/mainloop.c23
-rw-r--r--runtime/staprun/staprun.c102
-rw-r--r--runtime/staprun/staprun.h1
4 files changed, 128 insertions, 23 deletions
diff --git a/runtime/staprun/common.c b/runtime/staprun/common.c
index 93da51d8..dca45e4d 100644
--- a/runtime/staprun/common.c
+++ b/runtime/staprun/common.c
@@ -314,3 +314,28 @@ err:
close(fd);
return -1;
}
+
+
+/**
+ * send_request - send request to kernel over control channel
+ * @type: the relay-app command id
+ * @data: pointer to the data to be sent
+ * @len: length of the data to be sent
+ *
+ * Returns 0 on success, negative otherwise.
+ * XXX: no, it doesn't ... it should return @len on success.
+ */
+int send_request(int type, void *data, int len)
+{
+ char buf[1024];
+
+ /* Before doing memcpy, make sure 'buf' is big enough. */
+ if ((len + 4) > (int)sizeof(buf)) {
+ _err("exceeded maximum send_request size.\n");
+ return -1;
+ }
+ memcpy(buf, &type, 4);
+ memcpy(&buf[4], data, len);
+
+ return write(control_channel, buf, len + 4);
+}
diff --git a/runtime/staprun/mainloop.c b/runtime/staprun/mainloop.c
index 2bbadbc9..42037473 100644
--- a/runtime/staprun/mainloop.c
+++ b/runtime/staprun/mainloop.c
@@ -19,27 +19,6 @@ static int use_old_transport = 0;
//enum _stp_sig_type { sig_none, sig_done, sig_detach };
//static enum _stp_sig_type got_signal = sig_none;
-/**
- * send_request - send request to kernel over control channel
- * @type: the relay-app command id
- * @data: pointer to the data to be sent
- * @len: length of the data to be sent
- *
- * Returns 0 on success, negative otherwise.
- */
-int send_request(int type, void *data, int len)
-{
- char buf[1024];
-
- /* Before doing memcpy, make sure 'buf' is big enough. */
- if ((len + 4) > (int)sizeof(buf)) {
- _err("exceeded maximum send_request size.\n");
- return -1;
- }
- memcpy(buf, &type, 4);
- memcpy(&buf[4], data, len);
- return write(control_channel, buf, len + 4);
-}
static void *signal_thread(void *arg)
{
@@ -308,8 +287,8 @@ int stp_main_loop(void)
setvbuf(ofp, (char *)NULL, _IOLBF, 0);
setup_main_signals();
-
dbug(2, "in main loop\n");
+
send_request(STP_READY, NULL, 0);
/* handle messages from control channel */
diff --git a/runtime/staprun/staprun.c b/runtime/staprun/staprun.c
index 0291d01f..daebe705 100644
--- a/runtime/staprun/staprun.c
+++ b/runtime/staprun/staprun.c
@@ -21,12 +21,17 @@
*/
#include "staprun.h"
+#include <sys/uio.h>
+
/* used in dbug, _err and _perr */
char *__name__ = "staprun";
extern long delete_module(const char *, unsigned int);
+int send_relocations ();
+
+
static int run_as(uid_t uid, gid_t gid, const char *path, char *const argv[])
{
pid_t pid;
@@ -206,6 +211,8 @@ int init_staprun(void)
return -1;
if (insert_stap_module() < 0)
return -1;
+ if (send_relocations() < 0)
+ return -1;
}
return 0;
}
@@ -288,3 +295,98 @@ err:
remove_module(modname, 1);
return 1;
}
+
+
+
+/* Send a variety of relocation-related data to the kernel: for the
+ kernel proper, just the "_stext" symbol address; for all loaded
+ modules, a variety of symbol base addresses.
+
+ We do this under protest. The kernel ought expose this data to
+ modules such as ourselves, but instead the upstream community
+ continually shrinks its module-facing interfaces, including this
+ stuff, even when users exist.
+*/
+
+
+void send_a_relocation (const char* module, const char* reloc, unsigned long long address)
+{
+ struct _stp_msg_relocation msg;
+
+ if (strlen(module) >= STP_MODULE_NAME_LEN)
+ { _perr ("module name too long: %s", module); return; }
+ strcpy (msg.module, module);
+
+ if (strlen(reloc) >= STP_SYMBOL_NAME_LEN)
+ { _perr ("reloc name too long: %s", reloc); return; }
+ strcpy (msg.reloc, reloc);
+
+ msg.address = address;
+
+ send_request (STP_RELOCATION, & msg, sizeof (msg));
+ /* XXX: verify send_request RC */
+}
+
+
+int send_relocation_kernel ()
+{
+ FILE* kallsyms = fopen ("/proc/kallsyms", "r");
+ if (kallsyms == NULL)
+ {
+ perror("cannot open /proc/kallsyms");
+ // ... and the kernel module will almost certainly fail to initialize.
+ }
+ else
+ {
+ while (! feof(kallsyms))
+ {
+ char *line = NULL;
+ size_t linesz = 0;
+ ssize_t linesize = getline (& line, & linesz, kallsyms);
+ if (linesize < 0)
+ break;
+ else
+ {
+ unsigned long long address;
+ char type;
+ char* symbol = NULL;
+ int rc = sscanf (line, "%llx %c %as", &address, &type, &symbol);
+ free (line); line=NULL;
+
+#ifdef __powerpc__
+#define KERNEL_RELOC_SYMBOL ".__start"
+#else
+#define KERNEL_RELOC_SYMBOL "_stext"
+#endif
+ if ((rc == 3) && (0 == strcmp(symbol,KERNEL_RELOC_SYMBOL)))
+ {
+ send_a_relocation ("kernel", KERNEL_RELOC_SYMBOL, address);
+
+ /* We need nothing more from the kernel. */
+ fclose (kallsyms);
+ return 0;
+ }
+ if (symbol != NULL) free (symbol);
+ }
+ }
+ fclose (kallsyms);
+ }
+
+ return -1;
+}
+
+
+void send_relocation_modules ()
+{
+ /* XXX */
+}
+
+
+
+int send_relocations ()
+{
+ int rc = send_relocation_kernel ();
+ send_relocation_modules ();
+ return rc;
+}
+
diff --git a/runtime/staprun/staprun.h b/runtime/staprun/staprun.h
index 60bab391..0a35fee6 100644
--- a/runtime/staprun/staprun.h
+++ b/runtime/staprun/staprun.h
@@ -116,7 +116,6 @@ int init_stapio(void);
int stp_main_loop(void);
int send_request(int type, void *data, int len);
void cleanup_and_exit (int);
-void send_unwind_data(const char *name);
int init_ctl_channel(const char *name, int verb);
void close_ctl_channel(void);
int init_relayfs(void);