diff options
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r-- | include/linux/kernel.h | 104 |
1 files changed, 94 insertions, 10 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 5a9d9059520b..00cec4dc0ae2 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -187,14 +187,76 @@ NORET_TYPE void do_exit(long error_code) | |||
187 | ATTRIB_NORET; | 187 | ATTRIB_NORET; |
188 | NORET_TYPE void complete_and_exit(struct completion *, long) | 188 | NORET_TYPE void complete_and_exit(struct completion *, long) |
189 | 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 | |||
190 | extern unsigned long simple_strtoul(const char *,char **,unsigned int); | 251 | extern unsigned long simple_strtoul(const char *,char **,unsigned int); |
191 | extern long simple_strtol(const char *,char **,unsigned int); | 252 | extern long simple_strtol(const char *,char **,unsigned int); |
192 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); | 253 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
193 | extern long long simple_strtoll(const char *,char **,unsigned int); | 254 | extern long long simple_strtoll(const char *,char **,unsigned int); |
194 | extern int __must_check strict_strtoul(const char *, unsigned int, unsigned long *); | 255 | #define strict_strtoul kstrtoul |
195 | extern int __must_check strict_strtol(const char *, unsigned int, long *); | 256 | #define strict_strtol kstrtol |
196 | extern int __must_check strict_strtoull(const char *, unsigned int, unsigned long long *); | 257 | #define strict_strtoull kstrtoull |
197 | extern int __must_check strict_strtoll(const char *, unsigned int, long long *); | 258 | #define strict_strtoll kstrtoll |
259 | |||
198 | extern int sprintf(char * buf, const char * fmt, ...) | 260 | extern int sprintf(char * buf, const char * fmt, ...) |
199 | __attribute__ ((format (printf, 2, 3))); | 261 | __attribute__ ((format (printf, 2, 3))); |
200 | extern int vsprintf(char *buf, const char *, va_list) | 262 | extern int vsprintf(char *buf, const char *, va_list) |
@@ -243,6 +305,8 @@ extern int test_taint(unsigned flag); | |||
243 | extern unsigned long get_taint(void); | 305 | extern unsigned long get_taint(void); |
244 | extern int root_mountflags; | 306 | extern int root_mountflags; |
245 | 307 | ||
308 | extern bool early_boot_irqs_disabled; | ||
309 | |||
246 | /* Values used for system_state */ | 310 | /* Values used for system_state */ |
247 | extern enum system_states { | 311 | extern enum system_states { |
248 | SYSTEM_BOOTING, | 312 | SYSTEM_BOOTING, |
@@ -573,12 +637,6 @@ struct sysinfo { | |||
573 | 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.. */ |
574 | }; | 638 | }; |
575 | 639 | ||
576 | /* Force a compilation error if condition is true */ | ||
577 | #define BUILD_BUG_ON(condition) ((void)BUILD_BUG_ON_ZERO(condition)) | ||
578 | |||
579 | /* Force a compilation error if condition is constant and true */ | ||
580 | #define MAYBE_BUILD_BUG_ON(cond) ((void)sizeof(char[1 - 2 * !!(cond)])) | ||
581 | |||
582 | /* 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 */ |
583 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ | 641 | #define BUILD_BUG_ON_NOT_POWER_OF_2(n) \ |
584 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) | 642 | BUILD_BUG_ON((n) == 0 || (((n) & ((n) - 1)) != 0)) |
@@ -590,6 +648,32 @@ struct sysinfo { | |||
590 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) | 648 | #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) |
591 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) | 649 | #define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); })) |
592 | 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 | |||
593 | /* Trap pasters of __FUNCTION__ at compile-time */ | 677 | /* Trap pasters of __FUNCTION__ at compile-time */ |
594 | #define __FUNCTION__ (__func__) | 678 | #define __FUNCTION__ (__func__) |
595 | 679 | ||