+ chan_id = ust_reg_chan.id;
+
+ /*
+ * The application returns the typing information of the channel's
+ * context fields. In per-PID buffering mode, this is the first and only
+ * time we get this information. It is our chance to finalize the
+ * initialiation of the channel and serialize it's layout's description
+ * to the trace's metadata.
+ *
+ * However, in per-UID buffering mode, every application will provide
+ * this information (redundantly). The first time will allow us to
+ * complete the initialization. The following times, we simply validate
+ * that all apps provide the same typing for the context fields as a
+ * sanity check.
+ */
+ try {
+ auto app_context_fields = lsu::create_trace_fields_from_ust_ctl_fields(
+ *locked_registry_session,
+ ust_ctl_context_fields.get(),
+ context_field_count,
+ lst::field_location::root::EVENT_RECORD_COMMON_CONTEXT,
+ lsu::ctl_field_quirks::UNDERSCORE_PREFIXED_VARIANT_TAG_MAPPINGS);
+
+ if (!ust_reg_chan.is_registered()) {
+ lst::type::cuptr event_context = app_context_fields.size() ?
+ lttng::make_unique<lst::structure_type>(
+ 0, std::move(app_context_fields)) :
+ nullptr;
+
+ ust_reg_chan.event_context(std::move(event_context));
+ } else {
+ /*
+ * Validate that the context fields match between
+ * registry and newcoming application.
+ */
+ bool context_fields_match;
+ const auto *previous_event_context = ust_reg_chan.event_context();