refactor: separate syscall interfaces from kernel space, into posix compliant structure.
authorMinep <zelong56@gmail.com>
Thu, 29 Dec 2022 01:03:17 +0000 (01:03 +0000)
committerMinep <zelong56@gmail.com>
Thu, 29 Dec 2022 01:03:17 +0000 (01:03 +0000)
44 files changed:
lunaix-os/includes/lunaix/fctrl.h [deleted file]
lunaix-os/includes/lunaix/foptions.h
lunaix-os/includes/lunaix/ioctl.h
lunaix-os/includes/lunaix/lunistd.h [deleted file]
lunaix-os/includes/lunaix/lxsignal.h [deleted file]
lunaix-os/includes/lunaix/signal.h
lunaix-os/includes/lunaix/syscall.h
lunaix-os/includes/lunaix/types.h
lunaix-os/includes/usr/errno.h [new file with mode: 0644]
lunaix-os/includes/usr/fcntl.h [new file with mode: 0644]
lunaix-os/includes/usr/fcntl_defs.h [new file with mode: 0644]
lunaix-os/includes/usr/signal.h [new file with mode: 0644]
lunaix-os/includes/usr/signal_defs.h [new file with mode: 0644]
lunaix-os/includes/usr/sys/dirent.h [new file with mode: 0644]
lunaix-os/includes/usr/sys/dirent_defs.h [new file with mode: 0644]
lunaix-os/includes/usr/sys/ioctl.h [new file with mode: 0644]
lunaix-os/includes/usr/sys/ioctl_defs.h [new file with mode: 0644]
lunaix-os/includes/usr/sys/lunaix.h [new file with mode: 0644]
lunaix-os/includes/usr/sys/mount.h [new file with mode: 0644]
lunaix-os/includes/usr/sys/types.h
lunaix-os/includes/usr/unistd.h [new file with mode: 0644]
lunaix-os/kernel/asm/x86/pfault.c
lunaix-os/kernel/demos/dir_read.c
lunaix-os/kernel/demos/input_test.c
lunaix-os/kernel/demos/iotest.c
lunaix-os/kernel/demos/signal_demo.c
lunaix-os/kernel/demos/simple_sh.c
lunaix-os/kernel/device/devfs.c
lunaix-os/kernel/fs/iso9660/directory.c
lunaix-os/kernel/fs/vfs.c
lunaix-os/kernel/lxinit.c
lunaix-os/kernel/proc0.c
lunaix-os/kernel/process/signal.c
lunaix-os/kernel/process/taskfs.c
lunaix-os/kernel/tty/lxconsole.c
lunaix-os/libs/ulibc/printf.c
lunaix-os/usr/api/dirent.c [new file with mode: 0644]
lunaix-os/usr/api/errno.c [new file with mode: 0644]
lunaix-os/usr/api/fcntl.c [new file with mode: 0644]
lunaix-os/usr/api/ioctl.c [new file with mode: 0644]
lunaix-os/usr/api/lunaix.c [moved from lunaix-os/includes/lunaix/lunaix.h with 62% similarity]
lunaix-os/usr/api/mount.c [new file with mode: 0644]
lunaix-os/usr/api/signal.c [new file with mode: 0644]
lunaix-os/usr/api/unistd.c [new file with mode: 0644]

diff --git a/lunaix-os/includes/lunaix/fctrl.h b/lunaix-os/includes/lunaix/fctrl.h
deleted file mode 100644 (file)
index 36efb4b..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#ifndef __LUNAIX_FCTRL_H
-#define __LUNAIX_FCTRL_H
-
-#include <lunaix/dirent.h>
-#include <lunaix/syscall.h>
-#include <stddef.h>
-
-__LXSYSCALL2(int, open, const char*, path, int, options)
-
-__LXSYSCALL1(int, mkdir, const char*, path)
-__LXSYSCALL2(int, unlinkat, int, fd, const char*, pathname)
-
-__LXSYSCALL2(int, sys_readdir, int, fd, struct dirent*, dent)
-
-__LXSYSCALL4(int,
-             readlinkat,
-             int,
-             dirfd,
-             const char*,
-             pathname,
-             char*,
-             buf,
-             size_t,
-             size)
-
-__LXSYSCALL3(int, realpathat, int, fd, char*, buf, size_t, size)
-
-__LXSYSCALL4(int,
-             mount,
-             const char*,
-             source,
-             const char*,
-             target,
-             const char*,
-             fstype,
-             int,
-             options)
-
-__LXSYSCALL1(int, unmount, const char*, target)
-
-__LXSYSCALL4(int,
-             getxattr,
-             const char*,
-             path,
-             const char*,
-             name,
-             void*,
-             value,
-             size_t,
-             len)
-
-__LXSYSCALL4(int,
-             setxattr,
-             const char*,
-             path,
-             const char*,
-             name,
-             void*,
-             value,
-             size_t,
-             len)
-
-__LXSYSCALL4(int,
-             fgetxattr,
-             int,
-             fd,
-             const char*,
-             name,
-             void*,
-             value,
-             size_t,
-             len)
-
-__LXSYSCALL4(int,
-             fsetxattr,
-             int,
-             fd,
-             const char*,
-             name,
-             void*,
-             value,
-             size_t,
-             len)
-
-#endif /* __LUNAIX_FCTRL_H */
index 0bb6ac4821a8951ac3258bc01cde2c4d93297266..46b1500ae442ae8c63cae2f627cb92a43466e8a8 100644 (file)
@@ -1,14 +1,6 @@
 #ifndef __LUNAIX_FOPTIONS_H
 #define __LUNAIX_FOPTIONS_H
 
-#define FO_CREATE 0x1
-#define FO_APPEND 0x2
-#define FO_DIRECT 0x4
-
-#define FSEEK_SET 0x1
-#define FSEEK_CUR 0x2
-#define FSEEK_END 0x3
-
-#define MNT_RO 0x1
+#include <usr/fcntl_defs.h>
 
 #endif /* __LUNAIX_FOPTIONS_H */
index e074bbaaf65217554a4cde9c9ae48997586a23b4..f72d41e866f138f91a9bcff3e6a265aa495d5d7c 100644 (file)
@@ -1,19 +1,6 @@
 #ifndef __LUNAIX_IOCTL_H
 #define __LUNAIX_IOCTL_H
 
-#include <lunaix/syscall.h>
-
-#define IOREQ(cmd, arg_num) ((((cmd)&0xffff) << 8) | ((arg_num)&0xff))
-
-#define IOCMD(req) ((req) >> 8)
-
-#define IOARGNUM(req) ((req)&0xff)
-
-#define TIOCGPGRP IOREQ(1, 0)
-#define TIOCSPGRP IOREQ(1, 1)
-#define TIOCCLSBUF IOREQ(2, 0)
-#define TIOCFLUSH IOREQ(3, 0)
-
-__LXSYSCALL2_VARG(int, ioctl, int, fd, int, req);
+#include <usr/sys/ioctl_defs.h>
 
 #endif /* __LUNAIX_IOCTL_H */
diff --git a/lunaix-os/includes/lunaix/lunistd.h b/lunaix-os/includes/lunaix/lunistd.h
deleted file mode 100644 (file)
index 9f2ef9e..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef __LUNAIX_UNISTD_H
-#define __LUNAIX_UNISTD_H
-
-#include <lunaix/syscall.h>
-#include <lunaix/types.h>
-#include <stddef.h>
-
-__LXSYSCALL(pid_t, fork)
-
-__LXSYSCALL1(int, sbrk, void*, addr)
-
-__LXSYSCALL1(void*, brk, unsigned long, size)
-
-__LXSYSCALL(pid_t, getpid)
-
-__LXSYSCALL(pid_t, getppid)
-
-__LXSYSCALL(pid_t, getpgid)
-
-__LXSYSCALL2(pid_t, setpgid, pid_t, pid, pid_t, pgid)
-
-__LXSYSCALL1(void, _exit, int, status)
-
-__LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
-
-__LXSYSCALL(int, pause)
-
-__LXSYSCALL2(int, kill, pid_t, pid, int, signum)
-
-__LXSYSCALL1(unsigned int, alarm, unsigned int, seconds)
-
-__LXSYSCALL2(int, link, const char*, oldpath, const char*, newpath)
-
-__LXSYSCALL1(int, rmdir, const char*, pathname)
-
-__LXSYSCALL3(int, read, int, fd, void*, buf, unsigned int, count)
-
-__LXSYSCALL3(int, write, int, fd, void*, buf, unsigned int, count)
-
-__LXSYSCALL3(int, readlink, const char*, path, char*, buf, size_t, size)
-
-__LXSYSCALL3(int, lseek, int, fd, int, offset, int, options)
-
-__LXSYSCALL1(int, unlink, const char*, pathname)
-
-__LXSYSCALL1(int, close, int, fd)
-
-__LXSYSCALL2(int, dup2, int, oldfd, int, newfd)
-
-__LXSYSCALL1(int, dup, int, oldfd)
-
-__LXSYSCALL1(int, fsync, int, fildes)
-
-__LXSYSCALL2(int, symlink, const char*, pathname, const char*, link_target)
-
-__LXSYSCALL1(int, chdir, const char*, path)
-
-__LXSYSCALL1(int, fchdir, int, fd)
-
-__LXSYSCALL2(char*, getcwd, char*, buf, size_t, size)
-
-__LXSYSCALL2(int, rename, const char*, oldpath, const char*, newpath)
-
-#endif /* __LUNAIX_UNISTD_H */
diff --git a/lunaix-os/includes/lunaix/lxsignal.h b/lunaix-os/includes/lunaix/lxsignal.h
deleted file mode 100644 (file)
index 5b54ffc..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef __LUNAIX_LXSIGNAL_H
-#define __LUNAIX_LXSIGNAL_H
-
-#include <lunaix/types.h>
-
-int
-signal_send(pid_t pid, int signum);
-
-#endif /* __LUNAIX_LXSIGNAL_H */
index 43cfb990b30023906adda352ee882df29e0383ad..55859ba37f749ac4b5075f85d6c446cb3dd58354 100644 (file)
@@ -1,21 +1,21 @@
 #ifndef __LUNAIX_SIGNAL_H
 #define __LUNAIX_SIGNAL_H
 
-#include <lunaix/syscall.h>
+#include <usr/signal_defs.h>
 
 #define _SIG_NUM 16
 
 #define _SIG_PENDING(bitmap, sig) ((bitmap) & (1 << (sig)))
 
-#define _SIGSEGV 1
-#define _SIGALRM 2
-#define _SIGCHLD 3
-#define _SIGCLD _SIGCHLD
-#define _SIGINT 4
-#define _SIGKILL 5
-#define _SIGSTOP 6
-#define _SIGCONT 7
-#define _SIGTERM 8
+#define _SIGSEGV SIGSEGV
+#define _SIGALRM SIGALRM
+#define _SIGCHLD SIGCHLD
+#define _SIGCLD SIGCLD
+#define _SIGINT SIGINT
+#define _SIGKILL SIGKILL
+#define _SIGSTOP SIGSTOP
+#define _SIGCONT SIGCONT
+#define _SIGTERM SIGTERM
 
 #define __SIGNAL(num) (1 << (num))
 #define __SIGSET(bitmap, num) (bitmap = bitmap | __SIGNAL(num))
 
 #define _SIGNAL_UNMASKABLE (__SIGNAL(_SIGKILL) | __SIGNAL(_SIGSTOP))
 
-#define _SIG_BLOCK 1
-#define _SIG_UNBLOCK 2
-#define _SIG_SETMASK 3
-
-typedef unsigned int sigset_t;
-typedef void (*sighandler_t)(int);
-
-__LXSYSCALL2(int, signal, int, signum, sighandler_t, handler);
-
-__LXSYSCALL1(int, sigpending, sigset_t, *set);
-__LXSYSCALL1(int, sigsuspend, const sigset_t, *mask);
-
-__LXSYSCALL3(int,
-             sigprocmask,
-             int,
-             how,
-             const sigset_t,
-             *set,
-             sigset_t,
-             *oldset);
+#define _SIG_BLOCK SIG_BLOCK
+#define _SIG_UNBLOCK SIG_UNBLOCK
+#define _SIG_SETMASK SIG_SETMASK
 
 #endif /* __LUNAIX_SIGNAL_H */
index 8da4dc5c91b65458f980259839f156aa94c26e09..6c4225202fde2cef1d171a573c013578699efbc8 100644 (file)
@@ -112,49 +112,48 @@ syscall_install();
     return (rettype)v;
 
 #define __LXSYSCALL(rettype, name)                                             \
-    static rettype name()                                                      \
+    rettype name()                                                             \
     {                                                                          \
         ___DOINT33(__SYSCALL_##name, rettype)                                  \
     }
 
 #define __LXSYSCALL1(rettype, name, t1, p1)                                    \
-    static rettype name(__PARAM_MAP1(t1, p1))                                  \
+    rettype name(__PARAM_MAP1(t1, p1))                                         \
     {                                                                          \
         asm("" ::"b"(p1));                                                     \
         ___DOINT33(__SYSCALL_##name, rettype)                                  \
     }
 
 #define __LXSYSCALL2(rettype, name, t1, p1, t2, p2)                            \
-    static rettype name(__PARAM_MAP2(t1, p1, t2, p2))                          \
+    rettype name(__PARAM_MAP2(t1, p1, t2, p2))                                 \
     {                                                                          \
         asm("\n" ::"b"(p1), "c"(p2));                                          \
         ___DOINT33(__SYSCALL_##name, rettype)                                  \
     }
 
 #define __LXSYSCALL3(rettype, name, t1, p1, t2, p2, t3, p3)                    \
-    static rettype name(__PARAM_MAP3(t1, p1, t2, p2, t3, p3))                  \
+    rettype name(__PARAM_MAP3(t1, p1, t2, p2, t3, p3))                         \
     {                                                                          \
         asm("\n" ::"b"(p1), "c"(p2), "d"(p3));                                 \
         ___DOINT33(__SYSCALL_##name, rettype)                                  \
     }
 
 #define __LXSYSCALL4(rettype, name, t1, p1, t2, p2, t3, p3, t4, p4)            \
-    static rettype name(__PARAM_MAP4(t1, p1, t2, p2, t3, p3, t4, p4))          \
+    rettype name(__PARAM_MAP4(t1, p1, t2, p2, t3, p3, t4, p4))                 \
     {                                                                          \
         asm("\n" ::"b"(p1), "c"(p2), "d"(p3), "D"(p4));                        \
         ___DOINT33(__SYSCALL_##name, rettype)                                  \
     }
 
 #define __LXSYSCALL5(rettype, name, t1, p1, t2, p2, t3, p3, t4, p4, t5, p5)    \
-    static rettype name(__PARAM_MAP5(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5))  \
+    rettype name(__PARAM_MAP5(t1, p1, t2, p2, t3, p3, t4, p4, t5, p5))         \
     {                                                                          \
         asm("" ::"r"(p5), "b"(p1), "c"(p2), "d"(p3), "D"(p4), "S"(p5));        \
         ___DOINT33(__SYSCALL_##name, rettype)                                  \
     }
 
 #define __LXSYSCALL2_VARG(rettype, name, t1, p1, t2, p2)                       \
-    __attribute__((noinline)) static rettype name(                             \
-      __PARAM_MAP2(t1, p1, t2, p2), ...)                                       \
+    __attribute__((noinline)) rettype name(__PARAM_MAP2(t1, p1, t2, p2), ...)  \
     {                                                                          \
         /* No inlining! This depends on the call frame assumption */           \
         void* _last = (void*)&p2 + sizeof(void*);                              \
index 0d1ad197fa05c8bb75bf4916ab7192c1e97ea431..7e6562c55c204d330b62e357a0be74b3d2cea7ba 100644 (file)
@@ -5,21 +5,6 @@
 #include <stdint.h>
 #include <usr/sys/types.h>
 
-#define PEXITTERM 0x100
-#define PEXITSTOP 0x200
-#define PEXITSIG 0x400
-
-#define PEXITNUM(flag, code) (flag | (code & 0xff))
-
-#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))
-
-#define WIFSIGNALED(wstatus) ((wstatus & PEXITSIG))
-
 #define PACKED __attribute__((packed))
 
 // TODO: WTERMSIG
diff --git a/lunaix-os/includes/usr/errno.h b/lunaix-os/includes/usr/errno.h
new file mode 100644 (file)
index 0000000..5b9b51b
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __LUNAIX_SYS_ERRNO_H
+#define __LUNAIX_SYS_ERRNO_H
+
+int
+geterrno();
+
+#define errno (geterrno())
+
+#endif /* __LUNAIX_ERRNO_H */
diff --git a/lunaix-os/includes/usr/fcntl.h b/lunaix-os/includes/usr/fcntl.h
new file mode 100644 (file)
index 0000000..2a83c93
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __LUNAIX_SYS_FCNTL_H
+#define __LUNAIX_SYS_FCNTL_H
+
+#include <usr/fcntl_defs.h>
+#include <usr/sys/types.h>
+
+int
+open(const char* path, int flags);
+
+#endif /* __LUNAIX_FCNTL_H */
diff --git a/lunaix-os/includes/usr/fcntl_defs.h b/lunaix-os/includes/usr/fcntl_defs.h
new file mode 100644 (file)
index 0000000..01930cb
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef __LUNAIX_SYS_FCNTL_DEFS_H
+#define __LUNAIX_SYS_FCNTL_DEFS_H
+
+#define FO_CREATE 0x1
+#define FO_APPEND 0x2
+#define FO_DIRECT 0x4
+
+#define FSEEK_SET 0x1
+#define FSEEK_CUR 0x2
+#define FSEEK_END 0x3
+
+#define MNT_RO 0x1
+
+#endif /* __LUNAIX_FNCTL_DEFS_H */
diff --git a/lunaix-os/includes/usr/signal.h b/lunaix-os/includes/usr/signal.h
new file mode 100644 (file)
index 0000000..cc7c7ed
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef __LUNAIX_SYS_SIGNAL_H
+#define __LUNAIX_SYS_SIGNAL_H
+
+#include <usr/signal_defs.h>
+#include <usr/sys/types.h>
+
+int
+signal(int signum, sighandler_t handler);
+
+int
+sigpending(sigset_t* set);
+
+int
+sigsuspend(const sigset_t* mask);
+
+int
+sigprocmask(int how, const sigset_t* set, sigset_t* oldset);
+
+#endif /* __LUNAIX_SIGNAL_H */
diff --git a/lunaix-os/includes/usr/signal_defs.h b/lunaix-os/includes/usr/signal_defs.h
new file mode 100644 (file)
index 0000000..ac102ab
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __LUNAIX_SYS_SIGNAL_DEFS_H
+#define __LUNAIX_SYS_SIGNAL_DEFS_H
+
+#define SIGSEGV 1
+#define SIGALRM 2
+#define SIGCHLD 3
+#define SIGCLD SIGCHLD
+#define SIGINT 4
+#define SIGKILL 5
+#define SIGSTOP 6
+#define SIGCONT 7
+#define SIGTERM 8
+
+#define SIG_BLOCK 1
+#define SIG_UNBLOCK 2
+#define SIG_SETMASK 3
+
+typedef unsigned int sigset_t;
+typedef void (*sighandler_t)(int);
+
+#endif /* __LUNAIX_SIGNAL_DEFS_H */
diff --git a/lunaix-os/includes/usr/sys/dirent.h b/lunaix-os/includes/usr/sys/dirent.h
new file mode 100644 (file)
index 0000000..54334d3
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __LUNAIX_SYS_DIRENT_H
+#define __LUNAIX_SYS_DIRENT_H
+
+#include <usr/sys/dirent_defs.h>
+
+int
+sys_readdir(int fd, struct lx_dirent* dirent);
+
+#endif /* __LUNAIX_DIRENT_H */
diff --git a/lunaix-os/includes/usr/sys/dirent_defs.h b/lunaix-os/includes/usr/sys/dirent_defs.h
new file mode 100644 (file)
index 0000000..7792355
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef __LUNAIX_SYS_DIRENT_DEFS_H
+#define __LUNAIX_SYS_DIRENT_DEFS_H
+
+#define DIRENT_NAME_MAX_LEN 256
+
+#define DT_FILE 0x0
+#define DT_DIR 0x1
+#define DT_SYMLINK 0x2
+#define DT_PIPE 0x2
+
+struct lx_dirent
+{
+    unsigned int d_type;
+    unsigned int d_offset;
+    unsigned int d_nlen;
+    char d_name[DIRENT_NAME_MAX_LEN];
+};
+
+#endif /* __LUNAIX_DIRENT_DEFS_H */
diff --git a/lunaix-os/includes/usr/sys/ioctl.h b/lunaix-os/includes/usr/sys/ioctl.h
new file mode 100644 (file)
index 0000000..827cd44
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef __LUNAIX_SYS_IOCTL_H
+#define __LUNAIX_SYS_IOCTL_H
+
+int
+ioctl(int fd, int req, ...);
+
+#endif /* __LUNAIX_IOCTL_H */
diff --git a/lunaix-os/includes/usr/sys/ioctl_defs.h b/lunaix-os/includes/usr/sys/ioctl_defs.h
new file mode 100644 (file)
index 0000000..7be48e7
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __LUNAIX_SYS_IOCTL_DEFS_H
+#define __LUNAIX_SYS_IOCTL_DEFS_H
+
+#define IOREQ(cmd, arg_num) ((((cmd)&0xffff) << 8) | ((arg_num)&0xff))
+
+#define IOCMD(req) ((req) >> 8)
+
+#define IOARGNUM(req) ((req)&0xff)
+
+#define TIOCGPGRP IOREQ(1, 0)
+#define TIOCSPGRP IOREQ(1, 1)
+#define TIOCCLSBUF IOREQ(2, 0)
+#define TIOCFLUSH IOREQ(3, 0)
+
+#endif /* __LUNAIX_IOCTL_DEFS_H */
diff --git a/lunaix-os/includes/usr/sys/lunaix.h b/lunaix-os/includes/usr/sys/lunaix.h
new file mode 100644 (file)
index 0000000..b5ba65e
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef __LUNAIX_SYS_LUNAIX_H
+#define __LUNAIX_SYS_LUNAIX_H
+
+#include <usr/sys/types.h>
+
+void
+yield();
+
+pid_t
+wait(int* status);
+
+pid_t
+waitpid(pid_t pid, int* status, int flags);
+
+void
+syslog(int level, const char* fmt, ...);
+
+int
+realpathat(int fd, char* buf, size_t size);
+
+#endif /* __LUNAIX_LUNAIX_H */
diff --git a/lunaix-os/includes/usr/sys/mount.h b/lunaix-os/includes/usr/sys/mount.h
new file mode 100644 (file)
index 0000000..0a5a5a5
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef __LUNAIX_SYS_MOUNT_H
+#define __LUNAIX_SYS_MOUNT_H
+
+#include <usr/sys/types.h>
+
+int
+mount(const char* source, const char* target, const char* fstype, int flags);
+
+int
+unmount(const char* target);
+
+static inline int
+umount(const char* target)
+{
+    return unmount(target);
+}
+#endif /* __LUNAIX_MOUNT_H */
index 712d6877239e87e8f8ac274da1645817e169f60e..a4b7f2999d84e81ca71959a85ae704f13f8d5f72 100644 (file)
@@ -1,6 +1,21 @@
 #ifndef __LUNAIX_SYS_TYPES_H
 #define __LUNAIX_SYS_TYPES_H
 
+#define PEXITTERM 0x100
+#define PEXITSTOP 0x200
+#define PEXITSIG 0x400
+
+#define PEXITNUM(flag, code) (flag | (code & 0xff))
+
+#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))
+
+#define WIFSIGNALED(wstatus) ((wstatus & PEXITSIG))
+
 typedef signed long ssize_t;
 
 typedef int pid_t;
diff --git a/lunaix-os/includes/usr/unistd.h b/lunaix-os/includes/usr/unistd.h
new file mode 100644 (file)
index 0000000..92992be
--- /dev/null
@@ -0,0 +1,111 @@
+#ifndef __LUNAIX_SYS_UNISTD_H
+#define __LUNAIX_SYS_UNISTD_H
+
+#include <usr/sys/types.h>
+
+pid_t
+fork();
+
+pid_t
+getpid();
+
+pid_t
+getppid();
+
+pid_t
+getpgid();
+
+pid_t
+setpgid(pid_t pid, pid_t pgid);
+
+int
+sbrk(void* addr);
+
+void*
+brk(size_t size);
+
+void
+_exit(int status);
+
+unsigned int
+sleep(unsigned int);
+
+int
+pause();
+
+int
+kill(pid_t pid, int signum);
+
+unsigned int
+alarm(unsigned int seconds);
+
+int
+link(const char* oldpath, const char* newpath);
+
+int
+rmdir(const char* pathname);
+
+int
+read(int fd, void* buf, size_t size);
+
+int
+write(int fd, void* buf, size_t size);
+
+int
+readlink(const char* path, char* buffer, size_t size);
+
+int
+readlinkat(int dirfd, const char* pathname, char* buffer, size_t size);
+
+int
+lseek(int fd, off_t offset, int mode);
+
+int
+unlink(const char* pathname);
+
+int
+unlinat(int fd, const char* pathname);
+
+int
+mkdir(const char* path);
+
+int
+close(int fd);
+
+int
+dup2(int oldfd, int newfd);
+
+int
+dup(int oldfd);
+
+int
+fsync(int fd);
+
+int
+symlink(const char* pathname, const char* linktarget);
+
+int
+chdir(const char* path);
+
+int
+fchdir(int fd);
+
+char*
+getcwd(char* buf, size_t size);
+
+int
+rename(const char* oldpath, const char* newpath);
+
+int
+getxattr(const char* path, const char* name, void* value, size_t len);
+
+int
+setxattr(const char* path, const char* name, void* value, size_t len);
+
+int
+fgetxattr(int fd, const char* name, void* value, size_t len);
+
+int
+fsetxattr(int fd, const char* name, void* value, size_t len);
+
+#endif /* __LUNAIX_UNISTD_H */
index bbaf59f407655225f86794fd6c0025e3af7c7374..7b8a12bbeb096da41545e5cb8c00e46e7e798ef3 100644 (file)
@@ -1,11 +1,11 @@
 #include <arch/x86/interrupts.h>
 #include <lunaix/common.h>
-#include <lunaix/lxsignal.h>
 #include <lunaix/mm/mm.h>
 #include <lunaix/mm/pmm.h>
 #include <lunaix/mm/region.h>
 #include <lunaix/mm/vmm.h>
 #include <lunaix/sched.h>
+#include <lunaix/signal.h>
 #include <lunaix/status.h>
 #include <lunaix/syslog.h>
 
index 70070a1eafe3753413a5691e119d3f0f381b4689..c97dfc9f1442884c0b646f3c7c8375cce501d5ea 100644 (file)
@@ -1,27 +1,27 @@
-#include <lunaix/dirent.h>
-#include <lunaix/fctrl.h>
-#include <lunaix/lunaix.h>
-#include <lunaix/lunistd.h>
+#include <usr/errno.h>
+#include <usr/fcntl.h>
+#include <usr/sys/dirent.h>
+#include <usr/unistd.h>
 
 void
 _readdir_main()
 {
     int fd = open("/dev/./../dev/.", 0);
     if (fd == -1) {
-        printf("fail to open (%d)\n", geterrno());
+        printf("fail to open (%d)\n", errno);
         return;
     }
 
     char path[129];
     int len = realpathat(fd, path, 128);
     if (len < 0) {
-        printf("fail to read (%d)\n", geterrno());
+        printf("fail to read (%d)\n", errno);
     } else {
         path[len] = 0;
         printf("%s\n", path);
     }
 
-    struct dirent ent = { .d_offset = 0 };
+    struct lx_dirent ent = { .d_offset = 0 };
 
     while (sys_readdir(fd, &ent) == 1) {
         printf("%s\n", ent.d_name);
index 47e0081190ca066fa035be7a7a8e7fac44e0281f..f24a519dde92bc37973f00853a040104ad4e484c 100644 (file)
@@ -1,9 +1,10 @@
-#include <lunaix/fctrl.h>
-#include <lunaix/foptions.h>
 #include <lunaix/input.h>
-#include <lunaix/lunaix.h>
-#include <lunaix/lunistd.h>
+
 #include <ulibc/stdio.h>
+#include <usr/errno.h>
+#include <usr/fcntl.h>
+#include <usr/sys/lunaix.h>
+#include <usr/unistd.h>
 
 #define STDIN 1
 #define STDOUT 0
@@ -14,7 +15,7 @@ input_test()
     int fd = open("/dev/input/i8042-kbd", 0);
 
     if (fd < 0) {
-        printf("fail to open (%d)", geterrno());
+        printf("fail to open (%d)", errno);
         return;
     }
 
index cba89623af1ab9c3dc6893bf84195385380ca23e..91c3571043e3a09893bf14857c2cb9c31c90ed88 100644 (file)
@@ -1,8 +1,8 @@
-#include <lunaix/fctrl.h>
-#include <lunaix/foptions.h>
-#include <lunaix/lunaix.h>
-#include <lunaix/lunistd.h>
 #include <ulibc/stdio.h>
+#include <usr/errno.h>
+#include <usr/fcntl.h>
+#include <usr/sys/lunaix.h>
+#include <usr/unistd.h>
 
 void
 _iotest_main()
@@ -13,8 +13,8 @@ _iotest_main()
     char read_out[256];
 
     // 切换工作目录至 /dev
-    int errno = chdir("/dev");
-    if (errno) {
+    int status = chdir("/dev");
+    if (status) {
         write(stdout, "fail to chdir", 15);
         return;
     }
@@ -29,7 +29,7 @@ _iotest_main()
     int fd = open("./sda", 0);
 
     if (fd < 0) {
-        printf("fail to open (%d)\n", geterrno());
+        printf("fail to open (%d)\n", errno);
         return;
     }
 
index 3878a1881512cba292868e1cf1cc45b730e7da20..4d7897e41c8c1de1807deda0c77dd8e3e9d2689c 100644 (file)
@@ -1,10 +1,11 @@
-#include <lunaix/lunaix.h>
-#include <lunaix/lunistd.h>
-#include <lunaix/signal.h>
 #include <lunaix/spike.h>
-#include <lunaix/types.h>
+
 #include <ulibc/stdio.h>
 
+#include <usr/signal.h>
+#include <usr/sys/lunaix.h>
+#include <usr/unistd.h>
+
 void __USER__
 sigchild_handler(int signum)
 {
@@ -29,9 +30,9 @@ sigalrm_handler(int signum)
 void __USER__
 _signal_demo_main()
 {
-    signal(_SIGCHLD, sigchild_handler);
-    signal(_SIGSEGV, sigsegv_handler);
-    signal(_SIGALRM, sigalrm_handler);
+    signal(SIGCHLD, sigchild_handler);
+    signal(SIGSEGV, sigsegv_handler);
+    signal(SIGALRM, sigalrm_handler);
 
     alarm(5);
 
@@ -51,7 +52,7 @@ _signal_demo_main()
     for (int i = 0; i < 5; i++) {
         pid_t pid = 0;
         if (!(pid = fork())) {
-            signal(_SIGSEGV, sigsegv_handler);
+            signal(SIGSEGV, sigsegv_handler);
             sleep(i);
             if (i == 3) {
                 i = *(int*)0xdeadc0de; // seg fault!
index 8bb357bef15f741b284da29f6f0fb7e6008c97f3..26aa3bed4866026faea6a955b99f7e700cb7c537 100644 (file)
@@ -1,12 +1,12 @@
-#include <lunaix/fctrl.h>
-#include <lunaix/foptions.h>
 #include <lunaix/ioctl.h>
-#include <lunaix/lunaix.h>
-#include <lunaix/lunistd.h>
-#include <lunaix/signal.h>
 #include <lunaix/status.h>
 
+#include <usr/fcntl.h>
+#include <usr/signal.h>
+#include <usr/sys/dirent.h>
+#include <usr/sys/lunaix.h>
 #include <usr/sys/mann.h>
+#include <usr/unistd.h>
 
 #include <klibc/string.h>
 #include <ulibc/stdio.h>
@@ -101,7 +101,7 @@ do_ls(const char* path)
     if (fd < 0) {
         sh_printerr();
     } else {
-        struct dirent ent = { .d_offset = 0 };
+        struct lx_dirent ent = { .d_offset = 0 };
         int status;
         while ((status = sys_readdir(fd, &ent)) == 1) {
             if (ent.d_type == DT_DIR) {
@@ -125,7 +125,7 @@ do_mcat(const char* file)
     if (fd < 0) {
         sh_printerr();
     } else {
-        ptr_t p = mmap(NULL, 2048, 0, 0, fd, 0);
+        void* p = mmap(NULL, 2048, 0, 0, fd, 0);
         if ((int)p < 0) {
             sh_printerr();
         } else {
@@ -143,7 +143,7 @@ sh_loop()
     char buf[512];
     char *cmd, *argpart;
     pid_t p;
-    signal(_SIGINT, sigint_handle);
+    signal(SIGINT, sigint_handle);
 
     // set our shell as foreground process
     // (unistd.h:tcsetpgrp is essentially a wrapper of this)
index c265c4b36aa3b08e4e2b598ad8edd57da28b7b6e..69de7fa62cb2fa29b56bf7eaaead3b483252975d 100644 (file)
@@ -1,9 +1,10 @@
 #include <lunaix/device.h>
-#include <lunaix/dirent.h>
 #include <lunaix/fs.h>
 #include <lunaix/fs/devfs.h>
 #include <lunaix/spike.h>
 
+#include <usr/sys/dirent_defs.h>
+
 extern struct v_inode_ops devfs_inode_ops;
 extern struct v_file_ops devfs_file_ops;
 
index c3150dcbb64426b7da5bd2fe5c4ed5469694a2be..71da904459f6cd3a9b5ad545b1204d8a9929bd15 100644 (file)
@@ -1,4 +1,3 @@
-#include <lunaix/dirent.h>
 #include <lunaix/fs.h>
 #include <lunaix/fs/iso9660.h>
 #include <lunaix/mm/cake.h>
@@ -7,6 +6,8 @@
 
 #include <klibc/string.h>
 
+#include <usr/sys/dirent_defs.h>
+
 extern struct cake_pile* drec_cache_pile;
 
 void
index cbe3c39ab507a8021d453b01ab38f07803858bdb..e436eba969c1fea7e88a863adf9e518e579b7514 100644 (file)
@@ -44,7 +44,6 @@
 */
 
 #include <klibc/string.h>
-#include <lunaix/dirent.h>
 #include <lunaix/foptions.h>
 #include <lunaix/fs.h>
 #include <lunaix/mm/cake.h>
@@ -57,6 +56,8 @@
 
 #include <lunaix/fs/twifs.h>
 
+#include <usr/sys/dirent_defs.h>
+
 static struct cake_pile* dnode_pile;
 static struct cake_pile* inode_pile;
 static struct cake_pile* file_pile;
@@ -625,13 +626,13 @@ __vfs_readdir_callback(struct dir_context* dctx,
                        const int len,
                        const int dtype)
 {
-    struct dirent* dent = (struct dirent*)dctx->cb_data;
+    struct lx_dirent* dent = (struct lx_dirent*)dctx->cb_data;
     strncpy(dent->d_name, name, DIRENT_NAME_MAX_LEN);
     dent->d_nlen = len;
     dent->d_type = dtype;
 }
 
-__DEFINE_LXSYSCALL2(int, sys_readdir, int, fd, struct dirent*, dent)
+__DEFINE_LXSYSCALL2(int, sys_readdir, int, fd, struct lx_dirent*, dent)
 {
     struct v_fd* fd_s;
     int errno;
index f53405ab051acc45beddbac5186351131b7e07a8..d4622c92d3f7e7b198ca9bcc323c07e9382251fa 100644 (file)
@@ -1,7 +1,5 @@
 #include <hal/cpu.h>
 #include <lunaix/clock.h>
-#include <lunaix/lunaix.h>
-#include <lunaix/lunistd.h>
 #include <lunaix/lxconsole.h>
 #include <lunaix/mm/kalloc.h>
 #include <lunaix/mm/vmm.h>
@@ -9,6 +7,9 @@
 #include <lunaix/syslog.h>
 #include <lunaix/timer.h>
 
+#include <usr/sys/lunaix.h>
+#include <usr/unistd.h>
+
 extern uint8_t __kernel_start;
 
 LOG_MODULE("INIT")
index 19f04dce4d077b59bcd7c47099071ee5dc69d7b7..259c8bbaef8fea02454780edec13cf0a2b6e4783 100644 (file)
@@ -1,11 +1,8 @@
 #include <lunaix/block.h>
 #include <lunaix/common.h>
-#include <lunaix/fctrl.h>
 #include <lunaix/foptions.h>
 #include <lunaix/fs.h>
 #include <lunaix/fs/twifs.h>
-#include <lunaix/lunaix.h>
-#include <lunaix/lunistd.h>
 #include <lunaix/lxconsole.h>
 #include <lunaix/mm/cake.h>
 #include <lunaix/mm/pmm.h>
 #include <lunaix/syslog.h>
 #include <lunaix/types.h>
 
+#include <usr/fcntl.h>
+#include <usr/sys/lunaix.h>
+#include <usr/unistd.h>
+
 #include <sdbg/protocol.h>
 
 #include <hal/acpi/acpi.h>
index 9a9a34999dc86b19bf461b713c897b13357424c2..0f43b1f65216adc7d1dfadae52f365318b40248e 100644 (file)
@@ -1,6 +1,3 @@
-#include <klibc/string.h>
-#include <lunaix/lunistd.h>
-#include <lunaix/lxsignal.h>
 #include <lunaix/process.h>
 #include <lunaix/sched.h>
 #include <lunaix/signal.h>
@@ -8,6 +5,8 @@
 #include <lunaix/status.h>
 #include <lunaix/syscall.h>
 
+#include <klibc/string.h>
+
 extern struct scheduler sched_ctx; /* kernel/sched.c */
 
 void __USER__
index 753470306ea4b852bff5154ad543873d8559ceda..6507eb1d9b292453ff615738554b4e7f209cc329 100644 (file)
@@ -1,4 +1,3 @@
-#include <lunaix/dirent.h>
 #include <lunaix/fs/taskfs.h>
 #include <lunaix/fs/twimap.h>
 #include <lunaix/mm/valloc.h>
@@ -8,6 +7,8 @@
 #include <klibc/stdio.h>
 #include <klibc/string.h>
 
+#include <usr/sys/dirent_defs.h>
+
 #define COUNTER_MASK ((1 << 16) - 1)
 
 static struct hbucket* attr_export_table;
index 21802bed7a66f84bc2234f1bd4ff131d38163015..adf577a6ed5339c6d98b22229abe6d7d67460cb8 100644 (file)
@@ -8,11 +8,10 @@
 #include <lunaix/mm/valloc.h>
 #include <lunaix/mm/vmm.h>
 #include <lunaix/sched.h>
+#include <lunaix/signal.h>
 #include <lunaix/tty/console.h>
 #include <lunaix/tty/tty.h>
 
-#include <lunaix/lxsignal.h>
-
 static struct console lx_console;
 
 int
index 18e23876a289e86d2fdad557a37e3c714f3d31db..86c0b18a2d0304fb26e707e24b33053a1512aade 100644 (file)
@@ -1,8 +1,9 @@
 #include <klibc/stdio.h>
-#include <lunaix/lunistd.h>
 #include <lunaix/spike.h>
 #include <ulibc/stdio.h>
 
+#include <usr/unistd.h>
+
 // This is VERY bad implementation as it mixes both kernel and user space
 // code together. It is here however, just for the convenience of our testing
 // program.
diff --git a/lunaix-os/usr/api/dirent.c b/lunaix-os/usr/api/dirent.c
new file mode 100644 (file)
index 0000000..403d4e3
--- /dev/null
@@ -0,0 +1,4 @@
+#include <lunaix/syscall.h>
+#include <usr/sys/dirent.h>
+
+__LXSYSCALL2(int, sys_readdir, int, fd, struct lx_dirent*, dent)
diff --git a/lunaix-os/usr/api/errno.c b/lunaix-os/usr/api/errno.c
new file mode 100644 (file)
index 0000000..27b4124
--- /dev/null
@@ -0,0 +1,4 @@
+#include <lunaix/syscall.h>
+#include <usr/errno.h>
+
+__LXSYSCALL(int, geterrno);
\ No newline at end of file
diff --git a/lunaix-os/usr/api/fcntl.c b/lunaix-os/usr/api/fcntl.c
new file mode 100644 (file)
index 0000000..05a2cd4
--- /dev/null
@@ -0,0 +1,4 @@
+#include <lunaix/syscall.h>
+#include <usr/fcntl.h>
+
+__LXSYSCALL2(int, open, const char*, path, int, options)
diff --git a/lunaix-os/usr/api/ioctl.c b/lunaix-os/usr/api/ioctl.c
new file mode 100644 (file)
index 0000000..d9ee35b
--- /dev/null
@@ -0,0 +1,4 @@
+#include <lunaix/syscall.h>
+#include <usr/sys/ioctl.h>
+
+__LXSYSCALL2_VARG(int, ioctl, int, fd, int, req);
\ No newline at end of file
similarity index 62%
rename from lunaix-os/includes/lunaix/lunaix.h
rename to lunaix-os/usr/api/lunaix.c
index adbde1dca148513d2c627aaa8994bacc015183e9..c6c5f81c2c325e16433711269395a44c45a4be31 100644 (file)
@@ -1,8 +1,5 @@
-#ifndef __LUNAIX_LUNAIX_H
-#define __LUNAIX_LUNAIX_H
-
 #include <lunaix/syscall.h>
-#include <lunaix/types.h>
+#include <usr/sys/lunaix.h>
 
 __LXSYSCALL(void, yield);
 
@@ -10,8 +7,6 @@ __LXSYSCALL1(pid_t, wait, int*, status);
 
 __LXSYSCALL3(pid_t, waitpid, pid_t, pid, int*, status, int, options);
 
-__LXSYSCALL(int, geterrno);
-
 __LXSYSCALL2_VARG(void, syslog, int, level, const char*, fmt);
 
-#endif /* __LUNAIX_LUNAIX_H */
+__LXSYSCALL3(int, realpathat, int, fd, char*, buf, size_t, size)
diff --git a/lunaix-os/usr/api/mount.c b/lunaix-os/usr/api/mount.c
new file mode 100644 (file)
index 0000000..e073f37
--- /dev/null
@@ -0,0 +1,15 @@
+#include <lunaix/syscall.h>
+#include <usr/sys/mount.h>
+
+__LXSYSCALL4(int,
+             mount,
+             const char*,
+             source,
+             const char*,
+             target,
+             const char*,
+             fstype,
+             int,
+             options)
+
+__LXSYSCALL1(int, unmount, const char*, target)
\ No newline at end of file
diff --git a/lunaix-os/usr/api/signal.c b/lunaix-os/usr/api/signal.c
new file mode 100644 (file)
index 0000000..6e9039c
--- /dev/null
@@ -0,0 +1,16 @@
+#include <lunaix/syscall.h>
+#include <usr/signal.h>
+
+__LXSYSCALL2(int, signal, int, signum, sighandler_t, handler);
+
+__LXSYSCALL1(int, sigpending, sigset_t, *set);
+__LXSYSCALL1(int, sigsuspend, const sigset_t, *mask);
+
+__LXSYSCALL3(int,
+             sigprocmask,
+             int,
+             how,
+             const sigset_t,
+             *set,
+             sigset_t,
+             *oldset);
diff --git a/lunaix-os/usr/api/unistd.c b/lunaix-os/usr/api/unistd.c
new file mode 100644 (file)
index 0000000..bd7cb24
--- /dev/null
@@ -0,0 +1,117 @@
+#include <lunaix/syscall.h>
+#include <usr/unistd.h>
+
+__LXSYSCALL(pid_t, fork)
+
+__LXSYSCALL1(int, sbrk, void*, addr)
+
+__LXSYSCALL1(void*, brk, unsigned long, size)
+
+__LXSYSCALL(pid_t, getpid)
+
+__LXSYSCALL(pid_t, getppid)
+
+__LXSYSCALL(pid_t, getpgid)
+
+__LXSYSCALL2(pid_t, setpgid, pid_t, pid, pid_t, pgid)
+
+__LXSYSCALL1(void, _exit, int, status)
+
+__LXSYSCALL1(unsigned int, sleep, unsigned int, seconds)
+
+__LXSYSCALL(int, pause)
+
+__LXSYSCALL2(int, kill, pid_t, pid, int, signum)
+
+__LXSYSCALL1(unsigned int, alarm, unsigned int, seconds)
+
+__LXSYSCALL2(int, link, const char*, oldpath, const char*, newpath)
+
+__LXSYSCALL1(int, rmdir, const char*, pathname)
+
+__LXSYSCALL3(int, read, int, fd, void*, buf, size_t, count)
+
+__LXSYSCALL3(int, write, int, fd, void*, buf, size_t, count)
+
+__LXSYSCALL3(int, readlink, const char*, path, char*, buf, size_t, size)
+
+__LXSYSCALL3(int, lseek, int, fd, off_t, offset, int, options)
+
+__LXSYSCALL1(int, unlink, const char*, pathname)
+
+__LXSYSCALL1(int, close, int, fd)
+
+__LXSYSCALL2(int, dup2, int, oldfd, int, newfd)
+
+__LXSYSCALL1(int, dup, int, oldfd)
+
+__LXSYSCALL1(int, fsync, int, fildes)
+
+__LXSYSCALL2(int, symlink, const char*, pathname, const char*, link_target)
+
+__LXSYSCALL1(int, chdir, const char*, path)
+
+__LXSYSCALL1(int, fchdir, int, fd)
+
+__LXSYSCALL2(char*, getcwd, char*, buf, size_t, size)
+
+__LXSYSCALL2(int, rename, const char*, oldpath, const char*, newpath)
+
+__LXSYSCALL4(int,
+             getxattr,
+             const char*,
+             path,
+             const char*,
+             name,
+             void*,
+             value,
+             size_t,
+             len)
+
+__LXSYSCALL4(int,
+             setxattr,
+             const char*,
+             path,
+             const char*,
+             name,
+             void*,
+             value,
+             size_t,
+             len)
+
+__LXSYSCALL4(int,
+             fgetxattr,
+             int,
+             fd,
+             const char*,
+             name,
+             void*,
+             value,
+             size_t,
+             len)
+
+__LXSYSCALL4(int,
+             fsetxattr,
+             int,
+             fd,
+             const char*,
+             name,
+             void*,
+             value,
+             size_t,
+             len)
+
+__LXSYSCALL4(int,
+             readlinkat,
+             int,
+             dirfd,
+             const char*,
+             pathname,
+             char*,
+             buf,
+             size_t,
+             size)
+
+__LXSYSCALL2(int, unlinkat, int, fd, const char*, pathname)
+
+__LXSYSCALL1(int, mkdir, const char*, path)
\ No newline at end of file