diff options
Diffstat (limited to 'runtime/staprun')
-rw-r--r-- | runtime/staprun/common.c | 30 | ||||
-rw-r--r-- | runtime/staprun/mainloop.c | 25 | ||||
-rw-r--r-- | runtime/staprun/staprun.c | 108 | ||||
-rw-r--r-- | runtime/staprun/staprun.h | 1 |
4 files changed, 140 insertions, 24 deletions
diff --git a/runtime/staprun/common.c b/runtime/staprun/common.c index 93da51d8..fd16b4b8 100644 --- a/runtime/staprun/common.c +++ b/runtime/staprun/common.c @@ -14,6 +14,8 @@ #include <sys/types.h> #include <unistd.h> #include <sys/utsname.h> +#include <assert.h> + /* variables needed by parse_args() */ int verbose; @@ -314,3 +316,31 @@ 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. + */ +int send_request(int type, void *data, int len) +{ + char buf[1024]; + int rc = 0; + + /* 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); + + assert (control_channel >= 0); + rc = write (control_channel, buf, len + 4); + if (rc < 0) return rc; + return (rc != len+4); +} diff --git a/runtime/staprun/mainloop.c b/runtime/staprun/mainloop.c index 2bbadbc9..a7b919cb 100644 --- a/runtime/staprun/mainloop.c +++ b/runtime/staprun/mainloop.c @@ -1,6 +1,6 @@ /* -*- linux-c -*- * - * mainloop - staprun main loop + * mainloop - stapio main loop * * 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 @@ -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..cef96815 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,104 @@ 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))) + { + /* NB: even on ppc, we use the _stext relocation name. */ + send_a_relocation ("kernel", "_stext", 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; + rc = init_ctl_channel (modname, 0); + if (rc < 0) goto out; + rc = send_relocation_kernel (); + send_relocation_modules (); + close_ctl_channel (); + out: + 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); |