From f5e48e94a2f4d4bbd6e5628c7f2afafc6dbcc459 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 7 Mar 2024 17:28:52 -0500 Subject: build: Build mlibc + add distclean target Signed-off-by: Ian Moffett --- lib/mlibc/options/linux/generic/capabilities.cpp | 19 ---- lib/mlibc/options/linux/generic/cpuset.cpp | 71 ------------ lib/mlibc/options/linux/generic/ifaddrs.cpp | 15 --- lib/mlibc/options/linux/generic/linux-unistd.cpp | 33 ------ lib/mlibc/options/linux/generic/malloc.cpp | 7 -- lib/mlibc/options/linux/generic/mntent-stubs.cpp | 98 ----------------- lib/mlibc/options/linux/generic/module.cpp | 24 ---- lib/mlibc/options/linux/generic/pty-stubs.cpp | 101 ----------------- lib/mlibc/options/linux/generic/sched.cpp | 50 --------- lib/mlibc/options/linux/generic/sys-epoll.cpp | 58 ---------- lib/mlibc/options/linux/generic/sys-eventfd.cpp | 45 -------- lib/mlibc/options/linux/generic/sys-fsuid.cpp | 12 -- .../options/linux/generic/sys-inotify-stubs.cpp | 47 -------- lib/mlibc/options/linux/generic/sys-klog.cpp | 16 --- lib/mlibc/options/linux/generic/sys-mount.cpp | 29 ----- .../options/linux/generic/sys-prctl-stubs.cpp | 25 ----- .../options/linux/generic/sys-ptrace-stubs.cpp | 36 ------ lib/mlibc/options/linux/generic/sys-quota.cpp | 7 -- .../options/linux/generic/sys-random-stubs.cpp | 21 ---- lib/mlibc/options/linux/generic/sys-reboot.cpp | 13 --- .../options/linux/generic/sys-sendfile-stubs.cpp | 9 -- lib/mlibc/options/linux/generic/sys-signalfd.cpp | 17 --- .../options/linux/generic/sys-statfs-stubs.cpp | 26 ----- lib/mlibc/options/linux/generic/sys-swap.cpp | 24 ---- lib/mlibc/options/linux/generic/sys-sysinfo.cpp | 15 --- lib/mlibc/options/linux/generic/sys-timerfd.cpp | 33 ------ lib/mlibc/options/linux/generic/sys-xattr.cpp | 122 --------------------- lib/mlibc/options/linux/generic/utmp-stubs.cpp | 116 -------------------- lib/mlibc/options/linux/generic/utmpx.cpp | 45 -------- 29 files changed, 1134 deletions(-) delete mode 100644 lib/mlibc/options/linux/generic/capabilities.cpp delete mode 100644 lib/mlibc/options/linux/generic/cpuset.cpp delete mode 100644 lib/mlibc/options/linux/generic/ifaddrs.cpp delete mode 100644 lib/mlibc/options/linux/generic/linux-unistd.cpp delete mode 100644 lib/mlibc/options/linux/generic/malloc.cpp delete mode 100644 lib/mlibc/options/linux/generic/mntent-stubs.cpp delete mode 100644 lib/mlibc/options/linux/generic/module.cpp delete mode 100644 lib/mlibc/options/linux/generic/pty-stubs.cpp delete mode 100644 lib/mlibc/options/linux/generic/sched.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-epoll.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-eventfd.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-fsuid.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-inotify-stubs.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-klog.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-mount.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-prctl-stubs.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-ptrace-stubs.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-quota.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-random-stubs.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-reboot.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-sendfile-stubs.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-signalfd.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-statfs-stubs.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-swap.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-sysinfo.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-timerfd.cpp delete mode 100644 lib/mlibc/options/linux/generic/sys-xattr.cpp delete mode 100644 lib/mlibc/options/linux/generic/utmp-stubs.cpp delete mode 100644 lib/mlibc/options/linux/generic/utmpx.cpp (limited to 'lib/mlibc/options/linux/generic') diff --git a/lib/mlibc/options/linux/generic/capabilities.cpp b/lib/mlibc/options/linux/generic/capabilities.cpp deleted file mode 100644 index 871822a..0000000 --- a/lib/mlibc/options/linux/generic/capabilities.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int capset(void *, void *) { - mlibc::infoLogger() << "mlibc: capset is a no-op!" << frg::endlog; - return 0; -} - -int capget(void *, void *) { - mlibc::infoLogger() << "mlibc: capget is a no-op!" << frg::endlog; - return 0; -} - -#ifdef __cplusplus -} -#endif diff --git a/lib/mlibc/options/linux/generic/cpuset.cpp b/lib/mlibc/options/linux/generic/cpuset.cpp deleted file mode 100644 index d0292b7..0000000 --- a/lib/mlibc/options/linux/generic/cpuset.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include -#include - -cpu_set_t *__mlibc_cpu_alloc(int num_cpus) { - return reinterpret_cast(calloc(1, CPU_ALLOC_SIZE(num_cpus))); -} - -#define CPU_MASK_BITS (CHAR_BIT * sizeof(__cpu_mask)) - -size_t __mlibc_cpu_alloc_size(int num_cpus) { - /* calculate the (unaligned) remainder that doesn't neatly fit in one __cpu_mask; 0 or 1 */ - size_t remainder = ((num_cpus % CPU_MASK_BITS) + CPU_MASK_BITS - 1) / CPU_MASK_BITS; - return sizeof(__cpu_mask) * (num_cpus / CPU_MASK_BITS + remainder); -} - -void __mlibc_cpu_zero(const size_t setsize, cpu_set_t *set) { - memset(set, 0, CPU_ALLOC_SIZE(setsize)); -} - -void __mlibc_cpu_set(const int cpu, const size_t setsize, cpu_set_t *set) { - if(cpu >= static_cast(setsize * CHAR_BIT)) { - return; - } - - unsigned char *ptr = reinterpret_cast(set); - size_t off = cpu / CHAR_BIT; - size_t mask = 1 << (cpu % CHAR_BIT); - - ptr[off] |= mask; -} - -void __mlibc_cpu_clear(const int cpu, const size_t setsize, cpu_set_t *set) { - if(cpu >= static_cast(setsize * CHAR_BIT)) { - return; - } - - unsigned char *ptr = reinterpret_cast(set); - size_t off = cpu / CHAR_BIT; - size_t mask = 1 << (cpu % CHAR_BIT); - - ptr[off] &= ~mask; -} - - -int __mlibc_cpu_isset(const int cpu, const size_t setsize, const cpu_set_t *set) { - if(cpu >= static_cast(setsize * CHAR_BIT)) { - return false; - } - - const unsigned char *ptr = reinterpret_cast(set); - size_t off = cpu / CHAR_BIT; - size_t mask = 1 << (cpu % CHAR_BIT); - - return (ptr[off] & mask); -} - -int __mlibc_cpu_count(const size_t setsize, const cpu_set_t *set) { - size_t count = 0; - const unsigned char *ptr = reinterpret_cast(set); - - for(size_t i = 0; i < setsize; i++) { - for(size_t bit = 0; bit < CHAR_BIT; bit++) { - if((1 << bit) & ptr[i]) - count++; - } - } - - return count; -} diff --git a/lib/mlibc/options/linux/generic/ifaddrs.cpp b/lib/mlibc/options/linux/generic/ifaddrs.cpp deleted file mode 100644 index 67dfbc6..0000000 --- a/lib/mlibc/options/linux/generic/ifaddrs.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include -#include -#include - -int getifaddrs(struct ifaddrs **) { - mlibc::infoLogger() << "mlibc: getifaddrs fails unconditionally!" << frg::endlog; - errno = ENOSYS; - return -1; -} - -void freeifaddrs(struct ifaddrs *) { - mlibc::infoLogger() << "mlibc: freeifaddrs is a stub!" << frg::endlog; - return; -} diff --git a/lib/mlibc/options/linux/generic/linux-unistd.cpp b/lib/mlibc/options/linux/generic/linux-unistd.cpp deleted file mode 100644 index ec13f72..0000000 --- a/lib/mlibc/options/linux/generic/linux-unistd.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include - -#include -#include -#include - -int dup3(int oldfd, int newfd, int flags) { - if(oldfd == newfd) { - errno = EINVAL; - return -1; - } - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_dup2, -1); - if(int e = mlibc::sys_dup2(oldfd, flags, newfd); e) { - errno = e; - return -1; - } - return newfd; -} - -int vhangup(void) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} - -int getdtablesize(void){ - return sysconf(_SC_OPEN_MAX); -} - -int syncfs(int) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} diff --git a/lib/mlibc/options/linux/generic/malloc.cpp b/lib/mlibc/options/linux/generic/malloc.cpp deleted file mode 100644 index 065de6c..0000000 --- a/lib/mlibc/options/linux/generic/malloc.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -void *memalign(size_t, size_t) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} diff --git a/lib/mlibc/options/linux/generic/mntent-stubs.cpp b/lib/mlibc/options/linux/generic/mntent-stubs.cpp deleted file mode 100644 index 35c0e92..0000000 --- a/lib/mlibc/options/linux/generic/mntent-stubs.cpp +++ /dev/null @@ -1,98 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -namespace { - -char *internal_buf; -size_t internal_bufsize; - -} - -#define SENTINEL (char *)&internal_buf - -FILE *setmntent(const char *name, const char *mode) { - return fopen(name, mode); -} - -struct mntent *getmntent(FILE *f) { - static struct mntent mnt; - return getmntent_r(f, &mnt, SENTINEL, 0); -} - -int addmntent(FILE *f, const struct mntent *mnt) { - if(fseek(f, 0, SEEK_END)) { - return 1; - } - return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n", - mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts, - mnt->mnt_freq, mnt->mnt_passno) < 0; -} - -int endmntent(FILE *f) { - if(f) { - fclose(f); - } - return 1; -} - -char *hasmntopt(const struct mntent *mnt, const char *opt) { - return strstr(mnt->mnt_opts, opt); -} - -/* Adapted from musl */ -struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen) { - int n[8]; - bool use_internal = (linebuf == SENTINEL); - int len; - size_t i; - - mnt->mnt_freq = 0; - mnt->mnt_passno = 0; - - do { - if(use_internal) { - getline(&internal_buf, &internal_bufsize, f); - linebuf = internal_buf; - } else { - fgets(linebuf, buflen, f); - } - if(feof(f) || ferror(f)) { - return 0; - } - if(!strchr(linebuf, '\n')) { - fscanf(f, "%*[^\n]%*[\n]"); - errno = ERANGE; - return 0; - } - - len = strlen(linebuf); - if(len > INT_MAX) { - continue; - } - - for(i = 0; i < sizeof n / sizeof *n; i++) { - n[i] = len; - } - - sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d", - n, n + 1, n + 2, n + 3, n + 4, n + 5, n + 6, n + 7, - &mnt->mnt_freq, &mnt->mnt_passno); - } while(linebuf[n[0]] == '#' || n[1] == len); - - linebuf[n[1]] = 0; - linebuf[n[3]] = 0; - linebuf[n[5]] = 0; - linebuf[n[7]] = 0; - - mnt->mnt_fsname = linebuf + n[0]; - mnt->mnt_dir = linebuf + n[2]; - mnt->mnt_type = linebuf + n[4]; - mnt->mnt_opts = linebuf + n[6]; - - return mnt; -} diff --git a/lib/mlibc/options/linux/generic/module.cpp b/lib/mlibc/options/linux/generic/module.cpp deleted file mode 100644 index 53b6dc8..0000000 --- a/lib/mlibc/options/linux/generic/module.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include - -#include -#include -#include - -int init_module(void *module, unsigned long length, const char *args) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_init_module, -1); - if(int e = mlibc::sys_init_module(module, length, args); e) { - errno = e; - return -1; - } - return 0; -} - -int delete_module(const char *name, unsigned flags) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_delete_module, -1); - if(int e = mlibc::sys_delete_module(name, flags); e) { - errno = e; - return -1; - } - return 0; -} diff --git a/lib/mlibc/options/linux/generic/pty-stubs.cpp b/lib/mlibc/options/linux/generic/pty-stubs.cpp deleted file mode 100644 index 8d95027..0000000 --- a/lib/mlibc/options/linux/generic/pty-stubs.cpp +++ /dev/null @@ -1,101 +0,0 @@ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -int openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const struct winsize *win) { - int ptmx_fd; - if(int e = mlibc::sys_open("/dev/ptmx", O_RDWR | O_NOCTTY, 0, &ptmx_fd); e) { - errno = e; - goto fail; - } - - char spath[32]; - if(!name) - name = spath; - if(ptsname_r(ptmx_fd, name, 32)) - goto fail; - - int pts_fd; - unlockpt(ptmx_fd); - if(int e = mlibc::sys_open(name, O_RDWR | O_NOCTTY, 0, &pts_fd); e) { - errno = e; - goto fail; - } - - if(ios) - tcsetattr(ptmx_fd, TCSAFLUSH, ios); - - if(win) - ioctl(ptmx_fd, TIOCSWINSZ, (void*)win); - - *mfd = ptmx_fd; - *sfd = pts_fd; - return 0; - -fail: - mlibc::sys_close(ptmx_fd); - return -1; -} - -int login_tty(int fd) { - if(setsid() == -1) - return -1; - if(ioctl(fd, TIOCSCTTY, 0)) - return -1; - - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_dup2, -1); - if(int e = mlibc::sys_dup2(fd, 0, STDIN_FILENO); e) { - errno = e; - return -1; - } - if(int e = mlibc::sys_dup2(fd, 0, STDOUT_FILENO); e) { - errno = e; - return -1; - } - if(int e = mlibc::sys_dup2(fd, 0, STDERR_FILENO); e) { - errno = e; - return -1; - } - - if(int e = mlibc::sys_close(fd); e) { - errno = e; - return -1; - } - return 0; -} - -int forkpty(int *mfd, char *name, const struct termios *ios, const struct winsize *win) { - int sfd; - if(openpty(mfd, &sfd, name, ios, win)) - return -1; - - pid_t child; - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_fork, -1); - if(int e = mlibc::sys_fork(&child); e) { - errno = e; - return -1; - } - - if(!child) { - if(login_tty(sfd)) - mlibc::panicLogger() << "mlibc: TTY login fail in forkpty() child" << frg::endlog; - }else{ - if(int e = mlibc::sys_close(sfd); e) { - errno = e; - return -1; - } - } - - return child; -} - diff --git a/lib/mlibc/options/linux/generic/sched.cpp b/lib/mlibc/options/linux/generic/sched.cpp deleted file mode 100644 index 760a9f5..0000000 --- a/lib/mlibc/options/linux/generic/sched.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include -#include -#include - -#include -#include - -int sched_getcpu(void) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_getcpu, -1); - int cpu; - if(int e = mlibc::sys_getcpu(&cpu); e) { - errno = e; - return -1; - } - return cpu; -} - -int setns(int, int) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} - -int sched_getscheduler(pid_t) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} - -int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_getaffinity, -1); - if(int e = mlibc::sys_getaffinity(pid, cpusetsize, mask); e) { - errno = e; - return -1; - } - return 0; -} - -int unshare(int) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} - -int sched_setaffinity(pid_t, size_t, const cpu_set_t *) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} - -int clone(int (*)(void *), void *, int, void *, ...) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} diff --git a/lib/mlibc/options/linux/generic/sys-epoll.cpp b/lib/mlibc/options/linux/generic/sys-epoll.cpp deleted file mode 100644 index 799d1a9..0000000 --- a/lib/mlibc/options/linux/generic/sys-epoll.cpp +++ /dev/null @@ -1,58 +0,0 @@ - -#include -#include - -#include -#include -#include - -int epoll_create(int) { - int fd; - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_epoll_create, -1); - if(int e = mlibc::sys_epoll_create(0, &fd); e) { - errno = e; - return -1; - } - return fd; -} - -int epoll_pwait(int epfd, struct epoll_event *evnts, int n, int timeout, - const sigset_t *sigmask) { - int raised; - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_epoll_pwait, -1); - if(int e = mlibc::sys_epoll_pwait(epfd, evnts, n, timeout, sigmask, &raised)) { - errno = e; - return -1; - } - return raised; -} - -int epoll_create1(int flags) { - int fd; - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_epoll_create, -1); - if(int e = mlibc::sys_epoll_create(flags, &fd); e) { - errno = e; - return -1; - } - return fd; -} - -int epoll_ctl(int epfd, int mode, int fd, struct epoll_event *ev) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_epoll_ctl, -1); - if(int e = mlibc::sys_epoll_ctl(epfd, mode, fd, ev); e) { - errno = e; - return -1; - } - return 0; -} - -int epoll_wait(int epfd, struct epoll_event *evnts, int n, int timeout) { - int raised; - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_epoll_pwait, -1); - if(int e = mlibc::sys_epoll_pwait(epfd, evnts, n, timeout, NULL, &raised)) { - errno = e; - return -1; - } - return raised; -} - diff --git a/lib/mlibc/options/linux/generic/sys-eventfd.cpp b/lib/mlibc/options/linux/generic/sys-eventfd.cpp deleted file mode 100644 index 1d83d8c..0000000 --- a/lib/mlibc/options/linux/generic/sys-eventfd.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include - -#include -#include - -int eventfd(unsigned int initval, int flags) { - int fd = 0; - - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_eventfd_create, -1); - if (int e = mlibc::sys_eventfd_create(initval, flags, &fd); e) { - errno = e; - return -1; - } - - return fd; -} - -int eventfd_read(int fd, eventfd_t *value) { - ssize_t bytes_read; - if (int e = mlibc::sys_read(fd, value, 8, &bytes_read); e) { - errno = e; - return -1; - } - - if (bytes_read != 8) { - return -1; - } - - return 0; -} - -int eventfd_write(int fd, eventfd_t value) { - ssize_t bytes_written; - if (int e = mlibc::sys_write(fd, &value, 8, &bytes_written); e) { - errno = e; - return -1; - } - - if (bytes_written != 8) { - return -1; - } - - return 0; -} diff --git a/lib/mlibc/options/linux/generic/sys-fsuid.cpp b/lib/mlibc/options/linux/generic/sys-fsuid.cpp deleted file mode 100644 index 653456c..0000000 --- a/lib/mlibc/options/linux/generic/sys-fsuid.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -int setfsuid(uid_t) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} - -int setfsgid(gid_t) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} diff --git a/lib/mlibc/options/linux/generic/sys-inotify-stubs.cpp b/lib/mlibc/options/linux/generic/sys-inotify-stubs.cpp deleted file mode 100644 index 0bc25c9..0000000 --- a/lib/mlibc/options/linux/generic/sys-inotify-stubs.cpp +++ /dev/null @@ -1,47 +0,0 @@ - -#include -#include - -#include -#include -#include - -int inotify_init(void) { - int fd; - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_inotify_create, -1); - if(int e = mlibc::sys_inotify_create(0, &fd); e) { - errno = e; - return -1; - } - return fd; -} - -int inotify_init1(int flags) { - int fd; - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_inotify_create, -1); - if(int e = mlibc::sys_inotify_create(flags, &fd); e) { - errno = e; - return -1; - } - return fd; -} - -int inotify_add_watch(int ifd, const char *path, uint32_t mask) { - int wd; - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_inotify_add_watch, -1); - if(int e = mlibc::sys_inotify_add_watch(ifd, path, mask, &wd); e) { - errno = e; - return -1; - } - return wd; -} - -int inotify_rm_watch(int ifd, int wd) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_inotify_rm_watch, -1); - if(int e = mlibc::sys_inotify_rm_watch(ifd, wd); e) { - errno = e; - return -1; - } - return 0; -} - diff --git a/lib/mlibc/options/linux/generic/sys-klog.cpp b/lib/mlibc/options/linux/generic/sys-klog.cpp deleted file mode 100644 index 059e292..0000000 --- a/lib/mlibc/options/linux/generic/sys-klog.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -#include - -#include - -int klogctl(int type, char *bufp, int len) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_klogctl, -1); - int out; - if (int e = mlibc::sys_klogctl(type, bufp, len, &out); e) { - errno = e; - return -1; - } - return out; -} diff --git a/lib/mlibc/options/linux/generic/sys-mount.cpp b/lib/mlibc/options/linux/generic/sys-mount.cpp deleted file mode 100644 index 4783183..0000000 --- a/lib/mlibc/options/linux/generic/sys-mount.cpp +++ /dev/null @@ -1,29 +0,0 @@ - -#include -#include - -#include -#include - -int mount(const char *source, const char *target, - const char *fstype, unsigned long flags, const void *data) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_mount, -1); - if(int e = mlibc::sys_mount(source, target, fstype, flags, data); e) { - errno = e; - return -1; - } - return 0; -} - -int umount(const char *target) { - return umount2(target, 0); -} - -int umount2(const char *target, int flags) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_umount2, -1); - if(int e = mlibc::sys_umount2(target, flags); e) { - errno = e; - return -1; - } - return 0; -} diff --git a/lib/mlibc/options/linux/generic/sys-prctl-stubs.cpp b/lib/mlibc/options/linux/generic/sys-prctl-stubs.cpp deleted file mode 100644 index 5280332..0000000 --- a/lib/mlibc/options/linux/generic/sys-prctl-stubs.cpp +++ /dev/null @@ -1,25 +0,0 @@ - -#include -#include -#include -#include - -#include - -#include "mlibc/linux-sysdeps.hpp" - -int prctl(int op, ...) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_prctl, -1); - - int val; - va_list ap; - va_start(ap, op); - if(int e = mlibc::sys_prctl(op, ap, &val); e) { - errno = e; - return -1; - } - va_end(ap); - - return val; -} - diff --git a/lib/mlibc/options/linux/generic/sys-ptrace-stubs.cpp b/lib/mlibc/options/linux/generic/sys-ptrace-stubs.cpp deleted file mode 100644 index 8c836c5..0000000 --- a/lib/mlibc/options/linux/generic/sys-ptrace-stubs.cpp +++ /dev/null @@ -1,36 +0,0 @@ - -#include -#include -#include - -#include -#include -#include - -long ptrace(int req, ...) { - va_list ap; - - va_start(ap, req); - auto pid = va_arg(ap, pid_t); - auto addr = va_arg(ap, void *); - auto data = va_arg(ap, void *); - va_end(ap); - - long ret; - if(req > 0 && req < 4) { - data = &ret; - } - - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_ptrace, -1); - long out; - if(int e = mlibc::sys_ptrace(req, pid, addr, data, &out); e) { - errno = e; - return -1; - } else if(req > 0 && req < 4) { - errno = 0; - return ret; - } - - return out; -} - diff --git a/lib/mlibc/options/linux/generic/sys-quota.cpp b/lib/mlibc/options/linux/generic/sys-quota.cpp deleted file mode 100644 index 27c0e6d..0000000 --- a/lib/mlibc/options/linux/generic/sys-quota.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include - -int quotactl(int, const char *, int, caddr_t) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} diff --git a/lib/mlibc/options/linux/generic/sys-random-stubs.cpp b/lib/mlibc/options/linux/generic/sys-random-stubs.cpp deleted file mode 100644 index 5e5057f..0000000 --- a/lib/mlibc/options/linux/generic/sys-random-stubs.cpp +++ /dev/null @@ -1,21 +0,0 @@ - -#include -#include - -#include -#include - -#include - -ssize_t getrandom(void *buffer, size_t max_size, unsigned int flags) { - if(flags & ~(GRND_RANDOM | GRND_NONBLOCK)) { - errno = EINVAL; - return -1; - } - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_getentropy, -1); - if(int e = mlibc::sys_getentropy(buffer, max_size); e) { - errno = e; - return -1; - } - return max_size; -} diff --git a/lib/mlibc/options/linux/generic/sys-reboot.cpp b/lib/mlibc/options/linux/generic/sys-reboot.cpp deleted file mode 100644 index c9b503f..0000000 --- a/lib/mlibc/options/linux/generic/sys-reboot.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include -#include - -int reboot(int what) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_reboot, -1); - if (int e = mlibc::sys_reboot(what); e) { - errno = e; - return -1; - } - return 0; -} diff --git a/lib/mlibc/options/linux/generic/sys-sendfile-stubs.cpp b/lib/mlibc/options/linux/generic/sys-sendfile-stubs.cpp deleted file mode 100644 index 25cd0a0..0000000 --- a/lib/mlibc/options/linux/generic/sys-sendfile-stubs.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -#include -#include - -ssize_t sendfile(int, int, off_t *, size_t) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} - diff --git a/lib/mlibc/options/linux/generic/sys-signalfd.cpp b/lib/mlibc/options/linux/generic/sys-signalfd.cpp deleted file mode 100644 index 28cfea0..0000000 --- a/lib/mlibc/options/linux/generic/sys-signalfd.cpp +++ /dev/null @@ -1,17 +0,0 @@ - -#include -#include - -#include -#include - -int signalfd(int fd, const sigset_t *mask, int flags) { - __ensure(fd == -1); - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_signalfd_create, -1); - if(int e = mlibc::sys_signalfd_create(mask, flags, &fd); e) { - errno = e; - return -1; - } - return fd; -} - diff --git a/lib/mlibc/options/linux/generic/sys-statfs-stubs.cpp b/lib/mlibc/options/linux/generic/sys-statfs-stubs.cpp deleted file mode 100644 index 6152ef2..0000000 --- a/lib/mlibc/options/linux/generic/sys-statfs-stubs.cpp +++ /dev/null @@ -1,26 +0,0 @@ - -#include -#include -#include - -#include -#include - -int statfs(const char *path, struct statfs *buf) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_statfs, -1); - if(int e = mlibc::sys_statfs(path, buf); e) { - errno = e; - return -1; - } - return 0; -} - -int fstatfs(int fd, struct statfs *buf) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_fstatfs, -1); - if (int e = mlibc::sys_fstatfs(fd, buf); e) { - errno = e; - return -1; - } - return 0; -} - diff --git a/lib/mlibc/options/linux/generic/sys-swap.cpp b/lib/mlibc/options/linux/generic/sys-swap.cpp deleted file mode 100644 index 44ddf98..0000000 --- a/lib/mlibc/options/linux/generic/sys-swap.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include - -#include -#include -#include - -int swapon(const char *path, int flags) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_swapon, -1); - if(int e = mlibc::sys_swapon(path, flags); e) { - errno = e; - return -1; - } - return 0; -} - -int swapoff(const char *path) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_swapoff, -1); - if(int e = mlibc::sys_swapoff(path); e) { - errno = e; - return -1; - } - return 0; -} diff --git a/lib/mlibc/options/linux/generic/sys-sysinfo.cpp b/lib/mlibc/options/linux/generic/sys-sysinfo.cpp deleted file mode 100644 index 950c38a..0000000 --- a/lib/mlibc/options/linux/generic/sys-sysinfo.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -#include -#include -#include - -int sysinfo(struct sysinfo *info) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_sysinfo, -1); - if(int e = mlibc::sys_sysinfo(info); e) { - errno = e; - return -1; - } - return 0; -} diff --git a/lib/mlibc/options/linux/generic/sys-timerfd.cpp b/lib/mlibc/options/linux/generic/sys-timerfd.cpp deleted file mode 100644 index 80bca1b..0000000 --- a/lib/mlibc/options/linux/generic/sys-timerfd.cpp +++ /dev/null @@ -1,33 +0,0 @@ - -#include -#include - -#include -#include -#include - -int timerfd_create(int clockid, int flags) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_timerfd_create, -1); - int fd; - if(int e = mlibc::sys_timerfd_create(clockid, flags, &fd); e) { - errno = e; - return -1; - } - return fd; -} - -int timerfd_settime(int fd, int flags, const struct itimerspec *value, - struct itimerspec *oldvalue) { - MLIBC_CHECK_OR_ENOSYS(mlibc::sys_timerfd_settime, -1); - if(int e = mlibc::sys_timerfd_settime(fd, flags, value, oldvalue); e) { - errno = e; - return -1; - } - return 0; -} - -int timerfd_gettime(int, struct itimerspec *) { - __ensure(!"Not implemented"); - __builtin_unreachable(); -} - diff --git a/lib/mlibc/options/linux/generic/sys-xattr.cpp b/lib/mlibc/options/linux/generic/sys-xattr.cpp deleted file mode 100644 index c8d598f..0000000 --- a/lib/mlibc/options/linux/generic/sys-xattr.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include -#include - -#include -#include - -int setxattr(const char *path, const char *name, const void *val, size_t size, - int flags) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_setxattr, -1); - - if (int e = sysdep(path, name, val, size, flags); e) { - errno = e; - return -1; - } - return 0; -} - -int lsetxattr(const char *path, const char *name, const void *val, size_t size, - int flags) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_lsetxattr, -1); - - if (int e = sysdep(path, name, val, size, flags); e) { - errno = e; - return -1; - } - return 0; -} - -int fsetxattr(int fd, const char *name, const void *val, size_t size, - int flags) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_fsetxattr, -1); - - if (int e = sysdep(fd, name, val, size, flags); e) { - errno = e; - return -1; - } - return 0; -} - -ssize_t getxattr(const char *path, const char *name, void *val, size_t size) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_getxattr, -1); - - ssize_t nread; - if (int e = sysdep(path, name, val, size, &nread); e) { - errno = e; - return -1; - } - - return nread; -} - -ssize_t lgetxattr(const char *path, const char *name, void *val, size_t size) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_lgetxattr, -1); - - ssize_t nread; - if (int e = sysdep(path, name, val, size, &nread); e) { - errno = e; - return -1; - } - - return nread; -} - -ssize_t fgetxattr(int fd, const char *name, void *val, size_t size) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_fgetxattr, -1); - - ssize_t nread; - if (int e = sysdep(fd, name, val, size, &nread); e) { - errno = e; - return -1; - } - - return nread; -} - -int removexattr(const char *path, const char *name) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_removexattr, -1); - return sysdep(path, name); -} - -int lremovexattr(const char *path, const char *name) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_lremovexattr, -1); - return sysdep(path, name); -} - -int fremovexattr(int fd, const char *name) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_fremovexattr, -1); - return sysdep(fd, name); -} - -ssize_t listxattr(const char *path, char *list, size_t size) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_listxattr, -1); - - ssize_t nread; - if (int e = sysdep(path, list, size, &nread); e) { - errno = e; - return -1; - } - return nread; -} - -ssize_t llistxattr(const char *path, char *list, size_t size) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_llistxattr, -1); - - ssize_t nread; - if (int e = sysdep(path, list, size, &nread); e) { - errno = e; - return -1; - } - return nread; -} - -ssize_t flistxattr(int fd, char *list, size_t size) { - auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_flistxattr, -1); - - ssize_t nread; - if (int e = sysdep(fd, list, size, &nread); e) { - errno = e; - return -1; - } - return nread; -} diff --git a/lib/mlibc/options/linux/generic/utmp-stubs.cpp b/lib/mlibc/options/linux/generic/utmp-stubs.cpp deleted file mode 100644 index 658dfd3..0000000 --- a/lib/mlibc/options/linux/generic/utmp-stubs.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include -#include -#include -#include -#include - -#include -#include - -/* - * The code in this file is largely based on glibc. - * This includes: - * - setutent - * - read_last_entry - * - getutent - * - getutent_r - * - endutent - */ -static int fd = -1; -static off_t offset; - -static struct utmp last_entry; - -void setutent(void) { - if(fd < 0) { - fd = open("/run/utmp", O_RDONLY | O_LARGEFILE | O_CLOEXEC); - if(fd == -1) { - return; - } - } - - lseek(fd, 0, SEEK_SET); - offset = 0; -} - -static ssize_t read_last_entry(void) { - struct utmp buf; - ssize_t bytes_read = pread(fd, &buf, sizeof(buf), offset); - - if(bytes_read < 0) { - return -1; - } else if(bytes_read != sizeof(buf)) { - // EOF - return 0; - } else { - last_entry = buf; - offset += sizeof(buf); - return 1; - } -} - -struct utmp *getutent(void) { - struct utmp *result; - static struct utmp *buf; - if(buf == NULL) { - buf = (struct utmp *)malloc(sizeof(struct utmp)); - if(buf == NULL) { - return NULL; - } - } - - if(getutent_r(buf, &result) < 0) { - return NULL; - } - return result; -} - -int getutent_r(struct utmp *buf, struct utmp **res) { - int saved_errno = errno; - - if(fd < 0) { - setutent(); - } - - ssize_t bytes_read = read_last_entry(); - - if(bytes_read <= 0) { - if(bytes_read == 0) { - errno = saved_errno; - *res = NULL; - return -1; - } - } - - memcpy(buf, &last_entry, sizeof(struct utmp)); - *res = buf; - - return 0; -} - -void endutent(void) { - if(fd >= 0) { - close(fd); - fd = -1; - } -} - -struct utmp *pututline(const struct utmp *) { - mlibc::infoLogger() << "\e[31mmlibc: pututline() is a stub!\e[39m" << frg::endlog; - return NULL; -} - -struct utmp *getutline(const struct utmp *) { - mlibc::infoLogger() << "\e[31mmlibc: getutline() is a stub!\e[39m" << frg::endlog; - return NULL; -} - -int utmpname(const char *) { - mlibc::infoLogger() << "\e[31mmlibc: utmpname() is a stub!\e[39m" << frg::endlog; - return -1; -} - -struct utmp *getutid(const struct utmp *) { - mlibc::infoLogger() << "\e[31mmlibc: getutid() is a stub!\e[39m" << frg::endlog; - return NULL; -} diff --git a/lib/mlibc/options/linux/generic/utmpx.cpp b/lib/mlibc/options/linux/generic/utmpx.cpp deleted file mode 100644 index 4742567..0000000 --- a/lib/mlibc/options/linux/generic/utmpx.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include -#include - -void updwtmpx(const char *, const struct utmpx *) { - // Empty as musl does - mlibc::infoLogger() << "\e[31mmlibc: updwtmpx() is a stub\e[39m" << frg::endlog; -} - -void endutxent(void) { - // Empty as musl does - mlibc::infoLogger() << "\e[31mmlibc: endutxent() is a stub\e[39m" << frg::endlog; -} - -void setutxent(void) { - // Empty as musl does - mlibc::infoLogger() << "\e[31mmlibc: setutxent() is a stub\e[39m" << frg::endlog; -} - -struct utmpx *getutxent(void) { - // return NULL as musl does - mlibc::infoLogger() << "\e[31mmlibc: getutxent() is a stub\e[39m" << frg::endlog; - return NULL; -} - -struct utmpx *pututxline(const struct utmpx *) { - // return NULL as musl does - mlibc::infoLogger() << "\e[31mmlibc: pututxline() is a stub\e[39m" << frg::endlog; - return NULL; -} - -int utmpxname(const char *) { - // return -1 as musl does - mlibc::infoLogger() << "\e[31mmlibc: utmpxname() is a stub\e[39m" << frg::endlog; - errno = ENOSYS; - return -1; -} - -struct utmpx *getutxid(const struct utmpx *) { - // return NULL as musl does - mlibc::infoLogger() << "\e[31mmlibc: getutxid() is a stub\e[39m" << frg::endlog; - return NULL; -} -- cgit v1.2.3