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