X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Flib%2Flttng-ust-ctl%2Fustctl.c;h=784cb75db0b46a7c42a9b506199a3e10e2baf343;hb=2722f20cbda88b5f6250213a7be8412c19a11e8a;hp=e4434bc075b08a3c8c7ad160594b781b60cbb0e3;hpb=6bd9392ed14dabcfadc64772e972c76e8752c199;p=lttng-ust.git diff --git a/src/lib/lttng-ust-ctl/ustctl.c b/src/lib/lttng-ust-ctl/ustctl.c index e4434bc0..784cb75d 100644 --- a/src/lib/lttng-ust-ctl/ustctl.c +++ b/src/lib/lttng-ust-ctl/ustctl.c @@ -16,6 +16,9 @@ #include #include #include +#include +#include +#include #include "common/logging.h" #include "common/ustcomm.h" @@ -24,15 +27,14 @@ #include "common/ringbuffer/backend.h" #include "common/ringbuffer/frontend.h" -#include "lib/lttng-ust/ust-events-internal.h" +#include "common/events.h" #include "common/wait.h" -#include "lib/lttng-ust/lttng-rb-clients.h" -#include "lib/lttng-ust/clock.h" -#include "lib/lttng-ust/getenv.h" -#include "lib/lttng-ust/lttng-tracer-core.h" -#include "lib/lttng-ust/lttng-counter-client.h" +#include "common/ringbuffer-clients/clients.h" +#include "common/getenv.h" +#include "common/tracer.h" +#include "common/counter-clients/clients.h" -#include "common/counter/smp.h" +#include "common/smp.h" #include "common/counter/counter.h" /* @@ -44,11 +46,11 @@ /* * Channel representation within consumer. */ -struct ustctl_consumer_channel { +struct lttng_ust_ctl_consumer_channel { struct lttng_ust_channel_buffer *chan; /* lttng channel buffers */ /* initial attributes */ - struct ustctl_consumer_channel_attr attr; + struct lttng_ust_ctl_consumer_channel_attr attr; int wait_fd; /* monitor close() */ int wakeup_fd; /* monitor close() */ }; @@ -56,34 +58,96 @@ struct ustctl_consumer_channel { /* * Stream representation within consumer. */ -struct ustctl_consumer_stream { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *chan; +struct lttng_ust_ctl_consumer_stream { + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *chan; int shm_fd, wait_fd, wakeup_fd; int cpu; uint64_t memory_map_size; + void *memory_map_addr; }; -#define USTCTL_COUNTER_ATTR_DIMENSION_MAX 8 -struct ustctl_counter_attr { - enum ustctl_counter_arithmetic arithmetic; - enum ustctl_counter_bitness bitness; +#define LTTNG_UST_CTL_COUNTER_ATTR_DIMENSION_MAX 8 +struct lttng_ust_ctl_counter_attr { + enum lttng_ust_ctl_counter_arithmetic arithmetic; + enum lttng_ust_ctl_counter_bitness bitness; uint32_t nr_dimensions; int64_t global_sum_step; - struct ustctl_counter_dimension dimensions[USTCTL_COUNTER_ATTR_DIMENSION_MAX]; + struct lttng_ust_ctl_counter_dimension dimensions[LTTNG_UST_CTL_COUNTER_ATTR_DIMENSION_MAX]; bool coalesce_hits; }; /* * Counter representation within daemon. */ -struct ustctl_daemon_counter { +struct lttng_ust_ctl_daemon_counter { struct lib_counter *counter; const struct lttng_counter_ops *ops; - struct ustctl_counter_attr *attr; /* initial attributes */ + struct lttng_ust_ctl_counter_attr *attr; /* initial attributes */ }; -int ustctl_release_handle(int sock, int handle) +/* + * Evaluates to false if transaction begins, true if it has failed due to SIGBUS. + * The entire transaction must complete before the current function returns. + * A transaction can contain 0 or more tracked ranges as sigbus begin/end pairs. + */ +#define sigbus_begin() \ +({ \ + assert(!lttng_ust_sigbus_state.jmp_ready); \ + if (!lttng_ust_sigbus_state.head.next) { \ + /* \ + * Lazy init because static list initialisation is \ + * problematic for TLS variable. \ + */ \ + CDS_INIT_LIST_HEAD(<tng_ust_sigbus_state.head); \ + } \ + if (sigsetjmp(lttng_ust_sigbus_state.sj_env, 1)) { \ + /* SIGBUS. */ \ + CMM_STORE_SHARED(lttng_ust_sigbus_state.jmp_ready, 0); \ + true; \ + } \ + cmm_barrier(); \ + CMM_STORE_SHARED(lttng_ust_sigbus_state.jmp_ready, 1); \ + false; \ +}) + +static void sigbus_end(void) +{ + assert(lttng_ust_sigbus_state.jmp_ready); + cmm_barrier(); + CMM_STORE_SHARED(lttng_ust_sigbus_state.jmp_ready, 0); +} + +static +void lttng_ust_sigbus_add_range(struct lttng_ust_sigbus_range *range, void *start, size_t len) +{ + range->start = start; + range->end = (char *)start + len; + cds_list_add_rcu(&range->node, <tng_ust_sigbus_state.head); + cmm_barrier(); +} + +static +void lttng_ust_sigbus_del_range(struct lttng_ust_sigbus_range *range) +{ + cmm_barrier(); + cds_list_del_rcu(&range->node); +} + +void lttng_ust_ctl_sigbus_handle(void *addr) +{ + struct lttng_ust_sigbus_range *range; + + if (!CMM_LOAD_SHARED(lttng_ust_sigbus_state.jmp_ready)) + return; + cds_list_for_each_entry_rcu(range, <tng_ust_sigbus_state.head, node) { + if (addr < range->start || addr >= range->end) + continue; + siglongjmp(lttng_ust_sigbus_state.sj_env, 1); + } +} + +int lttng_ust_ctl_release_handle(int sock, int handle) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -100,7 +164,7 @@ int ustctl_release_handle(int sock, int handle) * If sock is negative, it means we don't have to notify the other side * (e.g. application has already vanished). */ -int ustctl_release_object(int sock, struct lttng_ust_abi_object_data *data) +int lttng_ust_ctl_release_object(int sock, struct lttng_ust_abi_object_data *data) { int ret; @@ -170,13 +234,13 @@ int ustctl_release_object(int sock, struct lttng_ust_abi_object_data *data) default: assert(0); } - return ustctl_release_handle(sock, data->handle); + return lttng_ust_ctl_release_handle(sock, data->handle); } /* * Send registration done packet to the application. */ -int ustctl_register_done(int sock) +int lttng_ust_ctl_register_done(int sock) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -195,7 +259,7 @@ int ustctl_register_done(int sock) /* * returns session handle. */ -int ustctl_create_session(int sock) +int lttng_ust_ctl_create_session(int sock) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -213,7 +277,7 @@ int ustctl_create_session(int sock) return session_handle; } -int ustctl_create_event(int sock, struct lttng_ust_abi_event *ev, +int lttng_ust_ctl_create_event(int sock, struct lttng_ust_abi_event *ev, struct lttng_ust_abi_object_data *channel_data, struct lttng_ust_abi_object_data **_event_data) { @@ -248,7 +312,18 @@ int ustctl_create_event(int sock, struct lttng_ust_abi_event *ev, return 0; } -int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx, +/* + * Protocol for LTTNG_UST_ABI_CONTEXT command: + * + * - send: struct ustcomm_ust_msg + * - send: var len ctx_name + * - receive: struct ustcomm_ust_reply + * + * TODO: At the next breaking protocol bump, we should indicate the total + * command message length as part of a message header so that the protocol can + * recover from invalid command errors. + */ +int lttng_ust_ctl_add_context(int sock, struct lttng_ust_context_attr *ctx, struct lttng_ust_abi_object_data *obj_data, struct lttng_ust_abi_object_data **_context_data) { @@ -319,6 +394,13 @@ int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx, } ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); if (ret < 0) { + if (ret == -EINVAL) { + /* + * Command unknown from remote end. The communication socket is + * now out-of-sync and needs to be shutdown. + */ + (void) ustcomm_shutdown_unix_sock(sock); + } goto end; } context_data->handle = -1; @@ -331,7 +413,18 @@ end: return ret; } -int ustctl_set_filter(int sock, struct lttng_ust_abi_filter_bytecode *bytecode, +/* + * Protocol for LTTNG_UST_ABI_FILTER command: + * + * - send: struct ustcomm_ust_msg + * - send: var len bytecode + * - receive: struct ustcomm_ust_reply + * + * TODO: At the next breaking protocol bump, we should indicate the total + * command message length as part of a message header so that the protocol can + * recover from invalid command errors. + */ +int lttng_ust_ctl_set_filter(int sock, struct lttng_ust_abi_filter_bytecode *bytecode, struct lttng_ust_abi_object_data *obj_data) { struct ustcomm_ust_msg lum; @@ -359,10 +452,26 @@ int ustctl_set_filter(int sock, struct lttng_ust_abi_filter_bytecode *bytecode, } if (ret != bytecode->len) return -EINVAL; - return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); + ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); + if (ret == -EINVAL) { + /* + * Command unknown from remote end. The communication socket is + * now out-of-sync and needs to be shutdown. + */ + (void) ustcomm_shutdown_unix_sock(sock); + } + return ret; } -int ustctl_set_capture(int sock, struct lttng_ust_abi_capture_bytecode *bytecode, +/* + * Protocol for LTTNG_UST_ABI_CAPTURE command: + * + * - send: struct ustcomm_ust_msg + * - receive: struct ustcomm_ust_reply + * - send: var len bytecode + * - receive: struct ustcomm_ust_reply (actual command return code) + */ +int lttng_ust_ctl_set_capture(int sock, struct lttng_ust_abi_capture_bytecode *bytecode, struct lttng_ust_abi_object_data *obj_data) { struct ustcomm_ust_msg lum; @@ -379,7 +488,7 @@ int ustctl_set_capture(int sock, struct lttng_ust_abi_capture_bytecode *bytecode lum.u.capture.reloc_offset = bytecode->reloc_offset; lum.u.capture.seqnum = bytecode->seqnum; - ret = ustcomm_send_app_msg(sock, &lum); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; /* send var len bytecode */ @@ -393,7 +502,18 @@ int ustctl_set_capture(int sock, struct lttng_ust_abi_capture_bytecode *bytecode return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); } -int ustctl_set_exclusion(int sock, struct lttng_ust_abi_event_exclusion *exclusion, +/* + * Protocol for LTTNG_UST_ABI_EXCLUSION command: + * + * - send: struct ustcomm_ust_msg + * - send: var len exclusion names + * - receive: struct ustcomm_ust_reply + * + * TODO: At the next breaking protocol bump, we should indicate the total + * command message length as part of a message header so that the protocol can + * recover from invalid command errors. + */ +int lttng_ust_ctl_set_exclusion(int sock, struct lttng_ust_abi_event_exclusion *exclusion, struct lttng_ust_abi_object_data *obj_data) { struct ustcomm_ust_msg lum; @@ -424,11 +544,19 @@ int ustctl_set_exclusion(int sock, struct lttng_ust_abi_event_exclusion *exclusi if (ret != exclusion->count * LTTNG_UST_ABI_SYM_NAME_LEN) { return -EINVAL; } - return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); + ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); + if (ret == -EINVAL) { + /* + * Command unknown from remote end. The communication socket is + * now out-of-sync and needs to be shutdown. + */ + (void) ustcomm_shutdown_unix_sock(sock); + } + return ret; } /* Enable event, channel and session ioctl */ -int ustctl_enable(int sock, struct lttng_ust_abi_object_data *object) +int lttng_ust_ctl_enable(int sock, struct lttng_ust_abi_object_data *object) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -448,7 +576,7 @@ int ustctl_enable(int sock, struct lttng_ust_abi_object_data *object) } /* Disable event, channel and session ioctl */ -int ustctl_disable(int sock, struct lttng_ust_abi_object_data *object) +int lttng_ust_ctl_disable(int sock, struct lttng_ust_abi_object_data *object) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -467,23 +595,31 @@ int ustctl_disable(int sock, struct lttng_ust_abi_object_data *object) return 0; } -int ustctl_start_session(int sock, int handle) +int lttng_ust_ctl_start_session(int sock, int handle) { struct lttng_ust_abi_object_data obj; obj.handle = handle; - return ustctl_enable(sock, &obj); + return lttng_ust_ctl_enable(sock, &obj); } -int ustctl_stop_session(int sock, int handle) +int lttng_ust_ctl_stop_session(int sock, int handle) { struct lttng_ust_abi_object_data obj; obj.handle = handle; - return ustctl_disable(sock, &obj); + return lttng_ust_ctl_disable(sock, &obj); } -int ustctl_create_event_notifier_group(int sock, int pipe_fd, +/* + * Protocol for LTTNG_UST_ABI_EVENT_NOTIFIER_GROUP_CREATE command: + * + * - send: struct ustcomm_ust_msg + * - receive: struct ustcomm_ust_reply + * - send: file descriptor + * - receive: struct ustcomm_ust_reply (actual command return code) + */ +int lttng_ust_ctl_create_event_notifier_group(int sock, int pipe_fd, struct lttng_ust_abi_object_data **_event_notifier_group_data) { struct lttng_ust_abi_object_data *event_notifier_group_data; @@ -505,7 +641,7 @@ int ustctl_create_event_notifier_group(int sock, int pipe_fd, lum.handle = LTTNG_UST_ABI_ROOT_HANDLE; lum.cmd = LTTNG_UST_ABI_EVENT_NOTIFIER_GROUP_CREATE; - ret = ustcomm_send_app_msg(sock, &lum); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) goto error; @@ -534,7 +670,15 @@ end: return ret; } -int ustctl_create_event_notifier(int sock, struct lttng_ust_abi_event_notifier *event_notifier, +/* + * Protocol for LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE command: + * + * - send: struct ustcomm_ust_msg + * - receive: struct ustcomm_ust_reply + * - send: struct lttng_ust_abi_event_notifier + * - receive: struct ustcomm_ust_reply (actual command return code) + */ +int lttng_ust_ctl_create_event_notifier(int sock, struct lttng_ust_abi_event_notifier *event_notifier, struct lttng_ust_abi_object_data *event_notifier_group, struct lttng_ust_abi_object_data **_event_notifier_data) { @@ -558,7 +702,7 @@ int ustctl_create_event_notifier(int sock, struct lttng_ust_abi_event_notifier * lum.cmd = LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE; lum.u.event_notifier.len = sizeof(*event_notifier); - ret = ustcomm_send_app_msg(sock, &lum); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) { free(event_notifier_data); return ret; @@ -584,7 +728,7 @@ int ustctl_create_event_notifier(int sock, struct lttng_ust_abi_event_notifier * return ret; } -int ustctl_tracepoint_list(int sock) +int lttng_ust_ctl_tracepoint_list(int sock) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -601,7 +745,7 @@ int ustctl_tracepoint_list(int sock) return tp_list_handle; } -int ustctl_tracepoint_list_get(int sock, int tp_list_handle, +int lttng_ust_ctl_tracepoint_list_get(int sock, int tp_list_handle, struct lttng_ust_abi_tracepoint_iter *iter) { struct ustcomm_ust_msg lum; @@ -624,7 +768,7 @@ int ustctl_tracepoint_list_get(int sock, int tp_list_handle, return 0; } -int ustctl_tracepoint_field_list(int sock) +int lttng_ust_ctl_tracepoint_field_list(int sock) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -641,7 +785,7 @@ int ustctl_tracepoint_field_list(int sock) return tp_field_list_handle; } -int ustctl_tracepoint_field_list_get(int sock, int tp_field_list_handle, +int lttng_ust_ctl_tracepoint_field_list_get(int sock, int tp_field_list_handle, struct lttng_ust_abi_field_iter *iter) { struct ustcomm_ust_msg lum; @@ -670,7 +814,7 @@ int ustctl_tracepoint_field_list_get(int sock, int tp_field_list_handle, return 0; } -int ustctl_tracer_version(int sock, struct lttng_ust_abi_tracer_version *v) +int lttng_ust_ctl_tracer_version(int sock, struct lttng_ust_abi_tracer_version *v) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -690,7 +834,7 @@ int ustctl_tracer_version(int sock, struct lttng_ust_abi_tracer_version *v) return 0; } -int ustctl_wait_quiescent(int sock) +int lttng_ust_ctl_wait_quiescent(int sock) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -706,7 +850,7 @@ int ustctl_wait_quiescent(int sock) return 0; } -int ustctl_calibrate(int sock __attribute__((unused)), +int lttng_ust_ctl_calibrate(int sock __attribute__((unused)), struct lttng_ust_abi_calibrate *calibrate) { if (!calibrate) @@ -715,7 +859,7 @@ int ustctl_calibrate(int sock __attribute__((unused)), return -ENOSYS; } -int ustctl_sock_flush_buffer(int sock, struct lttng_ust_abi_object_data *object) +int lttng_ust_ctl_sock_flush_buffer(int sock, struct lttng_ust_abi_object_data *object) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -735,7 +879,7 @@ int ustctl_sock_flush_buffer(int sock, struct lttng_ust_abi_object_data *object) } static -int ustctl_send_channel(int sock, +int lttng_ust_ctl_send_channel(int sock, enum lttng_ust_abi_chan_type type, void *data, uint64_t size, @@ -785,7 +929,7 @@ int ustctl_send_channel(int sock, } static -int ustctl_send_stream(int sock, +int lttng_ust_ctl_send_stream(int sock, uint32_t stream_nr, uint64_t memory_map_size, int shm_fd, int wakeup_fd, @@ -843,7 +987,7 @@ int ustctl_send_stream(int sock, return 0; } -int ustctl_recv_channel_from_consumer(int sock, +int lttng_ust_ctl_recv_channel_from_consumer(int sock, struct lttng_ust_abi_object_data **_channel_data) { struct lttng_ust_abi_object_data *channel_data; @@ -919,7 +1063,7 @@ error_alloc: return ret; } -int ustctl_recv_stream_from_consumer(int sock, +int lttng_ust_ctl_recv_stream_from_consumer(int sock, struct lttng_ust_abi_object_data **_stream_data) { struct lttng_ust_abi_object_data *stream_data; @@ -984,7 +1128,18 @@ error_alloc: return ret; } -int ustctl_send_channel_to_ust(int sock, int session_handle, +/* + * Protocol for LTTNG_UST_ABI_CHANNEL command: + * + * - send: struct ustcomm_ust_msg + * - send: file descriptors and channel data + * - receive: struct ustcomm_ust_reply + * + * TODO: At the next breaking protocol bump, we should indicate the total + * command message length as part of a message header so that the protocol can + * recover from invalid command errors. + */ +int lttng_ust_ctl_send_channel_to_ust(int sock, int session_handle, struct lttng_ust_abi_object_data *channel_data) { struct ustcomm_ust_msg lum; @@ -1003,7 +1158,7 @@ int ustctl_send_channel_to_ust(int sock, int session_handle, if (ret) return ret; - ret = ustctl_send_channel(sock, + ret = lttng_ust_ctl_send_channel(sock, channel_data->u.channel.type, channel_data->u.channel.data, channel_data->size, @@ -1014,11 +1169,28 @@ int ustctl_send_channel_to_ust(int sock, int session_handle, ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); if (!ret) { channel_data->handle = lur.ret_val; + } else if (ret == -EINVAL) { + /* + * Command unknown from remote end. The communication socket is + * now out-of-sync and needs to be shutdown. + */ + (void) ustcomm_shutdown_unix_sock(sock); } return ret; } -int ustctl_send_stream_to_ust(int sock, +/* + * Protocol for LTTNG_UST_ABI_STREAM command: + * + * - send: struct ustcomm_ust_msg + * - send: file descriptors and stream data + * - receive: struct ustcomm_ust_reply + * + * TODO: At the next breaking protocol bump, we should indicate the total + * command message length as part of a message header so that the protocol can + * recover from invalid command errors. + */ +int lttng_ust_ctl_send_stream_to_ust(int sock, struct lttng_ust_abi_object_data *channel_data, struct lttng_ust_abi_object_data *stream_data) { @@ -1038,17 +1210,25 @@ int ustctl_send_stream_to_ust(int sock, assert(stream_data); assert(stream_data->type == LTTNG_UST_ABI_OBJECT_TYPE_STREAM); - ret = ustctl_send_stream(sock, + ret = lttng_ust_ctl_send_stream(sock, stream_data->u.stream.stream_nr, stream_data->size, stream_data->u.stream.shm_fd, stream_data->u.stream.wakeup_fd, 1); if (ret) return ret; - return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); + ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd); + if (ret == -EINVAL) { + /* + * Command unknown from remote end. The communication socket is + * now out-of-sync and needs to be shutdown. + */ + (void) ustcomm_shutdown_unix_sock(sock); + } + return ret; } -int ustctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **dest, +int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **dest, struct lttng_ust_abi_object_data *src) { struct lttng_ust_abi_object_data *obj; @@ -1202,16 +1382,16 @@ error: /* Buffer operations */ -int ustctl_get_nr_stream_per_channel(void) +int lttng_ust_ctl_get_nr_stream_per_channel(void) { return num_possible_cpus(); } -struct ustctl_consumer_channel * - ustctl_create_channel(struct ustctl_consumer_channel_attr *attr, +struct lttng_ust_ctl_consumer_channel * + lttng_ust_ctl_create_channel(struct lttng_ust_ctl_consumer_channel_attr *attr, const int *stream_fds, int nr_stream_fds) { - struct ustctl_consumer_channel *chan; + struct lttng_ust_ctl_consumer_channel *chan; const char *transport_name; struct lttng_transport *transport; @@ -1269,8 +1449,8 @@ struct ustctl_consumer_channel * } chan->chan->ops = &transport->ops; memcpy(&chan->attr, attr, sizeof(chan->attr)); - chan->wait_fd = ustctl_channel_get_wait_fd(chan); - chan->wakeup_fd = ustctl_channel_get_wakeup_fd(chan); + chan->wait_fd = lttng_ust_ctl_channel_get_wait_fd(chan); + chan->wakeup_fd = lttng_ust_ctl_channel_get_wakeup_fd(chan); return chan; chan_error: @@ -1278,23 +1458,23 @@ chan_error: return NULL; } -void ustctl_destroy_channel(struct ustctl_consumer_channel *chan) +void lttng_ust_ctl_destroy_channel(struct lttng_ust_ctl_consumer_channel *chan) { - (void) ustctl_channel_close_wait_fd(chan); - (void) ustctl_channel_close_wakeup_fd(chan); + (void) lttng_ust_ctl_channel_close_wait_fd(chan); + (void) lttng_ust_ctl_channel_close_wakeup_fd(chan); chan->chan->ops->priv->channel_destroy(chan->chan); free(chan); } -int ustctl_send_channel_to_sessiond(int sock, - struct ustctl_consumer_channel *channel) +int lttng_ust_ctl_send_channel_to_sessiond(int sock, + struct lttng_ust_ctl_consumer_channel *channel) { struct shm_object_table *table; table = channel->chan->priv->rb_chan->handle->table; if (table->size <= 0) return -EINVAL; - return ustctl_send_channel(sock, + return lttng_ust_ctl_send_channel(sock, channel->attr.type, table->objects[0].memory_map, table->objects[0].memory_map_size, @@ -1302,27 +1482,27 @@ int ustctl_send_channel_to_sessiond(int sock, 0); } -int ustctl_send_stream_to_sessiond(int sock, - struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_send_stream_to_sessiond(int sock, + struct lttng_ust_ctl_consumer_stream *stream) { if (!stream) - return ustctl_send_stream(sock, -1U, -1U, -1, -1, 0); + return lttng_ust_ctl_send_stream(sock, -1U, -1U, -1, -1, 0); - return ustctl_send_stream(sock, + return lttng_ust_ctl_send_stream(sock, stream->cpu, stream->memory_map_size, stream->shm_fd, stream->wakeup_fd, 0); } -int ustctl_write_metadata_to_channel( - struct ustctl_consumer_channel *channel, +int lttng_ust_ctl_write_metadata_to_channel( + struct lttng_ust_ctl_consumer_channel *channel, const char *metadata_str, /* NOT null-terminated */ size_t len) /* metadata length */ { - struct lttng_ust_lib_ring_buffer_ctx ctx; + struct lttng_ust_ring_buffer_ctx ctx; struct lttng_ust_channel_buffer *lttng_chan_buf = channel->chan; - struct lttng_ust_lib_ring_buffer_channel *rb_chan = lttng_chan_buf->priv->rb_chan; + struct lttng_ust_ring_buffer_channel *rb_chan = lttng_chan_buf->priv->rb_chan; const char *str = metadata_str; int ret = 0, waitret; size_t reserve_len, pos; @@ -1331,7 +1511,7 @@ int ustctl_write_metadata_to_channel( reserve_len = min_t(size_t, lttng_chan_buf->ops->priv->packet_avail_size(lttng_chan_buf), len - pos); - lttng_ust_lib_ring_buffer_ctx_init(&ctx, rb_chan, reserve_len, sizeof(char), NULL); + lttng_ust_ring_buffer_ctx_init(&ctx, rb_chan, reserve_len, sizeof(char), NULL); /* * We don't care about metadata buffer's records lost * count, because we always retry here. Report error if @@ -1363,14 +1543,14 @@ end: * Write at most one packet in the channel. * Returns the number of bytes written on success, < 0 on error. */ -ssize_t ustctl_write_one_packet_to_channel( - struct ustctl_consumer_channel *channel, +ssize_t lttng_ust_ctl_write_one_packet_to_channel( + struct lttng_ust_ctl_consumer_channel *channel, const char *metadata_str, /* NOT null-terminated */ size_t len) /* metadata length */ { - struct lttng_ust_lib_ring_buffer_ctx ctx; + struct lttng_ust_ring_buffer_ctx ctx; struct lttng_ust_channel_buffer *lttng_chan_buf = channel->chan; - struct lttng_ust_lib_ring_buffer_channel *rb_chan = lttng_chan_buf->priv->rb_chan; + struct lttng_ust_ring_buffer_channel *rb_chan = lttng_chan_buf->priv->rb_chan; const char *str = metadata_str; ssize_t reserve_len; int ret; @@ -1378,7 +1558,7 @@ ssize_t ustctl_write_one_packet_to_channel( reserve_len = min_t(ssize_t, lttng_chan_buf->ops->priv->packet_avail_size(lttng_chan_buf), len); - lttng_ust_lib_ring_buffer_ctx_init(&ctx, rb_chan, reserve_len, sizeof(char), NULL); + lttng_ust_ring_buffer_ctx_init(&ctx, rb_chan, reserve_len, sizeof(char), NULL); ret = lttng_chan_buf->ops->event_reserve(&ctx); if (ret != 0) { DBG("LTTng: event reservation failed"); @@ -1393,9 +1573,9 @@ end: return reserve_len; } -int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel *consumer_chan) +int lttng_ust_ctl_channel_close_wait_fd(struct lttng_ust_ctl_consumer_channel *consumer_chan) { - struct lttng_ust_lib_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer_channel *chan; int ret; chan = consumer_chan->chan->priv->rb_chan; @@ -1406,9 +1586,9 @@ int ustctl_channel_close_wait_fd(struct ustctl_consumer_channel *consumer_chan) return ret; } -int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel *consumer_chan) +int lttng_ust_ctl_channel_close_wakeup_fd(struct lttng_ust_ctl_consumer_channel *consumer_chan) { - struct lttng_ust_lib_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer_channel *chan; int ret; chan = consumer_chan->chan->priv->rb_chan; @@ -1419,34 +1599,35 @@ int ustctl_channel_close_wakeup_fd(struct ustctl_consumer_channel *consumer_chan return ret; } -int ustctl_stream_close_wait_fd(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_stream_close_wait_fd(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer_channel *chan; chan = stream->chan->chan->priv->rb_chan; return ring_buffer_stream_close_wait_fd(&chan->backend.config, chan, chan->handle, stream->cpu); } -int ustctl_stream_close_wakeup_fd(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_stream_close_wakeup_fd(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer_channel *chan; chan = stream->chan->chan->priv->rb_chan; return ring_buffer_stream_close_wakeup_fd(&chan->backend.config, chan, chan->handle, stream->cpu); } -struct ustctl_consumer_stream * - ustctl_create_stream(struct ustctl_consumer_channel *channel, +struct lttng_ust_ctl_consumer_stream * + lttng_ust_ctl_create_stream(struct lttng_ust_ctl_consumer_channel *channel, int cpu) { - struct ustctl_consumer_stream *stream; + struct lttng_ust_ctl_consumer_stream *stream; struct lttng_ust_shm_handle *handle; - struct lttng_ust_lib_ring_buffer_channel *rb_chan; + struct lttng_ust_ring_buffer_channel *rb_chan; int shm_fd, wait_fd, wakeup_fd; uint64_t memory_map_size; - struct lttng_ust_lib_ring_buffer *buf; + void *memory_map_addr; + struct lttng_ust_ring_buffer *buf; int ret; if (!channel) @@ -1458,7 +1639,7 @@ struct ustctl_consumer_stream * buf = channel_get_ring_buffer(&rb_chan->backend.config, rb_chan, cpu, handle, &shm_fd, &wait_fd, - &wakeup_fd, &memory_map_size); + &wakeup_fd, &memory_map_size, &memory_map_addr); if (!buf) return NULL; ret = lib_ring_buffer_open_read(buf, handle); @@ -1474,6 +1655,7 @@ struct ustctl_consumer_stream * stream->wait_fd = wait_fd; stream->wakeup_fd = wakeup_fd; stream->memory_map_size = memory_map_size; + stream->memory_map_addr = memory_map_addr; stream->cpu = cpu; return stream; @@ -1481,21 +1663,21 @@ alloc_error: return NULL; } -void ustctl_destroy_stream(struct ustctl_consumer_stream *stream) +void lttng_ust_ctl_destroy_stream(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; assert(stream); buf = stream->buf; consumer_chan = stream->chan; - (void) ustctl_stream_close_wait_fd(stream); - (void) ustctl_stream_close_wakeup_fd(stream); + (void) lttng_ust_ctl_stream_close_wait_fd(stream); + (void) lttng_ust_ctl_stream_close_wakeup_fd(stream); lib_ring_buffer_release_read(buf, consumer_chan->chan->priv->rb_chan->handle); free(stream); } -int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel *chan) +int lttng_ust_ctl_channel_get_wait_fd(struct lttng_ust_ctl_consumer_channel *chan) { if (!chan) return -EINVAL; @@ -1503,7 +1685,7 @@ int ustctl_channel_get_wait_fd(struct ustctl_consumer_channel *chan) &chan->chan->priv->rb_chan->handle->chan._ref); } -int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel *chan) +int lttng_ust_ctl_channel_get_wakeup_fd(struct lttng_ust_ctl_consumer_channel *chan) { if (!chan) return -EINVAL; @@ -1511,10 +1693,10 @@ int ustctl_channel_get_wakeup_fd(struct ustctl_consumer_channel *chan) &chan->chan->priv->rb_chan->handle->chan._ref); } -int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_stream_get_wait_fd(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; if (!stream) return -EINVAL; @@ -1523,10 +1705,10 @@ int ustctl_stream_get_wait_fd(struct ustctl_consumer_stream *stream) return shm_get_wait_fd(consumer_chan->chan->priv->rb_chan->handle, &buf->self._ref); } -int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_stream_get_wakeup_fd(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; if (!stream) return -EINVAL; @@ -1537,25 +1719,34 @@ int ustctl_stream_get_wakeup_fd(struct ustctl_consumer_stream *stream) /* For mmap mode, readable without "get" operation */ -void *ustctl_get_mmap_base(struct ustctl_consumer_stream *stream) +void *lttng_ust_ctl_get_mmap_base(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_sigbus_range range; + void *p; if (!stream) return NULL; buf = stream->buf; consumer_chan = stream->chan; - return shmp(consumer_chan->chan->priv->rb_chan->handle, buf->backend.memory_map); + if (sigbus_begin()) + return NULL; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + p = shmp(consumer_chan->chan->priv->rb_chan->handle, buf->backend.memory_map); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return p; /* Users of this pointer should check for sigbus. */ } /* returns the length to mmap. */ -int ustctl_get_mmap_len(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_mmap_len(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *len) { - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ctl_consumer_channel *consumer_chan; unsigned long mmap_buf_len; - struct lttng_ust_lib_ring_buffer_channel *rb_chan; + struct lttng_ust_ring_buffer_channel *rb_chan; if (!stream) return -EINVAL; @@ -1573,11 +1764,11 @@ int ustctl_get_mmap_len(struct ustctl_consumer_stream *stream, } /* returns the maximum size for sub-buffers. */ -int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_max_subbuf_size(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *len) { - struct ustctl_consumer_channel *consumer_chan; - struct lttng_ust_lib_ring_buffer_channel *rb_chan; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer_channel *rb_chan; if (!stream) return -EINVAL; @@ -1593,15 +1784,17 @@ int ustctl_get_max_subbuf_size(struct ustctl_consumer_stream *stream, */ /* returns the offset of the subbuffer belonging to the mmap reader. */ -int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_mmap_read_offset(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *off) { - struct lttng_ust_lib_ring_buffer_channel *rb_chan; + struct lttng_ust_ring_buffer_channel *rb_chan; unsigned long sb_bindex; - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; - struct lttng_ust_lib_ring_buffer_backend_pages_shmp *barray_idx; - struct lttng_ust_lib_ring_buffer_backend_pages *pages; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer_backend_pages_shmp *barray_idx; + struct lttng_ust_ring_buffer_backend_pages *pages; + struct lttng_ust_sigbus_range range; + int ret; if (!stream) return -EINVAL; @@ -1610,26 +1803,41 @@ int ustctl_get_mmap_read_offset(struct ustctl_consumer_stream *stream, rb_chan = consumer_chan->chan->priv->rb_chan; if (rb_chan->backend.config.output != RING_BUFFER_MMAP) return -EINVAL; + + if (sigbus_begin()) + return -EIO; + ret = 0; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + sb_bindex = subbuffer_id_get_index(&rb_chan->backend.config, buf->backend.buf_rsb.id); barray_idx = shmp_index(rb_chan->handle, buf->backend.array, sb_bindex); - if (!barray_idx) - return -EINVAL; + if (!barray_idx) { + ret = -EINVAL; + goto end; + } pages = shmp(rb_chan->handle, barray_idx->shmp); - if (!pages) - return -EINVAL; + if (!pages) { + ret = -EINVAL; + goto end; + } *off = pages->mmap_offset; - return 0; +end: + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } /* returns the size of the current sub-buffer, without padding (for mmap). */ -int ustctl_get_subbuf_size(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_subbuf_size(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *len) { - struct ustctl_consumer_channel *consumer_chan; - struct lttng_ust_lib_ring_buffer_channel *rb_chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer_channel *rb_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; if (!stream) return -EINVAL; @@ -1637,73 +1845,110 @@ int ustctl_get_subbuf_size(struct ustctl_consumer_stream *stream, buf = stream->buf; consumer_chan = stream->chan; rb_chan = consumer_chan->chan->priv->rb_chan; + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); *len = lib_ring_buffer_get_read_data_size(&rb_chan->backend.config, buf, rb_chan->handle); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); return 0; } /* returns the size of the current sub-buffer, without padding (for mmap). */ -int ustctl_get_padded_subbuf_size(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_padded_subbuf_size(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *len) { - struct ustctl_consumer_channel *consumer_chan; - struct lttng_ust_lib_ring_buffer_channel *rb_chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer_channel *rb_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; if (!stream) return -EINVAL; buf = stream->buf; consumer_chan = stream->chan; rb_chan = consumer_chan->chan->priv->rb_chan; + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); *len = lib_ring_buffer_get_read_data_size(&rb_chan->backend.config, buf, rb_chan->handle); *len = LTTNG_UST_PAGE_ALIGN(*len); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); return 0; } /* Get exclusive read access to the next sub-buffer that can be read. */ -int ustctl_get_next_subbuf(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_get_next_subbuf(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_sigbus_range range; + int ret; if (!stream) return -EINVAL; buf = stream->buf; consumer_chan = stream->chan; - return lib_ring_buffer_get_next_subbuf(buf, + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = lib_ring_buffer_get_next_subbuf(buf, consumer_chan->chan->priv->rb_chan->handle); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } - /* Release exclusive sub-buffer access, move consumer forward. */ -int ustctl_put_next_subbuf(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_put_next_subbuf(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_sigbus_range range; if (!stream) return -EINVAL; buf = stream->buf; consumer_chan = stream->chan; + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); lib_ring_buffer_put_next_subbuf(buf, consumer_chan->chan->priv->rb_chan->handle); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); return 0; } /* snapshot */ /* Get a snapshot of the current ring buffer producer and consumer positions */ -int ustctl_snapshot(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_snapshot(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_sigbus_range range; + int ret; if (!stream) return -EINVAL; buf = stream->buf; consumer_chan = stream->chan; - return lib_ring_buffer_snapshot(buf, &buf->cons_snapshot, + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = lib_ring_buffer_snapshot(buf, &buf->cons_snapshot, &buf->prod_snapshot, consumer_chan->chan->priv->rb_chan->handle); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } /* @@ -1711,25 +1956,34 @@ int ustctl_snapshot(struct ustctl_consumer_stream *stream) * even if the consumed and produced positions are contained within the same * subbuffer. */ -int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_snapshot_sample_positions(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_sigbus_range range; + int ret; if (!stream) return -EINVAL; buf = stream->buf; consumer_chan = stream->chan; - return lib_ring_buffer_snapshot_sample_positions(buf, + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = lib_ring_buffer_snapshot_sample_positions(buf, &buf->cons_snapshot, &buf->prod_snapshot, consumer_chan->chan->priv->rb_chan->handle); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } /* Get the consumer position (iteration start) */ -int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_snapshot_get_consumed(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *pos) { - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer *buf; if (!stream) return -EINVAL; @@ -1739,10 +1993,10 @@ int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream, } /* Get the producer position (iteration end) */ -int ustctl_snapshot_get_produced(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_snapshot_get_produced(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *pos) { - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer *buf; if (!stream) return -EINVAL; @@ -1752,67 +2006,99 @@ int ustctl_snapshot_get_produced(struct ustctl_consumer_stream *stream, } /* Get exclusive read access to the specified sub-buffer position */ -int ustctl_get_subbuf(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_subbuf(struct lttng_ust_ctl_consumer_stream *stream, unsigned long *pos) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_sigbus_range range; + int ret; if (!stream) return -EINVAL; buf = stream->buf; consumer_chan = stream->chan; - return lib_ring_buffer_get_subbuf(buf, *pos, + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = lib_ring_buffer_get_subbuf(buf, *pos, consumer_chan->chan->priv->rb_chan->handle); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } /* Release exclusive sub-buffer access */ -int ustctl_put_subbuf(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_put_subbuf(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_sigbus_range range; if (!stream) return -EINVAL; buf = stream->buf; consumer_chan = stream->chan; + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); lib_ring_buffer_put_subbuf(buf, consumer_chan->chan->priv->rb_chan->handle); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); return 0; } -void ustctl_flush_buffer(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_flush_buffer(struct lttng_ust_ctl_consumer_stream *stream, int producer_active) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_sigbus_range range; assert(stream); buf = stream->buf; consumer_chan = stream->chan; + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); lib_ring_buffer_switch_slow(buf, producer_active ? SWITCH_ACTIVE : SWITCH_FLUSH, consumer_chan->chan->priv->rb_chan->handle); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return 0; } -void ustctl_clear_buffer(struct ustctl_consumer_stream *stream) +int lttng_ust_ctl_clear_buffer(struct lttng_ust_ctl_consumer_stream *stream) { - struct lttng_ust_lib_ring_buffer *buf; - struct ustctl_consumer_channel *consumer_chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_ctl_consumer_channel *consumer_chan; + struct lttng_ust_sigbus_range range; assert(stream); buf = stream->buf; consumer_chan = stream->chan; + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE, consumer_chan->chan->priv->rb_chan->handle); lib_ring_buffer_clear_reader(buf, consumer_chan->chan->priv->rb_chan->handle); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return 0; } static struct lttng_ust_client_lib_ring_buffer_client_cb *get_client_cb( - struct lttng_ust_lib_ring_buffer *buf __attribute__((unused)), - struct lttng_ust_lib_ring_buffer_channel *chan) + struct lttng_ust_ring_buffer *buf __attribute__((unused)), + struct lttng_ust_ring_buffer_channel *chan) { - const struct lttng_ust_lib_ring_buffer_config *config; + const struct lttng_ust_ring_buffer_config *config; struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; config = &chan->backend.config; @@ -1824,12 +2110,14 @@ struct lttng_ust_client_lib_ring_buffer_client_cb *get_client_cb( return client_cb; } -int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_timestamp_begin(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *timestamp_begin) { struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; - struct lttng_ust_lib_ring_buffer_channel *chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; + int ret; if (!stream || !timestamp_begin) return -EINVAL; @@ -1838,15 +2126,24 @@ int ustctl_get_timestamp_begin(struct ustctl_consumer_stream *stream, client_cb = get_client_cb(buf, chan); if (!client_cb) return -ENOSYS; - return client_cb->timestamp_begin(buf, chan, timestamp_begin); + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = client_cb->timestamp_begin(buf, chan, timestamp_begin); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } -int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_timestamp_end(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *timestamp_end) { struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; - struct lttng_ust_lib_ring_buffer_channel *chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; + int ret; if (!stream || !timestamp_end) return -EINVAL; @@ -1855,15 +2152,24 @@ int ustctl_get_timestamp_end(struct ustctl_consumer_stream *stream, client_cb = get_client_cb(buf, chan); if (!client_cb) return -ENOSYS; - return client_cb->timestamp_end(buf, chan, timestamp_end); + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = client_cb->timestamp_end(buf, chan, timestamp_end); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } -int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_events_discarded(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *events_discarded) { struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; - struct lttng_ust_lib_ring_buffer_channel *chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; + int ret; if (!stream || !events_discarded) return -EINVAL; @@ -1872,15 +2178,24 @@ int ustctl_get_events_discarded(struct ustctl_consumer_stream *stream, client_cb = get_client_cb(buf, chan); if (!client_cb) return -ENOSYS; - return client_cb->events_discarded(buf, chan, events_discarded); + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = client_cb->events_discarded(buf, chan, events_discarded); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } -int ustctl_get_content_size(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_content_size(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *content_size) { struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; - struct lttng_ust_lib_ring_buffer_channel *chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; + int ret; if (!stream || !content_size) return -EINVAL; @@ -1889,15 +2204,24 @@ int ustctl_get_content_size(struct ustctl_consumer_stream *stream, client_cb = get_client_cb(buf, chan); if (!client_cb) return -ENOSYS; - return client_cb->content_size(buf, chan, content_size); + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = client_cb->content_size(buf, chan, content_size); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } -int ustctl_get_packet_size(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_packet_size(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *packet_size) { struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; - struct lttng_ust_lib_ring_buffer_channel *chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; + int ret; if (!stream || !packet_size) return -EINVAL; @@ -1906,15 +2230,24 @@ int ustctl_get_packet_size(struct ustctl_consumer_stream *stream, client_cb = get_client_cb(buf, chan); if (!client_cb) return -ENOSYS; - return client_cb->packet_size(buf, chan, packet_size); + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = client_cb->packet_size(buf, chan, packet_size); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } -int ustctl_get_stream_id(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_stream_id(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *stream_id) { struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; - struct lttng_ust_lib_ring_buffer_channel *chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; + int ret; if (!stream || !stream_id) return -EINVAL; @@ -1923,15 +2256,24 @@ int ustctl_get_stream_id(struct ustctl_consumer_stream *stream, client_cb = get_client_cb(buf, chan); if (!client_cb) return -ENOSYS; - return client_cb->stream_id(buf, chan, stream_id); + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = client_cb->stream_id(buf, chan, stream_id); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } -int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_current_timestamp(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *ts) { struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; - struct lttng_ust_lib_ring_buffer_channel *chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; + int ret; if (!stream || !ts) return -EINVAL; @@ -1940,15 +2282,24 @@ int ustctl_get_current_timestamp(struct ustctl_consumer_stream *stream, client_cb = get_client_cb(buf, chan); if (!client_cb || !client_cb->current_timestamp) return -ENOSYS; - return client_cb->current_timestamp(buf, chan, ts); + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = client_cb->current_timestamp(buf, chan, ts); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } -int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_sequence_number(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *seq) { struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; - struct lttng_ust_lib_ring_buffer_channel *chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; + int ret; if (!stream || !seq) return -EINVAL; @@ -1957,15 +2308,24 @@ int ustctl_get_sequence_number(struct ustctl_consumer_stream *stream, client_cb = get_client_cb(buf, chan); if (!client_cb || !client_cb->sequence_number) return -ENOSYS; - return client_cb->sequence_number(buf, chan, seq); + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = client_cb->sequence_number(buf, chan, seq); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } -int ustctl_get_instance_id(struct ustctl_consumer_stream *stream, +int lttng_ust_ctl_get_instance_id(struct lttng_ust_ctl_consumer_stream *stream, uint64_t *id) { struct lttng_ust_client_lib_ring_buffer_client_cb *client_cb; - struct lttng_ust_lib_ring_buffer_channel *chan; - struct lttng_ust_lib_ring_buffer *buf; + struct lttng_ust_ring_buffer_channel *chan; + struct lttng_ust_ring_buffer *buf; + struct lttng_ust_sigbus_range range; + int ret; if (!stream || !id) return -EINVAL; @@ -1974,19 +2334,26 @@ int ustctl_get_instance_id(struct ustctl_consumer_stream *stream, client_cb = get_client_cb(buf, chan); if (!client_cb) return -ENOSYS; - return client_cb->instance_id(buf, chan, id); + if (sigbus_begin()) + return -EIO; + lttng_ust_sigbus_add_range(&range, stream->memory_map_addr, + stream->memory_map_size); + ret = client_cb->instance_id(buf, chan, id); + lttng_ust_sigbus_del_range(&range); + sigbus_end(); + return ret; } #ifdef HAVE_LINUX_PERF_EVENT_H -int ustctl_has_perf_counters(void) +int lttng_ust_ctl_has_perf_counters(void) { return 1; } #else -int ustctl_has_perf_counters(void) +int lttng_ust_ctl_has_perf_counters(void) { return 0; } @@ -2002,7 +2369,7 @@ int ustctl_has_perf_counters(void) */ static int get_cred(int sock, - const struct ustctl_reg_msg *reg_msg, + const struct lttng_ust_ctl_reg_msg *reg_msg, uint32_t *pid, uint32_t *ppid, uint32_t *uid, @@ -2045,7 +2412,7 @@ int get_cred(int sock, */ static int get_cred(int sock, - const struct ustctl_reg_msg *reg_msg, + const struct lttng_ust_ctl_reg_msg *reg_msg, uint32_t *pid, uint32_t *ppid, uint32_t *uid, @@ -2076,7 +2443,7 @@ int get_cred(int sock, #warning "Using insecure fallback: trusting user id provided by registered applications. Please consider implementing use of unix socket credentials on your platform." static int get_cred(int sock, - const struct ustctl_reg_msg *reg_msg, + const struct lttng_ust_ctl_reg_msg *reg_msg, uint32_t *pid, uint32_t *ppid, uint32_t *uid, @@ -2095,8 +2462,8 @@ int get_cred(int sock, /* * Returns 0 on success, negative error value on error. */ -int ustctl_recv_reg_msg(int sock, - enum ustctl_socket_type *type, +int lttng_ust_ctl_recv_reg_msg(int sock, + enum lttng_ust_ctl_socket_type *type, uint32_t *major, uint32_t *minor, uint32_t *pid, @@ -2113,7 +2480,7 @@ int ustctl_recv_reg_msg(int sock, char *name) { ssize_t len; - struct ustctl_reg_msg reg_msg; + struct lttng_ust_ctl_reg_msg reg_msg; len = ustcomm_recv_unix_sock(sock, ®_msg, sizeof(reg_msg)); if (len > 0 && len != sizeof(reg_msg)) @@ -2124,18 +2491,18 @@ int ustctl_recv_reg_msg(int sock, return len; if (reg_msg.magic == LTTNG_UST_ABI_COMM_MAGIC) { - *byte_order = BYTE_ORDER == BIG_ENDIAN ? - BIG_ENDIAN : LITTLE_ENDIAN; - } else if (reg_msg.magic == bswap_32(LTTNG_UST_ABI_COMM_MAGIC)) { - *byte_order = BYTE_ORDER == BIG_ENDIAN ? - LITTLE_ENDIAN : BIG_ENDIAN; + *byte_order = LTTNG_UST_BYTE_ORDER == LTTNG_UST_BIG_ENDIAN ? + LTTNG_UST_BIG_ENDIAN : LTTNG_UST_LITTLE_ENDIAN; + } else if (reg_msg.magic == lttng_ust_bswap_32(LTTNG_UST_ABI_COMM_MAGIC)) { + *byte_order = LTTNG_UST_BYTE_ORDER == LTTNG_UST_BIG_ENDIAN ? + LTTNG_UST_LITTLE_ENDIAN : LTTNG_UST_BIG_ENDIAN; } else { return -LTTNG_UST_ERR_INVAL_MAGIC; } switch (reg_msg.socket_type) { - case 0: *type = USTCTL_SOCKET_CMD; + case 0: *type = LTTNG_UST_CTL_SOCKET_CMD; break; - case 1: *type = USTCTL_SOCKET_NOTIFY; + case 1: *type = LTTNG_UST_CTL_SOCKET_NOTIFY; break; default: return -LTTNG_UST_ERR_INVAL_SOCKET_TYPE; @@ -2156,7 +2523,7 @@ int ustctl_recv_reg_msg(int sock, return get_cred(sock, ®_msg, pid, ppid, uid, gid); } -int ustctl_recv_notify(int sock, enum ustctl_notify_cmd *notify_cmd) +int lttng_ust_ctl_recv_notify(int sock, enum lttng_ust_ctl_notify_cmd *notify_cmd) { struct ustcomm_notify_hdr header; ssize_t len; @@ -2170,13 +2537,13 @@ int ustctl_recv_notify(int sock, enum ustctl_notify_cmd *notify_cmd) return len; switch (header.notify_cmd) { case 0: - *notify_cmd = USTCTL_NOTIFY_CMD_EVENT; + *notify_cmd = LTTNG_UST_CTL_NOTIFY_CMD_EVENT; break; case 1: - *notify_cmd = USTCTL_NOTIFY_CMD_CHANNEL; + *notify_cmd = LTTNG_UST_CTL_NOTIFY_CMD_CHANNEL; break; case 2: - *notify_cmd = USTCTL_NOTIFY_CMD_ENUM; + *notify_cmd = LTTNG_UST_CTL_NOTIFY_CMD_ENUM; break; default: return -EINVAL; @@ -2187,21 +2554,21 @@ int ustctl_recv_notify(int sock, enum ustctl_notify_cmd *notify_cmd) /* * Returns 0 on success, negative error value on error. */ -int ustctl_recv_register_event(int sock, +int lttng_ust_ctl_recv_register_event(int sock, int *session_objd, int *channel_objd, char *event_name, int *loglevel, char **signature, size_t *nr_fields, - struct ustctl_field **fields, + struct lttng_ust_ctl_field **fields, char **model_emf_uri) { ssize_t len; struct ustcomm_notify_event_msg msg; size_t signature_len, fields_len, model_emf_uri_len; char *a_sign = NULL, *a_model_emf_uri = NULL; - struct ustctl_field *a_fields = NULL; + struct lttng_ust_ctl_field *a_fields = NULL; len = ustcomm_recv_unix_sock(sock, &msg, sizeof(msg)); if (len > 0 && len != sizeof(msg)) @@ -2308,7 +2675,7 @@ signature_error: /* * Returns 0 on success, negative error value on error. */ -int ustctl_reply_register_event(int sock, +int lttng_ust_ctl_reply_register_event(int sock, uint32_t id, int ret_code) { @@ -2319,7 +2686,7 @@ int ustctl_reply_register_event(int sock, } reply; memset(&reply, 0, sizeof(reply)); - reply.header.notify_cmd = USTCTL_NOTIFY_CMD_EVENT; + reply.header.notify_cmd = LTTNG_UST_CTL_NOTIFY_CMD_EVENT; reply.r.ret_code = ret_code; reply.r.event_id = id; len = ustcomm_send_unix_sock(sock, &reply, sizeof(reply)); @@ -2333,16 +2700,16 @@ int ustctl_reply_register_event(int sock, /* * Returns 0 on success, negative UST or system error value on error. */ -int ustctl_recv_register_enum(int sock, +int lttng_ust_ctl_recv_register_enum(int sock, int *session_objd, char *enum_name, - struct ustctl_enum_entry **entries, + struct lttng_ust_ctl_enum_entry **entries, size_t *nr_entries) { ssize_t len; struct ustcomm_notify_enum_msg msg; size_t entries_len; - struct ustctl_enum_entry *a_entries = NULL; + struct lttng_ust_ctl_enum_entry *a_entries = NULL; len = ustcomm_recv_unix_sock(sock, &msg, sizeof(msg)); if (len > 0 && len != sizeof(msg)) @@ -2392,7 +2759,7 @@ entries_error: /* * Returns 0 on success, negative error value on error. */ -int ustctl_reply_register_enum(int sock, +int lttng_ust_ctl_reply_register_enum(int sock, uint64_t id, int ret_code) { @@ -2403,7 +2770,7 @@ int ustctl_reply_register_enum(int sock, } reply; memset(&reply, 0, sizeof(reply)); - reply.header.notify_cmd = USTCTL_NOTIFY_CMD_ENUM; + reply.header.notify_cmd = LTTNG_UST_CTL_NOTIFY_CMD_ENUM; reply.r.ret_code = ret_code; reply.r.enum_id = id; len = ustcomm_send_unix_sock(sock, &reply, sizeof(reply)); @@ -2417,16 +2784,16 @@ int ustctl_reply_register_enum(int sock, /* * Returns 0 on success, negative UST or system error value on error. */ -int ustctl_recv_register_channel(int sock, +int lttng_ust_ctl_recv_register_channel(int sock, int *session_objd, /* session descriptor (output) */ int *channel_objd, /* channel descriptor (output) */ size_t *nr_fields, - struct ustctl_field **fields) + struct lttng_ust_ctl_field **fields) { ssize_t len; struct ustcomm_notify_channel_msg msg; size_t fields_len; - struct ustctl_field *a_fields; + struct lttng_ust_ctl_field *a_fields; len = ustcomm_recv_unix_sock(sock, &msg, sizeof(msg)); if (len > 0 && len != sizeof(msg)) @@ -2479,9 +2846,9 @@ alloc_error: /* * Returns 0 on success, negative error value on error. */ -int ustctl_reply_register_channel(int sock, +int lttng_ust_ctl_reply_register_channel(int sock, uint32_t chan_id, - enum ustctl_channel_header header_type, + enum lttng_ust_ctl_channel_header header_type, int ret_code) { ssize_t len; @@ -2491,14 +2858,14 @@ int ustctl_reply_register_channel(int sock, } reply; memset(&reply, 0, sizeof(reply)); - reply.header.notify_cmd = USTCTL_NOTIFY_CMD_CHANNEL; + reply.header.notify_cmd = LTTNG_UST_CTL_NOTIFY_CMD_CHANNEL; reply.r.ret_code = ret_code; reply.r.chan_id = chan_id; switch (header_type) { - case USTCTL_CHANNEL_HEADER_COMPACT: + case LTTNG_UST_CTL_CHANNEL_HEADER_COMPACT: reply.r.header_type = 1; break; - case USTCTL_CHANNEL_HEADER_LARGE: + case LTTNG_UST_CTL_CHANNEL_HEADER_LARGE: reply.r.header_type = 2; break; default: @@ -2514,7 +2881,7 @@ int ustctl_reply_register_channel(int sock, } /* Regenerate the statedump. */ -int ustctl_regenerate_statedump(int sock, int handle) +int lttng_ust_ctl_regenerate_statedump(int sock, int handle) { struct ustcomm_ust_msg lum; struct ustcomm_ust_reply lur; @@ -2532,25 +2899,25 @@ int ustctl_regenerate_statedump(int sock, int handle) /* counter operations */ -int ustctl_get_nr_cpu_per_counter(void) +int lttng_ust_ctl_get_nr_cpu_per_counter(void) { - return lttng_counter_num_possible_cpus(); + return num_possible_cpus(); } -struct ustctl_daemon_counter * - ustctl_create_counter(size_t nr_dimensions, - const struct ustctl_counter_dimension *dimensions, +struct lttng_ust_ctl_daemon_counter * + lttng_ust_ctl_create_counter(size_t nr_dimensions, + const struct lttng_ust_ctl_counter_dimension *dimensions, int64_t global_sum_step, int global_counter_fd, int nr_counter_cpu_fds, const int *counter_cpu_fds, - enum ustctl_counter_bitness bitness, - enum ustctl_counter_arithmetic arithmetic, + enum lttng_ust_ctl_counter_bitness bitness, + enum lttng_ust_ctl_counter_arithmetic arithmetic, uint32_t alloc_flags, bool coalesce_hits) { const char *transport_name; - struct ustctl_daemon_counter *counter; + struct lttng_ust_ctl_daemon_counter *counter; struct lttng_counter_transport *transport; struct lttng_counter_dimension ust_dim[LTTNG_COUNTER_DIMENSION_MAX]; size_t i; @@ -2559,33 +2926,33 @@ struct ustctl_daemon_counter * return NULL; /* Currently, only per-cpu allocation is supported. */ switch (alloc_flags) { - case USTCTL_COUNTER_ALLOC_PER_CPU: + case LTTNG_UST_CTL_COUNTER_ALLOC_PER_CPU: break; - case USTCTL_COUNTER_ALLOC_PER_CPU | USTCTL_COUNTER_ALLOC_GLOBAL: - case USTCTL_COUNTER_ALLOC_GLOBAL: + case LTTNG_UST_CTL_COUNTER_ALLOC_PER_CPU | LTTNG_UST_CTL_COUNTER_ALLOC_GLOBAL: + case LTTNG_UST_CTL_COUNTER_ALLOC_GLOBAL: default: return NULL; } switch (bitness) { - case USTCTL_COUNTER_BITNESS_32: + case LTTNG_UST_CTL_COUNTER_BITNESS_32: switch (arithmetic) { - case USTCTL_COUNTER_ARITHMETIC_MODULAR: + case LTTNG_UST_CTL_COUNTER_ARITHMETIC_MODULAR: transport_name = "counter-per-cpu-32-modular"; break; - case USTCTL_COUNTER_ARITHMETIC_SATURATION: + case LTTNG_UST_CTL_COUNTER_ARITHMETIC_SATURATION: transport_name = "counter-per-cpu-32-saturation"; break; default: return NULL; } break; - case USTCTL_COUNTER_BITNESS_64: + case LTTNG_UST_CTL_COUNTER_BITNESS_64: switch (arithmetic) { - case USTCTL_COUNTER_ARITHMETIC_MODULAR: + case LTTNG_UST_CTL_COUNTER_ARITHMETIC_MODULAR: transport_name = "counter-per-cpu-64-modular"; break; - case USTCTL_COUNTER_ARITHMETIC_SATURATION: + case LTTNG_UST_CTL_COUNTER_ARITHMETIC_SATURATION: transport_name = "counter-per-cpu-64-saturation"; break; default: @@ -2639,7 +3006,7 @@ free_counter: return NULL; } -int ustctl_create_counter_data(struct ustctl_daemon_counter *counter, +int lttng_ust_ctl_create_counter_data(struct lttng_ust_ctl_daemon_counter *counter, struct lttng_ust_abi_object_data **_counter_data) { struct lttng_ust_abi_object_data *counter_data; @@ -2648,20 +3015,20 @@ int ustctl_create_counter_data(struct ustctl_daemon_counter *counter, int ret; switch (counter->attr->arithmetic) { - case USTCTL_COUNTER_ARITHMETIC_MODULAR: + case LTTNG_UST_CTL_COUNTER_ARITHMETIC_MODULAR: counter_conf.arithmetic = LTTNG_UST_ABI_COUNTER_ARITHMETIC_MODULAR; break; - case USTCTL_COUNTER_ARITHMETIC_SATURATION: + case LTTNG_UST_CTL_COUNTER_ARITHMETIC_SATURATION: counter_conf.arithmetic = LTTNG_UST_ABI_COUNTER_ARITHMETIC_SATURATION; break; default: return -EINVAL; } switch (counter->attr->bitness) { - case USTCTL_COUNTER_BITNESS_32: + case LTTNG_UST_CTL_COUNTER_BITNESS_32: counter_conf.bitness = LTTNG_UST_ABI_COUNTER_BITNESS_32; break; - case USTCTL_COUNTER_BITNESS_64: + case LTTNG_UST_CTL_COUNTER_BITNESS_64: counter_conf.bitness = LTTNG_UST_ABI_COUNTER_BITNESS_64; break; default: @@ -2704,7 +3071,7 @@ error_alloc: return ret; } -int ustctl_create_counter_global_data(struct ustctl_daemon_counter *counter, +int lttng_ust_ctl_create_counter_global_data(struct lttng_ust_ctl_daemon_counter *counter, struct lttng_ust_abi_object_data **_counter_global_data) { struct lttng_ust_abi_object_data *counter_global_data; @@ -2729,7 +3096,7 @@ error_alloc: return ret; } -int ustctl_create_counter_cpu_data(struct ustctl_daemon_counter *counter, int cpu, +int lttng_ust_ctl_create_counter_cpu_data(struct lttng_ust_ctl_daemon_counter *counter, int cpu, struct lttng_ust_abi_object_data **_counter_cpu_data) { struct lttng_ust_abi_object_data *counter_cpu_data; @@ -2755,14 +3122,22 @@ error_alloc: return ret; } -void ustctl_destroy_counter(struct ustctl_daemon_counter *counter) +void lttng_ust_ctl_destroy_counter(struct lttng_ust_ctl_daemon_counter *counter) { counter->ops->counter_destroy(counter->counter); free(counter->attr); free(counter); } -int ustctl_send_counter_data_to_ust(int sock, int parent_handle, +/* + * Protocol for LTTNG_UST_ABI_COUNTER command: + * + * - send: struct ustcomm_ust_msg + * - receive: struct ustcomm_ust_reply + * - send: counter data + * - receive: struct ustcomm_ust_reply (actual command return code) + */ +int lttng_ust_ctl_send_counter_data_to_ust(int sock, int parent_handle, struct lttng_ust_abi_object_data *counter_data) { struct ustcomm_ust_msg lum; @@ -2779,7 +3154,7 @@ int ustctl_send_counter_data_to_ust(int sock, int parent_handle, lum.handle = parent_handle; lum.cmd = LTTNG_UST_ABI_COUNTER; lum.u.counter.len = size; - ret = ustcomm_send_app_msg(sock, &lum); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; @@ -2799,7 +3174,15 @@ int ustctl_send_counter_data_to_ust(int sock, int parent_handle, return ret; } -int ustctl_send_counter_global_data_to_ust(int sock, +/* + * Protocol for LTTNG_UST_ABI_COUNTER_GLOBAL command: + * + * - send: struct ustcomm_ust_msg + * - receive: struct ustcomm_ust_reply + * - send: file descriptor + * - receive: struct ustcomm_ust_reply (actual command return code) + */ +int lttng_ust_ctl_send_counter_global_data_to_ust(int sock, struct lttng_ust_abi_object_data *counter_data, struct lttng_ust_abi_object_data *counter_global_data) { @@ -2817,7 +3200,7 @@ int ustctl_send_counter_global_data_to_ust(int sock, lum.handle = counter_data->handle; /* parent handle */ lum.cmd = LTTNG_UST_ABI_COUNTER_GLOBAL; lum.u.counter_global.len = size; - ret = ustcomm_send_app_msg(sock, &lum); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; @@ -2837,7 +3220,15 @@ int ustctl_send_counter_global_data_to_ust(int sock, return ret; } -int ustctl_send_counter_cpu_data_to_ust(int sock, +/* + * Protocol for LTTNG_UST_ABI_COUNTER_CPU command: + * + * - send: struct ustcomm_ust_msg + * - receive: struct ustcomm_ust_reply + * - send: file descriptor + * - receive: struct ustcomm_ust_reply (actual command return code) + */ +int lttng_ust_ctl_send_counter_cpu_data_to_ust(int sock, struct lttng_ust_abi_object_data *counter_data, struct lttng_ust_abi_object_data *counter_cpu_data) { @@ -2856,7 +3247,7 @@ int ustctl_send_counter_cpu_data_to_ust(int sock, lum.cmd = LTTNG_UST_ABI_COUNTER_CPU; lum.u.counter_cpu.len = size; lum.u.counter_cpu.cpu_nr = counter_cpu_data->u.counter_cpu.cpu_nr; - ret = ustcomm_send_app_msg(sock, &lum); + ret = ustcomm_send_app_cmd(sock, &lum, &lur); if (ret) return ret; @@ -2876,7 +3267,7 @@ int ustctl_send_counter_cpu_data_to_ust(int sock, return ret; } -int ustctl_counter_read(struct ustctl_daemon_counter *counter, +int lttng_ust_ctl_counter_read(struct lttng_ust_ctl_daemon_counter *counter, const size_t *dimension_indexes, int cpu, int64_t *value, bool *overflow, bool *underflow) @@ -2885,7 +3276,7 @@ int ustctl_counter_read(struct ustctl_daemon_counter *counter, value, overflow, underflow); } -int ustctl_counter_aggregate(struct ustctl_daemon_counter *counter, +int lttng_ust_ctl_counter_aggregate(struct lttng_ust_ctl_daemon_counter *counter, const size_t *dimension_indexes, int64_t *value, bool *overflow, bool *underflow) @@ -2894,31 +3285,33 @@ int ustctl_counter_aggregate(struct ustctl_daemon_counter *counter, value, overflow, underflow); } -int ustctl_counter_clear(struct ustctl_daemon_counter *counter, +int lttng_ust_ctl_counter_clear(struct lttng_ust_ctl_daemon_counter *counter, const size_t *dimension_indexes) { return counter->ops->counter_clear(counter->counter, dimension_indexes); } static -void ustctl_init(void) +void lttng_ust_ctl_ctor(void) __attribute__((constructor)); static -void ustctl_init(void) +void lttng_ust_ctl_ctor(void) { - lttng_ust_logging_init(); - lttng_ust_getenv_init(); /* Needs lttng_ust_logging_init() to be completed. */ - lttng_ust_clock_init(); + /* + * Call the liblttng-ust-common constructor to ensure it runs first. + */ + lttng_ust_common_ctor(); + lttng_ust_ring_buffer_clients_init(); lttng_ust_counter_clients_init(); lib_ringbuffer_signal_init(); } static -void ustctl_exit(void) +void lttng_ust_ctl_exit(void) __attribute__((destructor)); static -void ustctl_exit(void) +void lttng_ust_ctl_exit(void) { lttng_ust_counter_clients_exit(); lttng_ust_ring_buffer_clients_exit();