X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fkernel-probe.c;h=d2637f933efa18afb243049353cdab4c089908a2;hp=1934a76b1e261ffb44505fe8d02da21c5c74119a;hb=44635d77b591f83a80d48cd93497bd1cd6aa788d;hpb=808cb744a46310d2e5fbbe9ab025cd427bcfc0a8 diff --git a/src/common/kernel-probe.c b/src/common/kernel-probe.c index 1934a76b1..d2637f933 100644 --- a/src/common/kernel-probe.c +++ b/src/common/kernel-probe.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,6 +41,14 @@ bool lttng_kernel_probe_location_symbol_is_equal( const struct lttng_kernel_probe_location *a, const struct lttng_kernel_probe_location *b); +static +unsigned long lttng_kernel_probe_location_address_hash( + const struct lttng_kernel_probe_location *location); + +static +unsigned long lttng_kernel_probe_location_symbol_hash( + const struct lttng_kernel_probe_location *location); + enum lttng_kernel_probe_location_type lttng_kernel_probe_location_get_type( const struct lttng_kernel_probe_location *location) { @@ -99,7 +109,7 @@ lttng_kernel_probe_location_address_create(uint64_t address) location = zmalloc(sizeof(*location)); if (!location) { - PERROR("Error allocating userspace probe location"); + PERROR("Error allocating userspace probe location."); goto end; } @@ -109,6 +119,7 @@ lttng_kernel_probe_location_address_create(uint64_t address) ret->type = LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS; ret->equal = lttng_kernel_probe_location_address_is_equal; ret->serialize = lttng_kernel_probe_location_address_serialize; + ret->hash = lttng_kernel_probe_location_address_hash; end: return ret; @@ -145,6 +156,7 @@ lttng_kernel_probe_location_symbol_create(const char *symbol_name, ret->type = LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET; ret->equal = lttng_kernel_probe_location_symbol_is_equal; ret->serialize = lttng_kernel_probe_location_symbol_serialize; + ret->hash = lttng_kernel_probe_location_symbol_hash; goto end; error: @@ -433,20 +445,23 @@ ssize_t lttng_kernel_probe_location_create_from_payload( struct lttng_payload_view *view, struct lttng_kernel_probe_location **location) { - struct lttng_kernel_probe_location_comm *probe_location_comm; enum lttng_kernel_probe_location_type type; ssize_t consumed = 0; ssize_t ret; + const struct lttng_kernel_probe_location_comm *probe_location_comm; + const struct lttng_payload_view probe_location_comm_view = + lttng_payload_view_from_view( + view, 0, sizeof(*probe_location_comm)); assert(view); assert(location); - if (view->buffer.size <= sizeof(*probe_location_comm)) { + if (!lttng_payload_view_is_valid(&probe_location_comm_view)) { ret = -LTTNG_ERR_INVALID; goto end; } - probe_location_comm = (typeof(probe_location_comm)) view->buffer.data; + probe_location_comm = (typeof(probe_location_comm)) probe_location_comm_view.buffer.data; type = (enum lttng_kernel_probe_location_type) probe_location_comm->type; consumed += sizeof(*probe_location_comm); @@ -486,6 +501,22 @@ end: return ret; } +static +unsigned long lttng_kernel_probe_location_address_hash( + const struct lttng_kernel_probe_location *location) +{ + unsigned long hash = hash_key_ulong( + (void *) LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS, + lttng_ht_seed); + struct lttng_kernel_probe_location_address *address_location = + container_of(location, typeof(*address_location), + parent); + + hash ^= hash_key_u64(&address_location->address, lttng_ht_seed); + + return hash; +} + static bool lttng_kernel_probe_location_address_is_equal( const struct lttng_kernel_probe_location *_a, @@ -509,6 +540,23 @@ end: return is_equal; } +static +unsigned long lttng_kernel_probe_location_symbol_hash( + const struct lttng_kernel_probe_location *location) +{ + unsigned long hash = hash_key_ulong( + (void *) LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET, + lttng_ht_seed); + struct lttng_kernel_probe_location_symbol *symbol_location = + container_of(location, typeof(*symbol_location), + parent); + + hash ^= hash_key_str(symbol_location->symbol_name, lttng_ht_seed); + hash ^= hash_key_u64(&symbol_location->offset, lttng_ht_seed); + + return hash; +} + static bool lttng_kernel_probe_location_symbol_is_equal( const struct lttng_kernel_probe_location *_a, @@ -562,3 +610,117 @@ bool lttng_kernel_probe_location_is_equal( end: return is_equal; } + +static struct lttng_kernel_probe_location * +lttng_kernel_probe_location_symbol_copy( + const struct lttng_kernel_probe_location *location) +{ + struct lttng_kernel_probe_location *new_location = NULL; + struct lttng_kernel_probe_location_symbol *symbol_location; + enum lttng_kernel_probe_location_status status; + const char *symbol_name = NULL; + uint64_t offset; + + assert(location); + assert(location->type == LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET); + symbol_location = container_of( + location, typeof(*symbol_location), parent); + + /* Get probe location offset */ + status = lttng_kernel_probe_location_symbol_get_offset(location, &offset); + if (status != LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK) { + ERR("Get kernel probe location offset failed."); + goto error; + } + + symbol_name = lttng_kernel_probe_location_symbol_get_name(location); + if (!symbol_name) { + ERR("Kernel probe symbol name is NULL."); + goto error; + } + + /* Create the probe_location */ + new_location = lttng_kernel_probe_location_symbol_create( + symbol_name, offset); + + goto end; + +error: + new_location = NULL; +end: + return new_location; +} +static struct lttng_kernel_probe_location * +lttng_kernel_probe_location_address_copy( + const struct lttng_kernel_probe_location *location) +{ + struct lttng_kernel_probe_location *new_location = NULL; + struct lttng_kernel_probe_location_address *address_location; + enum lttng_kernel_probe_location_status status; + uint64_t address; + + assert(location); + assert(location->type == LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS); + address_location = container_of( + location, typeof(*address_location), parent); + + + /* Get probe location fields */ + status = lttng_kernel_probe_location_address_get_address(location, &address); + if (status != LTTNG_KERNEL_PROBE_LOCATION_STATUS_OK) { + ERR("Get kernel probe address failed."); + goto error; + } + + /* Create the probe_location */ + new_location = lttng_kernel_probe_location_address_create(address); + + goto end; + +error: + new_location = NULL; +end: + return new_location; +} + +LTTNG_HIDDEN +struct lttng_kernel_probe_location *lttng_kernel_probe_location_copy( + const struct lttng_kernel_probe_location *location) +{ + struct lttng_kernel_probe_location *new_location = NULL; + enum lttng_kernel_probe_location_type type; + + if (!location) { + goto err; + } + + type = lttng_kernel_probe_location_get_type(location); + switch (type) { + case LTTNG_KERNEL_PROBE_LOCATION_TYPE_ADDRESS: + new_location = + lttng_kernel_probe_location_address_copy(location); + if (!new_location) { + goto err; + } + break; + case LTTNG_KERNEL_PROBE_LOCATION_TYPE_SYMBOL_OFFSET: + new_location = + lttng_kernel_probe_location_symbol_copy(location); + if (!new_location) { + goto err; + } + break; + default: + new_location = NULL; + goto err; + } +err: + return new_location; +} + +LTTNG_HIDDEN +unsigned long lttng_kernel_probe_location_hash( + const struct lttng_kernel_probe_location *location) +{ + return location->hash(location); +}