ust: continue work
[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 /* CACHE */
128
129 #define ____cacheline_aligned
130
131 /* MATH */
132
133 static inline unsigned int hweight32(unsigned int w)
134 {
135 unsigned int res = w - ((w >> 1) & 0x55555555);
136 res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
137 res = (res + (res >> 4)) & 0x0F0F0F0F;
138 res = res + (res >> 8);
139 return (res + (res >> 16)) & 0x000000FF;
140 }
141
142 static inline int fls(int x)
143 {
144 int r;
145 //ust// #ifdef CONFIG_X86_CMOV
146 asm("bsrl %1,%0\n\t"
147 "cmovzl %2,%0"
148 : "=&r" (r) : "rm" (x), "rm" (-1));
149 //ust// #else
150 //ust// asm("bsrl %1,%0\n\t"
151 //ust// "jnz 1f\n\t"
152 //ust// "movl $-1,%0\n"
153 //ust// "1:" : "=r" (r) : "rm" (x));
154 //ust// #endif
155 return r + 1;
156 }
157
158 static __inline__ int get_count_order(unsigned int count)
159 {
160 int order;
161
162 order = fls(count) - 1;
163 if (count & (count - 1))
164 order++;
165 return order;
166 }
167
168
169 /* ARRAYS */
170
171 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
172
173 /* TRACE CLOCK */
174
175 static inline u64 trace_clock_read64(void)
176 {
177 return 0LL;
178 }
179
180 static inline unsigned int trace_clock_frequency(void)
181 {
182 return 0LL;
183 }
184
185 static inline u32 trace_clock_freq_scale(void)
186 {
187 return 0;
188 }
189
190 #endif /* KERNELCOMPAT_H */
This page took 0.036783 seconds and 4 git commands to generate.