/* *TODO:recursiondetectionhasbeendoneinthefgraph.Thusweneed *toaddacallbacktoincrementmissedcounter.
*/
ret_ip = ftrace_regs_get_return_address(fregs);
used = 0;
hlist_for_each_entry_from_rcu(node, hlist) { int data_size; void *data;
if (node->addr != func) break;
fp = READ_ONCE(node->fp); if (!fp || fprobe_disabled(fp)) continue;
data_size = fp->entry_data_size; if (data_size && fp->exit_handler)
data = fgraph_data + used + FPROBE_HEADER_SIZE_IN_LONG; else
data = NULL;
if (fprobe_shared_with_kprobes(fp))
ret = __fprobe_kprobe_handler(func, ret_ip, fp, fregs, data); else
ret = __fprobe_handler(func, ret_ip, fp, fregs, data);
/* If entry_handler returns !0, nmissed is not counted but skips exit_handler. */ if (!ret && fp->exit_handler) { int size_words = SIZE_IN_LONG(data_size);
if (write_fprobe_header(&fgraph_data[used], fp, size_words))
used += FPROBE_HEADER_SIZE_IN_LONG + size_words;
}
} if (used < reserved_words)
memset(fgraph_data + used, 0, reserved_words - used);
/* If any exit_handler is set, data must be used. */ return used != 0;
}
NOKPROBE_SYMBOL(fprobe_entry);
/* Add @addrs to the ftrace filter and register fgraph if needed. */ staticint fprobe_graph_add_ips(unsignedlong *addrs, int num)
{ int ret;
lockdep_assert_held(&fprobe_mutex);
ret = ftrace_set_filter_ips(&fprobe_graph_ops.ops, addrs, num, 0, 0); if (ret) return ret;
if (!fprobe_graph_active) {
ret = register_ftrace_graph(&fprobe_graph_ops); if (WARN_ON_ONCE(ret)) {
ftrace_free_filter(&fprobe_graph_ops.ops); return ret;
}
}
fprobe_graph_active++; return0;
}
/* Remove @addrs from the ftrace filter and unregister fgraph if possible. */ staticvoid fprobe_graph_remove_ips(unsignedlong *addrs, int num)
{
lockdep_assert_held(&fprobe_mutex);
fprobe_graph_active--; /* Q: should we unregister it ? */ if (!fprobe_graph_active)
unregister_ftrace_graph(&fprobe_graph_ops);
if (num)
ftrace_set_filter_ips(&fprobe_graph_ops.ops, addrs, num, 1, 0);
}
#ifdef CONFIG_MODULES
#define FPROBE_IPS_BATCH_INIT 8 /* instruction pointer address list */ struct fprobe_addr_list { int index; int size; unsignedlong *addrs;
};
if (val != MODULE_STATE_GOING) return NOTIFY_DONE;
alist.addrs = kcalloc(alist.size, sizeof(*alist.addrs), GFP_KERNEL); /* If failed to alloc memory, we can not remove ips from hash. */ if (!alist.addrs) return NOTIFY_DONE;
mutex_lock(&fprobe_mutex); for (i = 0; i < FPROBE_IP_TABLE_SIZE; i++)
fprobe_remove_node_in_module(mod, &fprobe_ip_table[i], &alist);
if (alist.index > 0)
ftrace_set_filter_ips(&fprobe_graph_ops.ops,
alist.addrs, alist.index, 1, 0);
mutex_unlock(&fprobe_mutex);
ret = kallsyms_on_each_symbol(filter_match_callback, &match); if (ret < 0) return ret; if (IS_ENABLED(CONFIG_MODULES)) {
ret = module_kallsyms_on_each_symbol(NULL, filter_match_callback, &match); if (ret < 0) return ret;
}
num = get_ips_from_filter(filter, notfilter, NULL, NULL, FPROBE_IPS_MAX); if (num < 0) return num;
addrs = kcalloc(num, sizeof(*addrs), GFP_KERNEL); if (!addrs) return -ENOMEM;
mods = kcalloc(num, sizeof(*mods), GFP_KERNEL); if (!mods) return -ENOMEM;
ret = get_ips_from_filter(filter, notfilter, addrs, mods, num); if (ret < 0) return ret;
ret = register_fprobe_ips(fp, addrs, ret);
for (int i = 0; i < num; i++) { if (mods[i])
module_put(mods[i]);
} return ret;
}
EXPORT_SYMBOL_GPL(register_fprobe);
/** *register_fprobe_ips()-Registerfprobetoftracebyaddress. *@fp:Afprobedatastructuretoberegistered. *@addrs:Anarrayoftargetfunctionaddress. *@num:Thenumberofentriesof@addrs. * *Register@fptoftraceforenablingtheprobeontheaddressgivenby@addrs. *The@addrsmustbetheaddressesofftracelocationaddress,whichmaybe *thesymboladdress+arch-dependentoffset. *Ifyouunsurewhatthismean,pleaseuseotherregistrationfunctions. * *Return0if@fpisregisteredsuccessfully,-errnoifnot.
*/ int register_fprobe_ips(struct fprobe *fp, unsignedlong *addrs, int num)
{ struct fprobe_hlist *hlist_array; int ret, i;
ret = fprobe_init(fp, addrs, num); if (ret) return ret;
mutex_lock(&fprobe_mutex);
hlist_array = fp->hlist_array;
ret = fprobe_graph_add_ips(addrs, num); if (!ret) {
add_fprobe_hash(fp); for (i = 0; i < hlist_array->size; i++)
insert_fprobe_node(&hlist_array->array[i]);
}
mutex_unlock(&fprobe_mutex);
/** *unregister_fprobe()-Unregisterfprobe. *@fp:Afprobedatastructuretobeunregistered. * *Unregisterfprobe(andremoveftracehooksfromthefunctionentries). * *Return0if@fpisunregisteredsuccessfully,-errnoifnot.
*/ int unregister_fprobe(struct fprobe *fp)
{ struct fprobe_hlist *hlist_array; unsignedlong *addrs = NULL; int ret = 0, i, count;
mutex_lock(&fprobe_mutex); if (!fp || !is_fprobe_still_exist(fp)) {
ret = -EINVAL; goto out;
}
hlist_array = fp->hlist_array;
addrs = kcalloc(hlist_array->size, sizeof(unsignedlong), GFP_KERNEL); if (!addrs) {
ret = -ENOMEM; /* TODO: Fallback to one-by-one loop */ goto out;
}
/* Remove non-synonim ips from table and hash */
count = 0; for (i = 0; i < hlist_array->size; i++) { if (!delete_fprobe_node(&hlist_array->array[i]))
addrs[count++] = hlist_array->array[i].addr;
}
del_fprobe_hash(fp);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.