ust: continue work
[ust.git] / share / kernelcompat.h
CommitLineData
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
b6bf28ec
PMF
12#define KERN_DEBUG ""
13#define KERN_NOTICE ""
14#define KERN_INFO ""
15#define KERN_ERR ""
16#define KERN_ALERT ""
c66d2821 17
59b161cd
PMF
18/* ERROR OPS */
19
20#define MAX_ERRNO 4095
21
22#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
23
c66d2821
PMF
24static inline void *ERR_PTR(long error)
25{
59b161cd 26 return (void *) error;
c66d2821
PMF
27}
28
59b161cd
PMF
29static inline long PTR_ERR(const void *ptr)
30{
31 return (long) ptr;
32}
33
34static inline long IS_ERR(const void *ptr)
35{
36 return IS_ERR_VALUE((unsigned long)ptr);
37}
38
39
40/* FIXED SIZE INTEGERS */
c66d2821
PMF
41
42#include <stdint.h>
43
59b161cd 44typedef uint8_t u8;
c66d2821
PMF
45typedef uint16_t u16;
46typedef uint32_t u32;
59b161cd 47typedef uint64_t u64;
c66d2821 48
b6bf28ec
PMF
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 */
c66d2821
PMF
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
b6bf28ec 70/* MALLOCATION */
c66d2821
PMF
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
b6bf28ec 79/* PRINTK */
c66d2821
PMF
80
81#include <stdio.h>
82#define printk(fmt, args...) printf(fmt, ## args)
83
59b161cd
PMF
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)
c66d2821 93
59b161cd 94/* RCU */
c66d2821 95
59b161cd 96#define rcu_assign_pointer(a, b) do {} while(0)
b6bf28ec
PMF
97#define call_rcu_sched(a,b) do {} while(0)
98#define rcu_barrier_sched() do {} while(0)
c66d2821 99
59b161cd 100/* ATOMICITY */
b6bf28ec 101
59b161cd
PMF
102#include <signal.h>
103
104typedef struct { sig_atomic_t counter; } atomic_t;
105
106static inline int atomic_dec_and_test(atomic_t *p)
107{
108 (p->counter)--;
109 return !p->counter;
110}
111
112static inline void atomic_set(atomic_t *p, int v)
113{
114 p->counter=v;
115}
116
117static inline void atomic_inc(atomic_t *p)
118{
119 p->counter++;
120}
121
122static int atomic_read(atomic_t *p)
123{
124 return p->counter;
125}
c66d2821 126
5f54827b
PMF
127/* LOCAL OPS */
128
129
130
131/* ATTRIBUTES */
b6bf28ec 132
59b161cd 133#define ____cacheline_aligned
5f54827b
PMF
134#define __init
135#define __exit
c66d2821 136
b6bf28ec
PMF
137/* MATH */
138
139static 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
148static 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
164static __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
5f54827b
PMF
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
b6bf28ec
PMF
187/* ARRAYS */
188
189#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
190
191/* TRACE CLOCK */
192
193static inline u64 trace_clock_read64(void)
194{
195 return 0LL;
196}
197
198static inline unsigned int trace_clock_frequency(void)
199{
200 return 0LL;
201}
202
203static inline u32 trace_clock_freq_scale(void)
204{
205 return 0;
206}
207
c66d2821 208#endif /* KERNELCOMPAT_H */
This page took 0.031122 seconds and 4 git commands to generate.