1 #ifndef _LINUX_KERNEL_H
2 #define _LINUX_KERNEL_H
5 * 'kernel.h' contains some often-used function prototypes etc
11 #include <linux/linkage.h>
12 #include <linux/stddef.h>
13 #include <linux/types.h>
14 #include <linux/compiler.h>
15 #include <asm/byteorder.h>
18 #define INT_MAX ((int)(~0U>>1))
19 #define INT_MIN (-INT_MAX - 1)
20 #define UINT_MAX (~0U)
21 #define LONG_MAX ((long)(~0UL>>1))
22 #define LONG_MIN (-LONG_MAX - 1)
23 #define ULONG_MAX (~0UL)
25 #define STACK_MAGIC 0xdeadbeef
27 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
30 #define KERN_EMERG "<0>" /* system is unusable */
31 #define KERN_ALERT "<1>" /* action must be taken immediately */
32 #define KERN_CRIT "<2>" /* critical conditions */
33 #define KERN_ERR "<3>" /* error conditions */
34 #define KERN_WARNING "<4>" /* warning conditions */
35 #define KERN_NOTICE "<5>" /* normal but significant condition */
36 #define KERN_INFO "<6>" /* informational */
37 #define KERN_DEBUG "<7>" /* debug-level messages */
39 extern int console_printk[];
41 #define console_loglevel (console_printk[0])
42 #define default_message_loglevel (console_printk[1])
43 #define minimum_console_loglevel (console_printk[2])
44 #define default_console_loglevel (console_printk[3])
48 #ifdef CONFIG_PREEMPT_VOLUNTARY
49 extern void __cond_resched(void);
50 # define might_resched() __cond_resched()
52 # define might_resched() do { } while (0)
55 #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
56 void __might_sleep(char *file, int line, int atomic_depth);
57 # define might_sleep() \
58 do { __might_sleep(__FILE__, __LINE__, 0); might_resched(); } while (0)
60 # define might_sleep() do { might_resched(); } while (0)
63 #define might_sleep_if(cond) do { if (unlikely(cond)) might_sleep(); } while (0)
67 (__x < 0) ? -__x : __x; \
72 (__x < 0) ? -__x : __x; \
75 extern struct notifier_block *panic_notifier_list;
76 NORET_TYPE void panic(const char * fmt, ...)
77 __attribute__ ((NORET_AND format (printf, 1, 2)));
78 asmlinkage NORET_TYPE void do_exit(long error_code)
80 NORET_TYPE void complete_and_exit(struct completion *, long)
82 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
83 extern long simple_strtol(const char *,char **,unsigned int);
84 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
85 extern long long simple_strtoll(const char *,char **,unsigned int);
86 extern int sprintf(char * buf, const char * fmt, ...)
87 __attribute__ ((format (printf, 2, 3)));
88 extern int vsprintf(char *buf, const char *, va_list);
89 extern int snprintf(char * buf, size_t size, const char * fmt, ...)
90 __attribute__ ((format (printf, 3, 4)));
91 extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
92 extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
93 __attribute__ ((format (printf, 3, 4)));
94 extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
96 extern int sscanf(const char *, const char *, ...)
97 __attribute__ ((format (scanf,2,3)));
98 extern int vsscanf(const char *, const char *, va_list);
100 extern int get_option(char **str, int *pint);
101 extern char *get_options(const char *str, int nints, int *ints);
102 extern unsigned long long memparse(char *ptr, char **retptr);
104 extern int __kernel_text_address(unsigned long addr);
105 extern int kernel_text_address(unsigned long addr);
106 extern int session_of_pgrp(int pgrp);
108 asmlinkage int printk(const char * fmt, ...)
109 __attribute__ ((format (printf, 1, 2)));
111 unsigned long int_sqrt(unsigned long);
113 static inline int __attribute_pure__ long_log2(unsigned long x)
116 for (x >>= 1; x > 0; x >>= 1)
122 extern int printk_ratelimit(void);
123 extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
125 static inline void console_silent(void)
127 console_loglevel = 0;
130 static inline void console_verbose(void)
132 if (console_loglevel)
133 console_loglevel = 15;
136 extern void bust_spinlocks(int yes);
137 extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */
138 extern int panic_on_oops;
140 extern const char *print_tainted(void);
142 extern void (*netdump_func) (struct pt_regs *regs);
143 extern int netdump_mode;
145 /* Values used for system_state */
146 extern enum system_states {
148 SYSTEM_BOOTING_SCHEDULER_OK,
155 #define TAINT_PROPRIETARY_MODULE (1<<0)
156 #define TAINT_FORCED_MODULE (1<<1)
157 #define TAINT_UNSAFE_SMP (1<<2)
158 #define TAINT_FORCED_RMMOD (1<<3)
160 extern void dump_stack(void);
163 #define pr_debug(fmt,arg...) \
164 printk(KERN_DEBUG fmt,##arg)
166 #define pr_debug(fmt,arg...) \
170 #define pr_info(fmt,arg...) \
171 printk(KERN_INFO fmt,##arg)
174 * Display an IP address in readable format.
177 #define NIPQUAD(addr) \
178 ((unsigned char *)&addr)[0], \
179 ((unsigned char *)&addr)[1], \
180 ((unsigned char *)&addr)[2], \
181 ((unsigned char *)&addr)[3]
184 ntohs((addr).s6_addr16[0]), \
185 ntohs((addr).s6_addr16[1]), \
186 ntohs((addr).s6_addr16[2]), \
187 ntohs((addr).s6_addr16[3]), \
188 ntohs((addr).s6_addr16[4]), \
189 ntohs((addr).s6_addr16[5]), \
190 ntohs((addr).s6_addr16[6]), \
191 ntohs((addr).s6_addr16[7])
193 #if defined(__LITTLE_ENDIAN)
194 #define HIPQUAD(addr) \
195 ((unsigned char *)&addr)[3], \
196 ((unsigned char *)&addr)[2], \
197 ((unsigned char *)&addr)[1], \
198 ((unsigned char *)&addr)[0]
199 #elif defined(__BIG_ENDIAN)
200 #define HIPQUAD NIPQUAD
202 #error "Please fix asm/byteorder.h"
203 #endif /* __LITTLE_ENDIAN */
206 * min()/max() macros that also do
207 * strict type-checking.. See the
208 * "unnecessary" pointer comparison.
210 #define min(x,y) ({ \
211 typeof(x) _x = (x); \
212 typeof(y) _y = (y); \
213 (void) (&_x == &_y); \
214 _x < _y ? _x : _y; })
216 #define max(x,y) ({ \
217 typeof(x) _x = (x); \
218 typeof(y) _y = (y); \
219 (void) (&_x == &_y); \
220 _x > _y ? _x : _y; })
223 * ..and if you can't take the strict
224 * types, you can specify one yourself.
226 * Or not use min/max at all, of course.
228 #define min_t(type,x,y) \
229 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
230 #define max_t(type,x,y) \
231 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
235 * container_of - cast a member of a structure out to the containing structure
237 * @ptr: the pointer to the member.
238 * @type: the type of the container struct this is embedded in.
239 * @member: the name of the member within the struct.
242 #define container_of(ptr, type, member) ({ \
243 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
244 (type *)( (char *)__mptr - offsetof(type,member) );})
247 * Check at compile time that something is of a particular type.
248 * Always evaluates to 1 so you may use it easily in comparisons.
250 #define typecheck(type,x) \
252 typeof(x) __dummy2; \
253 (void)(&__dummy == &__dummy2); \
257 #endif /* __KERNEL__ */
259 #define SI_LOAD_SHIFT 16
261 long uptime; /* Seconds since boot */
262 unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
263 unsigned long totalram; /* Total usable main memory size */
264 unsigned long freeram; /* Available memory size */
265 unsigned long sharedram; /* Amount of shared memory */
266 unsigned long bufferram; /* Memory used by buffers */
267 unsigned long totalswap; /* Total swap space size */
268 unsigned long freeswap; /* swap space still available */
269 unsigned short procs; /* Number of current processes */
270 unsigned short pad; /* explicit padding for m68k */
271 unsigned long totalhigh; /* Total high memory size */
272 unsigned long freehigh; /* Available high memory size */
273 unsigned int mem_unit; /* Memory unit size in bytes */
274 char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
277 extern void BUILD_BUG(void);
278 #define BUILD_BUG_ON(condition) do { if (condition) BUILD_BUG(); } while(0)
280 /* Trap pasters of __FUNCTION__ at compile-time */
281 #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
282 #define __FUNCTION__ (__func__)