xref: /linux-6.15/include/linux/kernel.h (revision bcdcd8e7)
11da177e4SLinus Torvalds #ifndef _LINUX_KERNEL_H
21da177e4SLinus Torvalds #define _LINUX_KERNEL_H
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds /*
51da177e4SLinus Torvalds  * 'kernel.h' contains some often-used function prototypes etc
61da177e4SLinus Torvalds  */
71da177e4SLinus Torvalds 
81da177e4SLinus Torvalds #ifdef __KERNEL__
91da177e4SLinus Torvalds 
101da177e4SLinus Torvalds #include <stdarg.h>
111da177e4SLinus Torvalds #include <linux/linkage.h>
121da177e4SLinus Torvalds #include <linux/stddef.h>
131da177e4SLinus Torvalds #include <linux/types.h>
141da177e4SLinus Torvalds #include <linux/compiler.h>
151da177e4SLinus Torvalds #include <linux/bitops.h>
16f0d1b0b3SDavid Howells #include <linux/log2.h>
171da177e4SLinus Torvalds #include <asm/byteorder.h>
181da177e4SLinus Torvalds #include <asm/bug.h>
191da177e4SLinus Torvalds 
203eb3c740SRoman Zippel extern const char linux_banner[];
213eb3c740SRoman Zippel extern const char linux_proc_banner[];
223eb3c740SRoman Zippel 
231da177e4SLinus Torvalds #define INT_MAX		((int)(~0U>>1))
241da177e4SLinus Torvalds #define INT_MIN		(-INT_MAX - 1)
251da177e4SLinus Torvalds #define UINT_MAX	(~0U)
261da177e4SLinus Torvalds #define LONG_MAX	((long)(~0UL>>1))
271da177e4SLinus Torvalds #define LONG_MIN	(-LONG_MAX - 1)
281da177e4SLinus Torvalds #define ULONG_MAX	(~0UL)
29111ebb6eSOGAWA Hirofumi #define LLONG_MAX	((long long)(~0ULL>>1))
30111ebb6eSOGAWA Hirofumi #define LLONG_MIN	(-LLONG_MAX - 1)
31111ebb6eSOGAWA Hirofumi #define ULLONG_MAX	(~0ULL)
321da177e4SLinus Torvalds 
331da177e4SLinus Torvalds #define STACK_MAGIC	0xdeadbeef
341da177e4SLinus Torvalds 
352ea58144SLinus Torvalds #define ALIGN(x,a)		__ALIGN_MASK(x,(typeof(x))(a)-1)
362ea58144SLinus Torvalds #define __ALIGN_MASK(x,mask)	(((x)+(mask))&~(mask))
372ea58144SLinus Torvalds 
38c5e631cfSRusty Russell #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
39c5e631cfSRusty Russell 
404552d5dcSJan Beulich #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
41930631edSSteven Whitehouse #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
42b4cac1a0SDavid Howells #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
431da177e4SLinus Torvalds 
44218e180eSAndrew Morton /**
45218e180eSAndrew Morton  * upper_32_bits - return bits 32-63 of a number
46218e180eSAndrew Morton  * @n: the number we're accessing
47218e180eSAndrew Morton  *
48218e180eSAndrew Morton  * A basic shift-right of a 64- or 32-bit quantity.  Use this to suppress
49218e180eSAndrew Morton  * the "right shift count >= width of type" warning when that quantity is
50218e180eSAndrew Morton  * 32-bits.
51218e180eSAndrew Morton  */
52218e180eSAndrew Morton #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
53218e180eSAndrew Morton 
541da177e4SLinus Torvalds #define	KERN_EMERG	"<0>"	/* system is unusable			*/
551da177e4SLinus Torvalds #define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
561da177e4SLinus Torvalds #define	KERN_CRIT	"<2>"	/* critical conditions			*/
571da177e4SLinus Torvalds #define	KERN_ERR	"<3>"	/* error conditions			*/
581da177e4SLinus Torvalds #define	KERN_WARNING	"<4>"	/* warning conditions			*/
591da177e4SLinus Torvalds #define	KERN_NOTICE	"<5>"	/* normal but significant condition	*/
601da177e4SLinus Torvalds #define	KERN_INFO	"<6>"	/* informational			*/
611da177e4SLinus Torvalds #define	KERN_DEBUG	"<7>"	/* debug-level messages			*/
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds extern int console_printk[];
641da177e4SLinus Torvalds 
651da177e4SLinus Torvalds #define console_loglevel (console_printk[0])
661da177e4SLinus Torvalds #define default_message_loglevel (console_printk[1])
671da177e4SLinus Torvalds #define minimum_console_loglevel (console_printk[2])
681da177e4SLinus Torvalds #define default_console_loglevel (console_printk[3])
691da177e4SLinus Torvalds 
701da177e4SLinus Torvalds struct completion;
71df2e71fbS[email protected] struct pt_regs;
72df2e71fbS[email protected] struct user;
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds /**
751da177e4SLinus Torvalds  * might_sleep - annotation for functions that can sleep
761da177e4SLinus Torvalds  *
771da177e4SLinus Torvalds  * this macro will print a stack trace if it is executed in an atomic
781da177e4SLinus Torvalds  * context (spinlock, irq-handler, ...).
791da177e4SLinus Torvalds  *
801da177e4SLinus Torvalds  * This is a useful debugging help to be able to catch problems early and not
81e20ec991SJim Cromie  * be bitten later when the calling function happens to sleep when it is not
821da177e4SLinus Torvalds  * supposed to.
831da177e4SLinus Torvalds  */
84f8cbd99bSIngo Molnar #ifdef CONFIG_PREEMPT_VOLUNTARY
85f8cbd99bSIngo Molnar extern int cond_resched(void);
86f8cbd99bSIngo Molnar # define might_resched() cond_resched()
871da177e4SLinus Torvalds #else
88f8cbd99bSIngo Molnar # define might_resched() do { } while (0)
891da177e4SLinus Torvalds #endif
901da177e4SLinus Torvalds 
91f8cbd99bSIngo Molnar #ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
92f8cbd99bSIngo Molnar   void __might_sleep(char *file, int line);
93f8cbd99bSIngo Molnar # define might_sleep() \
94f8cbd99bSIngo Molnar 	do { __might_sleep(__FILE__, __LINE__); might_resched(); } while (0)
95f8cbd99bSIngo Molnar #else
96f8cbd99bSIngo Molnar # define might_sleep() do { might_resched(); } while (0)
97f8cbd99bSIngo Molnar #endif
98f8cbd99bSIngo Molnar 
99368a5fa1SHua Zhong #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
100f8cbd99bSIngo Molnar 
1011da177e4SLinus Torvalds #define abs(x) ({				\
1021da177e4SLinus Torvalds 		int __x = (x);			\
1031da177e4SLinus Torvalds 		(__x < 0) ? -__x : __x;		\
1041da177e4SLinus Torvalds 	})
1051da177e4SLinus Torvalds 
106e041c683SAlan Stern extern struct atomic_notifier_head panic_notifier_list;
1071da177e4SLinus Torvalds extern long (*panic_blink)(long time);
1081da177e4SLinus Torvalds NORET_TYPE void panic(const char * fmt, ...)
1091da177e4SLinus Torvalds 	__attribute__ ((NORET_AND format (printf, 1, 2)));
110dd287796SAndrew Morton extern void oops_enter(void);
111dd287796SAndrew Morton extern void oops_exit(void);
112dd287796SAndrew Morton extern int oops_may_print(void);
1131da177e4SLinus Torvalds fastcall NORET_TYPE void do_exit(long error_code)
1141da177e4SLinus Torvalds 	ATTRIB_NORET;
1151da177e4SLinus Torvalds NORET_TYPE void complete_and_exit(struct completion *, long)
1161da177e4SLinus Torvalds 	ATTRIB_NORET;
1171da177e4SLinus Torvalds extern unsigned long simple_strtoul(const char *,char **,unsigned int);
1181da177e4SLinus Torvalds extern long simple_strtol(const char *,char **,unsigned int);
1191da177e4SLinus Torvalds extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
1201da177e4SLinus Torvalds extern long long simple_strtoll(const char *,char **,unsigned int);
1211da177e4SLinus Torvalds extern int sprintf(char * buf, const char * fmt, ...)
1221da177e4SLinus Torvalds 	__attribute__ ((format (printf, 2, 3)));
1231da177e4SLinus Torvalds extern int vsprintf(char *buf, const char *, va_list)
1241da177e4SLinus Torvalds 	__attribute__ ((format (printf, 2, 0)));
1251da177e4SLinus Torvalds extern int snprintf(char * buf, size_t size, const char * fmt, ...)
1261da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 4)));
1271da177e4SLinus Torvalds extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
1281da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 0)));
1291da177e4SLinus Torvalds extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
1301da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 4)));
1311da177e4SLinus Torvalds extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
1321da177e4SLinus Torvalds 	__attribute__ ((format (printf, 3, 0)));
133e905914fSJeremy Fitzhardinge extern char *kasprintf(gfp_t gfp, const char *fmt, ...)
134e905914fSJeremy Fitzhardinge 	__attribute__ ((format (printf, 2, 3)));
13511443ec7SJeremy Fitzhardinge extern char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
1361da177e4SLinus Torvalds 
1371da177e4SLinus Torvalds extern int sscanf(const char *, const char *, ...)
1381da177e4SLinus Torvalds 	__attribute__ ((format (scanf, 2, 3)));
1391da177e4SLinus Torvalds extern int vsscanf(const char *, const char *, va_list)
1401da177e4SLinus Torvalds 	__attribute__ ((format (scanf, 2, 0)));
1411da177e4SLinus Torvalds 
1421da177e4SLinus Torvalds extern int get_option(char **str, int *pint);
1431da177e4SLinus Torvalds extern char *get_options(const char *str, int nints, int *ints);
1441da177e4SLinus Torvalds extern unsigned long long memparse(char *ptr, char **retptr);
1451da177e4SLinus Torvalds 
1465e376613STrent Piepho extern int core_kernel_text(unsigned long addr);
1471da177e4SLinus Torvalds extern int __kernel_text_address(unsigned long addr);
1481da177e4SLinus Torvalds extern int kernel_text_address(unsigned long addr);
14904a2e6a5SEric W. Biederman struct pid;
15004a2e6a5SEric W. Biederman extern struct pid *session_of_pgrp(struct pid *pgrp);
1511da177e4SLinus Torvalds 
152df2e71fbS[email protected] extern void dump_thread(struct pt_regs *regs, struct user *dump);
153df2e71fbS[email protected] 
154d59745ceSMatt Mackall #ifdef CONFIG_PRINTK
1551da177e4SLinus Torvalds asmlinkage int vprintk(const char *fmt, va_list args)
1561da177e4SLinus Torvalds 	__attribute__ ((format (printf, 1, 0)));
1571da177e4SLinus Torvalds asmlinkage int printk(const char * fmt, ...)
1581da177e4SLinus Torvalds 	__attribute__ ((format (printf, 1, 2)));
159d59745ceSMatt Mackall #else
160d59745ceSMatt Mackall static inline int vprintk(const char *s, va_list args)
161d59745ceSMatt Mackall 	__attribute__ ((format (printf, 1, 0)));
162d59745ceSMatt Mackall static inline int vprintk(const char *s, va_list args) { return 0; }
163d59745ceSMatt Mackall static inline int printk(const char *s, ...)
164d59745ceSMatt Mackall 	__attribute__ ((format (printf, 1, 2)));
165d59745ceSMatt Mackall static inline int printk(const char *s, ...) { return 0; }
166d59745ceSMatt Mackall #endif
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds unsigned long int_sqrt(unsigned long);
1691da177e4SLinus Torvalds 
1701da177e4SLinus Torvalds extern int printk_ratelimit(void);
1711da177e4SLinus Torvalds extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
172f46c4833SAndrew Morton extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
173f46c4833SAndrew Morton 				unsigned int interval_msec);
1741da177e4SLinus Torvalds 
1751da177e4SLinus Torvalds static inline void console_silent(void)
1761da177e4SLinus Torvalds {
1771da177e4SLinus Torvalds 	console_loglevel = 0;
1781da177e4SLinus Torvalds }
1791da177e4SLinus Torvalds 
1801da177e4SLinus Torvalds static inline void console_verbose(void)
1811da177e4SLinus Torvalds {
1821da177e4SLinus Torvalds 	if (console_loglevel)
1831da177e4SLinus Torvalds 		console_loglevel = 15;
1841da177e4SLinus Torvalds }
1851da177e4SLinus Torvalds 
1861da177e4SLinus Torvalds extern void bust_spinlocks(int yes);
187e3e8a75dSKirill Korotaev extern void wake_up_klogd(void);
1881da177e4SLinus Torvalds extern int oops_in_progress;		/* If set, an oops, panic(), BUG() or die() is in progress */
189aa727107SAdrian Bunk extern int panic_timeout;
1901da177e4SLinus Torvalds extern int panic_on_oops;
1918da5addaSDon Zickus extern int panic_on_unrecovered_nmi;
1921da177e4SLinus Torvalds extern int tainted;
1931da177e4SLinus Torvalds extern const char *print_tainted(void);
1941da177e4SLinus Torvalds extern void add_taint(unsigned);
1951da177e4SLinus Torvalds 
1961da177e4SLinus Torvalds /* Values used for system_state */
1971da177e4SLinus Torvalds extern enum system_states {
1981da177e4SLinus Torvalds 	SYSTEM_BOOTING,
1991da177e4SLinus Torvalds 	SYSTEM_RUNNING,
2001da177e4SLinus Torvalds 	SYSTEM_HALT,
2011da177e4SLinus Torvalds 	SYSTEM_POWER_OFF,
2021da177e4SLinus Torvalds 	SYSTEM_RESTART,
203729b4d4cSAlexey Starikovskiy 	SYSTEM_SUSPEND_DISK,
2041da177e4SLinus Torvalds } system_state;
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds #define TAINT_PROPRIETARY_MODULE	(1<<0)
2071da177e4SLinus Torvalds #define TAINT_FORCED_MODULE		(1<<1)
2081da177e4SLinus Torvalds #define TAINT_UNSAFE_SMP		(1<<2)
2091da177e4SLinus Torvalds #define TAINT_FORCED_RMMOD		(1<<3)
2101da177e4SLinus Torvalds #define TAINT_MACHINE_CHECK		(1<<4)
2111da177e4SLinus Torvalds #define TAINT_BAD_PAGE			(1<<5)
21234f5a398STheodore Ts'o #define TAINT_USER			(1<<6)
213*bcdcd8e7SPavel Emelianov #define TAINT_DIE			(1<<7)
2141da177e4SLinus Torvalds 
2151da177e4SLinus Torvalds extern void dump_stack(void);
2161da177e4SLinus Torvalds 
21799eaf3c4SRandy Dunlap enum {
21899eaf3c4SRandy Dunlap 	DUMP_PREFIX_NONE,
21999eaf3c4SRandy Dunlap 	DUMP_PREFIX_ADDRESS,
22099eaf3c4SRandy Dunlap 	DUMP_PREFIX_OFFSET
22199eaf3c4SRandy Dunlap };
222c7909234SRandy Dunlap extern void hex_dump_to_buffer(const void *buf, size_t len,
223c7909234SRandy Dunlap 				int rowsize, int groupsize,
224c7909234SRandy Dunlap 				char *linebuf, size_t linebuflen, bool ascii);
225c7909234SRandy Dunlap extern void print_hex_dump(const char *level, const char *prefix_str,
226c7909234SRandy Dunlap 				int prefix_type, int rowsize, int groupsize,
227c7909234SRandy Dunlap 				void *buf, size_t len, bool ascii);
228c7909234SRandy Dunlap extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
22999eaf3c4SRandy Dunlap 			void *buf, size_t len);
23099eaf3c4SRandy Dunlap #define hex_asc(x)	"0123456789abcdef"[x]
23199eaf3c4SRandy Dunlap 
2321da177e4SLinus Torvalds #ifdef DEBUG
2331cc6daf2SPavel Machek /* If you are writing a driver, please use dev_dbg instead */
2341da177e4SLinus Torvalds #define pr_debug(fmt,arg...) \
2351da177e4SLinus Torvalds 	printk(KERN_DEBUG fmt,##arg)
2361da177e4SLinus Torvalds #else
2378b2a1fd1SZach Brown static inline int __attribute__ ((format (printf, 1, 2))) pr_debug(const char * fmt, ...)
2388b2a1fd1SZach Brown {
2398b2a1fd1SZach Brown 	return 0;
2408b2a1fd1SZach Brown }
2411da177e4SLinus Torvalds #endif
2421da177e4SLinus Torvalds 
2431da177e4SLinus Torvalds #define pr_info(fmt,arg...) \
2441da177e4SLinus Torvalds 	printk(KERN_INFO fmt,##arg)
2451da177e4SLinus Torvalds 
2461da177e4SLinus Torvalds /*
2471da177e4SLinus Torvalds  *      Display an IP address in readable format.
2481da177e4SLinus Torvalds  */
2491da177e4SLinus Torvalds 
2501da177e4SLinus Torvalds #define NIPQUAD(addr) \
2511da177e4SLinus Torvalds 	((unsigned char *)&addr)[0], \
2521da177e4SLinus Torvalds 	((unsigned char *)&addr)[1], \
2531da177e4SLinus Torvalds 	((unsigned char *)&addr)[2], \
2541da177e4SLinus Torvalds 	((unsigned char *)&addr)[3]
25546b86a2dSJoe Perches #define NIPQUAD_FMT "%u.%u.%u.%u"
2561da177e4SLinus Torvalds 
2571da177e4SLinus Torvalds #define NIP6(addr) \
2581da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[0]), \
2591da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[1]), \
2601da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[2]), \
2611da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[3]), \
2621da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[4]), \
2631da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[5]), \
2641da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[6]), \
2651da177e4SLinus Torvalds 	ntohs((addr).s6_addr16[7])
26646b86a2dSJoe Perches #define NIP6_FMT "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
2679343e79aSYOSHIFUJI Hideaki #define NIP6_SEQFMT "%04x%04x%04x%04x%04x%04x%04x%04x"
2681da177e4SLinus Torvalds 
2691da177e4SLinus Torvalds #if defined(__LITTLE_ENDIAN)
2701da177e4SLinus Torvalds #define HIPQUAD(addr) \
2711da177e4SLinus Torvalds 	((unsigned char *)&addr)[3], \
2721da177e4SLinus Torvalds 	((unsigned char *)&addr)[2], \
2731da177e4SLinus Torvalds 	((unsigned char *)&addr)[1], \
2741da177e4SLinus Torvalds 	((unsigned char *)&addr)[0]
2751da177e4SLinus Torvalds #elif defined(__BIG_ENDIAN)
2761da177e4SLinus Torvalds #define HIPQUAD	NIPQUAD
2771da177e4SLinus Torvalds #else
2781da177e4SLinus Torvalds #error "Please fix asm/byteorder.h"
2791da177e4SLinus Torvalds #endif /* __LITTLE_ENDIAN */
2801da177e4SLinus Torvalds 
2811da177e4SLinus Torvalds /*
2821da177e4SLinus Torvalds  * min()/max() macros that also do
2831da177e4SLinus Torvalds  * strict type-checking.. See the
2841da177e4SLinus Torvalds  * "unnecessary" pointer comparison.
2851da177e4SLinus Torvalds  */
2861da177e4SLinus Torvalds #define min(x,y) ({ \
2871da177e4SLinus Torvalds 	typeof(x) _x = (x);	\
2881da177e4SLinus Torvalds 	typeof(y) _y = (y);	\
2891da177e4SLinus Torvalds 	(void) (&_x == &_y);		\
2901da177e4SLinus Torvalds 	_x < _y ? _x : _y; })
2911da177e4SLinus Torvalds 
2921da177e4SLinus Torvalds #define max(x,y) ({ \
2931da177e4SLinus Torvalds 	typeof(x) _x = (x);	\
2941da177e4SLinus Torvalds 	typeof(y) _y = (y);	\
2951da177e4SLinus Torvalds 	(void) (&_x == &_y);		\
2961da177e4SLinus Torvalds 	_x > _y ? _x : _y; })
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds /*
2991da177e4SLinus Torvalds  * ..and if you can't take the strict
3001da177e4SLinus Torvalds  * types, you can specify one yourself.
3011da177e4SLinus Torvalds  *
3021da177e4SLinus Torvalds  * Or not use min/max at all, of course.
3031da177e4SLinus Torvalds  */
3041da177e4SLinus Torvalds #define min_t(type,x,y) \
3051da177e4SLinus Torvalds 	({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
3061da177e4SLinus Torvalds #define max_t(type,x,y) \
3071da177e4SLinus Torvalds 	({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds 
3101da177e4SLinus Torvalds /**
3111da177e4SLinus Torvalds  * container_of - cast a member of a structure out to the containing structure
3121da177e4SLinus Torvalds  * @ptr:	the pointer to the member.
3131da177e4SLinus Torvalds  * @type:	the type of the container struct this is embedded in.
3141da177e4SLinus Torvalds  * @member:	the name of the member within the struct.
3151da177e4SLinus Torvalds  *
3161da177e4SLinus Torvalds  */
3171da177e4SLinus Torvalds #define container_of(ptr, type, member) ({			\
3181da177e4SLinus Torvalds 	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
3191da177e4SLinus Torvalds 	(type *)( (char *)__mptr - offsetof(type,member) );})
3201da177e4SLinus Torvalds 
3211da177e4SLinus Torvalds /*
3221da177e4SLinus Torvalds  * Check at compile time that something is of a particular type.
3231da177e4SLinus Torvalds  * Always evaluates to 1 so you may use it easily in comparisons.
3241da177e4SLinus Torvalds  */
3251da177e4SLinus Torvalds #define typecheck(type,x) \
3261da177e4SLinus Torvalds ({	type __dummy; \
3271da177e4SLinus Torvalds 	typeof(x) __dummy2; \
3281da177e4SLinus Torvalds 	(void)(&__dummy == &__dummy2); \
3291da177e4SLinus Torvalds 	1; \
3301da177e4SLinus Torvalds })
3311da177e4SLinus Torvalds 
332711a660dSChuck Ebbert /*
333711a660dSChuck Ebbert  * Check at compile time that 'function' is a certain type, or is a pointer
334711a660dSChuck Ebbert  * to that type (needs to use typedef for the function type.)
335711a660dSChuck Ebbert  */
336711a660dSChuck Ebbert #define typecheck_fn(type,function) \
337711a660dSChuck Ebbert ({	typeof(type) __tmp = function; \
338711a660dSChuck Ebbert 	(void)__tmp; \
339711a660dSChuck Ebbert })
340711a660dSChuck Ebbert 
341d4d23addSKyle McMartin struct sysinfo;
342d4d23addSKyle McMartin extern int do_sysinfo(struct sysinfo *info);
343d4d23addSKyle McMartin 
3441da177e4SLinus Torvalds #endif /* __KERNEL__ */
3451da177e4SLinus Torvalds 
3461da177e4SLinus Torvalds #define SI_LOAD_SHIFT	16
3471da177e4SLinus Torvalds struct sysinfo {
3481da177e4SLinus Torvalds 	long uptime;			/* Seconds since boot */
3491da177e4SLinus Torvalds 	unsigned long loads[3];		/* 1, 5, and 15 minute load averages */
3501da177e4SLinus Torvalds 	unsigned long totalram;		/* Total usable main memory size */
3511da177e4SLinus Torvalds 	unsigned long freeram;		/* Available memory size */
3521da177e4SLinus Torvalds 	unsigned long sharedram;	/* Amount of shared memory */
3531da177e4SLinus Torvalds 	unsigned long bufferram;	/* Memory used by buffers */
3541da177e4SLinus Torvalds 	unsigned long totalswap;	/* Total swap space size */
3551da177e4SLinus Torvalds 	unsigned long freeswap;		/* swap space still available */
3561da177e4SLinus Torvalds 	unsigned short procs;		/* Number of current processes */
3571da177e4SLinus Torvalds 	unsigned short pad;		/* explicit padding for m68k */
3581da177e4SLinus Torvalds 	unsigned long totalhigh;	/* Total high memory size */
3591da177e4SLinus Torvalds 	unsigned long freehigh;		/* Available high memory size */
3601da177e4SLinus Torvalds 	unsigned int mem_unit;		/* Memory unit size in bytes */
3611da177e4SLinus Torvalds 	char _f[20-2*sizeof(long)-sizeof(int)];	/* Padding: libc5 uses this.. */
3621da177e4SLinus Torvalds };
3631da177e4SLinus Torvalds 
364c0398ee6SNikita Danilov /* Force a compilation error if condition is true */
365921717a2SAndi Kleen #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
3661da177e4SLinus Torvalds 
3674552d5dcSJan Beulich /* Force a compilation error if condition is true, but also produce a
3684552d5dcSJan Beulich    result (of value 0 and type size_t), so the expression can be used
3694552d5dcSJan Beulich    e.g. in a structure initializer (or where-ever else comma expressions
3704552d5dcSJan Beulich    aren't permitted). */
3714552d5dcSJan Beulich #define BUILD_BUG_ON_ZERO(e) (sizeof(char[1 - 2 * !!(e)]) - 1)
3724552d5dcSJan Beulich 
3731da177e4SLinus Torvalds /* Trap pasters of __FUNCTION__ at compile-time */
3741da177e4SLinus Torvalds #define __FUNCTION__ (__func__)
3751da177e4SLinus Torvalds 
37608e0f6a9SChristoph Lameter /* This helps us to avoid #ifdef CONFIG_NUMA */
37708e0f6a9SChristoph Lameter #ifdef CONFIG_NUMA
37808e0f6a9SChristoph Lameter #define NUMA_BUILD 1
37908e0f6a9SChristoph Lameter #else
38008e0f6a9SChristoph Lameter #define NUMA_BUILD 0
38108e0f6a9SChristoph Lameter #endif
38208e0f6a9SChristoph Lameter 
3831da177e4SLinus Torvalds #endif
384