     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 <stdarg.h>
    11	#include <linux/linkage.h>
    12	#include <linux/stddef.h>
    13	#include <linux/types.h>
    14	
    15	/* Optimization barrier */
    16	/* The "volatile" is due to gcc bugs */
    17	#define barrier() __asm__ __volatile__("": : :"memory")
    18	
    19	#define INT_MAX		((int)(~0U>>1))
    20	#define INT_MIN		(-INT_MAX - 1)
    21	#define UINT_MAX	(~0U)
    22	#define LONG_MAX	((long)(~0UL>>1))
    23	#define LONG_MIN	(-LONG_MAX - 1)
    24	#define ULONG_MAX	(~0UL)
    25	
    26	#define STACK_MAGIC	0xdeadbeef
    27	
    28	#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
    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	# define NORET_TYPE    /**/
    47	# define ATTRIB_NORET  __attribute__((noreturn))
    48	# define NORET_AND     noreturn,
    49	
    50	#ifdef __i386__
    51	#define FASTCALL(x)	x __attribute__((regparm(3)))
    52	#else
    53	#define FASTCALL(x)	x
    54	#endif
    55	
    56	struct completion;
    57	
    58	extern struct notifier_block *panic_notifier_list;
    59	NORET_TYPE void panic(const char * fmt, ...)
    60		__attribute__ ((NORET_AND format (printf, 1, 2)));
    61	asmlinkage NORET_TYPE void do_exit(long error_code)
    62		ATTRIB_NORET;
    63	NORET_TYPE void complete_and_exit(struct completion *, long)
    64		ATTRIB_NORET;
    65	extern int abs(int);
    66	extern unsigned long simple_strtoul(const char *,char **,unsigned int);
    67	extern long simple_strtol(const char *,char **,unsigned int);
    68	extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
    69	extern long long simple_strtoll(const char *,char **,unsigned int);
    70	extern int sprintf(char * buf, const char * fmt, ...)
    71		__attribute__ ((format (printf, 2, 3)));
    72	extern int vsprintf(char *buf, const char *, va_list);
    73	extern int snprintf(char * buf, size_t size, const char * fmt, ...)
    74		__attribute__ ((format (printf, 3, 4)));
    75	extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
    76	
    77	extern int sscanf(const char *, const char *, ...)
    78		__attribute__ ((format (scanf,2,3)));
    79	extern int vsscanf(const char *, const char *, va_list);
    80	
    81	extern int get_option(char **str, int *pint);
    82	extern char *get_options(char *str, int nints, int *ints);
    83	extern unsigned long long memparse(char *ptr, char **retptr);
    84	extern void dev_probe_lock(void);
    85	extern void dev_probe_unlock(void);
    86	
    87	extern int session_of_pgrp(int pgrp);
    88	
    89	asmlinkage int printk(const char * fmt, ...)
    90		__attribute__ ((format (printf, 1, 2)));
    91	
    92	static inline void console_silent(void)
    93	{
    94		console_loglevel = 0;
    95	}
    96	
    97	static inline void console_verbose(void)
    98	{
    99		if (console_loglevel)
   100			console_loglevel = 15;
   101	}
   102	
   103	extern void bust_spinlocks(int yes);
   104	extern int oops_in_progress;		/* If set, an oops, panic(), BUG() or die() is in progress */
   105	
   106	extern int tainted;
   107	extern const char *print_tainted(void);
   108	
   109	#if DEBUG
   110	#define pr_debug(fmt,arg...) \
   111		printk(KERN_DEBUG fmt,##arg)
   112	#else
   113	#define pr_debug(fmt,arg...) \
   114		do { } while (0)
   115	#endif
   116	
   117	#define pr_info(fmt,arg...) \
   118		printk(KERN_INFO fmt,##arg)
   119	
   120	/*
   121	 *      Display an IP address in readable format.
   122	 */
   123	
   124	#define NIPQUAD(addr) \
   125		((unsigned char *)&addr)[0], \
   126		((unsigned char *)&addr)[1], \
   127		((unsigned char *)&addr)[2], \
   128		((unsigned char *)&addr)[3]
   129	
   130	#define HIPQUAD(addr) \
   131		((unsigned char *)&addr)[3], \
   132		((unsigned char *)&addr)[2], \
   133		((unsigned char *)&addr)[1], \
   134		((unsigned char *)&addr)[0]
   135	
   136	/*
   137	 * min()/max() macros that also do
   138	 * strict type-checking.. See the
   139	 * "unnecessary" pointer comparison.
   140	 */
   141	#define min(x,y) ({ \
   142		const typeof(x) _x = (x);	\
   143		const typeof(y) _y = (y);	\
   144		(void) (&_x == &_y);		\
   145		_x < _y ? _x : _y; })
   146	
   147	#define max(x,y) ({ \
   148		const typeof(x) _x = (x);	\
   149		const typeof(y) _y = (y);	\
   150		(void) (&_x == &_y);		\
   151		_x > _y ? _x : _y; })
   152	
   153	/*
   154	 * ..and if you can't take the strict
   155	 * types, you can specify one yourself.
   156	 *
   157	 * Or not use min/max at all, of course.
   158	 */
   159	#define min_t(type,x,y) \
   160		({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
   161	#define max_t(type,x,y) \
   162		({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
   163	
   164	#endif /* __KERNEL__ */
   165	
   166	#define SI_LOAD_SHIFT	16
   167	struct sysinfo {
   168		long uptime;			/* Seconds since boot */
   169		unsigned long loads[3];		/* 1, 5, and 15 minute load averages */
   170		unsigned long totalram;		/* Total usable main memory size */
   171		unsigned long freeram;		/* Available memory size */
   172		unsigned long sharedram;	/* Amount of shared memory */
   173		unsigned long bufferram;	/* Memory used by buffers */
   174		unsigned long totalswap;	/* Total swap space size */
   175		unsigned long freeswap;		/* swap space still available */
   176		unsigned short procs;		/* Number of current processes */
   177		unsigned short pad;		/* explicit padding for m68k */
   178		unsigned long totalhigh;	/* Total high memory size */
   179		unsigned long freehigh;		/* Available high memory size */
   180		unsigned int mem_unit;		/* Memory unit size in bytes */
   181		char _f[20-2*sizeof(long)-sizeof(int)];	/* Padding: libc5 uses this.. */
   182	};
   183	
   184	#endif
