ust: continue work
[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
15 /* ERROR OPS */
16
17 #define MAX_ERRNO 4095
18
19 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
20
21 static inline void *ERR_PTR(long error)
22 {
23 return (void *) error;
24 }
25
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 */
38
39 #include <stdint.h>
40
41 typedef uint8_t u8;
42 typedef uint16_t u16;
43 typedef uint32_t u32;
44 typedef uint64_t u64;
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
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)
77
78 /* RCU */
79
80 #define rcu_assign_pointer(a, b) do {} while(0)
81
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 }
107
108 /* CACHE */
109 #define ____cacheline_aligned
110
111 #endif /* KERNELCOMPAT_H */
This page took 0.031725 seconds and 5 git commands to generate.