6bc09caea232bc6f1257ad196380fd445ce5cad1
[lttng-ust.git] / share / kernelcompat.h
1 #ifndef KERNELCOMPAT_H
2 #define KERNELCOMPAT_H
3
4 #include "compiler.h"
5
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 #define KERN_INFO ""
15 #define KERN_ERR ""
16 #define KERN_ALERT ""
17
18 /* ERROR OPS */
19
20 #define MAX_ERRNO 4095
21
22 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
23
24 static inline void *ERR_PTR(long error)
25 {
26 return (void *) error;
27 }
28
29 static inline long PTR_ERR(const void *ptr)
30 {
31 return (long) ptr;
32 }
33
34 static inline long IS_ERR(const void *ptr)
35 {
36 return IS_ERR_VALUE((unsigned long)ptr);
37 }
38
39
40 /* FIXED SIZE INTEGERS */
41
42 #include <stdint.h>
43
44 typedef uint8_t u8;
45 typedef uint16_t u16;
46 typedef uint32_t u32;
47 typedef uint64_t u64;
48
49 #define min_t(type, x, y) ({ \
50 type __min1 = (x); \
51 type __min2 = (y); \
52 __min1 < __min2 ? __min1: __min2; })
53
54 #define max_t(type, x, y) ({ \
55 type __max1 = (x); \
56 type __max2 = (y); \
57 __max1 > __max2 ? __max1: __max2; })
58
59
60 /* MUTEXES */
61
62 #include <pthread.h>
63
64 #define DEFINE_MUTEX(m) pthread_mutex_t (m) = PTHREAD_MUTEX_INITIALIZER;
65
66 #define mutex_lock(m) pthread_mutex_lock(m)
67
68 #define mutex_unlock(m) pthread_mutex_unlock(m)
69
70 /* MALLOCATION */
71
72 #include <stdlib.h>
73
74 #define kmalloc(s, t) malloc(s)
75 #define kzalloc(s, t) malloc(s)
76 #define kfree(p) free((void *)p)
77 #define kstrdup(s, t) strdup(s)
78
79 /* PRINTK */
80
81 #include <stdio.h>
82 #define printk(fmt, args...) printf(fmt, ## args)
83
84 /* MEMORY BARRIERS */
85
86 #define smp_rmb() do {} while(0)
87 #define smp_wmb() do {} while(0)
88 #define smp_mb() do {} while(0)
89 #define smp_mb__after_atomic_inc() do {} while(0)
90
91 #define read_barrier_depends() do {} while(0)
92 #define smp_read_barrier_depends() do {} while(0)
93
94 /* RCU */
95
96 #define rcu_assign_pointer(a, b) do {} while(0)
97 #define call_rcu_sched(a,b) do {} while(0)
98 #define rcu_barrier_sched() do {} while(0)
99
100 /* ATOMICITY */
101
102 #include <signal.h>
103
104 typedef struct { sig_atomic_t counter; } atomic_t;
105
106 static inline int atomic_dec_and_test(atomic_t *p)
107 {
108 (p->counter)--;
109 return !p->counter;
110 }
111
112 static inline void atomic_set(atomic_t *p, int v)
113 {
114 p->counter=v;
115 }
116
117 static inline void atomic_inc(atomic_t *p)
118 {
119 p->counter++;
120 }
121
122 static int atomic_read(atomic_t *p)
123 {
124 return p->counter;
125 }
126
127 /* LOCAL OPS */
128
129
130
131 /* ATTRIBUTES */
132
133 #define ____cacheline_aligned
134 #define __init
135 #define __exit
136
137 /* MATH */
138
139 static inline unsigned int hweight32(unsigned int w)
140 {
141 unsigned int res = w - ((w >> 1) & 0x55555555);
142 res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
143 res = (res + (res >> 4)) & 0x0F0F0F0F;
144 res = res + (res >> 8);
145 return (res + (res >> 16)) & 0x000000FF;
146 }
147
148 static inline int fls(int x)
149 {
150 int r;
151 //ust// #ifdef CONFIG_X86_CMOV
152 asm("bsrl %1,%0\n\t"
153 "cmovzl %2,%0"
154 : "=&r" (r) : "rm" (x), "rm" (-1));
155 //ust// #else
156 //ust// asm("bsrl %1,%0\n\t"
157 //ust// "jnz 1f\n\t"
158 //ust// "movl $-1,%0\n"
159 //ust// "1:" : "=r" (r) : "rm" (x));
160 //ust// #endif
161 return r + 1;
162 }
163
164 static __inline__ int get_count_order(unsigned int count)
165 {
166 int order;
167
168 order = fls(count) - 1;
169 if (count & (count - 1))
170 order++;
171 return order;
172 }
173
174
175
176
177 #include <unistd.h>
178
179 #define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
180 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
181 #define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE)
182 #define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
183
184
185
186
187 /* ARRAYS */
188
189 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
190
191 /* TRACE CLOCK */
192
193 static inline u64 trace_clock_read64(void)
194 {
195 return 0LL;
196 }
197
198 static inline unsigned int trace_clock_frequency(void)
199 {
200 return 0LL;
201 }
202
203 static inline u32 trace_clock_freq_scale(void)
204 {
205 return 0;
206 }
207
208 #endif /* KERNELCOMPAT_H */
This page took 0.033627 seconds and 3 git commands to generate.