+int lttng_syscalls_register_event_notifier(
+ struct lttng_event_notifier_enabler *event_notifier_enabler,
+ void *filter)
+{
+ struct lttng_event_notifier_group *group = event_notifier_enabler->group;
+ unsigned int i;
+ int ret = 0;
+
+ wrapper_vmalloc_sync_mappings();
+
+ if (!group->event_notifier_syscall_dispatch) {
+ group->event_notifier_syscall_dispatch =
+ kzalloc(sizeof(struct hlist_head) * ARRAY_SIZE(sc_table),
+ GFP_KERNEL);
+ if (!group->event_notifier_syscall_dispatch)
+ return -ENOMEM;
+
+ /* Initialize all list_head */
+ for (i = 0; i < ARRAY_SIZE(sc_table); i++)
+ INIT_HLIST_HEAD(&group->event_notifier_syscall_dispatch[i]);
+
+ /* Init the unknown syscall notifier list. */
+ INIT_HLIST_HEAD(&group->event_notifier_unknown_syscall_dispatch);
+ }
+
+ if (!group->event_notifier_exit_syscall_dispatch) {
+ group->event_notifier_exit_syscall_dispatch =
+ kzalloc(sizeof(struct hlist_head) * ARRAY_SIZE(sc_table),
+ GFP_KERNEL);
+ if (!group->event_notifier_exit_syscall_dispatch)
+ return -ENOMEM;
+
+ /* Initialize all list_head */
+ for (i = 0; i < ARRAY_SIZE(sc_table); i++)
+ INIT_HLIST_HEAD(&group->event_notifier_exit_syscall_dispatch[i]);
+
+ /* Init the unknown exit syscall notifier list. */
+ INIT_HLIST_HEAD(&group->event_notifier_exit_unknown_syscall_dispatch);
+ }
+
+#ifdef CONFIG_COMPAT
+ if (!group->event_notifier_compat_syscall_dispatch) {
+ group->event_notifier_compat_syscall_dispatch =
+ kzalloc(sizeof(struct hlist_head) * ARRAY_SIZE(compat_sc_table),
+ GFP_KERNEL);
+ if (!group->event_notifier_syscall_dispatch)
+ return -ENOMEM;
+
+ /* Initialize all list_head */
+ for (i = 0; i < ARRAY_SIZE(compat_sc_table); i++)
+ INIT_HLIST_HEAD(&group->event_notifier_compat_syscall_dispatch[i]);
+
+ /* Init the unknown syscall notifier list. */
+ INIT_HLIST_HEAD(&group->event_notifier_compat_unknown_syscall_dispatch);
+ }
+
+ if (!group->event_notifier_exit_compat_syscall_dispatch) {
+ group->event_notifier_exit_compat_syscall_dispatch =
+ kzalloc(sizeof(struct hlist_head) * ARRAY_SIZE(compat_sc_exit_table),
+ GFP_KERNEL);
+ if (!group->event_notifier_exit_syscall_dispatch)
+ return -ENOMEM;
+
+ /* Initialize all list_head */
+ for (i = 0; i < ARRAY_SIZE(compat_sc_exit_table); i++)
+ INIT_HLIST_HEAD(&group->event_notifier_exit_compat_syscall_dispatch[i]);
+
+ /* Init the unknown exit syscall notifier list. */
+ INIT_HLIST_HEAD(&group->event_notifier_exit_compat_unknown_syscall_dispatch);
+ }
+#endif
+
+ if (!group->sc_filter) {
+ group->sc_filter = kzalloc(sizeof(struct lttng_syscall_filter),
+ GFP_KERNEL);
+ if (!group->sc_filter)
+ return -ENOMEM;
+ }
+
+ if (!group->sys_enter_registered) {
+ ret = lttng_wrapper_tracepoint_probe_register("sys_enter",
+ (void *) syscall_entry_event_notifier_probe, group);
+ if (ret)
+ return ret;
+ group->sys_enter_registered = 1;
+ }
+
+ if (!group->sys_exit_registered) {
+ ret = lttng_wrapper_tracepoint_probe_register("sys_exit",
+ (void *) syscall_exit_event_notifier_probe, group);
+ if (ret) {
+ WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter",
+ (void *) syscall_entry_event_notifier_probe, group));
+ return ret;
+ }
+ group->sys_exit_registered = 1;
+ }
+
+ return ret;
+}
+
+static
+int create_unknown_event_notifier(
+ struct lttng_event_notifier_enabler *event_notifier_enabler,
+ enum sc_type type)
+{
+ struct lttng_event_notifier *notifier;
+ const struct lttng_event_desc *desc;
+ struct lttng_event_notifier_group *group = event_notifier_enabler->group;
+ struct lttng_kernel_event_notifier event_notifier_param;
+ uint64_t user_token = event_notifier_enabler->base.user_token;
+ uint64_t error_counter_index = event_notifier_enabler->error_counter_index;
+ struct lttng_enabler *base_enabler = lttng_event_notifier_enabler_as_enabler(
+ event_notifier_enabler);
+ struct hlist_head *unknown_dispatch_list;
+ int ret = 0;
+ bool found = false;
+ enum lttng_kernel_syscall_abi abi;
+ enum lttng_kernel_syscall_entryexit entryexit;
+ struct hlist_head *head;
+
+ switch (type) {
+ case SC_TYPE_ENTRY:
+ desc = &__event_desc___syscall_entry_unknown;
+ unknown_dispatch_list = &group->event_notifier_unknown_syscall_dispatch;
+ entryexit = LTTNG_KERNEL_SYSCALL_ENTRY;
+ abi = LTTNG_KERNEL_SYSCALL_ABI_NATIVE;
+ break;
+ case SC_TYPE_EXIT:
+ desc = &__event_desc___syscall_exit_unknown;
+ unknown_dispatch_list = &group->event_notifier_exit_unknown_syscall_dispatch;
+ entryexit = LTTNG_KERNEL_SYSCALL_EXIT;
+ abi = LTTNG_KERNEL_SYSCALL_ABI_NATIVE;
+ break;
+ case SC_TYPE_COMPAT_ENTRY:
+ desc = &__event_desc___compat_syscall_entry_unknown;
+ unknown_dispatch_list = &group->event_notifier_compat_unknown_syscall_dispatch;
+ entryexit = LTTNG_KERNEL_SYSCALL_ENTRY;
+ abi = LTTNG_KERNEL_SYSCALL_ABI_COMPAT;
+ break;
+ case SC_TYPE_COMPAT_EXIT:
+ desc = &__event_desc___compat_syscall_exit_unknown;
+ unknown_dispatch_list = &group->event_notifier_exit_compat_unknown_syscall_dispatch;
+ entryexit = LTTNG_KERNEL_SYSCALL_EXIT;
+ abi = LTTNG_KERNEL_SYSCALL_ABI_COMPAT;
+ break;
+ default:
+ BUG_ON(1);
+ }
+
+ /*
+ * Check if already created.
+ */
+ head = utils_borrow_hash_table_bucket(group->event_notifiers_ht.table,
+ LTTNG_EVENT_NOTIFIER_HT_SIZE, desc->name);
+ lttng_hlist_for_each_entry(notifier, head, hlist) {
+ if (notifier->desc == desc &&
+ notifier->user_token == base_enabler->user_token)
+ found = true;
+ }
+ if (found)
+ goto end;
+
+ memset(&event_notifier_param, 0, sizeof(event_notifier_param));
+ strncat(event_notifier_param.event.name, desc->name,
+ LTTNG_KERNEL_SYM_NAME_LEN - strlen(event_notifier_param.event.name) - 1);
+
+ event_notifier_param.event.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
+
+ event_notifier_param.event.instrumentation = LTTNG_KERNEL_SYSCALL;
+ event_notifier_param.event.u.syscall.abi = abi;
+ event_notifier_param.event.u.syscall.entryexit = entryexit;
+
+ notifier = _lttng_event_notifier_create(desc, user_token,
+ error_counter_index, group, &event_notifier_param, NULL,
+ event_notifier_param.event.instrumentation);
+ if (IS_ERR(notifier)) {
+ printk(KERN_INFO "Unable to create unknown notifier %s\n",
+ desc->name);
+ ret = -ENOMEM;
+ goto end;
+ }
+
+ hlist_add_head_rcu(¬ifier->u.syscall.node, unknown_dispatch_list);
+
+end:
+ return ret;
+}
+
+static int create_matching_event_notifiers(
+ struct lttng_event_notifier_enabler *event_notifier_enabler,
+ void *filter, const struct trace_syscall_entry *table,
+ size_t table_len, enum sc_type type)
+{
+ struct lttng_event_notifier_group *group = event_notifier_enabler->group;
+ const struct lttng_event_desc *desc;
+ uint64_t user_token = event_notifier_enabler->base.user_token;
+ uint64_t error_counter_index = event_notifier_enabler->error_counter_index;
+ unsigned int i;
+ int ret = 0;
+
+ /* iterate over all syscall and create event_notifier that match */
+ for (i = 0; i < table_len; i++) {
+ struct lttng_event_notifier *event_notifier;
+ struct lttng_kernel_event_notifier event_notifier_param;
+ struct hlist_head *head;
+ int found = 0;
+
+ desc = table[i].desc;
+ if (!desc) {
+ /* Unknown syscall */
+ continue;
+ }
+
+ if (!lttng_desc_match_enabler(desc,
+ lttng_event_notifier_enabler_as_enabler(event_notifier_enabler)))
+ continue;
+
+ /*
+ * Check if already created.
+ */
+ head = utils_borrow_hash_table_bucket(group->event_notifiers_ht.table,
+ LTTNG_EVENT_NOTIFIER_HT_SIZE, desc->name);
+ lttng_hlist_for_each_entry(event_notifier, head, hlist) {
+ if (event_notifier->desc == desc
+ && event_notifier->user_token == event_notifier_enabler->base.user_token)
+ found = 1;
+ }
+ if (found)
+ continue;
+
+ memset(&event_notifier_param, 0, sizeof(event_notifier_param));
+ switch (type) {
+ case SC_TYPE_ENTRY:
+ event_notifier_param.event.u.syscall.entryexit = LTTNG_KERNEL_SYSCALL_ENTRY;
+ event_notifier_param.event.u.syscall.abi = LTTNG_KERNEL_SYSCALL_ABI_NATIVE;
+ break;
+ case SC_TYPE_EXIT:
+ event_notifier_param.event.u.syscall.entryexit = LTTNG_KERNEL_SYSCALL_EXIT;
+ event_notifier_param.event.u.syscall.abi = LTTNG_KERNEL_SYSCALL_ABI_NATIVE;
+ break;
+ case SC_TYPE_COMPAT_ENTRY:
+ event_notifier_param.event.u.syscall.entryexit = LTTNG_KERNEL_SYSCALL_ENTRY;
+ event_notifier_param.event.u.syscall.abi = LTTNG_KERNEL_SYSCALL_ABI_COMPAT;
+ break;
+ case SC_TYPE_COMPAT_EXIT:
+ event_notifier_param.event.u.syscall.entryexit = LTTNG_KERNEL_SYSCALL_EXIT;
+ event_notifier_param.event.u.syscall.abi = LTTNG_KERNEL_SYSCALL_ABI_COMPAT;
+ break;
+ }
+ strncat(event_notifier_param.event.name, desc->name,
+ LTTNG_KERNEL_SYM_NAME_LEN - strlen(event_notifier_param.event.name) - 1);
+ event_notifier_param.event.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
+ event_notifier_param.event.instrumentation = LTTNG_KERNEL_SYSCALL;
+
+ event_notifier = _lttng_event_notifier_create(desc, user_token,
+ error_counter_index, group, &event_notifier_param,
+ filter, event_notifier_param.event.instrumentation);
+ if (IS_ERR(event_notifier)) {
+ printk(KERN_INFO "Unable to create event_notifier %s\n",
+ desc->name);
+ ret = -ENOMEM;
+ goto end;
+ }
+
+ event_notifier->u.syscall.syscall_id = i;
+ }
+
+end:
+ return ret;
+
+}
+
+int lttng_syscals_create_matching_event_notifiers(
+ struct lttng_event_notifier_enabler *event_notifier_enabler,
+ void *filter)
+{
+ int ret;
+ struct lttng_enabler *base_enabler =
+ lttng_event_notifier_enabler_as_enabler(event_notifier_enabler);
+ enum lttng_kernel_syscall_entryexit entryexit =
+ base_enabler->event_param.u.syscall.entryexit;
+
+ if (entryexit == LTTNG_KERNEL_SYSCALL_ENTRY || entryexit == LTTNG_KERNEL_SYSCALL_ENTRYEXIT) {
+ ret = create_matching_event_notifiers(event_notifier_enabler,
+ filter, sc_table, ARRAY_SIZE(sc_table), SC_TYPE_ENTRY);
+ if (ret)
+ goto end;
+
+ ret = create_matching_event_notifiers(event_notifier_enabler,
+ filter, compat_sc_table, ARRAY_SIZE(compat_sc_table),
+ SC_TYPE_COMPAT_ENTRY);
+ if (ret)
+ goto end;
+
+ ret = create_unknown_event_notifier(event_notifier_enabler,
+ SC_TYPE_ENTRY);
+ if (ret)
+ goto end;
+
+ ret = create_unknown_event_notifier(event_notifier_enabler,
+ SC_TYPE_COMPAT_ENTRY);
+ if (ret)
+ goto end;
+ }
+
+ if (entryexit == LTTNG_KERNEL_SYSCALL_EXIT || entryexit == LTTNG_KERNEL_SYSCALL_ENTRYEXIT) {
+ ret = create_matching_event_notifiers(event_notifier_enabler,
+ filter, sc_exit_table, ARRAY_SIZE(sc_exit_table),
+ SC_TYPE_EXIT);
+ if (ret)
+ goto end;
+
+ ret = create_unknown_event_notifier(event_notifier_enabler,
+ SC_TYPE_EXIT);
+ if (ret)
+ goto end;
+
+ ret = create_matching_event_notifiers(event_notifier_enabler,
+ filter, compat_sc_exit_table, ARRAY_SIZE(compat_sc_exit_table),
+ SC_TYPE_COMPAT_EXIT);
+ if (ret)
+ goto end;
+
+ ret = create_unknown_event_notifier(event_notifier_enabler,
+ SC_TYPE_COMPAT_EXIT);
+ if (ret)
+ goto end;
+ }
+
+end:
+ return ret;
+}
+
+/*
+ * Unregister the syscall event_notifier probes from the callsites.
+ */
+int lttng_syscalls_unregister_event_notifier_group(
+ struct lttng_event_notifier_group *event_notifier_group)
+{
+ int ret;
+
+ /*
+ * Only register the event_notifier probe on the `sys_enter` callsite for now.
+ * At the moment, we don't think it's desirable to have one fired
+ * event_notifier for the entry and one for the exit of a syscall.
+ */
+ if (event_notifier_group->sys_enter_registered) {
+ ret = lttng_wrapper_tracepoint_probe_unregister("sys_enter",
+ (void *) syscall_entry_event_notifier_probe, event_notifier_group);
+ if (ret)
+ return ret;
+ event_notifier_group->sys_enter_registered = 0;
+ }
+ if (event_notifier_group->sys_exit_registered) {
+ ret = lttng_wrapper_tracepoint_probe_unregister("sys_exit",
+ (void *) syscall_exit_event_notifier_probe, event_notifier_group);
+ if (ret)
+ return ret;
+ event_notifier_group->sys_enter_registered = 0;
+ }
+
+ kfree(event_notifier_group->event_notifier_syscall_dispatch);
+ kfree(event_notifier_group->event_notifier_exit_syscall_dispatch);
+#ifdef CONFIG_COMPAT
+ kfree(event_notifier_group->event_notifier_compat_syscall_dispatch);
+ kfree(event_notifier_group->event_notifier_exit_compat_syscall_dispatch);
+#endif
+ return 0;
+}
+
+int lttng_syscalls_unregister_channel(struct lttng_channel *chan)