linux/include/linux/kernel.h
<<
>>
Prefs
   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#include <linux/compiler.h>
  15#include <linux/bitops.h>
  16#include <asm/byteorder.h>
  17#include <asm/bug.h>
  18
  19extern const char linux_banner[];
  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#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
  32
  33#define KERN_EMERG      "<0>"   /* system is unusable                   */
  34#define KERN_ALERT      "<1>"   /* action must be taken immediately     */
  35#define KERN_CRIT       "<2>"   /* critical conditions                  */
  36#define KERN_ERR        "<3>"   /* error conditions                     */
  37#define KERN_WARNING    "<4>"   /* warning conditions                   */
  38#define KERN_NOTICE     "<5>"   /* normal but significant condition     */
  39#define KERN_INFO       "<6>"   /* informational                        */
  40#define KERN_DEBUG      "<7>"   /* debug-level messages                 */
  41
  42extern int console_printk[];
  43
  44#define console_loglevel (console_printk[0])
  45#define default_message_loglevel (console_printk[1])
  46#define minimum_console_loglevel (console_printk[2])
  47#define default_console_loglevel (console_printk[3])
  48
  49struct completion;
  50
  51#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
  52void __might_sleep(char *file, int line);
  53#define might_sleep() __might_sleep(__FILE__, __LINE__)
  54#define might_sleep_if(cond) do { if (unlikely(cond)) might_sleep(); } while (0)
  55#else
  56#define might_sleep() do {} while(0)
  57#define might_sleep_if(cond) do {} while (0)
  58#endif
  59
  60#define abs(x) ({                               \
  61                int __x = (x);                  \
  62                (__x < 0) ? -__x : __x;         \
  63        })
  64
  65#define labs(x) ({                              \
  66                long __x = (x);                 \
  67                (__x < 0) ? -__x : __x;         \
  68        })
  69
  70extern struct notifier_block *panic_notifier_list;
  71extern long (*panic_blink)(long time);
  72NORET_TYPE void panic(const char * fmt, ...)
  73        __attribute__ ((NORET_AND format (printf, 1, 2)));
  74fastcall NORET_TYPE void do_exit(long error_code)
  75        ATTRIB_NORET;
  76NORET_TYPE void complete_and_exit(struct completion *, long)
  77        ATTRIB_NORET;
  78extern unsigned long simple_strtoul(const char *,char **,unsigned int);
  79extern long simple_strtol(const char *,char **,unsigned int);
  80extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
  81extern long long simple_strtoll(const char *,char **,unsigned int);
  82extern int sprintf(char * buf, const char * fmt, ...)
  83        __attribute__ ((format (printf, 2, 3)));
  84extern int vsprintf(char *buf, const char *, va_list);
  85extern int snprintf(char * buf, size_t size, const char * fmt, ...)
  86        __attribute__ ((format (printf, 3, 4)));
  87extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
  88extern int scnprintf(char * buf, size_t size, const char * fmt, ...)
  89        __attribute__ ((format (printf, 3, 4)));
  90extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
  91
  92extern int sscanf(const char *, const char *, ...)
  93        __attribute__ ((format (scanf,2,3)));
  94extern int vsscanf(const char *, const char *, va_list);
  95
  96extern int get_option(char **str, int *pint);
  97extern char *get_options(const char *str, int nints, int *ints);
  98extern unsigned long long memparse(char *ptr, char **retptr);
  99
 100extern int __kernel_text_address(unsigned long addr);
 101extern int kernel_text_address(unsigned long addr);
 102extern int session_of_pgrp(int pgrp);
 103
 104asmlinkage int vprintk(const char *fmt, va_list args);
 105asmlinkage int printk(const char * fmt, ...)
 106        __attribute__ ((format (printf, 1, 2)));
 107
 108unsigned long int_sqrt(unsigned long);
 109
 110static inline int __attribute_pure__ long_log2(unsigned long x)
 111{
 112        int r = 0;
 113        for (x >>= 1; x > 0; x >>= 1)
 114                r++;
 115        return r;
 116}
 117
 118static inline unsigned long __attribute_const__ roundup_pow_of_two(unsigned long x)
 119{
 120        return (1UL << fls(x - 1));
 121}
 122
 123extern int printk_ratelimit(void);
 124extern int __printk_ratelimit(int ratelimit_jiffies, int ratelimit_burst);
 125
 126static inline void console_silent(void)
 127{
 128        console_loglevel = 0;
 129}
 130
 131static inline void console_verbose(void)
 132{
 133        if (console_loglevel)
 134                console_loglevel = 15;
 135}
 136
 137extern void bust_spinlocks(int yes);
 138extern int oops_in_progress;            /* If set, an oops, panic(), BUG() or die() is in progress */
 139extern int panic_timeout;
 140extern int panic_on_oops;
 141extern int tainted;
 142extern const char *print_tainted(void);
 143extern void add_taint(unsigned);
 144
 145/* Values used for system_state */
 146extern enum system_states {
 147        SYSTEM_BOOTING,
 148        SYSTEM_RUNNING,
 149        SYSTEM_HALT,
 150        SYSTEM_POWER_OFF,
 151        SYSTEM_RESTART,
 152} system_state;
 153
 154#define TAINT_PROPRIETARY_MODULE        (1<<0)
 155#define TAINT_FORCED_MODULE             (1<<1)
 156#define TAINT_UNSAFE_SMP                (1<<2)
 157#define TAINT_FORCED_RMMOD              (1<<3)
 158#define TAINT_MACHINE_CHECK             (1<<4)
 159#define TAINT_BAD_PAGE                  (1<<5)
 160
 161extern void dump_stack(void);
 162
 163#ifdef DEBUG
 164#define pr_debug(fmt,arg...) \
 165        printk(KERN_DEBUG fmt,##arg)
 166#else
 167#define pr_debug(fmt,arg...) \
 168        do { } while (0)
 169#endif
 170
 171#define pr_info(fmt,arg...) \
 172        printk(KERN_INFO fmt,##arg)
 173
 174/*
 175 *      Display an IP address in readable format.
 176 */
 177
 178#define NIPQUAD(addr) \
 179        ((unsigned char *)&addr)[0], \
 180        ((unsigned char *)&addr)[1], \
 181        ((unsigned char *)&addr)[2], \
 182        ((unsigned char *)&addr)[3]
 183
 184#define NIP6(addr) \
 185        ntohs((addr).s6_addr16[0]), \
 186        ntohs((addr).s6_addr16[1]), \
 187        ntohs((addr).s6_addr16[2]), \
 188        ntohs((addr).s6_addr16[3]), \
 189        ntohs((addr).s6_addr16[4]), \
 190        ntohs((addr).s6_addr16[5]), \
 191        ntohs((addr).s6_addr16[6]), \
 192        ntohs((addr).s6_addr16[7])
 193
 194#if defined(__LITTLE_ENDIAN)
 195#define HIPQUAD(addr) \
 196        ((unsigned char *)&addr)[3], \
 197        ((unsigned char *)&addr)[2], \
 198        ((unsigned char *)&addr)[1], \
 199        ((unsigned char *)&addr)[0]
 200#elif defined(__BIG_ENDIAN)
 201#define HIPQUAD NIPQUAD
 202#else
 203#error "Please fix asm/byteorder.h"
 204#endif /* __LITTLE_ENDIAN */
 205
 206/*
 207 * min()/max() macros that also do
 208 * strict type-checking.. See the
 209 * "unnecessary" pointer comparison.
 210 */
 211#define min(x,y) ({ \
 212        typeof(x) _x = (x);     \
 213        typeof(y) _y = (y);     \
 214        (void) (&_x == &_y);            \
 215        _x < _y ? _x : _y; })
 216
 217#define max(x,y) ({ \
 218        typeof(x) _x = (x);     \
 219        typeof(y) _y = (y);     \
 220        (void) (&_x == &_y);            \
 221        _x > _y ? _x : _y; })
 222
 223/*
 224 * ..and if you can't take the strict
 225 * types, you can specify one yourself.
 226 *
 227 * Or not use min/max at all, of course.
 228 */
 229#define min_t(type,x,y) \
 230        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
 231#define max_t(type,x,y) \
 232        ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
 233
 234
 235/**
 236 * container_of - cast a member of a structure out to the containing structure
 237 *
 238 * @ptr:        the pointer to the member.
 239 * @type:       the type of the container struct this is embedded in.
 240 * @member:     the name of the member within the struct.
 241 *
 242 */
 243#define container_of(ptr, type, member) ({                      \
 244        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
 245        (type *)( (char *)__mptr - offsetof(type,member) );})
 246
 247/*
 248 * Check at compile time that something is of a particular type.
 249 * Always evaluates to 1 so you may use it easily in comparisons.
 250 */
 251#define typecheck(type,x) \
 252({      type __dummy; \
 253        typeof(x) __dummy2; \
 254        (void)(&__dummy == &__dummy2); \
 255        1; \
 256})
 257
 258#endif /* __KERNEL__ */
 259
 260#define SI_LOAD_SHIFT   16
 261struct sysinfo {
 262        long uptime;                    /* Seconds since boot */
 263        unsigned long loads[3];         /* 1, 5, and 15 minute load averages */
 264        unsigned long totalram;         /* Total usable main memory size */
 265        unsigned long freeram;          /* Available memory size */
 266        unsigned long sharedram;        /* Amount of shared memory */
 267        unsigned long bufferram;        /* Memory used by buffers */
 268        unsigned long totalswap;        /* Total swap space size */
 269        unsigned long freeswap;         /* swap space still available */
 270        unsigned short procs;           /* Number of current processes */
 271        unsigned short pad;             /* explicit padding for m68k */
 272        unsigned long totalhigh;        /* Total high memory size */
 273        unsigned long freehigh;         /* Available high memory size */
 274        unsigned int mem_unit;          /* Memory unit size in bytes */
 275        char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
 276};
 277
 278extern void BUILD_BUG(void);
 279#define BUILD_BUG_ON(condition) do { if (condition) BUILD_BUG(); } while(0)
 280
 281/* Trap pasters of __FUNCTION__ at compile-time */
 282#if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
 283#define __FUNCTION__ (__func__)
 284#endif
 285
 286#endif
 287
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.