Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __TOOLS_LINUX_KERNEL_H
3#define __TOOLS_LINUX_KERNEL_H
4
5#include <stdarg.h>
6#include <stddef.h>
7#include <assert.h>
8#include <linux/build_bug.h>
9#include <linux/compiler.h>
10#include <linux/math.h>
11#include <linux/panic.h>
12#include <endian.h>
13#include <byteswap.h>
14#include <linux/container_of.h>
15
16#ifndef UINT_MAX
17#define UINT_MAX (~0U)
18#endif
19
20#define _RET_IP_ ((unsigned long)__builtin_return_address(0))
21
22#define PERF_ALIGN(x, a) __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
23#define __PERF_ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
24
25#ifndef offsetof
26#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
27#endif
28
29#ifndef max
30#define max(x, y) ({ \
31 typeof(x) _max1 = (x); \
32 typeof(y) _max2 = (y); \
33 (void) (&_max1 == &_max2); \
34 _max1 > _max2 ? _max1 : _max2; })
35#endif
36
37#ifndef min
38#define min(x, y) ({ \
39 typeof(x) _min1 = (x); \
40 typeof(y) _min2 = (y); \
41 (void) (&_min1 == &_min2); \
42 _min1 < _min2 ? _min1 : _min2; })
43#endif
44
45#define max_t(type, x, y) max((type)x, (type)y)
46#define min_t(type, x, y) min((type)x, (type)y)
47#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi)
48
49#ifndef BUG_ON
50#ifdef NDEBUG
51#define BUG_ON(cond) do { if (cond) {} } while (0)
52#else
53#define BUG_ON(cond) assert(!(cond))
54#endif
55#endif
56#define BUG() BUG_ON(1)
57
58#if __BYTE_ORDER == __BIG_ENDIAN
59#define cpu_to_le16 bswap_16
60#define cpu_to_le32 bswap_32
61#define cpu_to_le64 bswap_64
62#define le16_to_cpu bswap_16
63#define le32_to_cpu bswap_32
64#define le64_to_cpu bswap_64
65#define cpu_to_be16
66#define cpu_to_be32
67#define cpu_to_be64
68#define be16_to_cpu
69#define be32_to_cpu
70#define be64_to_cpu
71#else
72#define cpu_to_le16
73#define cpu_to_le32
74#define cpu_to_le64
75#define le16_to_cpu
76#define le32_to_cpu
77#define le64_to_cpu
78#define cpu_to_be16 bswap_16
79#define cpu_to_be32 bswap_32
80#define cpu_to_be64 bswap_64
81#define be16_to_cpu bswap_16
82#define be32_to_cpu bswap_32
83#define be64_to_cpu bswap_64
84#endif
85
86int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
87int scnprintf(char * buf, size_t size, const char * fmt, ...);
88int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);
89
90#ifndef ARRAY_SIZE
91#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
92#endif
93
94#define current_gfp_context(k) 0
95#define synchronize_rcu()
96
97#endif