* receiving the side_call arguments.
*
* * Event descriptions can be extended by adding fields at the end of
- * the structure. The "struct side_event_description" is therefore a
- * structure with flexible size and must not be used within arrays.
+ * the structure. The "struct side_event_description" and "struct
+ * side_event_state" are therefore structures with flexible size and
+ * must not be used within arrays.
*/
#define SIDE_ABI_VERSION 0
* fields.
*/
struct side_event_state {
- uintptr_t enabled;
- const struct side_callback *callbacks;
- struct side_event_description *desc;
+ uint32_t struct_size; /* Size of this structure. */
+ uint32_t enabled;
+ side_ptr_t(const struct side_callback) callbacks;
+ side_ptr_t(struct side_event_description) desc;
+
+ char end[]; /* End with a flexible array to account for extensibility. */
};
/* Event and type attributes */
_identifier; \
_linkage struct side_event_state __attribute__((section("side_event_state"))) \
side_event_state__##_identifier = { \
+ .struct_size = offsetof(struct side_event_state, end), \
.enabled = 0, \
- .callbacks = &side_empty_callback, \
- .desc = &(_identifier), \
+ .callbacks = SIDE_PTR_INIT(&side_empty_callback), \
+ .desc = SIDE_PTR_INIT(&(_identifier)), \
}; \
_linkage struct side_event_description __attribute__((section("side_event_description"))) \
_identifier = { \
return;
if (side_unlikely(!initialized))
side_init();
- assert(!(event_state->desc->flags & SIDE_EVENT_FLAG_VARIADIC));
+ assert(!(side_ptr_get(event_state->desc)->flags & SIDE_EVENT_FLAG_VARIADIC));
enabled = __atomic_load_n(&event_state->enabled, __ATOMIC_RELAXED);
if (side_unlikely(enabled & SIDE_EVENT_ENABLED_KERNEL_USER_EVENT_MASK)) {
// TODO: call kernel write.
}
side_rcu_read_begin(&rcu_gp, &rcu_read_state);
- for (side_cb = side_rcu_dereference(event_state->callbacks); side_cb->u.call != NULL; side_cb++)
- side_cb->u.call(event_state->desc, side_arg_vec, side_cb->priv);
+ for (side_cb = side_rcu_dereference(side_ptr_get(event_state->callbacks)); side_cb->u.call != NULL; side_cb++)
+ side_cb->u.call(side_ptr_get(event_state->desc), side_arg_vec, side_cb->priv);
side_rcu_read_end(&rcu_gp, &rcu_read_state);
}
return;
if (side_unlikely(!initialized))
side_init();
- assert(event_state->desc->flags & SIDE_EVENT_FLAG_VARIADIC);
+ assert(side_ptr_get(event_state->desc)->flags & SIDE_EVENT_FLAG_VARIADIC);
enabled = __atomic_load_n(&event_state->enabled, __ATOMIC_RELAXED);
if (side_unlikely(enabled & SIDE_EVENT_ENABLED_KERNEL_USER_EVENT_MASK)) {
// TODO: call kernel write.
}
side_rcu_read_begin(&rcu_gp, &rcu_read_state);
- for (side_cb = side_rcu_dereference(event_state->callbacks); side_cb->u.call_variadic != NULL; side_cb++)
- side_cb->u.call_variadic(event_state->desc, side_arg_vec, var_struct, side_cb->priv);
+ for (side_cb = side_rcu_dereference(side_ptr_get(event_state->callbacks)); side_cb->u.call_variadic != NULL; side_cb++)
+ side_cb->u.call_variadic(side_ptr_get(event_state->desc), side_arg_vec, var_struct, side_cb->priv);
side_rcu_read_end(&rcu_gp, &rcu_read_state);
}
struct side_event_state *event_state = side_ptr_get(desc->state);
const struct side_callback *cb;
- for (cb = event_state->callbacks; cb->u.call != NULL; cb++) {
+ for (cb = side_ptr_get(event_state->callbacks); cb->u.call != NULL; cb++) {
if ((void *) cb->u.call == call && cb->priv == priv)
return cb;
}
ret = SIDE_ERROR_EXIST;
goto unlock;
}
- old_cb = (struct side_callback *) event_state->callbacks;
+ old_cb = (struct side_callback *) side_ptr_get(event_state->callbacks);
/* old_nr_cb + 1 (new cb) + 1 (NULL) */
new_cb = (struct side_callback *) calloc(old_nr_cb + 2, sizeof(struct side_callback));
if (!new_cb) {
new_cb[old_nr_cb].u.call =
(side_tracer_callback_func) call;
new_cb[old_nr_cb].priv = priv;
- side_rcu_assign_pointer(event_state->callbacks, new_cb);
+ /* High order bits are already zeroed. */
+ side_rcu_assign_pointer(side_ptr_get(event_state->callbacks), new_cb);
side_rcu_wait_grace_period(&rcu_gp);
if (old_nr_cb)
free(old_cb);
goto unlock;
}
old_nr_cb = desc->nr_callbacks;
- old_cb = (struct side_callback *) event_state->callbacks;
+ old_cb = (struct side_callback *) side_ptr_get(event_state->callbacks);
if (old_nr_cb == 1) {
new_cb = (struct side_callback *) &side_empty_callback;
} else {
- pos_idx = cb_pos - event_state->callbacks;
+ pos_idx = cb_pos - side_ptr_get(event_state->callbacks);
/* Remove entry at pos_idx. */
/* old_nr_cb - 1 (removed cb) + 1 (NULL) */
new_cb = (struct side_callback *) calloc(old_nr_cb, sizeof(struct side_callback));
memcpy(new_cb, old_cb, pos_idx);
memcpy(&new_cb[pos_idx], &old_cb[pos_idx + 1], old_nr_cb - pos_idx - 1);
}
- side_rcu_assign_pointer(event_state->callbacks, new_cb);
+ /* High order bits are already zeroed. */
+ side_rcu_assign_pointer(side_ptr_get(event_state->callbacks), new_cb);
side_rcu_wait_grace_period(&rcu_gp);
free(old_cb);
desc->nr_callbacks--;
if (!nr_cb)
return;
- old_cb = (struct side_callback *) event_state->callbacks;
+ old_cb = (struct side_callback *) side_ptr_get(event_state->callbacks);
(void) __atomic_add_fetch(&event_state->enabled, -1, __ATOMIC_RELAXED);
/*
* Setting the state back to 0 cb and empty callbacks out of
* unreachable.
*/
desc->nr_callbacks = 0;
- side_rcu_assign_pointer(event_state->callbacks, &side_empty_callback);
+ side_rcu_assign_pointer(side_ptr_get(event_state->callbacks), &side_empty_callback);
/*
* No need to wait for grace period because instrumentation is
* unreachable.