linux-bk/include/linux/kernel.h History
<<
>>
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 <asm/byteorder.h>
  16#include <asm/bug.h>
  17
  18#define INT_MAX         ((int)(~0U>>1))
  19#define INT_MIN         (-INT_MAX - 1)
  20#define UINT_MAX        (~0U)
  21#define LONG_MAX        ((long)(~0UL>>1))
  22#define LONG_MIN        (-LONG_MAX - 1)
  23#define ULONG_MAX       (~0UL)
  24
  25#define STACK_MAGIC     0xdeadbeef
  26
  27#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  28#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
  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
  39extern 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
  46struct completion;
  47
  48#ifdef CONFIG_DEBUG_SPINLOCK_SLEEP
  49void __might_sleep(char *file, int line);
  50#define might_sleep() __might_sleep(__FILE__, __LINE__)
  51#define might_sleep_if(cond) do { if (unlikely(cond)) might_sleep(); } while (0)
  52#else
  53#define might_sleep() do {} while(0)
  54#define might_sleep_if(cond) do {} while (0)
  55#endif
  56
  57extern struct notifier_block *panic_notifier_list;
  58NORET_TYPE void panic(const char * fmt, ...)
  59        __attribute__ ((NORET_AND format (printf, 1, 2)));
  60asmlinkage NORET_TYPE void do_exit(long error_code)
  61        ATTRIB_NORET;
  62NORET_TYPE void complete_and_exit(struct completion *, long)
  63        ATTRIB_NORET;
  64extern int abs(int);
  65extern unsigned long simple_strtoul(const char *,char **,unsigned int);
  66extern long simple_strtol(const char *,char **,unsigned int);
  67extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
  68extern long long simple_strtoll(const char *,char **,unsigned int);
  69extern int sprintf(char * buf, const char * fmt, ...)
  70        __attribute__ ((format (printf, 2, 3)));
  71extern int vsprintf(char *buf, const char *, va_list);
  72extern int snprintf(char * buf, size_t size, const char * fmt, ...)
  73        __attribute__ ((format (printf, 3, 4)));
  74extern int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
  75
  76extern int sscanf(const char *, const char *, ...)
  77        __attribute__ ((format (scanf,2,3)));
  78extern int vsscanf(const char *, const char *, va_list);
  79
  80extern int get_option(char **str, int *pint);
  81extern char *get_options(const char *str, int nints, int *ints);
  82extern unsigned long long memparse(char *ptr, char **retptr);
  83
  84extern int kernel_text_address(unsigned long addr);
  85extern int session_of_pgrp(int pgrp);
  86
  87asmlinkage int printk(const char * fmt, ...)
  88        __attribute__ ((format (printf, 1, 2)));
  89
  90unsigned long int_sqrt(unsigned long);
  91
  92static inline void console_silent(void)
  93{
  94        console_loglevel = 0;
  95}
  96
  97static inline void console_verbose(void)
  98{
  99        if (console_loglevel)
 100                console_loglevel = 15;
 101}
 102
 103extern void bust_spinlocks(int yes);
 104extern int oops_in_progress;            /* If set, an oops, panic(), BUG() or die() is in progress */
 105extern int panic_on_oops;
 106extern int system_running;
 107extern int tainted;
 108extern const char *print_tainted(void);
 109#define TAINT_PROPRIETARY_MODULE        (1<<0)
 110#define TAINT_FORCED_MODULE             (1<<1)
 111#define TAINT_UNSAFE_SMP                (1<<2)
 112#define TAINT_FORCED_RMMOD              (1<<3)
 113
 114extern void dump_stack(void);
 115
 116#ifdef DEBUG
 117#define pr_debug(fmt,arg...) \
 118        printk(KERN_DEBUG fmt,##arg)
 119#else
 120#define pr_debug(fmt,arg...) \
 121        do { } while (0)
 122#endif
 123
 124#define pr_info(fmt,arg...) \
 125        printk(KERN_INFO fmt,##arg)
 126
 127/*
 128 *      Display an IP address in readable format.
 129 */
 130
 131#define NIPQUAD(addr) \
 132        ((unsigned char *)&addr)[0], \
 133        ((unsigned char *)&addr)[1], \
 134        ((unsigned char *)&addr)[2], \
 135        ((unsigned char *)&addr)[3]
 136
 137#define NIP6(addr) \
 138        ntohs((addr).s6_addr16[0]), \
 139        ntohs((addr).s6_addr16[1]), \
 140        ntohs((addr).s6_addr16[2]), \
 141        ntohs((addr).s6_addr16[3]), \
 142        ntohs((addr).s6_addr16[4]), \
 143        ntohs((addr).s6_addr16[5]), \
 144        ntohs((addr).s6_addr16[6]), \
 145        ntohs((addr).s6_addr16[7])
 146
 147#if defined(__LITTLE_ENDIAN)
 148#define HIPQUAD(addr) \
 149        ((unsigned char *)&addr)[3], \
 150        ((unsigned char *)&addr)[2], \
 151        ((unsigned char *)&addr)[1], \
 152        ((unsigned char *)&addr)[0]
 153#elif defined(__BIG_ENDIAN)
 154#define HIPQUAD NIPQUAD
 155#else
 156#error "Please fix asm/byteorder.h"
 157#endif /* __LITTLE_ENDIAN */
 158
 159/*
 160 * min()/max() macros that also do
 161 * strict type-checking.. See the
 162 * "unnecessary" pointer comparison.
 163 */
 164#define min(x,y) ({ \
 165        const typeof(x) _x = (x);       \
 166        const typeof(y) _y = (y);       \
 167        (void) (&_x == &_y);            \
 168        _x < _y ? _x : _y; })
 169
 170#define max(x,y) ({ \
 171        const typeof(x) _x = (x);       \
 172        const typeof(y) _y = (y);       \
 173        (void) (&_x == &_y);            \
 174        _x > _y ? _x : _y; })
 175
 176/*
 177 * ..and if you can't take the strict
 178 * types, you can specify one yourself.
 179 *
 180 * Or not use min/max at all, of course.
 181 */
 182#define min_t(type,x,y) \
 183        ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
 184#define max_t(type,x,y) \
 185        ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
 186
 187
 188/**
 189 * container_of - cast a member of a structure out to the containing structure
 190 *
 191 * @ptr:        the pointer to the member.
 192 * @type:       the type of the container struct this is embedded in.
 193 * @member:     the name of the member within the struct.
 194 *
 195 */
 196#define container_of(ptr, type, member) ({                      \
 197        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
 198        (type *)( (char *)__mptr - offsetof(type,member) );})
 199
 200/*
 201 * Check at compile time that something is of a particular type.
 202 * Always evaluates to 1 so you may use it easily in comparisons.
 203 */
 204#define typecheck(type,x) \
 205({      type __dummy; \
 206        typeof(x) __dummy2; \
 207        (void)(&__dummy == &__dummy2); \
 208        1; \
 209})
 210
 211#endif /* __KERNEL__ */
 212
 213#define SI_LOAD_SHIFT   16
 214struct sysinfo {
 215        long uptime;                    /* Seconds since boot */
 216        unsigned long loads[3];         /* 1, 5, and 15 minute load averages */
 217        unsigned long totalram;         /* Total usable main memory size */
 218        unsigned long freeram;          /* Available memory size */
 219        unsigned long sharedram;        /* Amount of shared memory */
 220        unsigned long bufferram;        /* Memory used by buffers */
 221        unsigned long totalswap;        /* Total swap space size */
 222        unsigned long freeswap;         /* swap space still available */
 223        unsigned short procs;           /* Number of current processes */
 224        unsigned short pad;             /* explicit padding for m68k */
 225        unsigned long totalhigh;        /* Total high memory size */
 226        unsigned long freehigh;         /* Available high memory size */
 227        unsigned int mem_unit;          /* Memory unit size in bytes */
 228        char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
 229};
 230
 231extern void BUILD_BUG(void);
 232#define BUILD_BUG_ON(condition) do { if (condition) BUILD_BUG(); } while(0)
 233
 234/* Trap pasters of __FUNCTION__ at compile-time */
 235#if __GNUC__ > 2 || __GNUC_MINOR__ >= 95
 236#define __FUNCTION__ (__func__)
 237#endif
 238
 239#endif
 240
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.