From: Mathieu Desnoyers Date: Mon, 15 Sep 2014 19:07:02 +0000 (-0400) Subject: Implement kernctl_syscall_mask X-Git-Tag: v2.6.0-rc1~38 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=46820c8b8f1fbbc15b3afdbb18472b703da1fcd4;p=lttng-tools.git Implement kernctl_syscall_mask Signed-off-by: Mathieu Desnoyers Signed-off-by: David Goulet --- diff --git a/src/common/align.h b/src/common/align.h new file mode 100644 index 000000000..fe3267354 --- /dev/null +++ b/src/common/align.h @@ -0,0 +1,64 @@ +#ifndef _LTTNG_ALIGN_H +#define _LTTNG_ALIGN_H + +/* + * align.h + * + * (C) Copyright 2010-2011 - Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include "bug.h" +#include +#include + +#ifndef PAGE_SIZE /* Cygwin limits.h defines its own PAGE_SIZE */ +#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) +#endif + +#define PAGE_MASK (~(PAGE_SIZE - 1)) +#define __ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask)) +#define ALIGN(v, align) __ALIGN_MASK(v, (__typeof__(v)) (align) - 1) +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) + +/** + * offset_align - Calculate the offset needed to align an object on its natural + * alignment towards higher addresses. + * @align_drift: object offset from an "alignment"-aligned address. + * @alignment: natural object alignment. Must be non-zero, power of 2. + * + * Returns the offset that must be added to align towards higher + * addresses. + */ +#define offset_align(align_drift, alignment) \ + ({ \ + LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \ + || ((alignment) & ((alignment) - 1))); \ + (((alignment) - (align_drift)) & ((alignment) - 1)); \ + }) + +/** + * offset_align_floor - Calculate the offset needed to align an object + * on its natural alignment towards lower addresses. + * @align_drift: object offset from an "alignment"-aligned address. + * @alignment: natural object alignment. Must be non-zero, power of 2. + * + * Returns the offset that must be substracted to align towards lower addresses. + */ +#define offset_align_floor(align_drift, alignment) \ + ({ \ + LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \ + || ((alignment) & ((alignment) - 1))); \ + (((align_drift) - (alignment)) & ((alignment) - 1); \ + }) + +#endif /* _LTTNG_ALIGN_H */ diff --git a/src/common/bug.h b/src/common/bug.h new file mode 100644 index 000000000..9368c0897 --- /dev/null +++ b/src/common/bug.h @@ -0,0 +1,54 @@ +#ifndef _LTTNG_BUG_H +#define _LTTNG_BUG_H + +/* + * lttng/bug.h + * + * (C) Copyright 2010-2011 - Mathieu Desnoyers + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + +#include +#include +#include + +#define LTTNG_BUG_ON(condition) \ + do { \ + if (caa_unlikely(condition)) { \ + fprintf(stderr, \ + "LTTng BUG in file %s, line %d.\n", \ + __FILE__, __LINE__); \ + exit(EXIT_FAILURE); \ + } \ + } while (0) + +#define LTTNG_BUILD_BUG_ON(condition) \ + ((void) sizeof(char[-!!(condition)])) + +/** + * LTTNG_BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime + * @condition: the condition which should be false. + * + * If the condition is a constant and true, the compiler will generate a build + * error. If the condition is not constant, a BUG will be triggered at runtime + * if the condition is ever true. If the condition is constant and false, no + * code is emitted. + */ +#define LTTNG_BUILD_RUNTIME_BUG_ON(condition) \ + do { \ + if (__builtin_constant_p(condition)) \ + LTTNG_BUILD_BUG_ON(condition); \ + else \ + LTTNG_BUG_ON(condition); \ + } while (0) + +#endif 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/align.h b/src/lib/lttng-ctl/filter/align.h deleted file mode 100644 index fe3267354..000000000 --- a/src/lib/lttng-ctl/filter/align.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef _LTTNG_ALIGN_H -#define _LTTNG_ALIGN_H - -/* - * align.h - * - * (C) Copyright 2010-2011 - Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#include "bug.h" -#include -#include - -#ifndef PAGE_SIZE /* Cygwin limits.h defines its own PAGE_SIZE */ -#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) -#endif - -#define PAGE_MASK (~(PAGE_SIZE - 1)) -#define __ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask)) -#define ALIGN(v, align) __ALIGN_MASK(v, (__typeof__(v)) (align) - 1) -#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) - -/** - * offset_align - Calculate the offset needed to align an object on its natural - * alignment towards higher addresses. - * @align_drift: object offset from an "alignment"-aligned address. - * @alignment: natural object alignment. Must be non-zero, power of 2. - * - * Returns the offset that must be added to align towards higher - * addresses. - */ -#define offset_align(align_drift, alignment) \ - ({ \ - LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \ - || ((alignment) & ((alignment) - 1))); \ - (((alignment) - (align_drift)) & ((alignment) - 1)); \ - }) - -/** - * offset_align_floor - Calculate the offset needed to align an object - * on its natural alignment towards lower addresses. - * @align_drift: object offset from an "alignment"-aligned address. - * @alignment: natural object alignment. Must be non-zero, power of 2. - * - * Returns the offset that must be substracted to align towards lower addresses. - */ -#define offset_align_floor(align_drift, alignment) \ - ({ \ - LTTNG_BUILD_RUNTIME_BUG_ON((alignment) == 0 \ - || ((alignment) & ((alignment) - 1))); \ - (((align_drift) - (alignment)) & ((alignment) - 1); \ - }) - -#endif /* _LTTNG_ALIGN_H */ diff --git a/src/lib/lttng-ctl/filter/bug.h b/src/lib/lttng-ctl/filter/bug.h deleted file mode 100644 index 9368c0897..000000000 --- a/src/lib/lttng-ctl/filter/bug.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _LTTNG_BUG_H -#define _LTTNG_BUG_H - -/* - * lttng/bug.h - * - * (C) Copyright 2010-2011 - Mathieu Desnoyers - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - */ - -#include -#include -#include - -#define LTTNG_BUG_ON(condition) \ - do { \ - if (caa_unlikely(condition)) { \ - fprintf(stderr, \ - "LTTng BUG in file %s, line %d.\n", \ - __FILE__, __LINE__); \ - exit(EXIT_FAILURE); \ - } \ - } while (0) - -#define LTTNG_BUILD_BUG_ON(condition) \ - ((void) sizeof(char[-!!(condition)])) - -/** - * LTTNG_BUILD_RUNTIME_BUG_ON - check condition at build (if constant) or runtime - * @condition: the condition which should be false. - * - * If the condition is a constant and true, the compiler will generate a build - * error. If the condition is not constant, a BUG will be triggered at runtime - * if the condition is ever true. If the condition is constant and false, no - * code is emitted. - */ -#define LTTNG_BUILD_RUNTIME_BUG_ON(condition) \ - do { \ - if (__builtin_constant_p(condition)) \ - LTTNG_BUILD_BUG_ON(condition); \ - else \ - LTTNG_BUG_ON(condition); \ - } while (0) - -#endif 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"