Add syscall listing support
[lttng-tools.git] / src / common / kernel-ctl / kernel-ctl.c
index b45efd0efa1dc7e6b5e8520419d9f7f6dff99ebd..a387b93bf87f0334365c3217c95537cf1487e29b 100644 (file)
@@ -19,6 +19,7 @@
 #define __USE_LINUX_IOCTL_DEFS
 #include <sys/ioctl.h>
 #include <string.h>
+#include <common/align.h>
 
 #include "kernel-ctl.h"
 #include "kernel-ioctl.h"
@@ -99,7 +100,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);
 }
@@ -134,11 +135,86 @@ 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_enable_syscall(int fd, const char *syscall_name)
+{
+       struct lttng_kernel_event event;
+
+       memset(&event, 0, sizeof(event));
+       strncpy(event.name, syscall_name, sizeof(event.name));
+       event.name[sizeof(event.name) - 1] = '\0';
+       event.instrumentation = LTTNG_KERNEL_SYSCALL;
+       event.u.syscall.enable = 1;
+       return ioctl(fd, LTTNG_KERNEL_EVENT, &event);
+}
+
+int kernctl_disable_syscall(int fd, const char *syscall_name)
+{
+       struct lttng_kernel_event event;
+
+       memset(&event, 0, sizeof(event));
+       strncpy(event.name, syscall_name, sizeof(event.name));
+       event.name[sizeof(event.name) - 1] = '\0';
+       event.instrumentation = LTTNG_KERNEL_SYSCALL;
+       event.u.syscall.enable = 0;
+       return ioctl(fd, LTTNG_KERNEL_EVENT, &event);
+}
+
+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_create_stream(int fd)
 {
        return compat_ioctl_no_arg(fd, LTTNG_KERNEL_OLD_STREAM,
@@ -188,7 +264,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 =
@@ -235,6 +311,11 @@ int kernctl_tracepoint_list(int fd)
                        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;
@@ -390,3 +471,45 @@ 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);
+}
This page took 0.02559 seconds and 5 git commands to generate.