]> git.sesse.net Git - bcachefs-tools-debian/blobdiff - include/linux/kernel.h
add a fallback __DECLARE_FLEX_ARRAY
[bcachefs-tools-debian] / include / linux / kernel.h
index 30451cb94073d7fa6e998be44b4864737bce53b3..da01c38161a11e00746e48d4fec8838afb3cc825 100644 (file)
@@ -13,6 +13,9 @@
 #include <linux/compiler.h>
 #include <linux/math.h>
 
+#define BIT(nr)                        (1UL << (nr))
+#define BIT_ULL(nr)            (1ULL << (nr))
+
 #define __ARG_PLACEHOLDER_1 0,
 #define __take_second_arg(__ignored, val, ...) val
 
        (type *)((char *)__mptr - offsetof(type, member)); })
 #endif
 
+#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
+       union { \
+               struct { MEMBERS } ATTRS; \
+               struct TAG { MEMBERS } ATTRS NAME; \
+       }
+#define struct_group(NAME, MEMBERS...) \
+       __struct_group(/* no tag */, NAME, /* no attrs */, MEMBERS)
+
 #define max(x, y) ({                           \
        typeof(x) _max1 = (x);                  \
        typeof(y) _max2 = (y);                  \
 
 #define might_sleep()
 
-#define cpu_relax()            do {} while (0)
-#define cpu_relax_lowlatency() do {} while (0)
+#define cpu_relax()            barrier()
+#define cpu_relax_lowlatency() barrier()
 
 #define panic(fmt, ...)                                        \
 do {                                                   \
@@ -228,6 +239,19 @@ static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *
        return kstrtoint(s, base, res);
 }
 
+struct printbuf;
+extern void prt_u64(struct printbuf *out, u64 num);
+
+extern __printf(2, 0) void prt_vprintf(struct printbuf *out, const char *fmt, va_list args);
+extern __printf(2, 3) void prt_printf(struct printbuf *out, const char *fmt, ...);
+
+static const char hex_asc[] = "0123456789abcdef";
+#define hex_asc_lo(x)  hex_asc[((x) & 0x0f)]
+#define hex_asc_hi(x)  hex_asc[((x) & 0xf0) >> 4]
+static const char hex_asc_upper[] = "0123456789ABCDEF";
+#define hex_asc_upper_lo(x)    hex_asc_upper[((x) & 0x0f)]
+#define hex_asc_upper_hi(x)    hex_asc_upper[((x) & 0xf0) >> 4]
+
 /* The hash is always the low bits of hash_len */
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  #define HASH_LEN_DECLARE u32 hash; u32 len
@@ -251,4 +275,13 @@ struct qstr {
 
 static inline void dump_stack(void) {}
 
+#define unsafe_memcpy(dst, src, bytes, justification)          \
+       memcpy(dst, src, bytes)
+
+#ifdef __DECLARE_FLEX_ARRAY
+#define DECLARE_FLEX_ARRAY(TYPE, NAME) __DECLARE_FLEX_ARRAY(TYPE, NAME)
+#else
+#define __DECLARE_FLEX_ARRAY(T, member)        T member[0]
+#endif
+
 #endif