BarryServer : Git

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

// Related

OrionLibC

Barry Importing existing Orion LibC 03048a9 (2 years, 2 months ago)
diff --git a/sys/ioctl.c b/sys/ioctl.c
new file mode 100644
index 0000000..db6d27d
--- /dev/null
+++ b/sys/ioctl.c
@@ -0,0 +1,17 @@
+#include <sys/syscall.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+
+/* Send an I/O Control request to a file descriptor */
+int
+ioctl(int fd, unsigned long request, ...)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_IOCTL),
+	             "c" (3), "S" (&fd));
+
+	if (ret >= 0)
+		return ret;
+	errno = -ret;
+	return -1;
+}
diff --git a/sys/ipc.c b/sys/ipc.c
new file mode 100644
index 0000000..3a563fe
--- /dev/null
+++ b/sys/ipc.c
@@ -0,0 +1,43 @@
+#include <stdint.h>
+#include <sys/ipc.h>
+#include <sys/syscall.h>
+
+/* Send a message without blocking */
+Message *
+nb_send_msg(pid_t to, uint16_t type, MessageContent *msg)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_NB_SEND_MSG),
+	             "c" (3), "S" (&to));
+	return (Message *) ret;
+}
+
+/* Send a message and block until delivery */
+Message *
+send_msg(pid_t to, uint16_t type, MessageContent *msg)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_SEND_MSG),
+	             "c" (3), "S" (&to));
+	return (Message *) ret;
+}
+
+/* Receive a message if available */
+pid_t
+nb_recv_msg(Message *buf, pid_t from)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_NB_RECV_MSG),
+	             "c" (2), "S" (&buf));
+	return (pid_t) ret;
+}
+
+/* Block until a message is received */
+pid_t
+recv_msg(Message *buf, pid_t from)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_RECV_MSG),
+	             "c" (2), "S" (&buf));
+	return (pid_t) ret;
+}
diff --git a/sys/mkdir.c b/sys/mkdir.c
new file mode 100644
index 0000000..0c6e7e4
--- /dev/null
+++ b/sys/mkdir.c
@@ -0,0 +1,16 @@
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <errno.h>
+
+/* Make a directory */
+int
+mkdir(const char *pathname, mode_t mode)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_MKDIR),
+	             "c" (2), "S" (&pathname));
+	if (ret >= 0)
+		return ret;
+	errno = -ret;
+	return -1;
+}
diff --git a/sys/mmap.c b/sys/mmap.c
new file mode 100644
index 0000000..b80a2aa
--- /dev/null
+++ b/sys/mmap.c
@@ -0,0 +1,16 @@
+#include <stdint.h>
+#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <errno.h>
+
+void *
+mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_MMAP),
+	             "c" (6), "S" (&addr));
+	if (ret >= 0)
+		return (void *) ret;
+	errno = -ret;
+	return MAP_FAILED;
+}
diff --git a/sys/mount.c b/sys/mount.c
new file mode 100644
index 0000000..ec2f200
--- /dev/null
+++ b/sys/mount.c
@@ -0,0 +1,16 @@
+#include <sys/mount.h>
+#include <sys/syscall.h>
+#include <errno.h>
+
+int
+mount(const char *src, const char *target, const char *type,
+      unsigned long flags, void *data)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_MOUNT),
+	             "c" (6), "S" (&src));
+	if (ret >= 0)
+		return ret;
+	errno = -ret;
+	return -1;
+}
diff --git a/sys/stat.c b/sys/stat.c
new file mode 100644
index 0000000..3c42fd9
--- /dev/null
+++ b/sys/stat.c
@@ -0,0 +1,31 @@
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <errno.h>
+
+/* Get file status */
+int
+stat(const char *pathname, struct stat *statbuf)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_STAT),
+	             "c" (2), "S" (&pathname));
+	if (ret >= 0)
+		return ret;
+	errno = -ret;
+	return -1;
+
+}
+
+/* Get file status by file descriptor */
+int
+fstat(int fd, struct stat *statbuf)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_FSTAT),
+	             "c" (2), "S" (&fd));
+	if (ret >= 0)
+		return ret;
+	errno = -ret;
+	return -1;
+
+}
diff --git a/sys/wait.c b/sys/wait.c
new file mode 100644
index 0000000..912712a
--- /dev/null
+++ b/sys/wait.c
@@ -0,0 +1,23 @@
+#include <sys/syscall.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+/* Wait for a process to change state */
+pid_t
+wait(int *wstatus)
+{
+	return waitpid(-1, wstatus, 0);
+}
+
+/* Wait for a specific process to change state */
+pid_t
+waitpid(pid_t pid, int *wstatus, int options)
+{
+	int ret;
+	asm volatile("int $0x80" : "=a" (ret) : "0" (SYSCALL_WAITPID),
+	             "c" (3), "S" (&pid));
+	if (ret >= 0)
+		return ret;
+	errno = -ret;
+	return -1;
+}