From 46820c8b8f1fbbc15b3afdbb18472b703da1fcd4 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 15 Sep 2014 15:07:02 -0400 Subject: [PATCH] Implement kernctl_syscall_mask Signed-off-by: Mathieu Desnoyers Signed-off-by: David Goulet --- src/{lib/lttng-ctl/filter => common}/align.h | 0 src/{lib/lttng-ctl/filter => common}/bug.h | 0 src/common/kernel-ctl/kernel-ctl.c | 51 +++++++++++++++++++ src/common/kernel-ctl/kernel-ctl.h | 14 +++++ src/common/lttng-kernel.h | 2 +- .../filter/filter-visitor-generate-bytecode.c | 3 +- 6 files changed, 68 insertions(+), 2 deletions(-) rename src/{lib/lttng-ctl/filter => common}/align.h (100%) rename src/{lib/lttng-ctl/filter => common}/bug.h (100%) diff --git a/src/lib/lttng-ctl/filter/align.h b/src/common/align.h similarity index 100% rename from src/lib/lttng-ctl/filter/align.h rename to src/common/align.h diff --git a/src/lib/lttng-ctl/filter/bug.h b/src/common/bug.h similarity index 100% rename from src/lib/lttng-ctl/filter/bug.h rename to src/common/bug.h diff --git a/src/common/kernel-ctl/kernel-ctl.c b/src/common/kernel-ctl/kernel-ctl.c index 078d85280..6cc962703 100644 --- a/src/common/kernel-ctl/kernel-ctl.c +++ b/src/common/kernel-ctl/kernel-ctl.c @@ -19,6 +19,7 @@ #define __USE_LINUX_IOCTL_DEFS #include #include +#include #include "kernel-ctl.h" #include "kernel-ioctl.h" @@ -163,6 +164,56 @@ int kernctl_disable_syscall(int fd, const char *syscall_name) 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, diff --git a/src/common/kernel-ctl/kernel-ctl.h b/src/common/kernel-ctl/kernel-ctl.h index a20c68997..4ef1b8795 100644 --- a/src/common/kernel-ctl/kernel-ctl.h +++ b/src/common/kernel-ctl/kernel-ctl.h @@ -44,6 +44,20 @@ int kernctl_calibrate(int fd, struct lttng_kernel_calibrate *calibrate); int kernctl_enable_syscall(int fd, const char *syscall_name); int kernctl_disable_syscall(int fd, const char *syscall_name); +/* + * kernctl_syscall_mask - Get syscall mask associated to a channel FD. + * + * The parameter @syscall_mask should initially be either NULL or point + * to memory allocated with malloc(3) or realloc(3). When the function + * returns, it will point to a memory area of the size required for the + * bitmask (using realloc(3) to resize the memory). + * + * It returns 0 if OK, -1 on error. In all cases (error and OK), + * @syscall_mask should be freed by the caller with free(3). + */ +int kernctl_syscall_mask(int fd, char **syscall_mask, + uint32_t *nr_bits); + /* Buffer operations */ /* For mmap mode, readable without "get" operation */ diff --git a/src/common/lttng-kernel.h b/src/common/lttng-kernel.h index a4ca1825d..4df324005 100644 --- a/src/common/lttng-kernel.h +++ b/src/common/lttng-kernel.h @@ -133,7 +133,7 @@ struct lttng_kernel_calibrate { } LTTNG_PACKED; struct lttng_kernel_syscall_mask { - uint32_t len; + uint32_t len; /* in bits */ char mask[]; } LTTNG_PACKED; diff --git a/src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c b/src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c index 1cf7cb5c3..4dd52d8d0 100644 --- a/src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c +++ b/src/lib/lttng-ctl/filter/filter-visitor-generate-bytecode.c @@ -22,7 +22,8 @@ #include #include #include -#include "align.h" +#include + #include "filter-bytecode.h" #include "filter-ir.h" #include "filter-ast.h" -- 2.34.1