/* This function is called from finish_task_switch when task tk becomes dead, so that we can recycle any function-return probe instances associated with this task. These left over instances represent probed functions that have been called but will never return.  */
void __kprobes kprobe_flush_task(struct task_struct *tk)
/* This function is called from finish_task_switch when task tk becomes dead, so that we can recycle any function-return probe instances associated with this task. These left over instances represent probed functions that have been called but will never return.  */
void __kprobes kprobe_flush_task(struct task_struct *tk)
{
	struct kretprobe_instance *ri;
	struct hlist_head *head, empty_rp;
	struct hlist_node *node, *tmp;
	unsigned long hash, flags = 0;
	if (unlikely(!kprobes_initialized))
		return;
	hash = hash_ptr(tk, KPROBE_HASH_BITS);
	head = &kretprobe_inst_table[hash];
	kretprobe_table_lock(hash, &flags);
	hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
		if (ri->task == tk)
			recycle_rp_inst(ri, &empty_rp);
	}
	kretprobe_table_unlock(hash, &flags);
	INIT_HLIST_HEAD(&empty_rp);
	hlist_for_each_entry_safe(ri, node, tmp, &empty_rp, hlist) {
		hlist_del(&ri->hlist);
		kfree(ri);
	}
}