diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 102 |
1 files changed, 62 insertions, 40 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 328bca609b9b..2b0a35e6bc69 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | /* | 4 | /* |
| 5 | * 'kernel.h' contains some often-used function prototypes etc | 5 | * 'kernel.h' contains some often-used function prototypes etc |
| 6 | */ | 6 | */ |
| 7 | #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) | ||
| 8 | #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) | ||
| 7 | 9 | ||
| 8 | #ifdef __KERNEL__ | 10 | #ifdef __KERNEL__ |
| 9 | 11 | ||
| @@ -22,9 +24,9 @@ | |||
| 22 | extern const char linux_banner[]; | 24 | extern const char linux_banner[]; |
| 23 | extern const char linux_proc_banner[]; | 25 | extern const char linux_proc_banner[]; |
| 24 | 26 | ||
| 25 | #define USHORT_MAX ((u16)(~0U)) | 27 | #define USHRT_MAX ((u16)(~0U)) |
| 26 | #define SHORT_MAX ((s16)(USHORT_MAX>>1)) | 28 | #define SHRT_MAX ((s16)(USHRT_MAX>>1)) |
| 27 | #define SHORT_MIN (-SHORT_MAX - 1) | 29 | #define SHRT_MIN ((s16)(-SHRT_MAX - 1)) |
| 28 | #define INT_MAX ((int)(~0U>>1)) | 30 | #define INT_MAX ((int)(~0U>>1)) |
| 29 | #define INT_MIN (-INT_MAX - 1) | 31 | #define INT_MIN (-INT_MAX - 1) |
| 30 | #define UINT_MAX (~0U) | 32 | #define UINT_MAX (~0U) |
| @@ -37,13 +39,23 @@ extern const char linux_proc_banner[]; | |||
| 37 | 39 | ||
| 38 | #define STACK_MAGIC 0xdeadbeef | 40 | #define STACK_MAGIC 0xdeadbeef |
| 39 | 41 | ||
| 40 | #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) | 42 | #define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) |
| 41 | #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) | 43 | #define __ALIGN_MASK(x, mask) __ALIGN_KERNEL_MASK((x), (mask)) |
| 42 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) | 44 | #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) |
| 43 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) | 45 | #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0) |
| 44 | 46 | ||
| 45 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) | 47 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr)) |
| 46 | 48 | ||
| 49 | /* | ||
| 50 | * This looks more complex than it should be. But we need to | ||
| 51 | * get the type for the ~ right in round_down (it needs to be | ||
| 52 | * as wide as the result!), and we want to evaluate the macro | ||
| 53 | * arguments just once each. | ||
| 54 | */ | ||
| 55 | #define __round_mask(x, y) ((__typeof__(x))((y)-1)) | ||
| 56 | #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) | ||
| 57 | #define round_down(x, y) ((x) & ~__round_mask(x, y)) | ||
| 58 | |||
| 47 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) | 59 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
| 48 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) | 60 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
| 49 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) | 61 | #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) |
| @@ -124,7 +136,7 @@ extern int _cond_resched(void); | |||
| 124 | #endif | 136 | #endif |
| 125 | 137 | ||
| 126 | #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP | 138 | #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP |
| 127 | void __might_sleep(char *file, int line, int preempt_offset); | 139 | void __might_sleep(const char *file, int line, int preempt_offset); |
| 128 | /** | 140 | /** |
| 129 | * might_sleep - annotation for functions that can sleep | 141 | * might_sleep - annotation for functions that can sleep |
| 130 | * | 142 | * |
| @@ -138,7 +150,8 @@ extern int _cond_resched(void); | |||
| 138 | # define might_sleep() \ | 150 | # define might_sleep() \ |
| 139 | do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) | 151 | do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0) |
| 140 | #else | 152 | #else |
| 141 | static inline void __might_sleep(char *file, int line, int preempt_offset) { } | 153 | static inline void __might_sleep(const char *file, int line, |
| 154 | int preempt_offset) { } | ||
| 142 | # define might_sleep() do { might_resched(); } while (0) | 155 | # define might_sleep() do { might_resched(); } while (0) |
| 143 | #endif | 156 | #endif |
| 144 | 157 | ||
| @@ -158,12 +171,18 @@ static inline void might_fault(void) | |||
| 158 | } | 171 | } |
| 159 | #endif | 172 | #endif |
| 160 | 173 | ||
| 174 | struct va_format { | ||
| 175 | const char *fmt; | ||
| 176 | va_list *va; | ||
| 177 | }; | ||
| 178 | |||
| 161 | extern struct atomic_notifier_head panic_notifier_list; | 179 | extern struct atomic_notifier_head panic_notifier_list; |
| 162 | extern long (*panic_blink)(long time); | 180 | extern long (*panic_blink)(int state); |
| 163 | NORET_TYPE void panic(const char * fmt, ...) | 181 | NORET_TYPE void panic(const char * fmt, ...) |
| 164 | __attribute__ ((NORET_AND format (printf, 1, 2))) __cold; | 182 | __attribute__ ((NORET_AND format (printf, 1, 2))) __cold; |
| 165 | extern void oops_enter(void); | 183 | extern void oops_enter(void); |
| 166 | extern void oops_exit(void); | 184 | extern void oops_exit(void); |
| 185 | void print_oops_end_marker(void); | ||
| 167 | extern int oops_may_print(void); | 186 | extern int oops_may_print(void); |
| 168 | NORET_TYPE void do_exit(long error_code) | 187 | NORET_TYPE void do_exit(long error_code) |
| 169 | ATTRIB_NORET; | 188 | ATTRIB_NORET; |
| @@ -234,6 +253,13 @@ extern struct pid *session_of_pgrp(struct pid *pgrp); | |||
| 234 | #define FW_WARN "[Firmware Warn]: " | 253 | #define FW_WARN "[Firmware Warn]: " |
| 235 | #define FW_INFO "[Firmware Info]: " | 254 | #define FW_INFO "[Firmware Info]: " |
| 236 | 255 | ||
| 256 | /* | ||
| 257 | * HW_ERR | ||
| 258 | * Add this to a message for hardware errors, so that user can report | ||
| 259 | * it to hardware vendor instead of LKML or software vendor. | ||
| 260 | */ | ||
| 261 | #define HW_ERR "[Hardware Error]: " | ||
| 262 | |||
| 237 | #ifdef CONFIG_PRINTK | 263 | #ifdef CONFIG_PRINTK |
| 238 | asmlinkage int vprintk(const char *fmt, va_list args) | 264 | asmlinkage int vprintk(const char *fmt, va_list args) |
| 239 | __attribute__ ((format (printf, 1, 0))); | 265 | __attribute__ ((format (printf, 1, 0))); |
| @@ -280,6 +306,13 @@ static inline void log_buf_kexec_setup(void) | |||
| 280 | } | 306 | } |
| 281 | #endif | 307 | #endif |
| 282 | 308 | ||
| 309 | /* | ||
| 310 | * Dummy printk for disabled debugging statements to use whilst maintaining | ||
| 311 | * gcc's format and side-effect checking. | ||
| 312 | */ | ||
| 313 | static inline __attribute__ ((format (printf, 1, 2))) | ||
| 314 | int no_printk(const char *s, ...) { return 0; } | ||
| 315 | |||
| 283 | extern int printk_needs_cpu(int cpu); | 316 | extern int printk_needs_cpu(int cpu); |
| 284 | extern void printk_tick(void); | 317 | extern void printk_tick(void); |
| 285 | 318 | ||
| @@ -333,6 +366,7 @@ extern enum system_states { | |||
| 333 | #define TAINT_OVERRIDDEN_ACPI_TABLE 8 | 366 | #define TAINT_OVERRIDDEN_ACPI_TABLE 8 |
| 334 | #define TAINT_WARN 9 | 367 | #define TAINT_WARN 9 |
| 335 | #define TAINT_CRAP 10 | 368 | #define TAINT_CRAP 10 |
| 369 | #define TAINT_FIRMWARE_WORKAROUND 11 | ||
| 336 | 370 | ||
| 337 | extern void dump_stack(void) __cold; | 371 | extern void dump_stack(void) __cold; |
| 338 | 372 | ||
| @@ -361,6 +395,8 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
| 361 | return buf; | 395 | return buf; |
| 362 | } | 396 | } |
| 363 | 397 | ||
| 398 | extern int hex_to_bin(char ch); | ||
| 399 | |||
| 364 | #ifndef pr_fmt | 400 | #ifndef pr_fmt |
| 365 | #define pr_fmt(fmt) fmt | 401 | #define pr_fmt(fmt) fmt |
| 366 | #endif | 402 | #endif |
| @@ -375,6 +411,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
| 375 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | 411 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
| 376 | #define pr_warning(fmt, ...) \ | 412 | #define pr_warning(fmt, ...) \ |
| 377 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) | 413 | printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
| 414 | #define pr_warn pr_warning | ||
| 378 | #define pr_notice(fmt, ...) \ | 415 | #define pr_notice(fmt, ...) \ |
| 379 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) | 416 | printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
| 380 | #define pr_info(fmt, ...) \ | 417 | #define pr_info(fmt, ...) \ |
| @@ -409,14 +446,13 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
| 409 | * no local ratelimit_state used in the !PRINTK case | 446 | * no local ratelimit_state used in the !PRINTK case |
| 410 | */ | 447 | */ |
| 411 | #ifdef CONFIG_PRINTK | 448 | #ifdef CONFIG_PRINTK |
| 412 | #define printk_ratelimited(fmt, ...) ({ \ | 449 | #define printk_ratelimited(fmt, ...) ({ \ |
| 413 | static struct ratelimit_state _rs = { \ | 450 | static DEFINE_RATELIMIT_STATE(_rs, \ |
| 414 | .interval = DEFAULT_RATELIMIT_INTERVAL, \ | 451 | DEFAULT_RATELIMIT_INTERVAL, \ |
| 415 | .burst = DEFAULT_RATELIMIT_BURST, \ | 452 | DEFAULT_RATELIMIT_BURST); \ |
| 416 | }; \ | 453 | \ |
| 417 | \ | 454 | if (__ratelimit(&_rs)) \ |
| 418 | if (!__ratelimit(&_rs)) \ | 455 | printk(fmt, ##__VA_ARGS__); \ |
| 419 | printk(fmt, ##__VA_ARGS__); \ | ||
| 420 | }) | 456 | }) |
| 421 | #else | 457 | #else |
| 422 | /* No effect, but we still get type checking even in the !PRINTK case: */ | 458 | /* No effect, but we still get type checking even in the !PRINTK case: */ |
| @@ -433,6 +469,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
| 433 | printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) | 469 | printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) |
| 434 | #define pr_warning_ratelimited(fmt, ...) \ | 470 | #define pr_warning_ratelimited(fmt, ...) \ |
| 435 | printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) | 471 | printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) |
| 472 | #define pr_warn_ratelimited pr_warning_ratelimited | ||
| 436 | #define pr_notice_ratelimited(fmt, ...) \ | 473 | #define pr_notice_ratelimited(fmt, ...) \ |
| 437 | printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) | 474 | printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) |
| 438 | #define pr_info_ratelimited(fmt, ...) \ | 475 | #define pr_info_ratelimited(fmt, ...) \ |
| @@ -479,14 +516,18 @@ static inline void tracing_off(void) { } | |||
| 479 | static inline void tracing_off_permanent(void) { } | 516 | static inline void tracing_off_permanent(void) { } |
| 480 | static inline int tracing_is_on(void) { return 0; } | 517 | static inline int tracing_is_on(void) { return 0; } |
| 481 | #endif | 518 | #endif |
| 519 | |||
| 520 | enum ftrace_dump_mode { | ||
| 521 | DUMP_NONE, | ||
| 522 | DUMP_ALL, | ||
| 523 | DUMP_ORIG, | ||
| 524 | }; | ||
| 525 | |||
| 482 | #ifdef CONFIG_TRACING | 526 | #ifdef CONFIG_TRACING |
| 483 | extern void tracing_start(void); | 527 | extern void tracing_start(void); |
| 484 | extern void tracing_stop(void); | 528 | extern void tracing_stop(void); |
| 485 | extern void ftrace_off_permanent(void); | 529 | extern void ftrace_off_permanent(void); |
| 486 | 530 | ||
| 487 | extern void | ||
| 488 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3); | ||
| 489 | |||
| 490 | static inline void __attribute__ ((format (printf, 1, 2))) | 531 | static inline void __attribute__ ((format (printf, 1, 2))) |
| 491 | ____trace_printk_check_format(const char *fmt, ...) | 532 | ____trace_printk_check_format(const char *fmt, ...) |
| 492 | { | 533 | { |
| @@ -560,10 +601,8 @@ __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); | |||
| 560 | extern int | 601 | extern int |
| 561 | __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); | 602 | __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); |
| 562 | 603 | ||
| 563 | extern void ftrace_dump(void); | 604 | extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); |
| 564 | #else | 605 | #else |
| 565 | static inline void | ||
| 566 | ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { } | ||
| 567 | static inline int | 606 | static inline int |
| 568 | trace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); | 607 | trace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); |
| 569 | 608 | ||
| @@ -581,21 +620,10 @@ ftrace_vprintk(const char *fmt, va_list ap) | |||
| 581 | { | 620 | { |
| 582 | return 0; | 621 | return 0; |
| 583 | } | 622 | } |
| 584 | static inline void ftrace_dump(void) { } | 623 | static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } |
| 585 | #endif /* CONFIG_TRACING */ | 624 | #endif /* CONFIG_TRACING */ |
| 586 | 625 | ||
| 587 | /* | 626 | /* |
| 588 | * Display an IP address in readable format. | ||
| 589 | */ | ||
| 590 | |||
| 591 | #define NIPQUAD(addr) \ | ||
| 592 | ((unsigned char *)&addr)[0], \ | ||
| 593 | ((unsigned char *)&addr)[1], \ | ||
| 594 | ((unsigned char *)&addr)[2], \ | ||
| 595 | ((unsigned char *)&addr)[3] | ||
| 596 | #define NIPQUAD_FMT "%u.%u.%u.%u" | ||
| 597 | |||
| 598 | /* | ||
| 599 | * min()/max()/clamp() macros that also do | 627 | * min()/max()/clamp() macros that also do |
| 600 | * strict type-checking.. See the | 628 | * strict type-checking.. See the |
| 601 | * "unnecessary" pointer comparison. | 629 | * "unnecessary" pointer comparison. |
| @@ -704,12 +732,6 @@ extern int do_sysinfo(struct sysinfo *info); | |||
| 704 | 732 | ||
| 705 | #endif /* __KERNEL__ */ | 733 | #endif /* __KERNEL__ */ |
| 706 | 734 | ||
| 707 | #ifndef __EXPORTED_HEADERS__ | ||
| 708 | #ifndef __KERNEL__ | ||
| 709 | #warning Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders | ||
| 710 | #endif /* __KERNEL__ */ | ||
| 711 | #endif /* __EXPORTED_HEADERS__ */ | ||
| 712 | |||
| 713 | #define SI_LOAD_SHIFT 16 | 735 | #define SI_LOAD_SHIFT 16 |
| 714 | struct sysinfo { | 736 | struct sysinfo { |
| 715 | long uptime; /* Seconds since boot */ | 737 | long uptime; /* Seconds since boot */ |
