BarryServer : Git

All the code for all my projects
// BarryServer : Git / OrionLibC / commit / 03048a95d88cc7a78171393371f5c22a0250a014 / include / sys

// Related

OrionLibC

Barry Importing existing Orion LibC 03048a9 (2 years, 2 months ago)
diff --git a/include/sys/fb.h b/include/sys/fb.h
new file mode 100644
index 0000000..b56497e
--- /dev/null
+++ b/include/sys/fb.h
@@ -0,0 +1,26 @@
+#ifndef _SYS_FB_H
+#define _SYS_FB_H
+
+#include <stdint.h>
+#include <stddef.h>
+
+/* ioctl() calls */
+enum FrameBufferIoctls {
+	FBIOGET_VSCREENINFO,
+	FBIOPUT_VSCREENINFO,
+	FBIOGET_FSCREENINFO,
+};
+
+/* Structure for fixed framebuffer info */
+typedef struct FBFixInfo {
+	uintptr_t fbmem;
+	size_t fbmemLen;
+} FBFixInfo;
+
+/* Structure for variable framebuffer info */
+typedef struct FBVarInfo {
+	uint32_t xres, yres;
+	uint32_t bpp;
+} FBVarInfo;
+
+#endif
diff --git a/include/sys/ioctl.h b/include/sys/ioctl.h
new file mode 100644
index 0000000..9c95275
--- /dev/null
+++ b/include/sys/ioctl.h
@@ -0,0 +1,6 @@
+#ifndef _SYS_IOCTL_H
+#define _SYS_IOCTL_H
+
+int ioctl(int fd, unsigned long request, ...);
+
+#endif
diff --git a/include/sys/ipc.h b/include/sys/ipc.h
new file mode 100644
index 0000000..e81e077
--- /dev/null
+++ b/include/sys/ipc.h
@@ -0,0 +1,38 @@
+#ifndef _SYS_IPC_H
+#define _SYS_IPC_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+/* Processes */
+enum Process {
+        NO_PROCESS,
+        SYSTEM,
+
+        ANY = 0xFFFFFFFF
+};
+
+/* Message encodings */
+typedef union MessageContent MessageContent;
+union MessageContent {
+	/* Generics */
+	char raw[16];
+	void *ptr;
+	uint32_t num;
+} __attribute__((__transparent_union__));
+
+/* Structure for a message */
+typedef struct Message Message;
+struct Message {
+	pid_t from;
+	uint16_t type;
+	MessageContent msg;
+	Message *next;
+} __attribute__((packed));
+
+Message *nb_send_msg(pid_t to, uint16_t type, MessageContent *msg);
+Message *send_msg(pid_t to, uint16_t type, MessageContent *msg);
+pid_t nb_recv_msg(Message *buf, pid_t from);
+pid_t recv_msg(Message *buf, pid_t from);
+
+#endif
diff --git a/include/sys/limits.h b/include/sys/limits.h
new file mode 100644
index 0000000..835e765
--- /dev/null
+++ b/include/sys/limits.h
@@ -0,0 +1,9 @@
+#ifndef _SYS_LIMITS_H
+#define _SYS_LIMITS_H
+
+#define NAME_MAX 255
+#define PATH_MAX 1024
+
+#define HOST_NAME_MAX 64
+
+#endif
diff --git a/include/sys/mman.h b/include/sys/mman.h
new file mode 100644
index 0000000..0e9518e
--- /dev/null
+++ b/include/sys/mman.h
@@ -0,0 +1,35 @@
+#ifndef _SYS_MMAN_H
+#define _SYS_MMAN_H
+
+#include <stddef.h>
+#include <sys/types.h>
+
+/* Virtual Memory Region Protection */
+enum VMRegionProt {
+	PROT_NONE,
+	PROT_EXEC = (1 << 0),
+	PROT_WRITE = (1 << 1),
+	PROT_READ = (1 << 2),
+};
+
+/* Virtual Memory Region flags */
+enum VMRegionFlag {
+	MAP_SHARED,
+	MAP_PRIVATE = (1 << 0),
+	MAP_ANONYMOUS = (1 << 1),
+};
+
+#define MAP_ANON MAP_ANONYMOUS
+#define MAP_FAILED ((void *) -1)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/sys/mount.h b/include/sys/mount.h
new file mode 100644
index 0000000..c5508ae
--- /dev/null
+++ b/include/sys/mount.h
@@ -0,0 +1,20 @@
+#ifndef _SYS_MOUNT_H
+#define _SYS_MOUNT_H
+
+#define MS_REMOUNT (1 << 0)
+#define MS_BIND    (1 << 1)
+#define MS_MOVE    (1 << 2)
+#define MS_RDONLY  (1 << 3)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int mount(const char *src, const char *target, const char *type,
+          unsigned long flags, void *data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/sys/param.h b/include/sys/param.h
new file mode 100644
index 0000000..11ca58a
--- /dev/null
+++ b/include/sys/param.h
@@ -0,0 +1,32 @@
+#ifndef _SYS_PARAM_H
+#define _SYS_PARAM_H
+
+#include <stddef.h>
+#include <sys/types.h>
+
+#define NBBY 8
+
+/* Bit map related macros.  */
+#define setbit(a,i)     ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
+#define clrbit(a,i)     ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
+#define isset(a,i)      ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
+#define isclr(a,i)      (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
+
+/* Macros for counting and rounding.  */
+#ifndef howmany
+# define howmany(x, y)  (((x) + ((y) - 1)) / (y))
+#endif
+#ifdef __GNUC__
+# define roundup(x, y)  (__builtin_constant_p (y) && powerof2 (y)             \
+                         ? (((x) + (y) - 1) & ~((y) - 1))                     \
+                         : ((((x) + ((y) - 1)) / (y)) * (y)))
+#else
+# define roundup(x, y)  ((((x) + ((y) - 1)) / (y)) * (y))
+#endif
+#define powerof2(x)     ((((x) - 1) & (x)) == 0)
+
+/* Macros for min/max.  */
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+#endif
diff --git a/include/sys/sched.h b/include/sys/sched.h
new file mode 100644
index 0000000..fe17753
--- /dev/null
+++ b/include/sys/sched.h
@@ -0,0 +1,19 @@
+#ifndef _SYS_SCHED_H
+#define _SYS_SCHED_H
+
+#include <sys/types.h>
+
+/* Flags for clone syscall */
+enum CloneFlag {
+	CLONE_NONE   = (1 << 0),
+	CLONE_PARENT = (1 << 1),
+	CLONE_THREAD = (1 << 2),
+	CLONE_FILES  = (1 << 3),
+	CLONE_FS     = (1 << 4),
+	CLONE_VM     = (1 << 5),
+	CLONE_IPC    = (1 << 6), // TODO: Add IPC namespace
+};
+
+pid_t clone(int flags);
+
+#endif
diff --git a/include/sys/stat.h b/include/sys/stat.h
new file mode 100644
index 0000000..b83cf2d
--- /dev/null
+++ b/include/sys/stat.h
@@ -0,0 +1,67 @@
+#ifndef _SYS_STAT_H
+#define _SYS_STAT_H
+
+#include <stddef.h>
+#include <sys/types.h>
+
+#define S_IFMT   0170000
+
+#define S_IFSOCK 0140000
+#define S_IFLNK  0120000
+#define S_IFREG  0100000
+#define S_IFBLK  0060000
+#define S_IFDIR  0040000
+#define S_IFCHR  0020000
+#define S_IFIFO  0010000
+
+#define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
+#define S_ISDIR(m) ((m & S_IFMT) == S_IFDIR)
+#define S_ISCHR(m) ((m & S_IFMT) == S_IFCHR)
+#define S_ISBLK(m) ((m & S_IFMT) == S_IFBLK)
+#define S_ISFIFO(m) ((m & S_IFMT) == S_IFIFO)
+#define S_ISLNK(m) ((m & S_IFMT) == S_IFLNK)
+#define S_ISSOCK(m) ((m & S_IFMT) == S_IFSOCK)
+
+#define S_ISUID 04000
+#define S_ISGID 02000
+#define S_ISVTX 01000
+
+#define S_IRWXU 00700
+#define S_IRUSR 00400
+#define S_IWUSR 00200
+#define S_IXUSR 00100
+
+#define S_IRWXG 00070
+#define S_IRGRP 00040
+#define S_IWGRP 00020
+#define S_IXGRP 00010
+
+#define S_IRWXO 00007
+#define S_IROTH 00004
+#define S_IWOTH 00002
+#define S_IXOTH 00001
+
+/* Structure for a stat() call */
+typedef struct stat {
+	ino_t inode;
+	mode_t mode;
+	nlink_t nlink;
+	uid_t uid;
+	gid_t gid;
+	size_t size;
+} Stat;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int mkdir(const char *pathname, mode_t mode);
+int mknod(const char *pathname, mode_t mode, dev_t dev);
+int stat(const char *pathname, struct stat *statbuf);
+int fstat(int fd, struct stat *statbuf);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/sys/syscall.h b/include/sys/syscall.h
new file mode 100644
index 0000000..d732c59
--- /dev/null
+++ b/include/sys/syscall.h
@@ -0,0 +1,60 @@
+#ifndef _SYS_SYSCALL_H
+#define _SYS_SYSCALL_H
+
+enum SystemCall {
+	/* Tasking */
+	SYSCALL_DBGPRINTF,
+	SYSCALL_CLONE,
+	SYSCALL_EXIT,
+	SYSCALL_GETPID,
+	SYSCALL_GETUID,
+	SYSCALL_SETUID,
+	SYSCALL_GETEUID,
+	SYSCALL_SETEUID,
+	SYSCALL_GETGID,
+	SYSCALL_SETGID,
+	SYSCALL_GETEGID,
+	SYSCALL_SETEGID,
+	SYSCALL_EXECVE,
+	SYSCALL_WAITPID,
+	SYSCALL_TGKILL,
+	SYSCALL_KILL,
+	SYSCALL_TIME,
+	SYSCALL_TIMES,
+	SYSCALL_SLEEP,
+
+	/* Files */
+	SYSCALL_OPEN,
+	SYSCALL_CLOSE,
+	SYSCALL_READ,
+	SYSCALL_WRITE,
+	SYSCALL_IOCTL,
+	SYSCALL_LSEEK,
+	SYSCALL_STAT,
+	SYSCALL_FSTAT,
+	SYSCALL_GETDENTS,
+	SYSCALL_MKDIR,
+	SYSCALL_RMDIR,
+	SYSCALL_MKNOD,
+	SYSCALL_RENAME,
+	SYSCALL_DUP,
+	SYSCALL_DUP2,
+	SYSCALL_ISATTY,
+
+	/* File System */
+	SYSCALL_MOUNT,
+	SYSCALL_CHDIR,
+	SYSCALL_CHROOT,
+	SYSCALL_GETCWD,
+
+	/* Memory */
+	SYSCALL_MMAP,
+
+	/* Messaging */
+	SYSCALL_NB_SEND_MSG,
+	SYSCALL_SEND_MSG,
+	SYSCALL_NB_RECV_MSG,
+	SYSCALL_RECV_MSG,
+};
+
+#endif
diff --git a/include/sys/times.h b/include/sys/times.h
new file mode 100644
index 0000000..70d57f0
--- /dev/null
+++ b/include/sys/times.h
@@ -0,0 +1,18 @@
+#ifndef _SYS_TIMES_H
+#define _SYS_TIMES_H
+
+#include <time.h>
+
+typedef uint64_t clock_t;
+
+/* Structure for a times call */
+typedef struct tms {
+	clock_t utime;
+	clock_t stime;
+	clock_t cutime;
+	clock_t cstime;
+} Times;
+
+clock_t times(Times *buf);
+
+#endif
diff --git a/include/sys/types.h b/include/sys/types.h
new file mode 100644
index 0000000..f8d727a
--- /dev/null
+++ b/include/sys/types.h
@@ -0,0 +1,14 @@
+#ifndef _SYS_TYPES_H
+#define _SYS_TYPES_H
+
+typedef int pid_t;
+typedef unsigned short uid_t;
+typedef unsigned short gid_t;
+typedef unsigned int dev_t;
+typedef int ino_t;
+typedef int off_t;
+typedef int mode_t;
+typedef int nlink_t;
+typedef int refcount_t;
+
+#endif
diff --git a/include/sys/wait.h b/include/sys/wait.h
new file mode 100644
index 0000000..47ff26c
--- /dev/null
+++ b/include/sys/wait.h
@@ -0,0 +1,22 @@
+#ifndef _SYS_INCLUDE_H
+#define _SYS_INCLUDE_H
+
+#include <sys/types.h>
+
+#define WIFEXITED(status) (status & (1 << 31))
+#define WEXITSTATUS(status) (status & 0x0F)
+#define WIFSIGNALED(status) (!(status & (1 << 31)))
+#define WTERMSIG(status) (status & 0xFF)
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+pid_t wait(int *wstatus);
+pid_t waitpid(pid_t pid, int *wstatus, int options);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif