Пример #1
0
/* stapkp_refresh is called for two reasons: either a kprobe needs to be
 * enabled/disabled (modname is NULL), or a module has been loaded/unloaded and
 * kprobes need to be registered/unregistered (modname is !NULL). */
static void
stapkp_refresh(const char *modname,
               struct stap_dwarf_probe *probes,
               size_t nprobes)
{
   size_t i;

   for (i = 0; i < nprobes; i++) {

      struct stap_dwarf_probe *sdp = &probes[i];

      // was this probe's target module loaded/unloaded
      if (modname && sdp->module
            && strcmp(modname, sdp->module) == 0) {
         int rc;
         unsigned long addr = stapkp_relocate_addr(sdp);

         // module being loaded?
         if (sdp->registered_p == 0 && addr != 0)
            stapkp_register_probe(sdp);
         // module/section being unloaded?
         else if (sdp->registered_p == 1 && addr == 0)
            stapkp_unregister_probe(sdp);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
      } else if (stapkp_should_enable_probe(sdp)
              || stapkp_should_disable_probe(sdp)) {
         stapkp_refresh_probe(sdp);
#endif
      }
   }
}
Пример #2
0
static int
stapkp_init(struct stap_kprobe_probe *probes,
            size_t nprobes)
{
    size_t i;

#ifdef STAPCONF_KALLSYMS_ON_EACH_SYMBOL
    // If we have any symbol_name+offset probes, we need to try to
    // convert those into address-based probes.
    size_t probe_max = 0;
    for (i = 0; i < nprobes; i++) {
        struct stap_kprobe_probe *skp = &probes[i];

        if (! skp->symbol_name)
            continue;
        ++probe_max;
    }
    if (probe_max > 0) {
        // Here we're going to try to convert any symbol_name+offset
        // probes into address probes.
        struct stapkp_symbol_data sd;
        dbug_stapkp("looking up %lu probes\n", probe_max);
        sd.probes = probes;
        sd.nprobes = nprobes;
        sd.probe_max = probe_max;
        sd.modname = NULL;
        preempt_disable();
        kallsyms_on_each_symbol(stapkp_symbol_callback, &sd);
        preempt_enable();
        dbug_stapkp("found %lu probes\n", sd.probe_max);
    }
#endif

    for (i = 0; i < nprobes; i++) {
        struct stap_kprobe_probe *skp = &probes[i];
        int rc = 0;

        rc = stapkp_register_probe(skp);
        if (rc == 1) // failed to relocate addr?
            continue; // don't fuss about it, module probably not loaded

        // NB: We keep going even if a probe failed to register (PR6749). We only
        // warn about it if it wasn't optional and isn't in a module.
        if (rc && !skp->optional_p
                && ((skp->module == NULL) || skp->module[0] == '\0'
                    || strcmp(skp->module, "kernel") == 0)) {
            if (skp->symbol_name)
                _stp_warn("probe %s (%s+%u) registration error (rc %d)",
                          skp->probe->pp, skp->symbol_name, skp->offset, rc);
            else
                _stp_warn("probe %s (address 0x%lx) registration error (rc %d)",
                          skp->probe->pp, stapkp_relocate_addr(skp), rc);
        }
    }

    return 0;
}
Пример #3
0
static int
stapkp_init(struct stap_dwarf_probe *probes,
            size_t nprobes)
{
   size_t i;
   for (i = 0; i < nprobes; i++) {

      struct stap_dwarf_probe *sdp = &probes[i];
      int rc = 0;

      rc = stapkp_register_probe(sdp);
      if (rc == 1) // failed to relocate addr?
         continue; // don't fuss about it, module probably not loaded

      // NB: We keep going even if a probe failed to register (PR6749). We only
      // warn about it if it wasn't optional.
      if (rc && !sdp->optional_p) {
         _stp_warn("probe %s (address 0x%lx) registration error (rc %d)",
                   sdp->probe->pp, stapkp_relocate_addr(sdp), rc);
      }
   }

   return 0;
}
Пример #4
0
/* stapkp_refresh is called for two reasons: either a kprobe needs to be
 * enabled/disabled (modname is NULL), or a module has been loaded/unloaded and
 * kprobes need to be registered/unregistered (modname is !NULL). */
static void
stapkp_refresh(const char *modname,
               struct stap_kprobe_probe *probes,
               size_t nprobes)
{
    size_t i;

    dbug_stapkp("refresh %lu probes with module %s\n", nprobes, modname ?: "?");

#ifdef STAPCONF_KALLSYMS_ON_EACH_SYMBOL
    if (modname) {
        size_t probe_max = 0;
        for (i = 0; i < nprobes; i++) {
            struct stap_kprobe_probe *skp = &probes[i];

            // If this probe is in the same module that is being
            // loaded/unloaded and the probe is symbol_name+offset based
            // and it isn't registered (so the module must be loaded),
            // try to convert all probes in the same module to
            // address-based probes.
            if (skp->module && strcmp(modname, skp->module) == 0
                    && skp->symbol_name && skp->registered_p == 0)
                ++probe_max;
        }
        if (probe_max > 0) {
            struct stapkp_symbol_data sd;
            sd.probes = probes;
            sd.nprobes = nprobes;
            sd.probe_max = probe_max;
            sd.modname = modname;
            preempt_disable();
            kallsyms_on_each_symbol(stapkp_symbol_callback, &sd);
            preempt_enable();
        }
    }
#endif

    for (i = 0; i < nprobes; i++) {

        struct stap_kprobe_probe *skp = &probes[i];

        // was this probe's target module loaded/unloaded
        if (modname && skp->module
                && strcmp(modname, skp->module) == 0) {
            int rc;
            unsigned long addr = (! skp->symbol_name
                                  ? stapkp_relocate_addr(skp) : 0);

            // module being loaded?
            if (skp->registered_p == 0 && (addr != 0 || skp->symbol_name))
                stapkp_register_probe(skp);
            // module/section being unloaded?
            else if (skp->registered_p == 1 && addr == 0)
                stapkp_unregister_probe(skp);

        }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
        else if (stapkp_should_enable_probe(skp)
                 || stapkp_should_disable_probe(skp)) {
            stapkp_refresh_probe(skp);
        }
#endif
    }
}