1#ifndef _LINUX_KERNEL_H
2#define _LINUX_KERNEL_H
3
4
5
6
7
8#ifdef __KERNEL__
9
10#include <stdarg.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
17
18
19#define barrier() __asm__ __volatile__("": : :"memory")
20
21#define INT_MAX ((int)(~0U>>1))
22#define INT_MIN (-INT_MAX - 1)
23#define UINT_MAX (~0U)
24#define LONG_MAX ((long)(~0UL>>1))
25#define LONG_MIN (-LONG_MAX - 1)
26#define ULONG_MAX (~0UL)
27
28#define STACK_MAGIC 0xdeadbeef
29
30#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31
32#define KERN_EMERG "<0>"
33#define KERN_ALERT "<1>"
34#define KERN_CRIT "<2>"
35#define KERN_ERR "<3>"
36#define KERN_WARNING "<4>"
37#define KERN_NOTICE "<5>"
38#define KERN_INFO "<6>"
39#define KERN_DEBUG "<7>"
40
41extern int console_printk[];
42
43#define console_loglevel (console_printk[0])
44#define default_message_loglevel (console_printk[1])
45#define minimum_console_loglevel (console_printk[2])
46#define default_console_loglevel (console_printk[3])
47
48# define NORET_TYPE
49# define ATTRIB_NORET __attribute__((noreturn))
50# define NORET_AND noreturn,
51
52#ifdef __i386__
53#define FASTCALL(x) x __attribute__((regparm(3)))
54#define fastcall __attribute__((regparm(3)))
55#else
56#define FASTCALL(x) x
57#define fastcall
58#endif
59
60struct completion;
61
62extern struct notifier_block *panic_notifier_list;
63NORET_TYPE void panic(const char * fmt, ...)
64 __attribute__ ((NORET_AND format (printf, 1, 2)));
65asmlinkage NORET_TYPE void do_exit(long error_code)
66 ATTRIB_NORET;
67NORET_TYPE void complete_and_exit(struct completion *, long)
68 ATTRIB_NORET;
69extern int abs(int);
70extern unsigned long simple_strtoul(const char *,char **,unsigned int);
71extern long simple_strtol(const char *,char **,unsigned int);
72extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
73extern long long simple_strtoll(const char *,char **,unsigned int);
74extern int sprintf(char * buf, const char * fmt, ...)
75 __attribute__ ((format (printf, 2, 3)));
76extern int vsprintf(char *buf, const char *, va_list);
77extern int snprintf(char * buf, size_t size, const char * fmt, ...)
78 __attribute__ ((format (printf, 3, 4)));
79extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
80
81extern int sscanf(const char *, const char *, ...)
82 __attribute__ ((format (scanf,2,3)));
83extern int vsscanf(const char *, const char *, va_list);
84
85extern int get_option(char **str, int *pint);
86extern char *get_options(char *str, int nints, int *ints);
87extern unsigned long long memparse(char *ptr, char **retptr);
88extern void dev_probe_lock(void);
89extern void dev_probe_unlock(void);
90
91extern int session_of_pgrp(int pgrp);
92
93asmlinkage int printk(const char * fmt, ...)
94 __attribute__ ((format (printf, 1, 2)));
95
96static inline void console_silent(void)
97{
98 console_loglevel = 0;
99}
100
101static inline void console_verbose(void)
102{
103 if (console_loglevel)
104 console_loglevel = 15;
105}
106
107extern void bust_spinlocks(int yes);
108extern int oops_in_progress;
109
110extern int tainted;
111extern const char *print_tainted(void);
112
113extern void dump_stack(void);
114
115#if DEBUG
116#define pr_debug(fmt,arg...) \
117 printk(KERN_DEBUG fmt,##arg)
118#else
119#define pr_debug(fmt,arg...) \
120 do { } while (0)
121#endif
122
123#define pr_info(fmt,arg...) \
124 printk(KERN_INFO fmt,##arg)
125
126
127
128
129
130#define NIPQUAD(addr) \
131 ((unsigned char *)&addr)[0], \
132 ((unsigned char *)&addr)[1], \
133 ((unsigned char *)&addr)[2], \
134 ((unsigned char *)&addr)[3]
135
136#if defined(__LITTLE_ENDIAN)
137#define HIPQUAD(addr) \
138 ((unsigned char *)&addr)[3], \
139 ((unsigned char *)&addr)[2], \
140 ((unsigned char *)&addr)[1], \
141 ((unsigned char *)&addr)[0]
142#elif defined(__BIG_ENDIAN)
143#define HIPQUAD NIPQUAD
144#else
145#error "Please fix asm/byteorder.h"
146#endif
147
148
149
150
151
152
153#define min(x,y) ({ \
154 const typeof(x) _x = (x); \
155 const typeof(y) _y = (y); \
156 (void) (&_x == &_y); \
157 _x < _y ? _x : _y; })
158
159#define max(x,y) ({ \
160 const typeof(x) _x = (x); \
161 const typeof(y) _y = (y); \
162 (void) (&_x == &_y); \
163 _x > _y ? _x : _y; })
164
165
166
167
168
169
170
171#define min_t(type,x,y) \
172 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
173#define max_t(type,x,y) \
174 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
175
176extern void __out_of_line_bug(int line) ATTRIB_NORET;
177#define out_of_line_bug() __out_of_line_bug(__LINE__)
178
179#endif
180
181#define SI_LOAD_SHIFT 16
182struct sysinfo {
183 long uptime;
184 unsigned long loads[3];
185 unsigned long totalram;
186 unsigned long freeram;
187 unsigned long sharedram;
188 unsigned long bufferram;
189 unsigned long totalswap;
190 unsigned long freeswap;
191 unsigned short procs;
192 unsigned short pad;
193 unsigned long totalhigh;
194 unsigned long freehigh;
195 unsigned int mem_unit;
196 char _f[20-2*sizeof(long)-sizeof(int)];
197};
198
199#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
200
201#define WARN_ON(condition) do { \
202 if (unlikely((condition)!=0)) { \
203 printk("Badness in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
204 dump_stack(); \
205 } \
206} while (0)
207
208#endif
209