if (has_return)
{
+ o->newline() << "#ifdef ARCH_SUPPORTS_KRETPROBES";
o->newline() << probe_name << ".handler = &" << func_name << ";";
o->newline() << probe_name << ".maxactive = 1;";
// XXX: pending PR 1289
// o->newline() << probe_name << ".kp_fault_handler = &stap_kprobe_fault_handler;";
o->newline() << "rc = register_kretprobe (&(" << probe_name << "));";
+ o->newline() << "#else";
+ o->newline() << "rc = 1;";
+ o->newline() << "#endif";
}
else
{
o->newline() << "if (unlikely (rc)) while (--i > 0)";
o->indent(1);
if (has_return)
- o->newline() << "unregister_kretprobe (&(" << probe_name << "));";
+ {
+ o->newline() << "#ifdef ARCH_SUPPORTS_KRETPROBES";
+ o->newline() << "unregister_kretprobe (&(" << probe_name << "));";
+ o->newline() << "#else";
+ o->newline() << ";";
+ o->newline() << "#endif";
+ }
else
o->newline() << "unregister_kprobe (&(" << probe_name << "));";
o->newline(-2) << "}";
string probe_name = struct_kprobe_array_name(probenum) + "[i]";
o->indent(1);
if (has_return)
- o->newline() << "unregister_kretprobe (&(" << probe_name << "));";
+ {
+ o->newline() << "#ifdef ARCH_SUPPORTS_KRETPROBES";
+ o->newline() << "unregister_kretprobe (&(" << probe_name << "));";
+ o->newline() << "#else";
+ o->newline() << ";";
+ o->newline() << "#endif";
+ }
else
o->newline() << "unregister_kprobe (&(" << probe_name << "));";
o->indent(-1);
assert(locations.size() == probe_points.size());
if (has_return)
+ {
+ o->newline() << "#ifdef ARCH_SUPPORTS_KRETPROBES";
o->newline() << "static struct kretprobe "
<< probe_array
<< "[" << probe_points.size() << "]"
<< "= {";
+ }
else
o->newline() << "static struct kprobe "
<< probe_array
}
o->newline(-1) << "};";
+ if (has_return)
+ o->newline() << "#endif /* ARCH_SUPPORTS_KRETPROBES */";
+
o->newline();
// This is somewhat gross, but it should work: we allocate a
// Construct a single entry function, and a struct kprobe pointing into
// the entry function. The entry function will call the probe function.
o->newline();
+ if (has_return)
+ o->newline() << "#ifdef ARCH_SUPPORTS_KRETPROBES";
o->newline() << "static int ";
o->newline() << function_name(probenum) << " (";
if (has_return)
o->newline() << "atomic_dec (& c->busy);";
o->newline() << "return 0;";
o->newline(-1) << "}" << endl;
+ if (has_return)
+ o->newline() << "#endif /* ARCH_SUPPORTS_KRETPROBES */";
o->newline();
}
{
// XXX: tapsets.cxx should be able to add additional definitions
- o->newline() << "#include \"loc2c-runtime.h\" ";
- o->newline() << "#define MAXNESTING 30";
- o->newline() << "#define MAXCONCURRENCY NR_CPUS";
- o->newline() << "#define MAXSTRINGLEN 128";
- o->newline() << "#define MAXTRYLOCK 20";
- o->newline() << "#define MAXACTION 1000";
- o->newline() << "#define MAXMAPENTRIES 2048";
- o->newline();
o->newline() << "typedef char string_t[MAXSTRINGLEN];";
o->newline() << "typedef struct { } stats_t;";
o->newline();
// probe from attempting to run.
o->newline(1) << "atomic_set (&session_state, STAP_SESSION_ERROR);";
+ // XXX: would be nice to print failing probe point
+ o->newline() << "_stp_error (\"probe " << i << " registration failed"
+ << ", rc=%d, %s\\n\", rc, "
+ << lex_cast_qstring(*session->probes[i]->tok)
+ << ");";
+
// We need to deregister any already probes set up - this is
// essential for kprobes.
if (i > 0)
// otherwise act like probe insertion was a success.
o->newline() << "if (atomic_read (&session_state) == STAP_SESSION_STARTING)";
o->newline(1) << "atomic_set (&session_state, STAP_SESSION_RUNNING);";
- // XXX: else maybe set anyrc and thus return a failure from module_init?
o->newline(-1) << "goto out;";
- // recovery code for partially successful registration (rc != 0)
+ // Recovery code for partially successful registration (rc != 0)
+ // XXX: Do we need to delay here to ensure any triggered probes have
+ // terminated? Probably not much, as they should all test for
+ // SESSION_STARTING state right at the top and return. ("begin"
+ // probes don't count, as they return synchronously.)
o->newline();
for (int i=session->probes.size()-2; i >= 0; i--) // NB: -2
{
}
o->newline();
+ // If any registrations failed, we will need to deregister the globals,
+ // as this is our only chance.
+ for (unsigned i=0; i<session->globals.size(); i++)
+ {
+ vardecl* v = session->globals[i];
+ if (v->index_types.size() > 0)
+ o->newline() << getmap (v).fini();
+ }
+
o->newline(-1) << "out:";
o->newline(1) << "return rc;";
o->newline(-1) << "}" << endl;
o->newline() << "void systemtap_module_exit () {";
// rc?
o->newline(1) << "int holdon;";
+
+ // If we aborted startup, then everything has been cleaned up already, and
+ // module_exit shouldn't even have been called. But since it might be, let's
+ // beat a hasty retreat to avoid double uninitialization.
+ o->newline() << "if (atomic_read (&session_state) == STAP_SESSION_STARTING)";
+ o->newline(1) << "return;";
+ o->indent(-1);
o->newline() << "if (atomic_read (&session_state) == STAP_SESSION_RUNNING)";
// NB: only other valid state value is ERROR, in which case we don't
try
{
+ // This is at the very top of the file.
s.op->line() << "#define TEST_MODE " << (s.test_mode ? 1 : 0) << endl;
+ s.op->newline() << "#define MAXNESTING 30";
+ s.op->newline() << "#define MAXCONCURRENCY NR_CPUS";
+ s.op->newline() << "#define MAXSTRINGLEN 128";
+ s.op->newline() << "#define MAXTRYLOCK 20";
+ s.op->newline() << "#define MAXACTION 1000";
+ s.op->newline() << "#define MAXMAPENTRIES 2048";
+
+ // impedance mismatch
+ s.op->newline() << "#define STP_STRING_SIZE MAXSTRINGLEN";
+ s.op->newline() << "#define STP_NUM_STRINGS 1";
+
s.op->newline() << "#if TEST_MODE";
s.op->newline() << "#include \"runtime.h\"";
s.op->newline() << "#else";
- s.op->newline() << "#define STP_NUM_STRINGS 1";
s.op->newline() << "#include \"runtime.h\"";
s.op->newline() << "#include \"current.c\"";
s.op->newline() << "#include \"stack.c\"";
s.op->newline() << "#include <linux/string.h>";
s.op->newline() << "#include <linux/timer.h>";
s.op->newline() << "#endif";
+ s.op->newline() << "#include \"loc2c-runtime.h\" ";
s.up->emit_common_header ();
s.op->newline() << "#else";
s.op->newline();
- // XXX
+ // XXX impedance mismatch
s.op->newline() << "int probe_start () {";
- s.op->newline(1) << "return systemtap_module_init ();";
+ s.op->newline(1) << "return systemtap_module_init () ? -1 : 0;";
s.op->newline(-1) << "}";
s.op->newline();
s.op->newline() << "void probe_exit () {";