6ce5fcf3b71873e3ea2b7ce4243c03bff658aac0
[lunaix-os.git] / lunaix-os / includes / lunaix / types.h
1 #ifndef __LUNAIX_TYPES_H
2 #define __LUNAIX_TYPES_H
3
4 #include <lunaix/compiler.h>
5 #include <lunaix/limits.h>
6 #include <stdarg.h>
7 #include <usr/lunaix/types.h>
8
9 // TODO: WTERMSIG
10
11 // TODO: replace the integer type with these. To make thing more portable.
12
13 typedef unsigned char u8_t;
14 typedef unsigned short u16_t;
15 typedef unsigned int u32_t;
16 typedef unsigned long ptr_t;
17 typedef unsigned long reg_t;
18
19 #ifndef CONFIG_ARCH_BITS_64
20 typedef unsigned long long u64_t;
21 #else
22 typedef unsigned long u64_t;
23 #endif
24
25 typedef int pid_t;
26 typedef signed long ssize_t;
27
28 typedef unsigned int cpu_t;
29
30 typedef u64_t lba_t;
31
32 #define true 1
33 #define false 0
34 typedef int bool;
35
36 /**
37  * container_of - cast a member of a structure out to the containing structure
38  *
39  * @ptr:        the pointer to the member.
40  * @type:       the type of the container struct this is embedded in.
41  * @member:     the name of the member within the struct.
42  *
43  */
44 #define container_of(ptr, type, member)                                        \
45     ({                                                                         \
46         const typeof(((type*)0)->member)* __mptr = (ptr);                      \
47         ((ptr_t)ptr != 0UL) ? (type*)((char*)__mptr - offsetof(type, member)) : 0;           \
48     })
49
50 #define offset(data, off)   \
51             ((typeof(data))(__ptr(data) + (off)))
52
53 #define offset_t(data, type, off)   \
54             ((type*)(__ptr(data) + (off)))
55
56 #define __ptr(val)      ((ptr_t)(val))
57
58 typedef va_list* sc_va_list;
59
60 #endif /* __LUNAIX_TYPES_H */