docs: Correct GitHub URLs in lttng-ust.3
[lttng-ust.git] / src / common / macros.h
CommitLineData
35897f8b 1/*
c0c0989a 2 * SPDX-License-Identifier: LGPL-2.1-only
35897f8b 3 *
c0c0989a 4 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
35897f8b
MD
5 */
6
9d315d6d
MJ
7#ifndef _UST_COMMON_MACROS_H
8#define _UST_COMMON_MACROS_H
c0c0989a 9
35897f8b 10#include <stdlib.h>
97572c04
MD
11#include <stdbool.h>
12#include <string.h>
35897f8b 13
2eba8e39
MJ
14#include <lttng/ust-arch.h>
15
97572c04
MD
16/*
17 * calloc() does not always populate the page table for the allocated
18 * memory. Optionally enforce page table populate.
19 */
20static inline
21void *zmalloc_populate(size_t len, bool populate)
22 __attribute__((always_inline));
23static inline
24void *zmalloc_populate(size_t len, bool populate)
25{
26 if (populate) {
27 void *ret = malloc(len);
28 if (ret == NULL)
29 return ret;
30 bzero(ret, len);
31 return ret;
32 } else {
33 return calloc(len, 1);
34 }
35}
36
9d315d6d
MJ
37/*
38 * Memory allocation zeroed
39 */
5f6daaef
MJ
40static inline
41void *zmalloc(size_t len)
42 __attribute__((always_inline));
43static inline
35897f8b
MD
44void *zmalloc(size_t len)
45{
97572c04 46 return zmalloc_populate(len, false);
35897f8b
MD
47}
48
49#define max_t(type, x, y) \
50 ({ \
51 type __max1 = (x); \
52 type __max2 = (y); \
53 __max1 > __max2 ? __max1: __max2; \
54 })
55
56#define min_t(type, x, y) \
57 ({ \
58 type __min1 = (x); \
59 type __min2 = (y); \
60 __min1 <= __min2 ? __min1: __min2; \
61 })
62
fd67a004
MD
63#define LTTNG_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
64
171fcc6f
MD
65/*
66 * Use of __builtin_return_address(0) sometimes seems to cause stack
67 * corruption on 32-bit PowerPC. Disable this feature on that
68 * architecture for now by always using the NULL value for the ip
69 * context.
70 */
2eba8e39 71#if defined(LTTNG_UST_ARCH_PPC) && !defined(LTTNG_UST_ARCH_PPC64)
171fcc6f 72#define LTTNG_UST_CALLER_IP() NULL
2eba8e39 73#else
171fcc6f 74#define LTTNG_UST_CALLER_IP() __builtin_return_address(0)
2eba8e39 75#endif
171fcc6f 76
9d315d6d 77#endif /* _UST_COMMON_MACROS_H */
This page took 0.039306 seconds and 4 git commands to generate.