Commit | Line | Data |
---|---|---|
c66d2821 PMF |
1 | #ifndef KERNELCOMPAT_H |
2 | #define KERNELCOMPAT_H | |
3 | ||
59b161cd PMF |
4 | #include "compiler.h" |
5 | ||
c66d2821 PMF |
6 | #include <string.h> |
7 | ||
8 | #define container_of(ptr, type, member) ({ \ | |
9 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ | |
10 | (type *)( (char *)__mptr - offsetof(type,member) );}) | |
11 | ||
12 | #define KERN_DEBUG | |
13 | #define KERN_NOTICE | |
14 | ||
59b161cd PMF |
15 | /* ERROR OPS */ |
16 | ||
17 | #define MAX_ERRNO 4095 | |
18 | ||
19 | #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) | |
20 | ||
c66d2821 PMF |
21 | static inline void *ERR_PTR(long error) |
22 | { | |
59b161cd | 23 | return (void *) error; |
c66d2821 PMF |
24 | } |
25 | ||
59b161cd PMF |
26 | static inline long PTR_ERR(const void *ptr) |
27 | { | |
28 | return (long) ptr; | |
29 | } | |
30 | ||
31 | static inline long IS_ERR(const void *ptr) | |
32 | { | |
33 | return IS_ERR_VALUE((unsigned long)ptr); | |
34 | } | |
35 | ||
36 | ||
37 | /* FIXED SIZE INTEGERS */ | |
c66d2821 PMF |
38 | |
39 | #include <stdint.h> | |
40 | ||
59b161cd | 41 | typedef uint8_t u8; |
c66d2821 PMF |
42 | typedef uint16_t u16; |
43 | typedef uint32_t u32; | |
59b161cd | 44 | typedef uint64_t u64; |
c66d2821 PMF |
45 | |
46 | ||
47 | #include <pthread.h> | |
48 | ||
49 | #define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER; | |
50 | ||
51 | #define mutex_lock(m) pthread_mutex_lock(m) | |
52 | ||
53 | #define mutex_unlock(m) pthread_mutex_unlock(m) | |
54 | ||
55 | ||
56 | #include <stdlib.h> | |
57 | ||
58 | #define kmalloc(s, t) malloc(s) | |
59 | #define kzalloc(s, t) malloc(s) | |
60 | #define kfree(p) free((void *)p) | |
61 | #define kstrdup(s, t) strdup(s) | |
62 | ||
63 | ||
64 | #include <stdio.h> | |
65 | #define printk(fmt, args...) printf(fmt, ## args) | |
66 | ||
67 | ||
59b161cd PMF |
68 | /* MEMORY BARRIERS */ |
69 | ||
70 | #define smp_rmb() do {} while(0) | |
71 | #define smp_wmb() do {} while(0) | |
72 | #define smp_mb() do {} while(0) | |
73 | #define smp_mb__after_atomic_inc() do {} while(0) | |
74 | ||
75 | #define read_barrier_depends() do {} while(0) | |
76 | #define smp_read_barrier_depends() do {} while(0) | |
c66d2821 | 77 | |
59b161cd | 78 | /* RCU */ |
c66d2821 | 79 | |
59b161cd | 80 | #define rcu_assign_pointer(a, b) do {} while(0) |
c66d2821 | 81 | |
59b161cd PMF |
82 | /* ATOMICITY */ |
83 | #include <signal.h> | |
84 | ||
85 | typedef struct { sig_atomic_t counter; } atomic_t; | |
86 | ||
87 | static inline int atomic_dec_and_test(atomic_t *p) | |
88 | { | |
89 | (p->counter)--; | |
90 | return !p->counter; | |
91 | } | |
92 | ||
93 | static inline void atomic_set(atomic_t *p, int v) | |
94 | { | |
95 | p->counter=v; | |
96 | } | |
97 | ||
98 | static inline void atomic_inc(atomic_t *p) | |
99 | { | |
100 | p->counter++; | |
101 | } | |
102 | ||
103 | static int atomic_read(atomic_t *p) | |
104 | { | |
105 | return p->counter; | |
106 | } | |
c66d2821 | 107 | |
59b161cd PMF |
108 | /* CACHE */ |
109 | #define ____cacheline_aligned | |
c66d2821 | 110 | |
c66d2821 | 111 | #endif /* KERNELCOMPAT_H */ |