Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __TOOLS_LINUX_KERNEL_H
0003 #define __TOOLS_LINUX_KERNEL_H
0004 
0005 #include <stdarg.h>
0006 #include <stddef.h>
0007 #include <assert.h>
0008 #include <linux/build_bug.h>
0009 #include <linux/compiler.h>
0010 #include <linux/math.h>
0011 #include <endian.h>
0012 #include <byteswap.h>
0013 
0014 #ifndef UINT_MAX
0015 #define UINT_MAX    (~0U)
0016 #endif
0017 
0018 #define _RET_IP_        ((unsigned long)__builtin_return_address(0))
0019 
0020 #define PERF_ALIGN(x, a)    __PERF_ALIGN_MASK(x, (typeof(x))(a)-1)
0021 #define __PERF_ALIGN_MASK(x, mask)  (((x)+(mask))&~(mask))
0022 
0023 #ifndef offsetof
0024 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
0025 #endif
0026 
0027 #ifndef container_of
0028 /**
0029  * container_of - cast a member of a structure out to the containing structure
0030  * @ptr:    the pointer to the member.
0031  * @type:   the type of the container struct this is embedded in.
0032  * @member: the name of the member within the struct.
0033  *
0034  */
0035 #define container_of(ptr, type, member) ({          \
0036     const typeof(((type *)0)->member) * __mptr = (ptr); \
0037     (type *)((char *)__mptr - offsetof(type, member)); })
0038 #endif
0039 
0040 #ifndef max
0041 #define max(x, y) ({                \
0042     typeof(x) _max1 = (x);          \
0043     typeof(y) _max2 = (y);          \
0044     (void) (&_max1 == &_max2);      \
0045     _max1 > _max2 ? _max1 : _max2; })
0046 #endif
0047 
0048 #ifndef min
0049 #define min(x, y) ({                \
0050     typeof(x) _min1 = (x);          \
0051     typeof(y) _min2 = (y);          \
0052     (void) (&_min1 == &_min2);      \
0053     _min1 < _min2 ? _min1 : _min2; })
0054 #endif
0055 
0056 #define max_t(type, x, y)   max((type)x, (type)y)
0057 #define min_t(type, x, y)   min((type)x, (type)y)
0058 #define clamp(val, lo, hi)  min((typeof(val))max(val, lo), hi)
0059 
0060 #ifndef BUG_ON
0061 #ifdef NDEBUG
0062 #define BUG_ON(cond) do { if (cond) {} } while (0)
0063 #else
0064 #define BUG_ON(cond) assert(!(cond))
0065 #endif
0066 #endif
0067 #define BUG()   BUG_ON(1)
0068 
0069 #if __BYTE_ORDER == __BIG_ENDIAN
0070 #define cpu_to_le16 bswap_16
0071 #define cpu_to_le32 bswap_32
0072 #define cpu_to_le64 bswap_64
0073 #define le16_to_cpu bswap_16
0074 #define le32_to_cpu bswap_32
0075 #define le64_to_cpu bswap_64
0076 #define cpu_to_be16
0077 #define cpu_to_be32
0078 #define cpu_to_be64
0079 #define be16_to_cpu
0080 #define be32_to_cpu
0081 #define be64_to_cpu
0082 #else
0083 #define cpu_to_le16
0084 #define cpu_to_le32
0085 #define cpu_to_le64
0086 #define le16_to_cpu
0087 #define le32_to_cpu
0088 #define le64_to_cpu
0089 #define cpu_to_be16 bswap_16
0090 #define cpu_to_be32 bswap_32
0091 #define cpu_to_be64 bswap_64
0092 #define be16_to_cpu bswap_16
0093 #define be32_to_cpu bswap_32
0094 #define be64_to_cpu bswap_64
0095 #endif
0096 
0097 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
0098 int scnprintf(char * buf, size_t size, const char * fmt, ...);
0099 int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);
0100 
0101 #ifndef ARRAY_SIZE
0102 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
0103 #endif
0104 
0105 #define current_gfp_context(k) 0
0106 #define synchronize_rcu()
0107 
0108 #endif