コード例 #1
0
ファイル: kprobes.c プロジェクト: Open-Party/systemtap
/* 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
ファイル: kprobes.c プロジェクト: Open-Party/systemtap
static int
stapkp_prepare_kprobe(struct stap_dwarf_probe *sdp)
{
   struct kprobe *kp = &sdp->kprobe->u.kp;
   unsigned long addr = stapkp_relocate_addr(sdp);
   if (addr == 0)
      return 1;

   kp->addr = (void *) addr;
   kp->pre_handler = &enter_kprobe_probe;

#ifdef __ia64__ // PR6028
   sdp->kprobe->dummy.addr = kp->addr;
   sdp->kprobe->dummy.pre_handler = NULL;
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
   if (!sdp->probe->cond_enabled) {
      kp->flags |= KPROBE_FLAG_DISABLED;
      dbug_otf("registering as disabled (kprobe) pidx %zu\n",
               sdp->probe->index);
   }
#endif

   return 0;
}
コード例 #3
0
static int
stapkp_prepare_kretprobe(struct stap_kprobe_probe *skp)
{
    struct kretprobe *krp = &skp->kprobe->u.krp;
    unsigned long addr = 0;

    if (! skp->symbol_name) {
        addr = stapkp_relocate_addr(skp);
        if (addr == 0)
            return 1;
        krp->kp.addr = (void *) addr;
    }
    else {
#ifdef STAPCONF_KALLSYMS_ON_EACH_SYMBOL
        if (krp->kp.addr == 0)
            return 1;
#else
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0)
        if (krp->kp.symbol_name == NULL)
            krp->kp.symbol_name = kstrdup(skp->symbol_name, STP_ALLOC_FLAGS);
#else
        krp->kp.symbol_name = (typeof(krp->kp.symbol_name))skp->symbol_name;
#endif
        krp->kp.offset = skp->offset;
#endif
    }

    if (skp->maxactive_p)
        krp->maxactive = skp->maxactive_val;
    else
        krp->maxactive = KRETACTIVE;

    krp->handler = &enter_kretprobe_probe;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
    if (skp->entry_probe) {
        krp->entry_handler = &enter_kretprobe_entry_probe;
        krp->data_size = skp->saved_longs * sizeof(int64_t) +
                         skp->saved_strings * MAXSTRINGLEN;
    }
#endif

#ifdef __ia64__ // PR6028
    skp->kprobe->dummy.addr = krp->kp.addr;
    skp->kprobe->dummy.pre_handler = NULL;
    skp->kprobe->dummy.symbol_name = krp->kp.symbol_name;
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
    if (!skp->probe->cond_enabled) {
        krp->kp.flags |= KPROBE_FLAG_DISABLED;
        dbug_otf("registering as disabled (kretprobe) pidx %zu\n",
                 skp->probe->index);
    }
#endif

    return 0;
}
コード例 #4
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;
}
コード例 #5
0
ファイル: kprobes.c プロジェクト: Open-Party/systemtap
static int
stapkp_prepare_kretprobe(struct stap_dwarf_probe *sdp)
{
   struct kretprobe *krp = &sdp->kprobe->u.krp;
   unsigned long addr = stapkp_relocate_addr(sdp);
   if (addr == 0)
      return 1;

   krp->kp.addr = (void *) addr;

   if (sdp->maxactive_p)
      krp->maxactive = sdp->maxactive_val;
   else
      krp->maxactive = KRETACTIVE;

   krp->handler = &enter_kretprobe_probe;

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
   if (sdp->entry_probe) {
      krp->entry_handler = &enter_kretprobe_entry_probe;
      krp->data_size = sdp->saved_longs * sizeof(int64_t) +
                       sdp->saved_strings * MAXSTRINGLEN;
   }
#endif

#ifdef __ia64__ // PR6028
   sdp->kprobe->dummy.addr = krp->kp.addr;
   sdp->kprobe->dummy.pre_handler = NULL;
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
   if (!sdp->probe->cond_enabled) {
      krp->kp.flags |= KPROBE_FLAG_DISABLED;
      dbug_otf("registering as disabled (kretprobe) pidx %zu\n",
               sdp->probe->index);
   }
#endif

   return 0;
}
コード例 #6
0
ファイル: kprobes.c プロジェクト: Open-Party/systemtap
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;
}
コード例 #7
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
    }
}
コード例 #8
0
static int
stapkp_prepare_kprobe(struct stap_kprobe_probe *skp)
{
    struct kprobe *kp = &skp->kprobe->u.kp;
    unsigned long addr = 0;

    if (! skp->symbol_name) {
        addr = stapkp_relocate_addr(skp);
        if (addr == 0)
            return 1;
        kp->addr = (void *) addr;
    }
    else {
#ifdef STAPCONF_KALLSYMS_ON_EACH_SYMBOL
        // If we're doing symbolic name + offset probing (that gets
        // converted to an address), it doesn't really matter if the
        // symbol is in a module and the module isn't loaded right
        // now. The registration will fail, but will get tried again
        // when the module is loaded.
        if (kp->addr == 0)
            return 1;
#else
        // If we don't have kallsyms_on_each_symbol(), we'll use
        // symbol_name+offset probing and let
        // register_kprobe()/register_kretprobe() call
        // kallsyms_lookup_name() for us. However, on kernels < 3.11,
        // module_kallsyms_lookup_name() (called from
        // kallsyms_lookup_name()) has a bug where it modifies its
        // argument. So, for those kernels we'll workaround the bug by
        // duplicating the string (so we go from read-only memory in the
        // initialized struct data to read-write allocated memory). The
        // memory gets freed when the probe is unregistered.
        //
        // This bug was fixed in kernel 3.11+ by the following commit:
        //
        //   commit 4f6de4d51f4a3ab06a85e91e708cc89a513ef30c
        //      Author: Mathias Krause <*****@*****.**>
        //      Date:   Tue Jul 2 15:35:11 2013 +0930
        //
        //      module: don't modify argument of module_kallsyms_lookup_name()
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,11,0)
        if (kp->symbol_name == NULL)
            kp->symbol_name = kstrdup(skp->symbol_name, STP_ALLOC_FLAGS);
#else
        kp->symbol_name = (typeof(kp->symbol_name))skp->symbol_name;
#endif
        kp->offset = skp->offset;
#endif
    }

    kp->pre_handler = &enter_kprobe_probe;

#ifdef __ia64__ // PR6028
    skp->kprobe->dummy.addr = kp->addr;
    skp->kprobe->dummy.pre_handler = NULL;
    skp->kprobe->dummy.symbol_name = kp->symbol_name;
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
    if (!skp->probe->cond_enabled) {
        kp->flags |= KPROBE_FLAG_DISABLED;
        dbug_otf("registering as disabled (kprobe) pidx %zu\n",
                 skp->probe->index);
    }
#endif

    return 0;
}