From cd61d9bfa5fd334b086831dcbdec63da6c0d1a16 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 25 Feb 2021 15:46:02 -0500 Subject: [PATCH] Move compat macros in 'lttng/align.h' to a private header No need to expose those compat macros in a public header, only keep the actual align macros public. Change-Id: Iee0ac69cfb98400afd9ee83a8a8e218af48971bf Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- include/Makefile.am | 1 + include/lttng/align.h | 58 +------------------ include/ust-compat.h | 31 ++++++++++ libcounter/counter.c | 2 +- libcounter/shm.c | 2 +- liblttng-ust-ctl/ustctl.c | 1 + liblttng-ust-libc-wrapper/lttng-ust-malloc.c | 2 +- liblttng-ust/lttng-ring-buffer-client.h | 1 + .../lttng-ring-buffer-metadata-client.h | 1 + liblttng-ust/lttng-ust-comm.c | 2 +- libringbuffer/ring_buffer_backend.c | 1 + libringbuffer/ring_buffer_frontend.c | 1 + tests/unit/libringbuffer/shm.c | 2 +- 13 files changed, 45 insertions(+), 60 deletions(-) create mode 100644 include/ust-compat.h diff --git a/include/Makefile.am b/include/Makefile.am index 101e8ac7..2c78459e 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -55,6 +55,7 @@ noinst_HEADERS = \ ust-snprintf.h \ ust-bitmap.h \ ust-comm.h \ + ust-compat.h \ ust-fd.h \ ust-tid.h \ ust-bitfield.h \ diff --git a/include/lttng/align.h b/include/lttng/align.h index e46c0301..6384a00a 100644 --- a/include/lttng/align.h +++ b/include/lttng/align.h @@ -4,30 +4,10 @@ * Copyright (C) 2010-2011 Mathieu Desnoyers */ -#ifndef _UST_ALIGN_H -#define _UST_ALIGN_H +#ifndef _LTTNG_ALIGN_H +#define _LTTNG_ALIGN_H #include -#include -#include - -#ifdef __FreeBSD__ -#include -#endif - -#ifdef _SC_PAGE_SIZE -#define LTTNG_UST_PAGE_SIZE sysconf(_SC_PAGE_SIZE) -#elif defined(PAGE_SIZE) -#define LTTNG_UST_PAGE_SIZE PAGE_SIZE -#else -#error "Please add page size detection for your OS." -#endif - -#define LTTNG_UST_PAGE_MASK (~(LTTNG_UST_PAGE_SIZE - 1)) - -#define __LTTNG_UST_ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask)) -#define LTTNG_UST_ALIGN(v, align) __LTTNG_UST_ALIGN_MASK(v, (__typeof__(v)) (align) - 1) -#define LTTNG_UST_PAGE_ALIGN(addr) LTTNG_UST_ALIGN(addr, LTTNG_UST_PAGE_SIZE) /** * lttng_ust_offset_align - Calculate the offset needed to align an object on @@ -60,36 +40,4 @@ (((align_drift) - (alignment)) & ((alignment) - 1)); \ }) -/* - * Non-namespaced defines for backwards compatibility, - * introduced in 2.13, should be removed in the future. - */ - -/* Cygwin limits.h defines its own PAGE_SIZE */ -#ifndef PAGE_SIZE -#define PAGE_SIZE LTTNG_UST_PAGE_SIZE -#endif - -/* FreeBSD and macOS defines their own PAGE_MASK. */ -#ifndef PAGE_MASK -#define PAGE_MASK LTTNG_UST_PAGE_MASK -#endif - -/* FreeBSD machine/param.h defines its own ALIGN */ -#ifndef ALIGN -#define ALIGN LTTNG_UST_ALIGN -#endif - -#ifndef PAGE_ALIGN -#define PAGE_ALIGN LTTNG_UST_PAGE_ALIGN -#endif - -#ifndef offset_align -#define offset_align lttng_ust_offset_align -#endif - -#ifndef offset_align_floor -#define offset_align_floor lttng_ust_offset_align_floor -#endif - -#endif /* _UST_ALIGN_H */ +#endif /* _LTTNG_ALIGN_H */ diff --git a/include/ust-compat.h b/include/ust-compat.h new file mode 100644 index 00000000..c148e1be --- /dev/null +++ b/include/ust-compat.h @@ -0,0 +1,31 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2010-2011 Mathieu Desnoyers + */ + +#ifndef _LTTNG_UST_COMPAT_H +#define _LTTNG_UST_COMPAT_H + +#include +#include + +#ifdef __FreeBSD__ +#include +#endif + +#ifdef _SC_PAGE_SIZE +#define LTTNG_UST_PAGE_SIZE sysconf(_SC_PAGE_SIZE) +#elif defined(PAGE_SIZE) +#define LTTNG_UST_PAGE_SIZE PAGE_SIZE +#else +#error "Please add page size detection for your OS." +#endif + +#define LTTNG_UST_PAGE_MASK (~(LTTNG_UST_PAGE_SIZE - 1)) + +#define __LTTNG_UST_ALIGN_MASK(v, mask) (((v) + (mask)) & ~(mask)) +#define LTTNG_UST_ALIGN(v, align) __LTTNG_UST_ALIGN_MASK(v, (__typeof__(v)) (align) - 1) +#define LTTNG_UST_PAGE_ALIGN(addr) LTTNG_UST_ALIGN(addr, LTTNG_UST_PAGE_SIZE) + +#endif diff --git a/libcounter/counter.c b/libcounter/counter.c index c98589db..d2b7032a 100644 --- a/libcounter/counter.c +++ b/libcounter/counter.c @@ -13,9 +13,9 @@ #include #include #include -#include #include "smp.h" #include "shm.h" +#include "ust-compat.h" #include "ust-bitmap.h" diff --git a/libcounter/shm.c b/libcounter/shm.c index 13a9f642..1689ad45 100644 --- a/libcounter/shm.c +++ b/libcounter/shm.c @@ -368,6 +368,6 @@ struct lttng_counter_shm_ref lttng_counter_zalloc_shm(struct lttng_counter_shm_o void lttng_counter_align_shm(struct lttng_counter_shm_object *obj, size_t align) { - size_t offset_len = offset_align(obj->allocated_len, align); + size_t offset_len = lttng_ust_offset_align(obj->allocated_len, align); obj->allocated_len += offset_len; } diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index 38076928..057895d8 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -20,6 +20,7 @@ #include #include #include +#include "ust-compat.h" #include "../libringbuffer/backend.h" #include "../libringbuffer/frontend.h" diff --git a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c index 694eed17..be13f214 100644 --- a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c +++ b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c @@ -19,8 +19,8 @@ #include #include #include -#include #include +#include "ust-compat.h" #define TRACEPOINT_DEFINE #define TRACEPOINT_CREATE_PROBES diff --git a/liblttng-ust/lttng-ring-buffer-client.h b/liblttng-ust/lttng-ring-buffer-client.h index 42d68f66..79786af2 100644 --- a/liblttng-ust/lttng-ring-buffer-client.h +++ b/liblttng-ust/lttng-ring-buffer-client.h @@ -10,6 +10,7 @@ #include #include #include "ust-bitfield.h" +#include "ust-compat.h" #include "clock.h" #include "lttng-tracer.h" #include "../libringbuffer/frontend_types.h" diff --git a/liblttng-ust/lttng-ring-buffer-metadata-client.h b/liblttng-ust/lttng-ring-buffer-metadata-client.h index 0b0a65fc..98af8993 100644 --- a/liblttng-ust/lttng-ring-buffer-metadata-client.h +++ b/liblttng-ust/lttng-ring-buffer-metadata-client.h @@ -10,6 +10,7 @@ #include #include #include "ust-bitfield.h" +#include "ust-compat.h" #include "lttng-tracer.h" #include "../libringbuffer/frontend_types.h" diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 891eb16e..18701936 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -50,6 +49,7 @@ #include "getenv.h" #include "ust-events-internal.h" #include "context-internal.h" +#include "ust-compat.h" /* Concatenate lttng ust shared library name with its major version number. */ #define LTTNG_UST_LIB_SO_NAME "liblttng-ust.so." __ust_stringify(CONFIG_LTTNG_UST_LIBRARY_VERSION_MAJOR) diff --git a/libringbuffer/ring_buffer_backend.c b/libringbuffer/ring_buffer_backend.c index b50c2f3c..0d4afb4e 100644 --- a/libringbuffer/ring_buffer_backend.c +++ b/libringbuffer/ring_buffer_backend.c @@ -18,6 +18,7 @@ #include "frontend.h" #include "smp.h" #include "shm.h" +#include "ust-compat.h" /** * lib_ring_buffer_backend_allocate - allocate a channel buffer diff --git a/libringbuffer/ring_buffer_frontend.c b/libringbuffer/ring_buffer_frontend.c index 736c598a..3b338fc3 100644 --- a/libringbuffer/ring_buffer_frontend.c +++ b/libringbuffer/ring_buffer_frontend.c @@ -52,6 +52,7 @@ #include #include +#include #include "smp.h" #include #include "vatomic.h" diff --git a/tests/unit/libringbuffer/shm.c b/tests/unit/libringbuffer/shm.c index 4e6ac082..fe3cb6c0 100644 --- a/tests/unit/libringbuffer/shm.c +++ b/tests/unit/libringbuffer/shm.c @@ -12,8 +12,8 @@ #include #include -#include #include "libringbuffer/shm.h" +#include "ust-compat.h" #include "tap.h" -- 2.34.1