Rev 500 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
422 | giacomo | 1 | #ifndef _LINUX_KERNEL_H |
2 | #define _LINUX_KERNEL_H |
||
3 | |||
4 | /* |
||
5 | * 'kernel.h' contains some often-used function prototypes etc |
||
6 | */ |
||
7 | |||
8 | #ifdef __KERNEL__ |
||
9 | |||
10 | #include <linuxcomp.h> |
||
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> |
||
16 | #include <asm/bug.h> |
||
17 | |||
428 | giacomo | 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) |
||
422 | giacomo | 24 | |
25 | #define STACK_MAGIC 0xdeadbeef |
||
26 | |||
27 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
||
28 | #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1)) |
||
29 | |||
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 */ |
||
38 | |||
39 | extern int console_printk[]; |
||
40 | |||
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]) |
||
45 | |||
46 | struct completion; |
||
47 | |||
48 | #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP |
||
49 | void __might_sleep(char *file, int line); |
||
50 | #define might_sleep() __might_sleep(__FILE__, __LINE__) |
||
51 | #define might_sleep_if(cond) do { if (unlikely(cond)) might_sleep(); } while (0) |
||
52 | #else |
||
53 | #define might_sleep() do {} while(0) |
||
54 | #define might_sleep_if(cond) do {} while (0) |
||
55 | #endif |
||
56 | |||
57 | extern struct notifier_block *panic_notifier_list; |
||
500 | giacomo | 58 | void panic(const char * fmt, ...) |
59 | __attribute__ ((format (printf, 1, 2))); |
||
847 | giacomo | 60 | void do_exit(long error_code); |
61 | void complete_and_exit(struct completion *, long); |
||
422 | giacomo | 62 | extern int abs(int); |
63 | extern unsigned long simple_strtoul(const char *,char **,unsigned int); |
||
64 | extern long simple_strtol(const char *,char **,unsigned int); |
||
65 | extern unsigned long long simple_strtoull(const char *,char **,unsigned int); |
||
66 | extern long long simple_strtoll(const char *,char **,unsigned int); |
||
455 | giacomo | 67 | extern int sprintf26(char * buf, const char * fmt, ...) |
422 | giacomo | 68 | __attribute__ ((format (printf, 2, 3))); |
455 | giacomo | 69 | extern int vsprintf26(char *buf, const char *, va_list); |
70 | extern int snprintf26(char * buf, size_t size, const char * fmt, ...) |
||
422 | giacomo | 71 | __attribute__ ((format (printf, 3, 4))); |
455 | giacomo | 72 | extern int vsnprintf26(char *buf, size_t size, const char *fmt, va_list args); |
422 | giacomo | 73 | |
455 | giacomo | 74 | extern int sscanf26(const char *, const char *, ...) |
422 | giacomo | 75 | __attribute__ ((format (scanf,2,3))); |
455 | giacomo | 76 | extern int vsscanf26(const char *, const char *, va_list); |
422 | giacomo | 77 | |
78 | extern int get_option(char **str, int *pint); |
||
79 | extern char *get_options(const char *str, int nints, int *ints); |
||
80 | extern unsigned long long memparse(char *ptr, char **retptr); |
||
81 | |||
82 | extern int kernel_text_address(unsigned long addr); |
||
83 | extern int session_of_pgrp(int pgrp); |
||
84 | |||
85 | asmlinkage int printk(const char * fmt, ...) |
||
86 | __attribute__ ((format (printf, 1, 2))); |
||
87 | |||
88 | static inline void console_silent(void) |
||
89 | { |
||
90 | console_loglevel = 0; |
||
91 | } |
||
92 | |||
93 | static inline void console_verbose(void) |
||
94 | { |
||
95 | if (console_loglevel) |
||
96 | console_loglevel = 15; |
||
97 | } |
||
98 | |||
99 | extern void bust_spinlocks(int yes); |
||
100 | extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ |
||
101 | extern int panic_on_oops; |
||
102 | extern int system_running; |
||
103 | extern int tainted; |
||
104 | extern const char *print_tainted(void); |
||
105 | #define TAINT_PROPRIETARY_MODULE (1<<0) |
||
106 | #define TAINT_FORCED_MODULE (1<<1) |
||
107 | #define TAINT_UNSAFE_SMP (1<<2) |
||
108 | #define TAINT_FORCED_RMMOD (1<<3) |
||
109 | |||
110 | extern void dump_stack(void); |
||
111 | |||
112 | #ifdef DEBUG |
||
113 | #define pr_debug(fmt,arg...) \ |
||
114 | printk(KERN_DEBUG fmt,##arg) |
||
115 | #else |
||
116 | #define pr_debug(fmt,arg...) \ |
||
117 | do { } while (0) |
||
118 | #endif |
||
119 | |||
120 | #define pr_info(fmt,arg...) \ |
||
121 | printk(KERN_INFO fmt,##arg) |
||
122 | |||
123 | /* |
||
124 | * Display an IP address in readable format. |
||
125 | */ |
||
126 | |||
127 | #define NIPQUAD(addr) \ |
||
128 | ((unsigned char *)&addr)[0], \ |
||
129 | ((unsigned char *)&addr)[1], \ |
||
130 | ((unsigned char *)&addr)[2], \ |
||
131 | ((unsigned char *)&addr)[3] |
||
132 | |||
133 | #define NIP6(addr) \ |
||
134 | ntohs((addr).s6_addr16[0]), \ |
||
135 | ntohs((addr).s6_addr16[1]), \ |
||
136 | ntohs((addr).s6_addr16[2]), \ |
||
137 | ntohs((addr).s6_addr16[3]), \ |
||
138 | ntohs((addr).s6_addr16[4]), \ |
||
139 | ntohs((addr).s6_addr16[5]), \ |
||
140 | ntohs((addr).s6_addr16[6]), \ |
||
141 | ntohs((addr).s6_addr16[7]) |
||
142 | |||
143 | #if defined(__LITTLE_ENDIAN) |
||
144 | #define HIPQUAD(addr) \ |
||
145 | ((unsigned char *)&addr)[3], \ |
||
146 | ((unsigned char *)&addr)[2], \ |
||
147 | ((unsigned char *)&addr)[1], \ |
||
148 | ((unsigned char *)&addr)[0] |
||
149 | #elif defined(__BIG_ENDIAN) |
||
150 | #define HIPQUAD NIPQUAD |
||
151 | #else |
||
152 | #error "Please fix asm/byteorder.h" |
||
153 | #endif /* __LITTLE_ENDIAN */ |
||
154 | |||
155 | /* |
||
156 | * min()/max() macros that also do |
||
157 | * strict type-checking.. See the |
||
158 | * "unnecessary" pointer comparison. |
||
159 | */ |
||
160 | #define min(x,y) ({ \ |
||
161 | const typeof(x) _x = (x); \ |
||
162 | const typeof(y) _y = (y); \ |
||
163 | (void) (&_x == &_y); \ |
||
164 | _x < _y ? _x : _y; }) |
||
165 | |||
166 | #define max(x,y) ({ \ |
||
167 | const typeof(x) _x = (x); \ |
||
168 | const typeof(y) _y = (y); \ |
||
169 | (void) (&_x == &_y); \ |
||
170 | _x > _y ? _x : _y; }) |
||
171 | |||
428 | giacomo | 172 | |
173 | |||
422 | giacomo | 174 | /* |
175 | * ..and if you can't take the strict |
||
176 | * types, you can specify one yourself. |
||
177 | * |
||
178 | * Or not use min/max at all, of course. |
||
179 | */ |
||
180 | #define min_t(type,x,y) \ |
||
181 | ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) |
||
182 | #define max_t(type,x,y) \ |
||
183 | ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) |
||
184 | |||
185 | |||
186 | /** |
||
187 | * container_of - cast a member of a structure out to the containing structure |
||
188 | * |
||
189 | * @ptr: the pointer to the member. |
||
190 | * @type: the type of the container struct this is embedded in. |
||
191 | * @member: the name of the member within the struct. |
||
192 | * |
||
193 | */ |
||
194 | #define container_of(ptr, type, member) ({ \ |
||
195 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ |
||
196 | (type *)( (char *)__mptr - offsetof(type,member) );}) |
||
197 | |||
198 | /* |
||
199 | * Check at compile time that something is of a particular type. |
||
200 | * Always evaluates to 1 so you may use it easily in comparisons. |
||
201 | */ |
||
202 | #define typecheck(type,x) \ |
||
203 | ({ type __dummy; \ |
||
204 | typeof(x) __dummy2; \ |
||
205 | (void)(&__dummy == &__dummy2); \ |
||
206 | 1; \ |
||
207 | }) |
||
208 | |||
209 | #endif /* __KERNEL__ */ |
||
210 | |||
211 | #define SI_LOAD_SHIFT 16 |
||
212 | struct sysinfo { |
||
213 | long uptime; /* Seconds since boot */ |
||
214 | unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ |
||
215 | unsigned long totalram; /* Total usable main memory size */ |
||
216 | unsigned long freeram; /* Available memory size */ |
||
217 | unsigned long sharedram; /* Amount of shared memory */ |
||
218 | unsigned long bufferram; /* Memory used by buffers */ |
||
219 | unsigned long totalswap; /* Total swap space size */ |
||
220 | unsigned long freeswap; /* swap space still available */ |
||
221 | unsigned short procs; /* Number of current processes */ |
||
222 | unsigned short pad; /* explicit padding for m68k */ |
||
223 | unsigned long totalhigh; /* Total high memory size */ |
||
224 | unsigned long freehigh; /* Available high memory size */ |
||
225 | unsigned int mem_unit; /* Memory unit size in bytes */ |
||
226 | char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ |
||
227 | }; |
||
228 | |||
229 | extern void BUILD_BUG(void); |
||
230 | #define BUILD_BUG_ON(condition) do { if (condition) BUILD_BUG(); } while(0) |
||
231 | |||
232 | /* Trap pasters of __FUNCTION__ at compile-time */ |
||
233 | #if __GNUC__ > 2 || __GNUC_MINOR__ >= 95 |
||
234 | #define __FUNCTION__ (__func__) |
||
235 | #endif |
||
236 | |||
237 | #endif |