X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fkernel-ctl%2Fkernel-ctl.c;h=dd228773bc655eb985e88a6b2fe20e8c87221115;hp=e4a268ed48becd506ddbaf955deeacd3ef6d5373;hb=000fa86f1276f62aa32cdb18f6556db1bdeee09b;hpb=1be4792f346ea9a05cfc0acd38e295417c67d122 diff --git a/src/common/kernel-ctl/kernel-ctl.c b/src/common/kernel-ctl/kernel-ctl.c index e4a268ed4..dd228773b 100644 --- a/src/common/kernel-ctl/kernel-ctl.c +++ b/src/common/kernel-ctl/kernel-ctl.c @@ -16,9 +16,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _LGPL_SOURCE #define __USE_LINUX_IOCTL_DEFS #include #include +#include +#include #include "kernel-ctl.h" #include "kernel-ioctl.h" @@ -82,7 +85,13 @@ int kernctl_open_metadata(int fd, struct lttng_channel_attr *chops) old_channel.switch_timer_interval = chops->switch_timer_interval; old_channel.read_timer_interval = chops->read_timer_interval; old_channel.output = chops->output; - memcpy(old_channel.padding, chops->padding, sizeof(old_channel.padding)); + + memset(old_channel.padding, 0, sizeof(old_channel.padding)); + /* + * The new channel padding is smaller than the old ABI so we use the + * new ABI padding size for the memcpy. + */ + memcpy(old_channel.padding, chops->padding, sizeof(chops->padding)); return ioctl(fd, LTTNG_KERNEL_OLD_METADATA, &old_channel); } @@ -93,7 +102,7 @@ int kernctl_open_metadata(int fd, struct lttng_channel_attr *chops) channel.switch_timer_interval = chops->switch_timer_interval; channel.read_timer_interval = chops->read_timer_interval; channel.output = chops->output; - memcpy(channel.padding, chops->padding, sizeof(channel.padding)); + memcpy(channel.padding, chops->padding, sizeof(chops->padding)); return ioctl(fd, LTTNG_KERNEL_METADATA, &channel); } @@ -102,6 +111,7 @@ int kernctl_create_channel(int fd, struct lttng_channel_attr *chops) { struct lttng_kernel_channel channel; + memset(&channel, 0, sizeof(channel)); if (lttng_kernel_use_old_abi) { struct lttng_kernel_old_channel old_channel; @@ -111,7 +121,13 @@ int kernctl_create_channel(int fd, struct lttng_channel_attr *chops) old_channel.switch_timer_interval = chops->switch_timer_interval; old_channel.read_timer_interval = chops->read_timer_interval; old_channel.output = chops->output; - memcpy(old_channel.padding, chops->padding, sizeof(old_channel.padding)); + + memset(old_channel.padding, 0, sizeof(old_channel.padding)); + /* + * The new channel padding is smaller than the old ABI so we use the + * new ABI padding size for the memcpy. + */ + memcpy(old_channel.padding, chops->padding, sizeof(chops->padding)); return ioctl(fd, LTTNG_KERNEL_OLD_CHANNEL, &old_channel); } @@ -122,11 +138,77 @@ int kernctl_create_channel(int fd, struct lttng_channel_attr *chops) channel.switch_timer_interval = chops->switch_timer_interval; channel.read_timer_interval = chops->read_timer_interval; channel.output = chops->output; - memcpy(channel.padding, chops->padding, sizeof(channel.padding)); + memcpy(channel.padding, chops->padding, sizeof(chops->padding)); return ioctl(fd, LTTNG_KERNEL_CHANNEL, &channel); } +int kernctl_syscall_mask(int fd, char **syscall_mask, uint32_t *nr_bits) +{ + struct lttng_kernel_syscall_mask kmask_len, *kmask = NULL; + size_t array_alloc_len; + char *new_mask; + int ret = 0; + + if (!syscall_mask) { + ret = -1; + goto end; + } + + if (!nr_bits) { + ret = -1; + goto end; + } + + kmask_len.len = 0; + ret = ioctl(fd, LTTNG_KERNEL_SYSCALL_MASK, &kmask_len); + if (ret) { + goto end; + } + + array_alloc_len = ALIGN(kmask_len.len, 8) >> 3; + + kmask = zmalloc(sizeof(*kmask) + array_alloc_len); + if (!kmask) { + ret = -1; + goto end; + } + + kmask->len = kmask_len.len; + ret = ioctl(fd, LTTNG_KERNEL_SYSCALL_MASK, kmask); + if (ret) { + goto end; + } + + new_mask = realloc(*syscall_mask, array_alloc_len); + if (!new_mask) { + ret = -1; + goto end; + } + memcpy(new_mask, kmask->mask, array_alloc_len); + *syscall_mask = new_mask; + *nr_bits = kmask->len; + +end: + free(kmask); + return ret; +} + +int kernctl_track_pid(int fd, int pid) +{ + return ioctl(fd, LTTNG_KERNEL_SESSION_TRACK_PID, pid); +} + +int kernctl_untrack_pid(int fd, int pid) +{ + return ioctl(fd, LTTNG_KERNEL_SESSION_UNTRACK_PID, pid); +} + +int kernctl_list_tracker_pids(int fd) +{ + return ioctl(fd, LTTNG_KERNEL_SESSION_LIST_TRACKER_PIDS); +} + int kernctl_create_stream(int fd) { return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_STREAM, @@ -176,7 +258,7 @@ int kernctl_add_context(int fd, struct lttng_kernel_context *ctx) old_ctx.ctx = ctx->ctx; /* only type that uses the union */ - if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) { + if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER) { old_ctx.u.perf_counter.type = ctx->u.perf_counter.type; old_ctx.u.perf_counter.config = @@ -217,12 +299,36 @@ int kernctl_stop_session(int fd) LTTNG_KERNEL_SESSION_STOP); } +int kernctl_filter(int fd, struct lttng_filter_bytecode *filter) +{ + struct lttng_kernel_filter_bytecode *kb; + uint32_t len; + int ret; + + /* Translate bytecode to kernel bytecode */ + kb = zmalloc(sizeof(*kb) + filter->len); + if (!kb) + return -ENOMEM; + kb->len = len = filter->len; + kb->reloc_offset = filter->reloc_table_offset; + kb->seqnum = filter->seqnum; + memcpy(kb->data, filter->data, len); + ret = ioctl(fd, LTTNG_KERNEL_FILTER, kb); + free(kb); + return ret; +} + int kernctl_tracepoint_list(int fd) { return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_TRACEPOINT_LIST, LTTNG_KERNEL_TRACEPOINT_LIST); } +int kernctl_syscall_list(int fd) +{ + return ioctl(fd, LTTNG_KERNEL_SYSCALL_LIST); +} + int kernctl_tracer_version(int fd, struct lttng_kernel_tracer_version *v) { int ret; @@ -253,6 +359,12 @@ end: return ret; } +int kernctl_tracer_abi_version(int fd, + struct lttng_kernel_tracer_abi_version *v) +{ + return ioctl(fd, LTTNG_KERNEL_TRACER_ABI_VERSION, v); +} + int kernctl_wait_quiescent(int fd) { return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_WAIT_QUIESCENT, @@ -378,3 +490,57 @@ int kernctl_put_subbuf(int fd) { return ioctl(fd, RING_BUFFER_PUT_SUBBUF); } + +/* Returns the timestamp begin of the current sub-buffer. */ +int kernctl_get_timestamp_begin(int fd, uint64_t *timestamp_begin) +{ + return ioctl(fd, LTTNG_RING_BUFFER_GET_TIMESTAMP_BEGIN, timestamp_begin); +} + +/* Returns the timestamp end of the current sub-buffer. */ +int kernctl_get_timestamp_end(int fd, uint64_t *timestamp_end) +{ + return ioctl(fd, LTTNG_RING_BUFFER_GET_TIMESTAMP_END, timestamp_end); +} + +/* Returns the number of discarded events in the current sub-buffer. */ +int kernctl_get_events_discarded(int fd, uint64_t *events_discarded) +{ + return ioctl(fd, LTTNG_RING_BUFFER_GET_EVENTS_DISCARDED, events_discarded); +} + +/* Returns the content size in the current sub-buffer. */ +int kernctl_get_content_size(int fd, uint64_t *content_size) +{ + return ioctl(fd, LTTNG_RING_BUFFER_GET_CONTENT_SIZE, content_size); +} + +/* Returns the packet size in the current sub-buffer. */ +int kernctl_get_packet_size(int fd, uint64_t *packet_size) +{ + return ioctl(fd, LTTNG_RING_BUFFER_GET_PACKET_SIZE, packet_size); +} + +/* Returns the stream id of the current sub-buffer. */ +int kernctl_get_stream_id(int fd, uint64_t *stream_id) +{ + return ioctl(fd, LTTNG_RING_BUFFER_GET_STREAM_ID, stream_id); +} + +/* Returns the current timestamp. */ +int kernctl_get_current_timestamp(int fd, uint64_t *ts) +{ + return ioctl(fd, LTTNG_RING_BUFFER_GET_CURRENT_TIMESTAMP, ts); +} + +/* Returns the packet sequence number of the current sub-buffer. */ +int kernctl_get_sequence_number(int fd, uint64_t *seq) +{ + return ioctl(fd, LTTNG_RING_BUFFER_GET_SEQ_NUM, seq); +} + +/* Returns the stream instance id. */ +int kernctl_get_instance_id(int fd, uint64_t *id) +{ + return ioctl(fd, LTTNG_RING_BUFFER_INSTANCE_ID, id); +}