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#else
55#define FASTCALL(x) x
56#endif
57
58struct completion;
59
60extern struct notifier_block *panic_notifier_list;
61NORET_TYPE void panic(const char * fmt, ...)
62 __attribute__ ((NORET_AND format (printf, 1, 2)));
63asmlinkage NORET_TYPE void do_exit(long error_code)
64 ATTRIB_NORET;
65NORET_TYPE void complete_and_exit(struct completion *, long)
66 ATTRIB_NORET;
67extern int abs(int);
68extern unsigned long simple_strtoul(const char *,char **,unsigned int);
69extern long simple_strtol(const char *,char **,unsigned int);
70extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
71extern long long simple_strtoll(const char *,char **,unsigned int);
72extern int sprintf(char * buf, const char * fmt, ...)
73 __attribute__ ((format (printf, 2, 3)));
74extern int vsprintf(char *buf, const char *, va_list);
75extern int snprintf(char * buf, size_t size, const char * fmt, ...)
76 __attribute__ ((format (printf, 3, 4)));
77extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
78
79extern int sscanf(const char *, const char *, ...)
80 __attribute__ ((format (scanf,2,3)));
81extern int vsscanf(const char *, const char *, va_list);
82
83extern int get_option(char **str, int *pint);
84extern char *get_options(char *str, int nints, int *ints);
85extern unsigned long long memparse(char *ptr, char **retptr);
86extern void dev_probe_lock(void);
87extern void dev_probe_unlock(void);
88
89extern int session_of_pgrp(int pgrp);
90
91asmlinkage int printk(const char * fmt, ...)
92 __attribute__ ((format (printf, 1, 2)));
93
94static inline void console_silent(void)
95{
96 console_loglevel = 0;
97}
98
99static inline void console_verbose(void)
100{
101 if (console_loglevel)
102 console_loglevel = 15;
103}
104
105extern void bust_spinlocks(int yes);
106extern int oops_in_progress;
107
108extern int tainted;
109extern const char *print_tainted(void);
110
111extern void dump_stack(void);
112
113#if DEBUG
114#define pr_debug(fmt,arg...) \
115 printk(KERN_DEBUG fmt,##arg)
116#else
117#define pr_debug(fmt,arg...) \
118 do { } while (0)
119#endif
120
121#define pr_info(fmt,arg...) \
122 printk(KERN_INFO fmt,##arg)
123
124
125
126
127
128#define NIPQUAD(addr) \
129 ((unsigned char *)&addr)[0], \
130 ((unsigned char *)&addr)[1], \
131 ((unsigned char *)&addr)[2], \
132 ((unsigned char *)&addr)[3]
133
134#if defined(__LITTLE_ENDIAN)
135#define HIPQUAD(addr) \
136 ((unsigned char *)&addr)[3], \
137 ((unsigned char *)&addr)[2], \
138 ((unsigned char *)&addr)[1], \
139 ((unsigned char *)&addr)[0]
140#elif defined(__BIG_ENDIAN)
141#define HIPQUAD NIPQUAD
142#else
143#error "Please fix asm/byteorder.h"
144#endif
145
146
147
148
149
150
151#define min(x,y) ({ \
152 const typeof(x) _x = (x); \
153 const typeof(y) _y = (y); \
154 (void) (&_x == &_y); \
155 _x < _y ? _x : _y; })
156
157#define max(x,y) ({ \
158 const typeof(x) _x = (x); \
159 const typeof(y) _y = (y); \
160 (void) (&_x == &_y); \
161 _x > _y ? _x : _y; })
162
163
164
165
166
167
168
169#define min_t(type,x,y) \
170 ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
171#define max_t(type,x,y) \
172 ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
173
174extern void __out_of_line_bug(int line) ATTRIB_NORET;
175#define out_of_line_bug() __out_of_line_bug(__LINE__)
176
177#endif
178
179#define SI_LOAD_SHIFT 16
180struct sysinfo {
181 long uptime;
182 unsigned long loads[3];
183 unsigned long totalram;
184 unsigned long freeram;
185 unsigned long sharedram;
186 unsigned long bufferram;
187 unsigned long totalswap;
188 unsigned long freeswap;
189 unsigned short procs;
190 unsigned short pad;
191 unsigned long totalhigh;
192 unsigned long freehigh;
193 unsigned int mem_unit;
194 char _f[20-2*sizeof(long)-sizeof(int)];
195};
196
197#define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
198
199#endif
200