1#ifndef KERNEL_H
2#define KERNEL_H
3#include <stdbool.h>
4#include <stdlib.h>
5#include <stddef.h>
6#include <stdio.h>
7#include <string.h>
8#include <assert.h>
9#include <stdarg.h>
10
11#include <linux/compiler.h>
12#include <linux/types.h>
13#include <linux/printk.h>
14#include <linux/bug.h>
15#include <errno.h>
16#include <unistd.h>
17#include <asm/barrier.h>
18
19#define CONFIG_SMP
20
21#define PAGE_SIZE getpagesize()
22#define PAGE_MASK (~(PAGE_SIZE-1))
23#define PAGE_ALIGN(x) ((x + PAGE_SIZE - 1) & PAGE_MASK)
24
25typedef unsigned long long phys_addr_t;
26typedef unsigned long long dma_addr_t;
27typedef size_t __kernel_size_t;
28typedef unsigned int __wsum;
29
30struct page {
31 unsigned long long dummy;
32};
33
34
35#define virt_to_phys(p) ((unsigned long)p)
36#define phys_to_virt(a) ((void *)(unsigned long)(a))
37
38#define page_to_phys(p) ((dma_addr_t)(unsigned long)(p))
39#define virt_to_page(p) ((struct page *)((unsigned long)p & PAGE_MASK))
40
41#define offset_in_page(p) (((unsigned long)p) % PAGE_SIZE)
42
43#define __printf(a,b) __attribute__((format(printf,a,b)))
44
45#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
46
47extern void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end;
48static inline void *kmalloc(size_t s, gfp_t gfp)
49{
50 if (__kmalloc_fake)
51 return __kmalloc_fake;
52 return malloc(s);
53}
54static inline void *kzalloc(size_t s, gfp_t gfp)
55{
56 void *p = kmalloc(s, gfp);
57
58 memset(p, 0, s);
59 return p;
60}
61
62static inline void *alloc_pages_exact(size_t s, gfp_t gfp)
63{
64 return kmalloc(s, gfp);
65}
66
67static inline void kfree(void *p)
68{
69 if (p >= __kfree_ignore_start && p < __kfree_ignore_end)
70 return;
71 free(p);
72}
73
74static inline void free_pages_exact(void *p, size_t s)
75{
76 kfree(p);
77}
78
79static inline void *krealloc(void *p, size_t s, gfp_t gfp)
80{
81 return realloc(p, s);
82}
83
84
85static inline unsigned long __get_free_page(gfp_t gfp)
86{
87 void *p;
88
89 posix_memalign(&p, PAGE_SIZE, PAGE_SIZE);
90 return (unsigned long)p;
91}
92
93static inline void free_page(unsigned long addr)
94{
95 free((void *)addr);
96}
97
98#define container_of(ptr, type, member) ({ \
99 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
100 (type *)( (char *)__mptr - offsetof(type,member) );})
101
102#define uninitialized_var(x) x = x
103
104# ifndef likely
105# define likely(x) (__builtin_expect(!!(x), 1))
106# endif
107# ifndef unlikely
108# define unlikely(x) (__builtin_expect(!!(x), 0))
109# endif
110
111#define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
112#ifdef DEBUG
113#define pr_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
114#else
115#define pr_debug(format, ...) do {} while (0)
116#endif
117#define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
118#define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
119
120#define WARN_ON_ONCE(cond) ((cond) && fprintf (stderr, "WARNING\n"))
121
122#define min(x, y) ({ \
123 typeof(x) _min1 = (x); \
124 typeof(y) _min2 = (y); \
125 (void) (&_min1 == &_min2); \
126 _min1 < _min2 ? _min1 : _min2; })
127
128
129#define list_add_tail(a, b) do {} while (0)
130#define list_del(a) do {} while (0)
131#define list_for_each_entry(a, b, c) while (0)
132
133
134#endif
135