Framework for exporting system header to user space (#59)
[lunaix-os.git] / lunaix-os / includes / lunaix / types.h
index 1251b7033176297dfffe4fdfa077e4445cea615a..c7b09e87acd8a3f0cbc2b7710142de3e244e905a 100644 (file)
@@ -2,37 +2,65 @@
 #define __LUNAIX_TYPES_H
 
 #include <stdarg.h>
-#include <stddef.h>
-#include <stdint.h>
+#include <lunaix/compiler.h>
+#include <lunaix/limits.h>
+#include <usr/lunaix/types.h>
 
-#define PEXITTERM 0x100
-#define PEXITSTOP 0x200
-#define PEXITSIG 0x400
+#undef  NULL
+#define NULL                (void*)0
 
-#define PEXITNUM(flag, code) (flag | (code & 0xff))
+typedef unsigned char       u8_t;
+typedef unsigned short      u16_t;
+typedef unsigned int        u32_t;
 
-#define WNOHANG 1
-#define WUNTRACED 2
-#define WEXITSTATUS(wstatus) ((wstatus & 0xff))
-#define WIFSTOPPED(wstatus) ((wstatus & PEXITSTOP))
-#define WIFEXITED(wstatus)                                                     \
-    ((wstatus & PEXITTERM) && ((char)WEXITSTATUS(wstatus) >= 0))
+#ifndef CONFIG_ARCH_BITS_64
+typedef unsigned long long  u64_t;
+#else
+typedef unsigned long       u64_t;
+#endif
 
-#define WIFSIGNALED(wstatus) ((wstatus & PEXITSIG))
+typedef __lunaix_pid_t      pid_t;
+typedef __lunaix_tid_t      tid_t;
+typedef __lunaix_uid_t      uid_t;
+typedef __lunaix_gid_t      gid_t;
+typedef __lunaix_size_t     size_t;
+typedef __lunaix_ssize_t    ssize_t;
+typedef __lunaix_size_t     off_t;
+typedef __lunaix_ino_t      ino_t;
 
-#define PACKED __attribute__((packed))
+typedef unsigned long       ptr_t;
+typedef unsigned long       reg_t;
+typedef unsigned int        cpu_t;
+typedef u64_t               lba_t;
 
-// TODO: WTERMSIG
+typedef __lunaix_dev_t      dev_t;
 
-// TODO: replace the integer type with these. To make thing more portable.
+#define true 1
+#define false 0
+typedef int bool;
 
-typedef unsigned char u8_t;
-typedef unsigned short u16_t;
-typedef unsigned int u32_t;
-typedef unsigned long long u64_t;
-typedef unsigned long ptr_t;
+/**
+ * container_of - cast a member of a structure out to the containing structure
+ *
+ * @ptr:       the pointer to the member.
+ * @type:      the type of the container struct this is embedded in.
+ * @member:    the name of the member within the struct.
+ *
+ */
+#define container_of(ptr, type, member)                                        \
+    ({                                                                         \
+        const typeof(((type*)0)->member)* __mptr = (ptr);                      \
+        ((ptr_t)ptr != 0UL) ? (type*)((char*)__mptr - offsetof(type, member)) : 0;           \
+    })
 
-typedef int32_t pid_t;
-typedef int64_t lba_t;
+#define offset(data, off)   \
+            ((typeof(data))(__ptr(data) + (off)))
+
+#define offset_t(data, type, off)   \
+            ((type*)(__ptr(data) + (off)))
+
+#define __ptr(val)      ((ptr_t)(val))
+
+typedef va_list* sc_va_list;
 
 #endif /* __LUNAIX_TYPES_H */