diff options
Diffstat (limited to 'include/linux/kernel.h')
| -rw-r--r-- | include/linux/kernel.h | 133 |
1 files changed, 120 insertions, 13 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index b6de9a6f7018..00cec4dc0ae2 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
| @@ -56,6 +56,8 @@ | |||
| 56 | 56 | ||
| 57 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) | 57 | #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f)) |
| 58 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) | 58 | #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) |
| 59 | |||
| 60 | /* The `const' in roundup() prevents gcc-3.3 from calling __divdi3 */ | ||
| 59 | #define roundup(x, y) ( \ | 61 | #define roundup(x, y) ( \ |
| 60 | { \ | 62 | { \ |
| 61 | const typeof(y) __y = y; \ | 63 | const typeof(y) __y = y; \ |
| @@ -141,9 +143,22 @@ extern int _cond_resched(void); | |||
| 141 | 143 | ||
| 142 | #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) | 144 | #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) |
| 143 | 145 | ||
| 144 | #define abs(x) ({ \ | 146 | /* |
| 145 | long __x = (x); \ | 147 | * abs() handles unsigned and signed longs, ints, shorts and chars. For all |
| 146 | (__x < 0) ? -__x : __x; \ | 148 | * input types abs() returns a signed long. |
| 149 | * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64() | ||
| 150 | * for those. | ||
| 151 | */ | ||
| 152 | #define abs(x) ({ \ | ||
| 153 | long ret; \ | ||
| 154 | if (sizeof(x) == sizeof(long)) { \ | ||
| 155 | long __x = (x); \ | ||
| 156 | ret = (__x < 0) ? -__x : __x; \ | ||
| 157 | } else { \ | ||
| 158 | int __x = (x); \ | ||
| 159 | ret = (__x < 0) ? -__x : __x; \ | ||
| 160 | } \ | ||
| 161 | ret; \ | ||
| 147 | }) | 162 | }) |
| 148 | 163 | ||
| 149 | #define abs64(x) ({ \ | 164 | #define abs64(x) ({ \ |
| @@ -172,14 +187,76 @@ NORET_TYPE void do_exit(long error_code) | |||
| 172 | ATTRIB_NORET; | 187 | ATTRIB_NORET; |
| 173 | NORET_TYPE void complete_and_exit(struct completion *, long) | 188 | NORET_TYPE void complete_and_exit(struct completion *, long) |
| 174 | ATTRIB_NORET; | 189 | ATTRIB_NORET; |
| 190 | |||
| 191 | /* Internal, do not use. */ | ||
| 192 | int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res); | ||
| 193 | int __must_check _kstrtol(const char *s, unsigned int base, long *res); | ||
| 194 | |||
| 195 | int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); | ||
| 196 | int __must_check kstrtoll(const char *s, unsigned int base, long long *res); | ||
| 197 | static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) | ||
| 198 | { | ||
| 199 | /* | ||
| 200 | * We want to shortcut function call, but | ||
| 201 | * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0. | ||
| 202 | */ | ||
| 203 | if (sizeof(unsigned long) == sizeof(unsigned long long) && | ||
| 204 | __alignof__(unsigned long) == __alignof__(unsigned long long)) | ||
| 205 | return kstrtoull(s, base, (unsigned long long *)res); | ||
| 206 | else | ||
| 207 | return _kstrtoul(s, base, res); | ||
| 208 | } | ||
| 209 | |||
| 210 | static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) | ||
| 211 | { | ||
| 212 | /* | ||
| 213 | * We want to shortcut function call, but | ||
| 214 | * __builtin_types_compatible_p(long, long long) = 0. | ||
| 215 | */ | ||
| 216 | if (sizeof(long) == sizeof(long long) && | ||
| 217 | __alignof__(long) == __alignof__(long long)) | ||
| 218 | return kstrtoll(s, base, (long long *)res); | ||
| 219 | else | ||
| 220 | return _kstrtol(s, base, res); | ||
| 221 | } | ||
| 222 | |||
| 223 | int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res); | ||
| 224 | int __must_check kstrtoint(const char *s, unsigned int base, int *res); | ||
| 225 | |||
| 226 | static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res) | ||
| 227 | { | ||
| 228 | return kstrtoull(s, base, res); | ||
| 229 | } | ||
| 230 | |||
| 231 | static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res) | ||
| 232 | { | ||
| 233 | return kstrtoll(s, base, res); | ||
| 234 | } | ||
| 235 | |||
| 236 | static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res) | ||
| 237 | { | ||
| 238 | return kstrtouint(s, base, res); | ||
| 239 | } | ||
| 240 | |||
| 241 | static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res) | ||
| 242 | { | ||
| 243 | return kstrtoint(s, base, res); | ||
| 244 | } | ||
| 245 | |||
| 246 | int __must_check kstrtou16(const char *s, unsigned int base, u16 *res); | ||
| 247 | int __must_check kstrtos16(const char *s, unsigned int base, s16 *res); | ||
| 248 | int __must_check kstrtou8(const char *s, unsigned int base, u8 *res); | ||
| 249 | int __must_check kstrtos8(const char *s, unsigned int base, s8 *res); | ||
| 250 | |||
| 175 | extern unsigned long simple_strtoul(const char *,char **,unsigned int); | 251 | extern unsigned long simple_strtoul(const char *,char **,unsigned int); |
| 176 | extern long simple_strtol(const char *,char **,unsigned int); | 252 | extern long simple_strtol(const char *,char **,unsigned int); |
| 177 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); | 253 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
| 178 | extern long long simple_strtoll(const char *,char **,unsigned int); | 254 | extern long long simple_strtoll(const char *,char **,unsigned int); |
| 179 | extern int __must_check strict_strtoul(const char *, unsigned int, unsigned long *); | 255 | #define strict_strtoul kstrtoul |
| 180 | extern int __must_check strict_strtol(const char *, unsigned int, long *); | 256 | #define strict_strtol kstrtol |
| 181 | extern int __must_check strict_strtoull(const char *, unsigned int, unsigned long long *); | 257 | #define strict_strtoull kstrtoull |
| 182 | extern int __must_check strict_strtoll(const char *, unsigned int, long long *); | 258 | #define strict_strtoll kstrtoll |
| 259 | |||
| 183 | extern int sprintf(char * buf, const char * fmt, ...) | 260 | extern int sprintf(char * buf, const char * fmt, ...) |
| 184 | __attribute__ ((format (printf, 2, 3))); | 261 | __attribute__ ((format (printf, 2, 3))); |
| 185 | extern int vsprintf(char *buf, const char *, va_list) | 262 | extern int vsprintf(char *buf, const char *, va_list) |
| @@ -228,6 +305,8 @@ extern int test_taint(unsigned flag); | |||
| 228 | extern unsigned long get_taint(void); | 305 | extern unsigned long get_taint(void); |
| 229 | extern int root_mountflags; | 306 | extern int root_mountflags; |
| 230 | 307 | ||
| 308 | extern bool early_boot_irqs_disabled; | ||
| 309 | |||
| 231 | /* Values used for system_state */ | 310 | /* Values used for system_state */ |
| 232 | extern enum system_states { | 311 | extern enum system_states { |
| 233 | SYSTEM_BOOTING, | 312 | SYSTEM_BOOTING, |
| @@ -263,6 +342,7 @@ static inline char *pack_hex_byte(char *buf, u8 byte) | |||
| 263 | } | 342 | } |
| 264 | 343 | ||
| 265 | extern int hex_to_bin(char ch); | 344 | extern int hex_to_bin(char ch); |
| 345 | extern void hex2bin(u8 *dst, const char *src, size_t count); | ||
| 266 | 346 | ||
| 267 | /* | 347 | /* |
| 268 | * General tracing related utility functions - trace_printk(), | 348 | * General tracing related utility functions - trace_printk(), |
| @@ -557,12 +637,6 @@ struct sysinfo { | |||
| 557 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ | 637 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ |
| 558 | }; | 638 | }; |
| 559 | 639 | ||
| 560 | /* Force a compilation error if condition is true */ | ||
| 561 | #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) | ||
| 562 | |||
| 563 | /* Force a compilation error if condition is constant and true */ | ||
| 564 | #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) | ||
| 565 | |||
| 566 | /* Force a compilation error if a constant expression is not a power of 2 */ | 640 | /* Force a compilation error if a constant expression is not a power of 2 */ |
| 567 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ | 641 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ |
| 568 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) | 642 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) |
| @@ -574,6 +648,32 @@ struct sysinfo { | |||
| 574 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) | 648 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) |
| 575 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) | 649 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) |
| 576 | 650 | ||
| 651 | /** | ||
| 652 | * BUILD_BUG_ON - break compile if a condition is true. | ||
| 653 | * @condition: the condition which the compiler should know is false. | ||
| 654 | * | ||
| 655 | * If you have some code which relies on certain constants being equal, or | ||
| 656 | * other compile-time-evaluated condition, you should use BUILD_BUG_ON to | ||
| 657 | * detect if someone changes it. | ||
| 658 | * | ||
| 659 | * The implementation uses gcc's reluctance to create a negative array, but | ||
| 660 | * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments | ||
| 661 | * to inline functions). So as a fallback we use the optimizer; if it can't | ||
| 662 | * prove the condition is false, it will cause a link error on the undefined | ||
| 663 | * "__build_bug_on_failed". This error message can be harder to track down | ||
| 664 | * though, hence the two different methods. | ||
| 665 | */ | ||
| 666 | #ifndef __OPTIMIZE__ | ||
| 667 | #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) | ||
| 668 | #else | ||
| 669 | extern int __build_bug_on_failed; | ||
| 670 | #define BUILD_BUG_ON(condition) \ | ||
| 671 | do { \ | ||
| 672 | ((void)sizeof(char[1 - 2*!!(condition)])); \ | ||
| 673 | if (condition) __build_bug_on_failed = 1; \ | ||
| 674 | } while(0) | ||
| 675 | #endif | ||
| 676 | |||
| 577 | /* Trap pasters of __FUNCTION__ at compile-time */ | 677 | /* Trap pasters of __FUNCTION__ at compile-time */ |
| 578 | #define __FUNCTION__ (__func__) | 678 | #define __FUNCTION__ (__func__) |
| 579 | 679 | ||
| @@ -584,6 +684,13 @@ struct sysinfo { | |||
| 584 | #define NUMA_BUILD 0 | 684 | #define NUMA_BUILD 0 |
| 585 | #endif | 685 | #endif |
| 586 | 686 | ||
| 687 | /* This helps us avoid #ifdef CONFIG_COMPACTION */ | ||
| 688 | #ifdef CONFIG_COMPACTION | ||
| 689 | #define COMPACTION_BUILD 1 | ||
| 690 | #else | ||
| 691 | #define COMPACTION_BUILD 0 | ||
| 692 | #endif | ||
| 693 | |||
| 587 | /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ | 694 | /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ |
| 588 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD | 695 | #ifdef CONFIG_FTRACE_MCOUNT_RECORD |
| 589 | # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD | 696 | # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD |
