]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
feat: ulibc extensions for DOOM — mmap, munmap, ioctl, nanosleep, clock_gettime
authorTulio A M Mendes <[email protected]>
Thu, 12 Feb 2026 07:36:52 +0000 (04:36 -0300)
committerTulio A M Mendes <[email protected]>
Fri, 13 Feb 2026 02:44:55 +0000 (23:44 -0300)
Added userspace wrappers required for the DOOM port:
- sys/mman.h + mman.c: mmap() and munmap() for framebuffer mapping
- sys/ioctl.h + ioctl.c: ioctl() for framebuffer info queries
- time.h + time.c: nanosleep() and clock_gettime() for frame timing

All wrappers use the existing INT 0x80 syscall interface.

user/ulibc/include/sys/ioctl.h [new file with mode: 0644]
user/ulibc/include/sys/mman.h [new file with mode: 0644]
user/ulibc/include/time.h [new file with mode: 0644]
user/ulibc/src/ioctl.c [new file with mode: 0644]
user/ulibc/src/mman.c [new file with mode: 0644]
user/ulibc/src/time.c [new file with mode: 0644]

diff --git a/user/ulibc/include/sys/ioctl.h b/user/ulibc/include/sys/ioctl.h
new file mode 100644 (file)
index 0000000..25c0d56
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef ULIBC_SYS_IOCTL_H
+#define ULIBC_SYS_IOCTL_H
+
+int ioctl(int fd, unsigned long cmd, void* arg);
+
+#endif
diff --git a/user/ulibc/include/sys/mman.h b/user/ulibc/include/sys/mman.h
new file mode 100644 (file)
index 0000000..33cf649
--- /dev/null
@@ -0,0 +1,21 @@
+#ifndef ULIBC_SYS_MMAN_H
+#define ULIBC_SYS_MMAN_H
+
+#include <stddef.h>
+
+#define PROT_NONE   0x0
+#define PROT_READ   0x1
+#define PROT_WRITE  0x2
+#define PROT_EXEC   0x4
+
+#define MAP_SHARED    0x01
+#define MAP_PRIVATE   0x02
+#define MAP_FIXED     0x10
+#define MAP_ANONYMOUS 0x20
+
+#define MAP_FAILED ((void*)-1)
+
+void* mmap(void* addr, size_t length, int prot, int flags, int fd, int offset);
+int   munmap(void* addr, size_t length);
+
+#endif
diff --git a/user/ulibc/include/time.h b/user/ulibc/include/time.h
new file mode 100644 (file)
index 0000000..d69af90
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef ULIBC_TIME_H
+#define ULIBC_TIME_H
+
+#include <stdint.h>
+
+struct timespec {
+    uint32_t tv_sec;
+    uint32_t tv_nsec;
+};
+
+#define CLOCK_REALTIME  0
+#define CLOCK_MONOTONIC 1
+
+int nanosleep(const struct timespec* req, struct timespec* rem);
+int clock_gettime(int clk_id, struct timespec* tp);
+
+#endif
diff --git a/user/ulibc/src/ioctl.c b/user/ulibc/src/ioctl.c
new file mode 100644 (file)
index 0000000..8b324a3
--- /dev/null
@@ -0,0 +1,7 @@
+#include "sys/ioctl.h"
+#include "syscall.h"
+#include "errno.h"
+
+int ioctl(int fd, unsigned long cmd, void* arg) {
+    return __syscall_ret(_syscall3(SYS_IOCTL, fd, (int)cmd, (int)arg));
+}
diff --git a/user/ulibc/src/mman.c b/user/ulibc/src/mman.c
new file mode 100644 (file)
index 0000000..0a28821
--- /dev/null
@@ -0,0 +1,17 @@
+#include "sys/mman.h"
+#include "syscall.h"
+#include "errno.h"
+
+void* mmap(void* addr, size_t length, int prot, int flags, int fd, int offset) {
+    int ret = _syscall5(SYS_MMAP, (int)addr, (int)length, prot, flags, fd);
+    (void)offset;
+    if (ret < 0 && ret > -4096) {
+        errno = -ret;
+        return MAP_FAILED;
+    }
+    return (void*)ret;
+}
+
+int munmap(void* addr, size_t length) {
+    return __syscall_ret(_syscall2(SYS_MUNMAP, (int)addr, (int)length));
+}
diff --git a/user/ulibc/src/time.c b/user/ulibc/src/time.c
new file mode 100644 (file)
index 0000000..8f1b5f4
--- /dev/null
@@ -0,0 +1,11 @@
+#include "time.h"
+#include "syscall.h"
+#include "errno.h"
+
+int nanosleep(const struct timespec* req, struct timespec* rem) {
+    return __syscall_ret(_syscall2(SYS_NANOSLEEP, (int)req, (int)rem));
+}
+
+int clock_gettime(int clk_id, struct timespec* tp) {
+    return __syscall_ret(_syscall2(SYS_CLOCK_GETTIME, clk_id, (int)tp));
+}