summaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/bench2/bench.rb21
-rw-r--r--runtime/staprun/ChangeLog22
-rw-r--r--runtime/staprun/mainloop.c3
-rw-r--r--runtime/staprun/staprun.h5
-rw-r--r--runtime/staprun/staprun_funcs.c36
-rw-r--r--runtime/staprun/symbols.c214
-rw-r--r--runtime/transport/ChangeLog23
-rw-r--r--runtime/transport/control.c45
-rw-r--r--runtime/transport/procfs.c38
-rw-r--r--runtime/transport/symbols.c95
-rw-r--r--runtime/transport/transport.c32
-rw-r--r--runtime/transport/transport_msgs.h42
12 files changed, 369 insertions, 207 deletions
diff --git a/runtime/bench2/bench.rb b/runtime/bench2/bench.rb
index a671b582..b3e30204 100644
--- a/runtime/bench2/bench.rb
+++ b/runtime/bench2/bench.rb
@@ -138,9 +138,8 @@ class Bench
end
def load
- args = "-q"
- fork do exec "sudo #{@@staprun} #{args} -o #{@outfile} #{@dir}/bench.ko &> #{@dir}/xxx.out" end
- sleep 10
+ fork do exec "sudo #{@@staprun} -o #{@outfile} #{@dir}/bench.ko &> #{@dir}/xxx.out" end
+ sleep 5
end
def compile
@@ -287,10 +286,8 @@ class Stapbench < Bench
protected
def load
- args = "-vv -DSTP_NO_OVERLOAD"
- if @trans == BULK then args = "-bvv -DSTP_NO_OVERLOAD" end
- fork do exec "stap #{args} -o #{@outfile} bench.stp &> xxx.out" end
- sleep 30
+ fork do exec "sudo #{@@staprun} bench.ko &> xxx.out" end
+ sleep 5
end
def compile
@@ -316,6 +313,14 @@ class Stapbench < Bench
else
puts "NO CODE!"
end
+ args = "-p4 -vv -DSTP_NO_OVERLOAD"
+ if @trans == BULK then args = "-p4 -bvv -DSTP_NO_OVERLOAD" end
+ `stap #{args} -m bench.ko bench.stp &> xxx.out`
+ if ($? != 0)
+ puts "compile failed. status=#{$?}"
+ system("tail xxx.out")
+ exit
+ end
end
-
+
end
diff --git a/runtime/staprun/ChangeLog b/runtime/staprun/ChangeLog
index a7b00a9c..3f373863 100644
--- a/runtime/staprun/ChangeLog
+++ b/runtime/staprun/ChangeLog
@@ -1,3 +1,25 @@
+2008-01-14 Martin Hunt <hunt@redhat.com>
+
+ PR4037 and fixes to better synchronize staprun and stapio.
+ * symbols.c (send_data): Send header and data seperately, saving
+ a memcpy and avoiding any alignment issues.
+ (get_sections): Return -1 on error instead of just exiting
+ and leaving stapio hanging. Send data in proper format even if kernel
+ pointers are different size.
+ (send_module): Return -1 on error instead of just exiting
+ and leaving stapio hanging.
+ (do_module): Ditto.
+ (compar): Removed.
+ (do_kernel_symbols): Rewrite to be more robust. Return -1 on
+ error instead of just exiting and leaving stapio hanging.
+
+ * staprun_funcs.c (handle_symbols): Signal stapio if we error out.
+ Set kernel_ptr_size;
+
+ * staprun.h (kernel_ptr_size): Declare.
+
+ * mainloop.c (stp_main_loop): When ready, send STP_READY.
+
2008-01-12 Frank Ch. Eigler <fche@elastic.org>
PR 5603 horrible hack.
diff --git a/runtime/staprun/mainloop.c b/runtime/staprun/mainloop.c
index d8975d18..2e0c3c5c 100644
--- a/runtime/staprun/mainloop.c
+++ b/runtime/staprun/mainloop.c
@@ -7,7 +7,7 @@
* Public License (GPL); either version 2, or (at your option) any
* later version.
*
- * Copyright (C) 2005-2007 Red Hat Inc.
+ * Copyright (C) 2005-2008 Red Hat Inc.
*/
#include "staprun.h"
@@ -255,6 +255,7 @@ int stp_main_loop(void)
setup_main_signals(0);
dbug(2, "in main loop\n");
+ send_request(STP_READY, NULL, 0);
while (1) { /* handle messages from control channel */
nb = read(control_channel, recvbuf, sizeof(recvbuf));
diff --git a/runtime/staprun/staprun.h b/runtime/staprun/staprun.h
index c22cc4f3..1128fb4c 100644
--- a/runtime/staprun/staprun.h
+++ b/runtime/staprun/staprun.h
@@ -7,7 +7,7 @@
* Public License (GPL); either version 2, or (at your option) any
* later version.
*
- * Copyright (C) 2005-2007 Red Hat Inc.
+ * Copyright (C) 2005-2008 Red Hat Inc.
*/
#include <stdio.h>
@@ -119,7 +119,7 @@ int stp_main_loop(void);
int send_request(int type, void *data, int len);
void cleanup_and_exit (int);
int do_module(void *);
-void do_kernel_symbols(void);
+int do_kernel_symbols(void);
int init_ctl_channel(int);
void close_ctl_channel(void);
int init_relayfs(void);
@@ -156,6 +156,7 @@ int set_clexec(int fd);
extern int control_channel;
extern int ncpus;
extern int initialized;
+extern int kernel_ptr_size;
/* flags */
extern int verbose;
diff --git a/runtime/staprun/staprun_funcs.c b/runtime/staprun/staprun_funcs.c
index 86a72985..ebf05b34 100644
--- a/runtime/staprun/staprun_funcs.c
+++ b/runtime/staprun/staprun_funcs.c
@@ -7,7 +7,7 @@
* Public License (GPL); either version 2, or (at your option) any
* later version.
*
- * Copyright (C) 2007 Red Hat Inc.
+ * Copyright (C) 2007-2008 Red Hat Inc.
*/
#include "staprun.h"
@@ -16,6 +16,8 @@
#include <grp.h>
#include <pwd.h>
+void cleanup(int rc);
+
void setup_staprun_signals(void)
{
struct sigaction a;
@@ -386,18 +388,20 @@ int check_permissions(void)
}
pthread_t symbol_thread_id = (pthread_t)0;
+int kernel_ptr_size = 0;
/* Symbol handling thread */
void *handle_symbols(void __attribute__((unused)) *arg)
{
ssize_t nb;
void *data;
- int type;
+ int32_t type;
char recvbuf[8192];
dbug(2, "waiting for symbol requests\n");
- while (1) { /* handle messages from control channel */
+ /* handle messages from control channel */
+ while (1) {
nb = read(control_channel, recvbuf, sizeof(recvbuf));
if (nb <= 0) {
if (errno != EINTR)
@@ -405,14 +409,15 @@ void *handle_symbols(void __attribute__((unused)) *arg)
continue;
}
- type = *(int *)recvbuf;
- data = (void *)(recvbuf + sizeof(int));
-
+ type = *(int32_t *)recvbuf;
+ data = (void *)(recvbuf + sizeof(int32_t));
+
switch (type) {
case STP_MODULE:
{
dbug(2, "STP_MODULES request received\n");
- do_module(data);
+ if (do_module(data) < 0)
+ goto done;
break;
}
case STP_SYMBOLS:
@@ -421,14 +426,15 @@ void *handle_symbols(void __attribute__((unused)) *arg)
dbug(2, "STP_SYMBOLS request received\n");
if (req->endian != 0x1234) {
err("ERROR: staprun is compiled with different endianess than the kernel!\n");
- exit(1);
+ goto done;
}
- if (req->ptr_size != sizeof(char *)) {
- err("ERROR: staprun is compiled with %d-bit pointers and the kernel uses %d-bit.\n",
- 8*(int)sizeof(char *), 8*req->ptr_size);
- exit(1);
+ kernel_ptr_size = req->ptr_size;
+ if (kernel_ptr_size != 4 && kernel_ptr_size != 8) {
+ err("ERROR: invalid kernel pointer size %d\n", kernel_ptr_size);
+ goto done;
}
- do_kernel_symbols();
+ if (do_kernel_symbols() < 0)
+ goto done;
break;
}
default:
@@ -436,6 +442,10 @@ void *handle_symbols(void __attribute__((unused)) *arg)
}
}
+done:
+ /* signal stapio we're done */
+ kill(0, SIGINT);
+
return NULL;
}
diff --git a/runtime/staprun/symbols.c b/runtime/staprun/symbols.c
index e4d96ee0..5a4855b3 100644
--- a/runtime/staprun/symbols.c
+++ b/runtime/staprun/symbols.c
@@ -1,7 +1,7 @@
/* -*- linux-c -*-
* Symbols and modules functions for staprun.
*
- * Copyright (C) 2006, 2007 Red Hat Inc.
+ * Copyright (C) 2006-2008 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
@@ -10,16 +10,19 @@
*/
#include "staprun.h"
-#include "../sym.h"
+/* send symbol data */
static int send_data(void *data, int len)
{
+ int32_t type = STP_SYMBOLS;
+ if (write(control_channel, &type, 4) <= 0)
+ return -1;
return write(control_channel, data, len);
}
/* Get the sections for a module. Put them in the supplied buffer */
/* in the following order: */
-/* [struct _stp_module][struct _stp_symbol sections ...][string data] */
+/* [struct _stp_msg_module][struct _stp_symbol sections ...][string data]*/
/* Return the total length of all the data. */
#define SECDIR "/sys/module/%s/sections"
@@ -30,33 +33,35 @@ static int get_sections(char *name, char *data_start, int datalen)
char buf[32], strdata_start[32768];
char *strdata=strdata_start, *data=data_start;
int fd, len, res;
- struct _stp_module *mod = (struct _stp_module *)data_start;
+ struct _stp_msg_module *mod = (struct _stp_msg_module *)data_start;
struct dirent *d;
DIR *secdir;
- struct _stp_symbol *sec;
+ void *sec;
+ int struct_symbol_size = kernel_ptr_size == 8 ? sizeof(struct _stp_symbol64) : sizeof(struct _stp_symbol32);
+ uint64_t sec_addr;
- /* start of data is a struct _stp_module */
- data += sizeof(struct _stp_module);
+ /* start of data is a struct _stp_msg_module */
+ data += sizeof(struct _stp_msg_module);
res = snprintf(dir, sizeof(dir), SECDIR, name);
if (res >= (int)sizeof(dir)) {
_err("Couldn't fit module \"%s\" into dir buffer.\n" \
"This should never happen. Please file a bug report.\n", name);
- exit(1);
+ return -1;
}
if ((secdir = opendir(dir)) == NULL)
return 0;
/* Initialize mod. */
- memset(mod, 0, sizeof(struct _stp_module));
+ memset(mod, 0, sizeof(struct _stp_msg_module));
/* Copy name in and check for overflow. */
strncpy(mod->name, name, STP_MODULE_NAME_LEN);
if (mod->name[STP_MODULE_NAME_LEN - 1] != '\0') {
_err("Couldn't fit module \"%s\" into mod->name buffer.\n" \
"This should never happen. Please file a bug report.\n", name);
- exit(1);
+ return -1;
}
while ((d = readdir(secdir))) {
@@ -68,7 +73,7 @@ static int get_sections(char *name, char *data_start, int datalen)
_err("Couldn't fit secname \"%s\" into filename buffer.\n" \
"This should never happen. Please file a bug report.\n", secname);
closedir(secdir);
- exit(1);
+ return -1;
}
/* filter out some non-useful stuff */
@@ -88,12 +93,19 @@ static int get_sections(char *name, char *data_start, int datalen)
if ((fd = open(filename,O_RDONLY)) >= 0) {
if (read(fd, buf, 32) > 0) {
/* create next section */
- sec = (struct _stp_symbol *)data;
- if (data - data_start + (int)sizeof(struct _stp_symbol) > datalen)
+ sec = data;
+ if (data - data_start + struct_symbol_size > datalen)
goto err1;
- data += sizeof(struct _stp_symbol);
- sec->addr = strtoul(buf,NULL,16);
- sec->symbol = (char *)(strdata - strdata_start);
+ data += struct_symbol_size;
+
+ sec_addr = (uint64_t)strtoull(buf,NULL,16);
+ if (kernel_ptr_size == 8) {
+ ((struct _stp_symbol64 *)sec)->addr = sec_addr;
+ ((struct _stp_symbol64 *)sec)->symbol = (uint64_t)(strdata - strdata_start);
+ } else {
+ ((struct _stp_symbol32 *)sec)->addr = (uint32_t)sec_addr;
+ ((struct _stp_symbol32 *)sec)->symbol = (uint32_t)(strdata - strdata_start);
+ }
mod->num_sections++;
/* now create string data for the
@@ -106,13 +118,13 @@ static int get_sections(char *name, char *data_start, int datalen)
/* These sections are used a lot so keep the values handy */
if (!strcmp(secname, ".data") || !strncmp(secname, ".rodata", 7)) {
- if (mod->data == 0 || sec->addr < mod->data)
- mod->data = sec->addr;
+ if (mod->data == 0 || sec_addr < mod->data)
+ mod->data = sec_addr;
}
if (!strcmp(secname, ".text"))
- mod->text = sec->addr;
+ mod->text = sec_addr;
if (!strcmp(secname, ".gnu.linkonce.this_module"))
- mod->module = sec->addr;
+ mod->module = sec_addr;
}
close(fd);
}
@@ -135,56 +147,55 @@ err1:
err0:
/* if this happens, something went seriously wrong. */
_err("Unexpected error. Overflowed buffers.\n");
- exit(1);
- return 0; /* not reached */
+ return -1;
}
#undef SECDIR
/*
* For modules, we send the name, section names, and offsets
*/
-static void send_module (char *mname)
+static int send_module (char *mname)
{
- char data[32768];
- int len = get_sections(mname, data, sizeof(data));
- if (len) {
- if (send_request(STP_MODULE, data, len) < 0) {
+ char data[65536];
+ int len;
+ *(int32_t *)data = STP_MODULE;
+ len = get_sections(mname, data + sizeof(int32_t),
+ sizeof(data) - sizeof(int32_t));
+ if (len > 0) {
+ if (write(control_channel, data, len + sizeof(int32_t)) <= 0) {
_err("Loading of module %s failed. Exiting...\n", mname);
- exit(1);
+ return -1;
}
}
+ return len;
}
/*
* Send either all modules, or a specific one.
+ * Returns:
+ * >=0 : OK
+ * -1 : serious error (exit)
*/
int do_module (void *data)
{
- struct _stp_module *mod = (struct _stp_module *)data;
+ struct _stp_msg_module *mod = (struct _stp_msg_module *)data;
if (mod->name[0] == 0) {
struct dirent *d;
DIR *moddir = opendir("/sys/module");
if (moddir) {
while ((d = readdir(moddir)))
- send_module(d->d_name);
+ if (send_module(d->d_name) < 0) {
+ closedir(moddir);
+ return -1;
+ }
closedir(moddir);
}
- send_request(STP_MODULE, data, 0);
- return 1;
+ send_request(STP_MODULE, data, 1);
+ return 0;
}
- send_module(mod->name);
- return 0;
-}
-
-static int compar(const void *p1, const void *p2)
-{
- struct _stp_symbol *s1 = (struct _stp_symbol *)p1;
- struct _stp_symbol *s2 = (struct _stp_symbol *)p2;
- if (s1->addr == s2->addr) return 0;
- if (s1->addr < s2->addr) return -1;
- return 1;
+ return send_module(mod->name);
}
#define MAX_SYMBOLS 32*1024
@@ -194,29 +205,29 @@ static int compar(const void *p1, const void *p2)
* systemtap module. Ignore module symbols; the systemtap module
* can access them directly.
*/
-void do_kernel_symbols(void)
+int do_kernel_symbols(void)
{
FILE *kallsyms=NULL;
- char *sym_base=NULL, *data_base=NULL;
- char buf[256], *ptr, *name, *data, *dataptr, *datamax, type;
- unsigned long addr;
- struct _stp_symbol *syms;
- int num_syms, i = 0, max_syms= MAX_SYMBOLS;
- int data_basesize = MAX_SYMBOLS*32;
-
- sym_base = malloc(max_syms*sizeof(struct _stp_symbol)+sizeof(long));
+ char *name, *mod, *dataptr, *datamax, type, *data_base=NULL;
+ unsigned long long addr;
+ void *syms = NULL;
+ int ret, num_syms, i = 0, struct_symbol_size;
+ int max_syms= MAX_SYMBOLS, data_basesize = MAX_SYMBOLS*32;
+
+ if (kernel_ptr_size == 8)
+ struct_symbol_size = sizeof(struct _stp_symbol64);
+ else
+ struct_symbol_size = sizeof(struct _stp_symbol32);
+
+ syms = malloc(max_syms * struct_symbol_size);
data_base = malloc(data_basesize);
- if (data_base == NULL || sym_base == NULL) {
+ if (data_base == NULL || syms == NULL) {
_err("Failed to allocate memory for symbols\n");
goto err;
}
- *(int *)data_base = STP_SYMBOLS;
- dataptr = data = data_base + sizeof(long);
+ dataptr = data_base;
datamax = data_base + data_basesize;
- *(int *)sym_base = STP_SYMBOLS;
- syms = (struct _stp_symbol *)(sym_base + sizeof(long));
-
kallsyms = fopen ("/proc/kallsyms", "r");
if (!kallsyms) {
_perr("Fatal error: Unable to open /proc/kallsyms");
@@ -226,35 +237,28 @@ void do_kernel_symbols(void)
/* put empty string in data */
*dataptr++ = 0;
- while (fgets_unlocked(buf, 256, kallsyms) && dataptr < datamax) {
- addr = strtoul(buf, &ptr, 16);
- while (isspace(*ptr)) ptr++;
- type = *ptr++;
+ while ((ret = fscanf(kallsyms, "%llx %c %as [%as", &addr, &type, &name, &mod))>0
+ && dataptr < datamax) {
+ if (ret < 3)
+ continue;
+ if (ret > 3) {
+ /* ignore modules */
+ free(name);
+ free(mod);
+ /* modules are loaded above the kernel, so if we */
+ /* are getting modules, then we're done. */
+ break;
+ }
+
if (type == 't' || type == 'T' || type == 'A') {
- while (isspace(*ptr)) ptr++;
- name = ptr++;
- while (!isspace(*ptr)) ptr++;
- *ptr++ = 0;
- while (*ptr && *ptr != '[') ptr++;
- if (*ptr)
- continue; /* it was a module */
- syms[i].addr = addr;
- syms[i].symbol = (char *)(dataptr - data);
- while (*name) *dataptr++ = *name++;
- *dataptr++ = 0;
- i++;
- if (i >= max_syms) {
- char *s;
- max_syms *= 2;
- s = realloc(sym_base, max_syms*sizeof(struct _stp_symbol)+sizeof(long));
- if (s == NULL) {
- _err("Could not allocate enough space for symbols.\n");
- goto err;
- }
- syms = (struct _stp_symbol *)(s + sizeof(long));
- sym_base = s;
- }
- if (dataptr > datamax - 1024) {
+ if (kernel_ptr_size == 8) {
+ ((struct _stp_symbol64 *)syms)[i].addr = (uint64_t)addr;
+ ((struct _stp_symbol64 *)syms)[i].symbol = (uint64_t)(dataptr - data_base);
+ } else {
+ ((struct _stp_symbol32 *)syms)[i].addr = (uint32_t)addr;
+ ((struct _stp_symbol32 *)syms)[i].symbol = (uint32_t)(dataptr - data_base);
+ }
+ if (dataptr >= datamax - strlen(name)) {
char *db;
data_basesize *= 2;
db = realloc(data_base, data_basesize);
@@ -263,43 +267,55 @@ void do_kernel_symbols(void)
goto err;
}
dataptr = db + (dataptr - data_base);
- data = db + sizeof(long);
datamax = db + data_basesize;
data_base = db;
}
+ strcpy(dataptr, name);
+ dataptr += strlen(name) + 1;
+ free(name);
+ i++;
+ if (i >= max_syms) {
+ max_syms *= 2;
+ syms = realloc(syms, max_syms*struct_symbol_size);
+ if (syms == NULL) {
+ _err("Could not allocate enough space for symbols.\n");
+ goto err;
+ }
+ }
}
}
num_syms = i;
- qsort(syms, num_syms, sizeof(struct _stp_symbol), compar);
+ if (num_syms <= 0)
+ goto err;
/* send header */
- *(int *)buf = STP_SYMBOLS;
- *(int *)(buf+sizeof(long)) = num_syms;
- *(int *)(buf+sizeof(long)+sizeof(int)) = (unsigned)(dataptr - data);
- if (send_data(buf, 2*sizeof(int)+sizeof(long)) < 0)
+ struct _stp_msg_symbol_hdr smsh;
+ smsh.num_syms = num_syms;
+ smsh.sym_size = (uint32_t)(dataptr - data_base);
+ if (send_request(STP_SYMBOLS, &smsh, sizeof(smsh)) <= 0)
goto err;
/* send syms */
- if (send_data(sym_base, num_syms*sizeof(struct _stp_symbol)+sizeof(long)) < 0)
+ if (send_data(syms, num_syms*struct_symbol_size) < 0)
goto err;
/* send data */
- if (send_data(data_base, dataptr-data+sizeof(long)) < 0)
+ if (send_data(data_base, dataptr-data_base) < 0)
goto err;
free(data_base);
- free(sym_base);
+ free(syms);
fclose(kallsyms);
- return;
+ return 0;
err:
if (data_base)
free(data_base);
- if (sym_base)
- free(sym_base);
+ if (syms)
+ free(syms);
if (kallsyms)
fclose(kallsyms);
_err("Loading of symbols failed. Exiting...\n");
- exit(1);
+ return -1;
}
diff --git a/runtime/transport/ChangeLog b/runtime/transport/ChangeLog
index 26268e66..e7bbabd8 100644
--- a/runtime/transport/ChangeLog
+++ b/runtime/transport/ChangeLog
@@ -1,4 +1,27 @@
2008-01-15 Martin Hunt <hunt@redhat.com>
+
+ PR4037 and fixes to better synchronize staprun and stapio.
+ * transport_msgs.h (struct _stp_symbol32): New.
+ (struct _stp_symbol64): New.
+ (struct _stp_msg_symbol_hdr): New.
+ (struct _stp_msg_module): New.
+ (STP_READY): Declare.
+
+ * transport.c (_stp_handle_start): Don't set _stp_start_finished.
+ (_stp_work_queue): Don't use _stp_start_finished.
+ (_stp_transport_init): Don't call _stp_ask_for_symbols().
+
+ * symbols.c (_stp_do_symbols): Use _stp_msg_symbol_hdr;
+
+ * control.c (_stp_sym_write_cmd): Allow sending of headers
+ and data in separate messages.
+ (_stp_ctl_write_cmd): Add STP_READY message.
+
+ * procfs.c (_stp_sym_write_cmd): Allow sending of headers
+ and data in separate messages.
+ (_stp_ctl_write_cmd): Add STP_READY message.
+
+2008-01-15 Martin Hunt <hunt@redhat.com>
Support for DEBUG_MEM
* transport.c (_stp_transport): Call stp_mem_debug_done();
diff --git a/runtime/transport/control.c b/runtime/transport/control.c
index 3cfeca1e..3179f507 100644
--- a/runtime/transport/control.c
+++ b/runtime/transport/control.c
@@ -1,7 +1,7 @@
/* -*- linux-c -*-
*
* debugfs control channel
- * Copyright (C) 2007, 2008 Red Hat Inc.
+ * Copyright (C) 2007 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
@@ -22,38 +22,44 @@ spinlock_t _stp_sym_ready_lock = SPIN_LOCK_UNLOCKED;
static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
+ static int saved_type = 0;
int type;
- if (count < sizeof(int))
+ if (count < sizeof(int32_t))
return 0;
- if (get_user(type, (int __user *)buf))
- return -EFAULT;
-
- kbug ("count:%d type:%d\n", count, type);
-
- if (type == STP_SYMBOLS) {
- count -= sizeof(long);
- buf += sizeof(long);
+ /* Allow sending of packet type followed by data in the next packet.*/
+ if (count == sizeof(int32_t)) {
+ if (get_user(saved_type, (int __user *)buf))
+ return -EFAULT;
+ return count;
+ } else if (saved_type) {
+ type = saved_type;
+ saved_type = 0;
} else {
+ if (get_user(type, (int __user *)buf))
+ return -EFAULT;
count -= sizeof(int);
buf += sizeof(int);
}
+
+ kbug ("count:%d type:%d\n", (int)count, type);
switch (type) {
- case STP_SYMBOLS:
-
- if (count)
- count = _stp_do_symbols(buf, count);
+ case STP_SYMBOLS:
+ count = _stp_do_symbols(buf, count);
break;
case STP_MODULE:
- if (count)
+ if (count > 1)
count = _stp_do_module(buf, count);
else {
- /* count == 0 indicates end of initial modules list */
+ /* count == 1 indicates end of initial modules list */
_stp_ctl_send(STP_TRANSPORT, NULL, 0);
}
break;
+ case STP_EXIT:
+ _stp_exit_flag = 1;
+ break;
default:
errk ("invalid symbol command type %d\n", type);
return -EINVAL;
@@ -73,7 +79,7 @@ static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
if (get_user(type, (int __user *)buf))
return -EFAULT;
- // kbug ("count:%d type:%d\n", count, type);
+ kbug ("count:%d type:%d\n", (int)count, type);
count -= sizeof(int);
buf += sizeof(int);
@@ -99,6 +105,11 @@ static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
#else
return -1;
#endif
+ case STP_READY:
+ /* request symbolic information */
+ _stp_ask_for_symbols();
+ break;
+
default:
errk ("invalid command type %d\n", type);
return -EINVAL;
diff --git a/runtime/transport/procfs.c b/runtime/transport/procfs.c
index 5d40cae4..85e97d15 100644
--- a/runtime/transport/procfs.c
+++ b/runtime/transport/procfs.c
@@ -68,35 +68,38 @@ static struct file_operations _stp_proc_fops = {
static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
+ static int saved_type = 0;
int type;
- if (count < sizeof(int))
+ if (count < sizeof(int32_t))
return 0;
- if (get_user(type, (int __user *)buf))
- return -EFAULT;
-
- kbug ("count:%d type:%d\n", (int)count, type);
-
- if (type == STP_SYMBOLS) {
- count -= sizeof(long);
- buf += sizeof(long);
+ /* Allow sending of packet type followed by data in the next packet.*/
+ if (count == sizeof(int32_t)) {
+ if (get_user(saved_type, (int __user *)buf))
+ return -EFAULT;
+ return count;
+ } else if (saved_type) {
+ type = saved_type;
+ saved_type = 0;
} else {
+ if (get_user(type, (int __user *)buf))
+ return -EFAULT;
count -= sizeof(int);
buf += sizeof(int);
}
+
+ // kbug ("count:%d type:%d\n", (int)count, type);
switch (type) {
- case STP_SYMBOLS:
-
- if (count)
- count = _stp_do_symbols(buf, count);
+ case STP_SYMBOLS:
+ count = _stp_do_symbols(buf, count);
break;
case STP_MODULE:
- if (count)
+ if (count > 1)
count = _stp_do_module(buf, count);
else {
- /* count == 0 indicates end of initial modules list */
+ /* count == 1 indicates end of initial modules list */
_stp_ctl_send(STP_TRANSPORT, NULL, 0);
}
break;
@@ -106,6 +109,7 @@ static ssize_t _stp_sym_write_cmd (struct file *file, const char __user *buf,
}
return count;
+
}
static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
@@ -139,6 +143,10 @@ static ssize_t _stp_ctl_write_cmd (struct file *file, const char __user *buf,
case STP_EXIT:
_stp_exit_flag = 1;
break;
+ case STP_READY:
+ /* request symbolic information */
+ _stp_ask_for_symbols();
+ break;
default:
errk ("invalid command type %d\n", type);
return -EINVAL;
diff --git a/runtime/transport/symbols.c b/runtime/transport/symbols.c
index a3ab5807..dde0f967 100644
--- a/runtime/transport/symbols.c
+++ b/runtime/transport/symbols.c
@@ -1,7 +1,7 @@
/* -*- linux-c -*-
* symbols.c - stp symbol and module functions
*
- * Copyright (C) Red Hat Inc, 2006, 2007
+ * Copyright (C) Red Hat Inc, 2006-2008
*
* 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
@@ -84,15 +84,19 @@ static struct _stp_module * _stp_alloc_module(unsigned num, unsigned datasize)
goto bad;
mod->allocated |= 2;
}
+
mod->num_symbols = num;
return mod;
bad:
if (mod) {
- if (mod->allocated && mod->symbols)
- _stp_vfree(mod->symbols);
- else
- _stp_kfree(mod->symbols);
+ if (mod->symbols) {
+ if (mod->allocated & 1)
+ _stp_vfree(mod->symbols);
+ else
+ _stp_kfree(mod->symbols);
+ mod->symbols = NULL;
+ }
_stp_kfree(mod);
}
return NULL;
@@ -107,19 +111,25 @@ static struct _stp_module * _stp_alloc_module_from_module (struct module *m)
static void _stp_free_module(struct _stp_module *mod)
{
/* free symbol memory */
- if (mod->num_symbols) {
+ if (mod->symbols) {
if (mod->allocated & 1)
_stp_vfree(mod->symbols);
else
_stp_kfree(mod->symbols);
+ mod->symbols = NULL;
+ }
+ if (mod->symbol_data) {
if (mod->allocated & 2)
_stp_vfree(mod->symbol_data);
else
_stp_kfree(mod->symbol_data);
+ mod->symbol_data = NULL;
+
}
- if (mod->sections)
+ if (mod->sections) {
_stp_kfree(mod->sections);
-
+ mod->sections = NULL;
+ }
/* free module memory */
_stp_kfree(mod);
}
@@ -174,20 +184,21 @@ static unsigned long _stp_kallsyms_lookup_name(const char *name);
/* process the KERNEL symbols */
static int _stp_do_symbols(const char __user *buf, int count)
{
- unsigned i, datasize, num;
struct _stp_symbol *s;
+ unsigned datasize, num;
+ int i;
switch (_stp_symbol_state) {
case 0:
- if (count != 8) {
- errk(" _stp_do_symbols: count=%d\n", count);
+ if (count != sizeof(struct _stp_msg_symbol_hdr)) {
+ errk("count=%d\n", count);
return -EFAULT;
}
if (get_user(num, (unsigned __user *)buf))
return -EFAULT;
if (get_user(datasize, (unsigned __user *)(buf+4)))
return -EFAULT;
- // kbug("num=%d datasize=%d\n", num, datasize);
+ //kbug("num=%d datasize=%d\n", num, datasize);
_stp_modules[0] = _stp_alloc_module(num, datasize);
if (_stp_modules[0] == NULL) {
@@ -197,26 +208,27 @@ static int _stp_do_symbols(const char __user *buf, int count)
_stp_symbol_state = 1;
break;
case 1:
+ //kbug("got stap_symbols, count=%d\n", count);
if (copy_from_user ((char *)_stp_modules[0]->symbols, buf, count))
return -EFAULT;
- // kbug("got stap_symbols, count=%d\n", count);
_stp_symbol_state = 2;
break;
case 2:
+ //kbug("got symbol data, count=%d buf=%p\n", count, buf);
if (copy_from_user (_stp_modules[0]->symbol_data, buf, count))
return -EFAULT;
- // kbug("got symbol data, count=%d\n", count);
_stp_num_modules = 1;
-
s = _stp_modules[0]->symbols;
for (i = 0; i < _stp_modules[0]->num_symbols; i++)
s[i].symbol += (long)_stp_modules[0]->symbol_data;
+
_stp_symbol_state = 3;
/* NB: this mapping is used by kernel/_stext pseudo-relocations. */
_stp_modules[0]->text = _stp_kallsyms_lookup_name("_stext");
_stp_modules[0]->data = _stp_kallsyms_lookup_name("_etext");
_stp_modules_by_addr[0] = _stp_modules[0];
+ //kbug("done with symbol data\n");
break;
default:
errk("unexpected symbol data of size %d.\n", count);
@@ -433,8 +445,9 @@ done:
/* Called from procfs.c when a STP_MODULE msg is received */
static int _stp_do_module(const char __user *buf, int count)
{
- struct _stp_module tmpmod, *mod;
- unsigned i;
+ struct _stp_msg_module tmpmod;
+ struct _stp_module mod, *m;
+ unsigned i, section_len;
if (count < (int)sizeof(tmpmod)) {
errk("expected %d and got %d\n", (int)sizeof(tmpmod), count);
@@ -443,41 +456,53 @@ static int _stp_do_module(const char __user *buf, int count)
if (copy_from_user ((char *)&tmpmod, buf, sizeof(tmpmod)))
return -EFAULT;
- // kbug("Got module %s, count=%d(0x%x)\n", tmpmod.name, count,count);
-
- if (_stp_module_exists(&tmpmod))
+ section_len = count - sizeof(tmpmod);
+ if (section_len <= 0) {
+ errk("section_len = %d\n", section_len);
+ return -EFAULT;
+ }
+ kbug("Got module %s, count=%d section_len=%d\n",
+ tmpmod.name, count, section_len);
+
+ strcpy(mod.name, tmpmod.name);
+ mod.module = tmpmod.module;
+ mod.text = tmpmod.text;
+ mod.data = tmpmod.data;
+ mod.num_sections = tmpmod.num_sections;
+
+ if (_stp_module_exists(&mod))
return count;
/* copy in section data */
- tmpmod.sections = _stp_kmalloc(count - sizeof(tmpmod));
- if (tmpmod.sections == NULL) {
+ mod.sections = _stp_kmalloc(section_len);
+ if (mod.sections == NULL) {
errk("unable to allocate memory.\n");
return -EFAULT;
}
- if (copy_from_user ((char *)tmpmod.sections, buf+sizeof(tmpmod), count-sizeof(tmpmod))) {
- _stp_kfree(tmpmod.sections);
+ if (copy_from_user ((char *)mod.sections, buf+sizeof(tmpmod), section_len)) {
+ _stp_kfree(mod.sections);
return -EFAULT;
}
- for (i = 0; i < tmpmod.num_sections; i++) {
- tmpmod.sections[i].symbol =
- (char *)((long)tmpmod.sections[i].symbol
- + (long)((long)tmpmod.sections + tmpmod.num_sections * sizeof(struct _stp_symbol)));
+ for (i = 0; i < mod.num_sections; i++) {
+ mod.sections[i].symbol =
+ (char *)((long)mod.sections[i].symbol
+ + (long)((long)mod.sections + mod.num_sections * sizeof(struct _stp_symbol)));
}
#ifdef DEBUG_SYMBOLS
- for (i = 0; i < tmpmod.num_sections; i++)
- printk("section %d (stored at %p): %s %lx\n", i, &tmpmod.sections[i], tmpmod.sections[i].symbol, tmpmod.sections[i].addr);
+ for (i = 0; i < mod.num_sections; i++)
+ printk("section %d (stored at %p): %s %lx\n", i, &mod.sections[i], mod.sections[i].symbol, mod.sections[i].addr);
#endif
/* load symbols from tmpmod.module to mod */
- mod = _stp_load_module_symbols(&tmpmod);
- if (mod == NULL) {
- _stp_kfree(tmpmod.sections);
+ m = _stp_load_module_symbols(&mod);
+ if (m == NULL) {
+ _stp_kfree(mod.sections);
return 0;
}
- if (_stp_ins_module(mod) < 0) {
- _stp_free_module(mod);
+ if (_stp_ins_module(m) < 0) {
+ _stp_free_module(m);
return -ENOMEM;
}
diff --git a/runtime/transport/transport.c b/runtime/transport/transport.c
index 0b18b275..6b90ee64 100644
--- a/runtime/transport/transport.c
+++ b/runtime/transport/transport.c
@@ -31,7 +31,6 @@ static struct utt_trace *_stp_utt = NULL;
static unsigned int utt_seq = 1;
-static int _stp_start_finished = 0;
static int _stp_probes_started = 0;
/* module parameters */
@@ -61,6 +60,7 @@ static DECLARE_WORK(_stp_work, _stp_work_queue, NULL);
#endif
static struct workqueue_struct *_stp_wq;
+static void _stp_ask_for_symbols(void);
#ifdef STP_OLD_TRANSPORT
#include "procfs.c"
@@ -72,16 +72,20 @@ static void _stp_ask_for_symbols(void)
{
struct _stp_msg_symbol req;
struct _stp_module mod;
-
- /* ask for symbols and modules */
- kbug("AFS\n");
-
- req.endian = 0x1234;
- req.ptr_size = sizeof(char *);
- _stp_ctl_send(STP_SYMBOLS, &req, sizeof(req));
-
- strcpy(mod.name, "");
- _stp_ctl_send(STP_MODULE, &mod, sizeof(mod));
+ static int sent_symbols = 0;
+
+ if (sent_symbols == 0) {
+ /* ask for symbols and modules */
+ kbug("AFS\n");
+
+ req.endian = 0x1234;
+ req.ptr_size = sizeof(char *);
+ _stp_ctl_send(STP_SYMBOLS, &req, sizeof(req));
+
+ strcpy(mod.name, "");
+ _stp_ctl_send(STP_MODULE, &mod, sizeof(mod));
+ sent_symbols = 1;
+ }
}
/*
@@ -97,7 +101,6 @@ void _stp_handle_start (struct _stp_msg_start *st)
_stp_target = st->target;
st->res = probe_start();
- _stp_start_finished = 1;
if (st->res >= 0)
_stp_probes_started = 1;
@@ -193,7 +196,7 @@ static void _stp_work_queue (void *data)
wake_up_interruptible(&_stp_ctl_wq);
/* if exit flag is set AND we have finished with probe_start() */
- if (unlikely(_stp_exit_flag && _stp_start_finished))
+ if (unlikely(_stp_exit_flag))
_stp_cleanup_and_exit(0);
else if (likely(_stp_attached))
queue_delayed_work(_stp_wq, &_stp_work, STP_WORK_TIMER);
@@ -288,9 +291,6 @@ int _stp_transport_init(void)
_stp_wq = create_workqueue("systemtap");
if (!_stp_wq)
goto err3;
-
- /* request symbolic information */
- _stp_ask_for_symbols();
return 0;
err3:
diff --git a/runtime/transport/transport_msgs.h b/runtime/transport/transport_msgs.h
index c6090969..b2187cd5 100644
--- a/runtime/transport/transport_msgs.h
+++ b/runtime/transport/transport_msgs.h
@@ -1,7 +1,7 @@
/* -*- linux-c -*-
* transport_msgs.h - messages exchanged between module and userspace
*
- * Copyright (C) Red Hat Inc, 2006-2007
+ * Copyright (C) Red Hat Inc, 2006-2008
*
* 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
@@ -9,6 +9,8 @@
* later version.
*/
+#define STP_MODULE_NAME_LEN 64
+
struct _stp_trace {
uint32_t sequence; /* event number */
uint32_t pdu_len; /* length of data after this trace */
@@ -27,6 +29,7 @@ enum
STP_CONNECT,
STP_DISCONNECT,
STP_BULK,
+ STP_READY,
#ifdef STP_OLD_TRANSPORT
/** deprecated **/
STP_BUF_INFO,
@@ -58,6 +61,43 @@ struct _stp_msg_start
int32_t res; // for reply: result of probe_start()
};
+struct _stp_symbol32
+{
+ uint32_t addr;
+ uint32_t symbol;
+};
+
+struct _stp_symbol64
+{
+ uint64_t addr;
+ uint64_t symbol;
+};
+
+struct _stp_msg_symbol_hdr
+{
+ uint32_t num_syms;
+ uint32_t sym_size;
+ uint32_t unwind_size;
+};
+
+struct _stp_msg_module {
+ /* the module name, or "" for kernel */
+ char name[STP_MODULE_NAME_LEN];
+
+ /* A pointer to the struct module */
+ uint64_t module;
+
+ /* the start of the module's text and data sections */
+ uint64_t text;
+ uint64_t data;
+
+ /* how many sections this module has */
+ uint32_t num_sections;
+
+ /* length of unwind data */
+ uint32_t unwind_len;
+};
+
#ifdef STP_OLD_TRANSPORT
/**** for compatibility with old relayfs ****/
struct _stp_buf_info