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