| .. | .. |
|---|
| 2 | 2 | #ifndef _LINUX_KERNEL_H |
|---|
| 3 | 3 | #define _LINUX_KERNEL_H |
|---|
| 4 | 4 | |
|---|
| 5 | + |
|---|
| 5 | 6 | #include <stdarg.h> |
|---|
| 7 | +#include <linux/limits.h> |
|---|
| 6 | 8 | #include <linux/linkage.h> |
|---|
| 7 | 9 | #include <linux/stddef.h> |
|---|
| 8 | 10 | #include <linux/types.h> |
|---|
| 9 | 11 | #include <linux/compiler.h> |
|---|
| 10 | 12 | #include <linux/bitops.h> |
|---|
| 13 | +#include <linux/kstrtox.h> |
|---|
| 11 | 14 | #include <linux/log2.h> |
|---|
| 15 | +#include <linux/minmax.h> |
|---|
| 12 | 16 | #include <linux/typecheck.h> |
|---|
| 13 | 17 | #include <linux/printk.h> |
|---|
| 14 | 18 | #include <linux/build_bug.h> |
|---|
| 15 | 19 | #include <asm/byteorder.h> |
|---|
| 20 | +#include <asm/div64.h> |
|---|
| 16 | 21 | #include <uapi/linux/kernel.h> |
|---|
| 17 | | -#include <linux/limits.h> |
|---|
| 18 | 22 | |
|---|
| 19 | 23 | #define STACK_MAGIC 0xdeadbeef |
|---|
| 20 | 24 | |
|---|
| .. | .. |
|---|
| 31 | 35 | #define ALIGN_DOWN(x, a) __ALIGN_KERNEL((x) - ((a) - 1), (a)) |
|---|
| 32 | 36 | #define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) |
|---|
| 33 | 37 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) |
|---|
| 38 | +#define PTR_ALIGN_DOWN(p, a) ((typeof(p))ALIGN_DOWN((unsigned long)(p), (a))) |
|---|
| 34 | 39 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
|---|
| 35 | 40 | |
|---|
| 36 | 41 | /* generic data direction definitions */ |
|---|
| .. | .. |
|---|
| 42 | 47 | * @arr: array to be sized |
|---|
| 43 | 48 | */ |
|---|
| 44 | 49 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
|---|
| 50 | + |
|---|
| 51 | +#define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) |
|---|
| 45 | 52 | |
|---|
| 46 | 53 | #define u64_to_user_ptr(x) ( \ |
|---|
| 47 | 54 | { \ |
|---|
| .. | .. |
|---|
| 76 | 83 | */ |
|---|
| 77 | 84 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) |
|---|
| 78 | 85 | |
|---|
| 79 | | -/** |
|---|
| 80 | | - * FIELD_SIZEOF - get the size of a struct's field |
|---|
| 81 | | - * @t: the target struct |
|---|
| 82 | | - * @f: the target struct's field |
|---|
| 83 | | - * Return: the size of @f in the struct definition without having a |
|---|
| 84 | | - * declared instance of @t. |
|---|
| 85 | | - */ |
|---|
| 86 | | -#define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
|---|
| 86 | +#define typeof_member(T, m) typeof(((T*)0)->m) |
|---|
| 87 | 87 | |
|---|
| 88 | 88 | #define DIV_ROUND_UP __KERNEL_DIV_ROUND_UP |
|---|
| 89 | 89 | |
|---|
| .. | .. |
|---|
| 106 | 106 | * |
|---|
| 107 | 107 | * Rounds @x up to next multiple of @y. If @y will always be a power |
|---|
| 108 | 108 | * of 2, consider using the faster round_up(). |
|---|
| 109 | | - * |
|---|
| 110 | | - * The `const' here prevents gcc-3.3 from calling __divdi3 |
|---|
| 111 | 109 | */ |
|---|
| 112 | 110 | #define roundup(x, y) ( \ |
|---|
| 113 | 111 | { \ |
|---|
| 114 | | - const typeof(y) __y = y; \ |
|---|
| 112 | + typeof(y) __y = y; \ |
|---|
| 115 | 113 | (((x) + (__y - 1)) / __y) * __y; \ |
|---|
| 116 | 114 | } \ |
|---|
| 117 | 115 | ) |
|---|
| .. | .. |
|---|
| 176 | 174 | #define _RET_IP_ (unsigned long)__builtin_return_address(0) |
|---|
| 177 | 175 | #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; }) |
|---|
| 178 | 176 | |
|---|
| 179 | | -#ifdef CONFIG_LBDAF |
|---|
| 180 | | -# include <asm/div64.h> |
|---|
| 181 | | -# define sector_div(a, b) do_div(a, b) |
|---|
| 182 | | -#else |
|---|
| 183 | | -# define sector_div(n, b)( \ |
|---|
| 184 | | -{ \ |
|---|
| 185 | | - int _res; \ |
|---|
| 186 | | - _res = (n) % (b); \ |
|---|
| 187 | | - (n) /= (b); \ |
|---|
| 188 | | - _res; \ |
|---|
| 189 | | -} \ |
|---|
| 190 | | -) |
|---|
| 191 | | -#endif |
|---|
| 177 | +#define sector_div(a, b) do_div(a, b) |
|---|
| 192 | 178 | |
|---|
| 193 | 179 | /** |
|---|
| 194 | 180 | * upper_32_bits - return bits 32-63 of a number |
|---|
| .. | .. |
|---|
| 204 | 190 | * lower_32_bits - return bits 0-31 of a number |
|---|
| 205 | 191 | * @n: the number we're accessing |
|---|
| 206 | 192 | */ |
|---|
| 207 | | -#define lower_32_bits(n) ((u32)(n)) |
|---|
| 193 | +#define lower_32_bits(n) ((u32)((n) & 0xffffffff)) |
|---|
| 208 | 194 | |
|---|
| 209 | 195 | struct completion; |
|---|
| 210 | 196 | struct pt_regs; |
|---|
| .. | .. |
|---|
| 218 | 204 | #endif |
|---|
| 219 | 205 | |
|---|
| 220 | 206 | #ifdef CONFIG_DEBUG_ATOMIC_SLEEP |
|---|
| 221 | | - void ___might_sleep(const char *file, int line, int preempt_offset); |
|---|
| 222 | | - void __might_sleep(const char *file, int line, int preempt_offset); |
|---|
| 207 | +extern void ___might_sleep(const char *file, int line, int preempt_offset); |
|---|
| 208 | +extern void __might_sleep(const char *file, int line, int preempt_offset); |
|---|
| 209 | +extern void __cant_sleep(const char *file, int line, int preempt_offset); |
|---|
| 210 | + |
|---|
| 223 | 211 | /** |
|---|
| 224 | 212 | * might_sleep - annotation for functions that can sleep |
|---|
| 225 | 213 | * |
|---|
| 226 | 214 | * this macro will print a stack trace if it is executed in an atomic |
|---|
| 227 | | - * context (spinlock, irq-handler, ...). |
|---|
| 215 | + * context (spinlock, irq-handler, ...). Additional sections where blocking is |
|---|
| 216 | + * not allowed can be annotated with non_block_start() and non_block_end() |
|---|
| 217 | + * pairs. |
|---|
| 228 | 218 | * |
|---|
| 229 | 219 | * This is a useful debugging help to be able to catch problems early and not |
|---|
| 230 | 220 | * be bitten later when the calling function happens to sleep when it is not |
|---|
| .. | .. |
|---|
| 232 | 222 | */ |
|---|
| 233 | 223 | # define might_sleep() \ |
|---|
| 234 | 224 | do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) |
|---|
| 235 | | - |
|---|
| 236 | | -# define might_sleep_no_state_check() \ |
|---|
| 237 | | - do { ___might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) |
|---|
| 225 | +/** |
|---|
| 226 | + * cant_sleep - annotation for functions that cannot sleep |
|---|
| 227 | + * |
|---|
| 228 | + * this macro will print a stack trace if it is executed with preemption enabled |
|---|
| 229 | + */ |
|---|
| 230 | +# define cant_sleep() \ |
|---|
| 231 | + do { __cant_sleep(__FILE__, __LINE__, 0); } while (0) |
|---|
| 238 | 232 | # define sched_annotate_sleep() (current->task_state_change = 0) |
|---|
| 233 | +/** |
|---|
| 234 | + * non_block_start - annotate the start of section where sleeping is prohibited |
|---|
| 235 | + * |
|---|
| 236 | + * This is on behalf of the oom reaper, specifically when it is calling the mmu |
|---|
| 237 | + * notifiers. The problem is that if the notifier were to block on, for example, |
|---|
| 238 | + * mutex_lock() and if the process which holds that mutex were to perform a |
|---|
| 239 | + * sleeping memory allocation, the oom reaper is now blocked on completion of |
|---|
| 240 | + * that memory allocation. Other blocking calls like wait_event() pose similar |
|---|
| 241 | + * issues. |
|---|
| 242 | + */ |
|---|
| 243 | +# define non_block_start() (current->non_block_count++) |
|---|
| 244 | +/** |
|---|
| 245 | + * non_block_end - annotate the end of section where sleeping is prohibited |
|---|
| 246 | + * |
|---|
| 247 | + * Closes a section opened by non_block_start(). |
|---|
| 248 | + */ |
|---|
| 249 | +# define non_block_end() WARN_ON(current->non_block_count-- == 0) |
|---|
| 239 | 250 | #else |
|---|
| 240 | 251 | static inline void ___might_sleep(const char *file, int line, |
|---|
| 241 | 252 | int preempt_offset) { } |
|---|
| 242 | 253 | static inline void __might_sleep(const char *file, int line, |
|---|
| 243 | 254 | int preempt_offset) { } |
|---|
| 244 | 255 | # define might_sleep() do { might_resched(); } while (0) |
|---|
| 245 | | -# define might_sleep_no_state_check() do { might_resched(); } while (0) |
|---|
| 256 | +# define cant_sleep() do { } while (0) |
|---|
| 246 | 257 | # define sched_annotate_sleep() do { } while (0) |
|---|
| 258 | +# define non_block_start() do { } while (0) |
|---|
| 259 | +# define non_block_end() do { } while (0) |
|---|
| 247 | 260 | #endif |
|---|
| 248 | 261 | |
|---|
| 249 | 262 | #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) |
|---|
| 263 | + |
|---|
| 264 | +#ifndef CONFIG_PREEMPT_RT |
|---|
| 265 | +# define cant_migrate() cant_sleep() |
|---|
| 266 | +#else |
|---|
| 267 | + /* Placeholder for now */ |
|---|
| 268 | +# define cant_migrate() do { } while (0) |
|---|
| 269 | +#endif |
|---|
| 250 | 270 | |
|---|
| 251 | 271 | /** |
|---|
| 252 | 272 | * abs - return absolute value of an argument |
|---|
| .. | .. |
|---|
| 299 | 319 | #endif |
|---|
| 300 | 320 | |
|---|
| 301 | 321 | extern struct atomic_notifier_head panic_notifier_list; |
|---|
| 302 | | -extern void (*vendor_panic_cb)(u64 sp); |
|---|
| 303 | 322 | extern long (*panic_blink)(int state); |
|---|
| 304 | 323 | __printf(1, 2) |
|---|
| 305 | 324 | void panic(const char *fmt, ...) __noreturn __cold; |
|---|
| 306 | 325 | void nmi_panic(struct pt_regs *regs, const char *msg); |
|---|
| 326 | +void check_panic_on_warn(const char *origin); |
|---|
| 307 | 327 | extern void oops_enter(void); |
|---|
| 308 | 328 | extern void oops_exit(void); |
|---|
| 309 | | -void print_oops_end_marker(void); |
|---|
| 310 | | -extern int oops_may_print(void); |
|---|
| 329 | +extern bool oops_may_print(void); |
|---|
| 311 | 330 | void do_exit(long error_code) __noreturn; |
|---|
| 312 | 331 | void complete_and_exit(struct completion *, long) __noreturn; |
|---|
| 313 | | - |
|---|
| 314 | | -#ifdef CONFIG_ARCH_HAS_REFCOUNT |
|---|
| 315 | | -void refcount_error_report(struct pt_regs *regs, const char *err); |
|---|
| 316 | | -#else |
|---|
| 317 | | -static inline void refcount_error_report(struct pt_regs *regs, const char *err) |
|---|
| 318 | | -{ } |
|---|
| 319 | | -#endif |
|---|
| 320 | | - |
|---|
| 321 | | -/* Internal, do not use. */ |
|---|
| 322 | | -int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res); |
|---|
| 323 | | -int __must_check _kstrtol(const char *s, unsigned int base, long *res); |
|---|
| 324 | | - |
|---|
| 325 | | -int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); |
|---|
| 326 | | -int __must_check kstrtoll(const char *s, unsigned int base, long long *res); |
|---|
| 327 | | - |
|---|
| 328 | | -/** |
|---|
| 329 | | - * kstrtoul - convert a string to an unsigned long |
|---|
| 330 | | - * @s: The start of the string. The string must be null-terminated, and may also |
|---|
| 331 | | - * include a single newline before its terminating null. The first character |
|---|
| 332 | | - * may also be a plus sign, but not a minus sign. |
|---|
| 333 | | - * @base: The number base to use. The maximum supported base is 16. If base is |
|---|
| 334 | | - * given as 0, then the base of the string is automatically detected with the |
|---|
| 335 | | - * conventional semantics - If it begins with 0x the number will be parsed as a |
|---|
| 336 | | - * hexadecimal (case insensitive), if it otherwise begins with 0, it will be |
|---|
| 337 | | - * parsed as an octal number. Otherwise it will be parsed as a decimal. |
|---|
| 338 | | - * @res: Where to write the result of the conversion on success. |
|---|
| 339 | | - * |
|---|
| 340 | | - * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. |
|---|
| 341 | | - * Used as a replacement for the obsolete simple_strtoull. Return code must |
|---|
| 342 | | - * be checked. |
|---|
| 343 | | -*/ |
|---|
| 344 | | -static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) |
|---|
| 345 | | -{ |
|---|
| 346 | | - /* |
|---|
| 347 | | - * We want to shortcut function call, but |
|---|
| 348 | | - * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0. |
|---|
| 349 | | - */ |
|---|
| 350 | | - if (sizeof(unsigned long) == sizeof(unsigned long long) && |
|---|
| 351 | | - __alignof__(unsigned long) == __alignof__(unsigned long long)) |
|---|
| 352 | | - return kstrtoull(s, base, (unsigned long long *)res); |
|---|
| 353 | | - else |
|---|
| 354 | | - return _kstrtoul(s, base, res); |
|---|
| 355 | | -} |
|---|
| 356 | | - |
|---|
| 357 | | -/** |
|---|
| 358 | | - * kstrtol - convert a string to a long |
|---|
| 359 | | - * @s: The start of the string. The string must be null-terminated, and may also |
|---|
| 360 | | - * include a single newline before its terminating null. The first character |
|---|
| 361 | | - * may also be a plus sign or a minus sign. |
|---|
| 362 | | - * @base: The number base to use. The maximum supported base is 16. If base is |
|---|
| 363 | | - * given as 0, then the base of the string is automatically detected with the |
|---|
| 364 | | - * conventional semantics - If it begins with 0x the number will be parsed as a |
|---|
| 365 | | - * hexadecimal (case insensitive), if it otherwise begins with 0, it will be |
|---|
| 366 | | - * parsed as an octal number. Otherwise it will be parsed as a decimal. |
|---|
| 367 | | - * @res: Where to write the result of the conversion on success. |
|---|
| 368 | | - * |
|---|
| 369 | | - * Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error. |
|---|
| 370 | | - * Used as a replacement for the obsolete simple_strtoull. Return code must |
|---|
| 371 | | - * be checked. |
|---|
| 372 | | - */ |
|---|
| 373 | | -static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) |
|---|
| 374 | | -{ |
|---|
| 375 | | - /* |
|---|
| 376 | | - * We want to shortcut function call, but |
|---|
| 377 | | - * __builtin_types_compatible_p(long, long long) = 0. |
|---|
| 378 | | - */ |
|---|
| 379 | | - if (sizeof(long) == sizeof(long long) && |
|---|
| 380 | | - __alignof__(long) == __alignof__(long long)) |
|---|
| 381 | | - return kstrtoll(s, base, (long long *)res); |
|---|
| 382 | | - else |
|---|
| 383 | | - return _kstrtol(s, base, res); |
|---|
| 384 | | -} |
|---|
| 385 | | - |
|---|
| 386 | | -int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res); |
|---|
| 387 | | -int __must_check kstrtoint(const char *s, unsigned int base, int *res); |
|---|
| 388 | | - |
|---|
| 389 | | -static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res) |
|---|
| 390 | | -{ |
|---|
| 391 | | - return kstrtoull(s, base, res); |
|---|
| 392 | | -} |
|---|
| 393 | | - |
|---|
| 394 | | -static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res) |
|---|
| 395 | | -{ |
|---|
| 396 | | - return kstrtoll(s, base, res); |
|---|
| 397 | | -} |
|---|
| 398 | | - |
|---|
| 399 | | -static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res) |
|---|
| 400 | | -{ |
|---|
| 401 | | - return kstrtouint(s, base, res); |
|---|
| 402 | | -} |
|---|
| 403 | | - |
|---|
| 404 | | -static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res) |
|---|
| 405 | | -{ |
|---|
| 406 | | - return kstrtoint(s, base, res); |
|---|
| 407 | | -} |
|---|
| 408 | | - |
|---|
| 409 | | -int __must_check kstrtou16(const char *s, unsigned int base, u16 *res); |
|---|
| 410 | | -int __must_check kstrtos16(const char *s, unsigned int base, s16 *res); |
|---|
| 411 | | -int __must_check kstrtou8(const char *s, unsigned int base, u8 *res); |
|---|
| 412 | | -int __must_check kstrtos8(const char *s, unsigned int base, s8 *res); |
|---|
| 413 | | -int __must_check kstrtobool(const char *s, bool *res); |
|---|
| 414 | | - |
|---|
| 415 | | -int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res); |
|---|
| 416 | | -int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res); |
|---|
| 417 | | -int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res); |
|---|
| 418 | | -int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res); |
|---|
| 419 | | -int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res); |
|---|
| 420 | | -int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res); |
|---|
| 421 | | -int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res); |
|---|
| 422 | | -int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res); |
|---|
| 423 | | -int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res); |
|---|
| 424 | | -int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res); |
|---|
| 425 | | -int __must_check kstrtobool_from_user(const char __user *s, size_t count, bool *res); |
|---|
| 426 | | - |
|---|
| 427 | | -static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res) |
|---|
| 428 | | -{ |
|---|
| 429 | | - return kstrtoull_from_user(s, count, base, res); |
|---|
| 430 | | -} |
|---|
| 431 | | - |
|---|
| 432 | | -static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res) |
|---|
| 433 | | -{ |
|---|
| 434 | | - return kstrtoll_from_user(s, count, base, res); |
|---|
| 435 | | -} |
|---|
| 436 | | - |
|---|
| 437 | | -static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res) |
|---|
| 438 | | -{ |
|---|
| 439 | | - return kstrtouint_from_user(s, count, base, res); |
|---|
| 440 | | -} |
|---|
| 441 | | - |
|---|
| 442 | | -static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res) |
|---|
| 443 | | -{ |
|---|
| 444 | | - return kstrtoint_from_user(s, count, base, res); |
|---|
| 445 | | -} |
|---|
| 446 | | - |
|---|
| 447 | | -/* Obsolete, do not use. Use kstrto<foo> instead */ |
|---|
| 448 | | - |
|---|
| 449 | | -extern unsigned long simple_strtoul(const char *,char **,unsigned int); |
|---|
| 450 | | -extern long simple_strtol(const char *,char **,unsigned int); |
|---|
| 451 | | -extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
|---|
| 452 | | -extern long long simple_strtoll(const char *,char **,unsigned int); |
|---|
| 453 | 332 | |
|---|
| 454 | 333 | extern int num_to_str(char *buf, int size, |
|---|
| 455 | 334 | unsigned long long num, unsigned int width); |
|---|
| .. | .. |
|---|
| 491 | 370 | extern int kernel_text_address(unsigned long addr); |
|---|
| 492 | 371 | extern int func_ptr_is_kernel_text(void *ptr); |
|---|
| 493 | 372 | |
|---|
| 373 | +u64 int_pow(u64 base, unsigned int exp); |
|---|
| 494 | 374 | unsigned long int_sqrt(unsigned long); |
|---|
| 495 | 375 | |
|---|
| 496 | 376 | #if BITS_PER_LONG < 64 |
|---|
| .. | .. |
|---|
| 503 | 383 | #endif |
|---|
| 504 | 384 | |
|---|
| 505 | 385 | extern void bust_spinlocks(int yes); |
|---|
| 506 | | -extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ |
|---|
| 507 | 386 | extern int panic_timeout; |
|---|
| 387 | +extern unsigned long panic_print; |
|---|
| 508 | 388 | extern int panic_on_oops; |
|---|
| 509 | 389 | extern int panic_on_unrecovered_nmi; |
|---|
| 510 | 390 | extern int panic_on_io_nmi; |
|---|
| 511 | 391 | extern int panic_on_warn; |
|---|
| 392 | +extern unsigned long panic_on_taint; |
|---|
| 393 | +extern bool panic_on_taint_nousertaint; |
|---|
| 512 | 394 | extern int sysctl_panic_on_rcu_stall; |
|---|
| 513 | 395 | extern int sysctl_panic_on_stackoverflow; |
|---|
| 514 | 396 | |
|---|
| .. | .. |
|---|
| 577 | 459 | #define TAINT_AUX 16 |
|---|
| 578 | 460 | #define TAINT_RANDSTRUCT 17 |
|---|
| 579 | 461 | #define TAINT_FLAGS_COUNT 18 |
|---|
| 462 | +#define TAINT_FLAGS_MAX ((1UL << TAINT_FLAGS_COUNT) - 1) |
|---|
| 580 | 463 | |
|---|
| 581 | 464 | struct taint_flag { |
|---|
| 582 | 465 | char c_true; /* character printed when tainted */ |
|---|
| .. | .. |
|---|
| 608 | 491 | return buf; |
|---|
| 609 | 492 | } |
|---|
| 610 | 493 | |
|---|
| 494 | +#ifdef __GENKSYMS__ |
|---|
| 611 | 495 | extern int hex_to_bin(char ch); |
|---|
| 496 | +#else |
|---|
| 497 | +extern int hex_to_bin(unsigned char ch); |
|---|
| 498 | +#endif |
|---|
| 612 | 499 | extern int __must_check hex2bin(u8 *dst, const char *src, size_t count); |
|---|
| 613 | 500 | extern char *bin2hex(char *dst, const void *src, size_t count); |
|---|
| 614 | 501 | |
|---|
| .. | .. |
|---|
| 702 | 589 | #define do_trace_printk(fmt, args...) \ |
|---|
| 703 | 590 | do { \ |
|---|
| 704 | 591 | static const char *trace_printk_fmt __used \ |
|---|
| 705 | | - __attribute__((section("__trace_printk_fmt"))) = \ |
|---|
| 592 | + __section("__trace_printk_fmt") = \ |
|---|
| 706 | 593 | __builtin_constant_p(fmt) ? fmt : NULL; \ |
|---|
| 707 | 594 | \ |
|---|
| 708 | 595 | __trace_printk_check_format(fmt, ##args); \ |
|---|
| .. | .. |
|---|
| 746 | 633 | |
|---|
| 747 | 634 | #define trace_puts(str) ({ \ |
|---|
| 748 | 635 | static const char *trace_printk_fmt __used \ |
|---|
| 749 | | - __attribute__((section("__trace_printk_fmt"))) = \ |
|---|
| 636 | + __section("__trace_printk_fmt") = \ |
|---|
| 750 | 637 | __builtin_constant_p(str) ? str : NULL; \ |
|---|
| 751 | 638 | \ |
|---|
| 752 | 639 | if (__builtin_constant_p(str)) \ |
|---|
| .. | .. |
|---|
| 768 | 655 | do { \ |
|---|
| 769 | 656 | if (__builtin_constant_p(fmt)) { \ |
|---|
| 770 | 657 | static const char *trace_printk_fmt __used \ |
|---|
| 771 | | - __attribute__((section("__trace_printk_fmt"))) = \ |
|---|
| 658 | + __section("__trace_printk_fmt") = \ |
|---|
| 772 | 659 | __builtin_constant_p(fmt) ? fmt : NULL; \ |
|---|
| 773 | 660 | \ |
|---|
| 774 | 661 | __ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs); \ |
|---|
| .. | .. |
|---|
| 806 | 693 | } |
|---|
| 807 | 694 | static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } |
|---|
| 808 | 695 | #endif /* CONFIG_TRACING */ |
|---|
| 809 | | - |
|---|
| 810 | | -/* |
|---|
| 811 | | - * min()/max()/clamp() macros must accomplish three things: |
|---|
| 812 | | - * |
|---|
| 813 | | - * - avoid multiple evaluations of the arguments (so side-effects like |
|---|
| 814 | | - * "x++" happen only once) when non-constant. |
|---|
| 815 | | - * - perform strict type-checking (to generate warnings instead of |
|---|
| 816 | | - * nasty runtime surprises). See the "unnecessary" pointer comparison |
|---|
| 817 | | - * in __typecheck(). |
|---|
| 818 | | - * - retain result as a constant expressions when called with only |
|---|
| 819 | | - * constant expressions (to avoid tripping VLA warnings in stack |
|---|
| 820 | | - * allocation usage). |
|---|
| 821 | | - */ |
|---|
| 822 | | -#define __typecheck(x, y) \ |
|---|
| 823 | | - (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) |
|---|
| 824 | | - |
|---|
| 825 | | -/* |
|---|
| 826 | | - * This returns a constant expression while determining if an argument is |
|---|
| 827 | | - * a constant expression, most importantly without evaluating the argument. |
|---|
| 828 | | - * Glory to Martin Uecker <Martin.Uecker@med.uni-goettingen.de> |
|---|
| 829 | | - */ |
|---|
| 830 | | -#define __is_constexpr(x) \ |
|---|
| 831 | | - (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8))) |
|---|
| 832 | | - |
|---|
| 833 | | -#define __no_side_effects(x, y) \ |
|---|
| 834 | | - (__is_constexpr(x) && __is_constexpr(y)) |
|---|
| 835 | | - |
|---|
| 836 | | -#define __safe_cmp(x, y) \ |
|---|
| 837 | | - (__typecheck(x, y) && __no_side_effects(x, y)) |
|---|
| 838 | | - |
|---|
| 839 | | -#define __cmp(x, y, op) ((x) op (y) ? (x) : (y)) |
|---|
| 840 | | - |
|---|
| 841 | | -#define __cmp_once(x, y, unique_x, unique_y, op) ({ \ |
|---|
| 842 | | - typeof(x) unique_x = (x); \ |
|---|
| 843 | | - typeof(y) unique_y = (y); \ |
|---|
| 844 | | - __cmp(unique_x, unique_y, op); }) |
|---|
| 845 | | - |
|---|
| 846 | | -#define __careful_cmp(x, y, op) \ |
|---|
| 847 | | - __builtin_choose_expr(__safe_cmp(x, y), \ |
|---|
| 848 | | - __cmp(x, y, op), \ |
|---|
| 849 | | - __cmp_once(x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y), op)) |
|---|
| 850 | | - |
|---|
| 851 | | -/** |
|---|
| 852 | | - * min - return minimum of two values of the same or compatible types |
|---|
| 853 | | - * @x: first value |
|---|
| 854 | | - * @y: second value |
|---|
| 855 | | - */ |
|---|
| 856 | | -#define min(x, y) __careful_cmp(x, y, <) |
|---|
| 857 | | - |
|---|
| 858 | | -/** |
|---|
| 859 | | - * max - return maximum of two values of the same or compatible types |
|---|
| 860 | | - * @x: first value |
|---|
| 861 | | - * @y: second value |
|---|
| 862 | | - */ |
|---|
| 863 | | -#define max(x, y) __careful_cmp(x, y, >) |
|---|
| 864 | | - |
|---|
| 865 | | -/** |
|---|
| 866 | | - * min3 - return minimum of three values |
|---|
| 867 | | - * @x: first value |
|---|
| 868 | | - * @y: second value |
|---|
| 869 | | - * @z: third value |
|---|
| 870 | | - */ |
|---|
| 871 | | -#define min3(x, y, z) min((typeof(x))min(x, y), z) |
|---|
| 872 | | - |
|---|
| 873 | | -/** |
|---|
| 874 | | - * max3 - return maximum of three values |
|---|
| 875 | | - * @x: first value |
|---|
| 876 | | - * @y: second value |
|---|
| 877 | | - * @z: third value |
|---|
| 878 | | - */ |
|---|
| 879 | | -#define max3(x, y, z) max((typeof(x))max(x, y), z) |
|---|
| 880 | | - |
|---|
| 881 | | -/** |
|---|
| 882 | | - * min_not_zero - return the minimum that is _not_ zero, unless both are zero |
|---|
| 883 | | - * @x: value1 |
|---|
| 884 | | - * @y: value2 |
|---|
| 885 | | - */ |
|---|
| 886 | | -#define min_not_zero(x, y) ({ \ |
|---|
| 887 | | - typeof(x) __x = (x); \ |
|---|
| 888 | | - typeof(y) __y = (y); \ |
|---|
| 889 | | - __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) |
|---|
| 890 | | - |
|---|
| 891 | | -/** |
|---|
| 892 | | - * clamp - return a value clamped to a given range with strict typechecking |
|---|
| 893 | | - * @val: current value |
|---|
| 894 | | - * @lo: lowest allowable value |
|---|
| 895 | | - * @hi: highest allowable value |
|---|
| 896 | | - * |
|---|
| 897 | | - * This macro does strict typechecking of @lo/@hi to make sure they are of the |
|---|
| 898 | | - * same type as @val. See the unnecessary pointer comparisons. |
|---|
| 899 | | - */ |
|---|
| 900 | | -#define clamp(val, lo, hi) min((typeof(val))max(val, lo), hi) |
|---|
| 901 | | - |
|---|
| 902 | | -/* |
|---|
| 903 | | - * ..and if you can't take the strict |
|---|
| 904 | | - * types, you can specify one yourself. |
|---|
| 905 | | - * |
|---|
| 906 | | - * Or not use min/max/clamp at all, of course. |
|---|
| 907 | | - */ |
|---|
| 908 | | - |
|---|
| 909 | | -/** |
|---|
| 910 | | - * min_t - return minimum of two values, using the specified type |
|---|
| 911 | | - * @type: data type to use |
|---|
| 912 | | - * @x: first value |
|---|
| 913 | | - * @y: second value |
|---|
| 914 | | - */ |
|---|
| 915 | | -#define min_t(type, x, y) __careful_cmp((type)(x), (type)(y), <) |
|---|
| 916 | | - |
|---|
| 917 | | -/** |
|---|
| 918 | | - * max_t - return maximum of two values, using the specified type |
|---|
| 919 | | - * @type: data type to use |
|---|
| 920 | | - * @x: first value |
|---|
| 921 | | - * @y: second value |
|---|
| 922 | | - */ |
|---|
| 923 | | -#define max_t(type, x, y) __careful_cmp((type)(x), (type)(y), >) |
|---|
| 924 | | - |
|---|
| 925 | | -/** |
|---|
| 926 | | - * clamp_t - return a value clamped to a given range using a given type |
|---|
| 927 | | - * @type: the type of variable to use |
|---|
| 928 | | - * @val: current value |
|---|
| 929 | | - * @lo: minimum allowable value |
|---|
| 930 | | - * @hi: maximum allowable value |
|---|
| 931 | | - * |
|---|
| 932 | | - * This macro does no typechecking and uses temporary variables of type |
|---|
| 933 | | - * @type to make all the comparisons. |
|---|
| 934 | | - */ |
|---|
| 935 | | -#define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi) |
|---|
| 936 | | - |
|---|
| 937 | | -/** |
|---|
| 938 | | - * clamp_val - return a value clamped to a given range using val's type |
|---|
| 939 | | - * @val: current value |
|---|
| 940 | | - * @lo: minimum allowable value |
|---|
| 941 | | - * @hi: maximum allowable value |
|---|
| 942 | | - * |
|---|
| 943 | | - * This macro does no typechecking and uses temporary variables of whatever |
|---|
| 944 | | - * type the input argument @val is. This is useful when @val is an unsigned |
|---|
| 945 | | - * type and @lo and @hi are literals that will otherwise be assigned a signed |
|---|
| 946 | | - * integer type. |
|---|
| 947 | | - */ |
|---|
| 948 | | -#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) |
|---|
| 949 | | - |
|---|
| 950 | | - |
|---|
| 951 | | -/** |
|---|
| 952 | | - * swap - swap values of @a and @b |
|---|
| 953 | | - * @a: first value |
|---|
| 954 | | - * @b: second value |
|---|
| 955 | | - */ |
|---|
| 956 | | -#define swap(a, b) \ |
|---|
| 957 | | - do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) |
|---|
| 958 | 696 | |
|---|
| 959 | 697 | /* This counts to 12. Any more, it will return 13th argument. */ |
|---|
| 960 | 698 | #define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _n, X...) _n |
|---|