Fix: adding a user space probe fails on thumb functions
[lttng-tools.git] / src / bin / lttng-sessiond / kernel.c
index f1e61846d8a18911989b9b4a87120f9fbf9e7841..4c5227189612d8d02c1a858e8c8308d452025035 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
  *
  * SPDX-License-Identifier: GPL-2.0-only
  *
@@ -32,7 +32,7 @@
 #include <lttng/condition/event-rule-matches-internal.h>
 #include <lttng/event-rule/event-rule.h>
 #include <lttng/event-rule/event-rule-internal.h>
-#include <lttng/event-rule/userspace-probe-internal.h>
+#include <lttng/event-rule/kernel-uprobe-internal.h>
 
 #include "event-notifier-error-accounting.h"
 #include "lttng-sessiond.h"
@@ -62,6 +62,30 @@ static int kernel_tracer_event_notifier_group_fd = -1;
 static int kernel_tracer_event_notifier_group_notification_fd = -1;
 static struct cds_lfht *kernel_token_to_event_notifier_rule_ht;
 
+/*
+ * On some architectures, calling convention details are embedded in the symbol
+ * addresses. Uprobe requires a "clean" symbol offset (or at least, an address
+ * where an instruction boundary would be legal) to add
+ * instrumentation. sanitize_uprobe_offset implements that sanitization logic on
+ * a per-architecture basis.
+ */
+#if defined(__arm__) || defined(__aarch64__)
+static inline uint64_t sanitize_uprobe_offset(uint64_t raw_offset)
+{
+       /*
+        * The least significant bit is used when branching to switch to thumb
+        * ISA. However, it's an invalid address for us; mask the least
+        * significant bit.
+        */
+       return raw_offset &= ~0b1;
+}
+#else /* defined(__arm__) || defined(__aarch64__) */
+static inline uint64_t sanitize_uprobe_offset(uint64_t raw_offset)
+{
+       return raw_offset;
+}
+#endif
+
 /*
  * Add context on a kernel channel.
  *
@@ -446,7 +470,7 @@ int userspace_probe_add_callsite(
                        goto end;
                }
 
-               callsite.u.uprobe.offset = offset;
+               callsite.u.uprobe.offset = sanitize_uprobe_offset(offset);
                ret = kernctl_add_callsite(fd, &callsite);
                if (ret) {
                        WARN("Failed to add callsite to ELF userspace probe.");
@@ -473,7 +497,7 @@ int userspace_probe_add_callsite(
                        goto end;
                }
                for (i = 0; i < offsets_count; i++) {
-                       callsite.u.uprobe.offset = offsets[i];
+                       callsite.u.uprobe.offset = sanitize_uprobe_offset(offsets[i]);
                        ret = kernctl_add_callsite(fd, &callsite);
                        if (ret) {
                                WARN("Failed to add callsite to SDT userspace probe");
@@ -542,9 +566,9 @@ static int userspace_probe_event_rule_add_callsites(
        assert(creds);
 
        event_rule_type = lttng_event_rule_get_type(rule);
-       assert(event_rule_type == LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE);
+       assert(event_rule_type == LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE);
 
-       status = lttng_event_rule_userspace_probe_get_location(rule, &location);
+       status = lttng_event_rule_kernel_uprobe_get_location(rule, &location);
        if (status != LTTNG_EVENT_RULE_STATUS_OK || !location) {
                ret = -1;
                goto end;
@@ -1699,7 +1723,7 @@ enum lttng_error_code kernel_snapshot_record(
        }
 
        trace_path = setup_channel_trace_path(ksess->consumer,
-                       DEFAULT_KERNEL_TRACE_DIR, &consumer_path_offset);
+                       "", &consumer_path_offset);
        if (!trace_path) {
                status = LTTNG_ERR_INVALID;
                goto error;
@@ -2394,7 +2418,7 @@ static enum lttng_error_code kernel_create_event_notifier_rule(
        }
 
        if (lttng_event_rule_get_type(event_rule) ==
-                       LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE) {
+                       LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE) {
                ret = userspace_probe_event_rule_add_callsites(
                                event_rule, creds, event_notifier_rule->fd);
                if (ret) {
This page took 0.024572 seconds and 4 git commands to generate.