From a2592bc74839de3fbdb242757758f855125f1060 Mon Sep 17 00:00:00 2001 From: streaksu Date: Thu, 16 Nov 2023 07:12:12 +0100 Subject: [PATCH] sysdeps/ironclad: fold mlibc abi into ironclad abi added some Gloire changes as well --- abis/ironclad/access.h | 9 + abis/ironclad/blkcnt_t.h | 7 + abis/ironclad/blksize_t.h | 8 + abis/ironclad/clockid_t.h | 7 + abis/ironclad/dev_t.h | 6 + abis/ironclad/epoll.h | 6 + abis/ironclad/errno.h | 126 ++ abis/ironclad/fcntl.h | 97 +- abis/ironclad/fsblkcnt_t.h | 8 + abis/ironclad/fsfilcnt_t.h | 8 + abis/ironclad/gid_t.h | 6 + abis/ironclad/in.h | 168 +++ abis/ironclad/ino_t.h | 7 + abis/ironclad/inotify.h | 7 + abis/ironclad/ioctls.h | 13 + abis/ironclad/limits.h | 14 + abis/ironclad/mode_t.h | 6 + abis/ironclad/mqueue.h | 20 + abis/ironclad/msg.h | 39 + abis/ironclad/nlink_t.h | 6 + abis/ironclad/packet.h | 6 + abis/ironclad/pid_t.h | 6 + abis/ironclad/poll.h | 16 + abis/ironclad/ptrace.h | 56 + abis/ironclad/reboot.h | 12 + abis/ironclad/resource.h | 53 + abis/ironclad/shm.h | 21 + abis/ironclad/signal.h | 192 +++ abis/ironclad/socket.h | 165 +++ abis/ironclad/socklen_t.h | 6 + abis/ironclad/stat.h | 69 ++ abis/ironclad/statfs.h | 28 + abis/ironclad/statvfs.h | 29 + abis/ironclad/suseconds_t.h | 8 + abis/ironclad/termios.h | 109 ++ abis/ironclad/time.h | 15 + abis/ironclad/uid_t.h | 6 + abis/ironclad/utsname.h | 12 + abis/ironclad/vm-flags.h | 46 + abis/ironclad/wait.h | 25 + abis/ironclad/xattr.h | 21 + meson.build | 2 +- sysdeps/ironclad/crt-x86_64/crti.S | 11 + sysdeps/ironclad/crt-x86_64/crtn.S | 9 + sysdeps/ironclad/generic/generic.cpp | 1032 ++++++++++++++--- sysdeps/ironclad/generic/mac.cpp | 36 + sysdeps/ironclad/generic/mntent.cpp | 97 ++ sysdeps/ironclad/generic/mount.cpp | 34 + sysdeps/ironclad/generic/ptrace.cpp | 9 + sysdeps/ironclad/generic/pty.cpp | 18 + sysdeps/ironclad/generic/reboot.cpp | 9 + sysdeps/ironclad/generic/sched2.cpp | 20 + sysdeps/ironclad/generic/thread.S | 9 + sysdeps/ironclad/generic/thread.cpp | 54 + sysdeps/ironclad/include/abi-bits/access.h | 2 +- sysdeps/ironclad/include/abi-bits/blkcnt_t.h | 2 +- sysdeps/ironclad/include/abi-bits/blksize_t.h | 2 +- sysdeps/ironclad/include/abi-bits/clockid_t.h | 2 +- sysdeps/ironclad/include/abi-bits/dev_t.h | 2 +- sysdeps/ironclad/include/abi-bits/epoll.h | 2 +- sysdeps/ironclad/include/abi-bits/errno.h | 2 +- .../ironclad/include/abi-bits/fsblkcnt_t.h | 2 +- .../ironclad/include/abi-bits/fsfilcnt_t.h | 2 +- sysdeps/ironclad/include/abi-bits/gid_t.h | 2 +- sysdeps/ironclad/include/abi-bits/in.h | 2 +- sysdeps/ironclad/include/abi-bits/ino_t.h | 2 +- sysdeps/ironclad/include/abi-bits/inotify.h | 2 +- sysdeps/ironclad/include/abi-bits/ioctls.h | 2 +- sysdeps/ironclad/include/abi-bits/limits.h | 2 +- sysdeps/ironclad/include/abi-bits/mode_t.h | 2 +- sysdeps/ironclad/include/abi-bits/mqueue.h | 2 +- sysdeps/ironclad/include/abi-bits/msg.h | 2 +- sysdeps/ironclad/include/abi-bits/nlink_t.h | 2 +- sysdeps/ironclad/include/abi-bits/packet.h | 2 +- sysdeps/ironclad/include/abi-bits/pid_t.h | 2 +- sysdeps/ironclad/include/abi-bits/poll.h | 2 +- sysdeps/ironclad/include/abi-bits/ptrace.h | 2 +- sysdeps/ironclad/include/abi-bits/reboot.h | 2 +- sysdeps/ironclad/include/abi-bits/resource.h | 2 +- sysdeps/ironclad/include/abi-bits/shm.h | 2 +- sysdeps/ironclad/include/abi-bits/signal.h | 2 +- sysdeps/ironclad/include/abi-bits/socket.h | 2 +- sysdeps/ironclad/include/abi-bits/socklen_t.h | 2 +- sysdeps/ironclad/include/abi-bits/stat.h | 2 +- sysdeps/ironclad/include/abi-bits/statfs.h | 2 +- sysdeps/ironclad/include/abi-bits/statvfs.h | 2 +- .../ironclad/include/abi-bits/suseconds_t.h | 2 +- sysdeps/ironclad/include/abi-bits/termios.h | 2 +- sysdeps/ironclad/include/abi-bits/time.h | 2 +- sysdeps/ironclad/include/abi-bits/uid_t.h | 2 +- sysdeps/ironclad/include/abi-bits/utsname.h | 2 +- sysdeps/ironclad/include/abi-bits/vm-flags.h | 2 +- sysdeps/ironclad/include/abi-bits/wait.h | 2 +- sysdeps/ironclad/include/abi-bits/xattr.h | 2 +- sysdeps/ironclad/include/asm/ioctls.h | 102 ++ sysdeps/ironclad/include/linux/fb.h | 397 +++++++ sysdeps/ironclad/include/mntent.h | 46 + sysdeps/ironclad/include/pty.h | 16 + sysdeps/ironclad/include/sys/ironclad.h | 41 - .../ironclad/include/sys/ironclad_devices.h | 44 + sysdeps/ironclad/include/sys/mac.h | 46 + sysdeps/ironclad/include/sys/mount.h | 19 + sysdeps/ironclad/include/sys/ptrace.h | 23 + sysdeps/ironclad/include/sys/reboot.h | 16 + sysdeps/ironclad/include/sys/sched2.h | 24 + sysdeps/ironclad/include/sys/syscall.h | 184 ++- sysdeps/ironclad/meson.build | 51 +- 107 files changed, 3546 insertions(+), 352 deletions(-) create mode 100644 abis/ironclad/access.h create mode 100644 abis/ironclad/blkcnt_t.h create mode 100644 abis/ironclad/blksize_t.h create mode 100644 abis/ironclad/clockid_t.h create mode 100644 abis/ironclad/dev_t.h create mode 100644 abis/ironclad/epoll.h create mode 100644 abis/ironclad/errno.h create mode 100644 abis/ironclad/fsblkcnt_t.h create mode 100644 abis/ironclad/fsfilcnt_t.h create mode 100644 abis/ironclad/gid_t.h create mode 100644 abis/ironclad/in.h create mode 100644 abis/ironclad/ino_t.h create mode 100644 abis/ironclad/inotify.h create mode 100644 abis/ironclad/ioctls.h create mode 100644 abis/ironclad/limits.h create mode 100644 abis/ironclad/mode_t.h create mode 100644 abis/ironclad/mqueue.h create mode 100644 abis/ironclad/msg.h create mode 100644 abis/ironclad/nlink_t.h create mode 100644 abis/ironclad/packet.h create mode 100644 abis/ironclad/pid_t.h create mode 100644 abis/ironclad/poll.h create mode 100644 abis/ironclad/ptrace.h create mode 100644 abis/ironclad/reboot.h create mode 100644 abis/ironclad/resource.h create mode 100644 abis/ironclad/shm.h create mode 100644 abis/ironclad/signal.h create mode 100644 abis/ironclad/socket.h create mode 100644 abis/ironclad/socklen_t.h create mode 100644 abis/ironclad/stat.h create mode 100644 abis/ironclad/statfs.h create mode 100644 abis/ironclad/statvfs.h create mode 100644 abis/ironclad/suseconds_t.h create mode 100644 abis/ironclad/termios.h create mode 100644 abis/ironclad/time.h create mode 100644 abis/ironclad/uid_t.h create mode 100644 abis/ironclad/utsname.h create mode 100644 abis/ironclad/vm-flags.h create mode 100644 abis/ironclad/wait.h create mode 100644 abis/ironclad/xattr.h create mode 100644 sysdeps/ironclad/crt-x86_64/crti.S create mode 100644 sysdeps/ironclad/crt-x86_64/crtn.S create mode 100644 sysdeps/ironclad/generic/mac.cpp create mode 100644 sysdeps/ironclad/generic/mntent.cpp create mode 100644 sysdeps/ironclad/generic/mount.cpp create mode 100644 sysdeps/ironclad/generic/ptrace.cpp create mode 100644 sysdeps/ironclad/generic/pty.cpp create mode 100644 sysdeps/ironclad/generic/reboot.cpp create mode 100644 sysdeps/ironclad/generic/sched2.cpp create mode 100644 sysdeps/ironclad/generic/thread.S create mode 100644 sysdeps/ironclad/generic/thread.cpp create mode 100644 sysdeps/ironclad/include/asm/ioctls.h create mode 100644 sysdeps/ironclad/include/linux/fb.h create mode 100644 sysdeps/ironclad/include/mntent.h create mode 100644 sysdeps/ironclad/include/pty.h delete mode 100644 sysdeps/ironclad/include/sys/ironclad.h create mode 100644 sysdeps/ironclad/include/sys/ironclad_devices.h create mode 100644 sysdeps/ironclad/include/sys/mac.h create mode 100644 sysdeps/ironclad/include/sys/mount.h create mode 100644 sysdeps/ironclad/include/sys/ptrace.h create mode 100644 sysdeps/ironclad/include/sys/reboot.h create mode 100644 sysdeps/ironclad/include/sys/sched2.h diff --git a/abis/ironclad/access.h b/abis/ironclad/access.h new file mode 100644 index 0000000000..bc19728c48 --- /dev/null +++ b/abis/ironclad/access.h @@ -0,0 +1,9 @@ +#ifndef _ABIBITS_ACCESS_H +#define _ABIBITS_ACCESS_H + +#define F_OK 1 +#define R_OK 2 +#define W_OK 4 +#define X_OK 8 + +#endif // _ABIBITS_ACCESS_H diff --git a/abis/ironclad/blkcnt_t.h b/abis/ironclad/blkcnt_t.h new file mode 100644 index 0000000000..51c151981e --- /dev/null +++ b/abis/ironclad/blkcnt_t.h @@ -0,0 +1,7 @@ +#ifndef _ABIBITS_BLKCNT_T_H +#define _ABIBITS_BLKCNT_T_H + +// TODO: use int64_t? +typedef long blkcnt_t; + +#endif // _ABIBITS_BLKCNT_T_H diff --git a/abis/ironclad/blksize_t.h b/abis/ironclad/blksize_t.h new file mode 100644 index 0000000000..9f87294c7a --- /dev/null +++ b/abis/ironclad/blksize_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_BLKSIZE_T_H +#define _ABIBITS_BLKSIZE_T_H + +// TODO: use int64_t? +typedef long blksize_t; + +#endif // _ABIBITS_BLKSIZE_T_H + diff --git a/abis/ironclad/clockid_t.h b/abis/ironclad/clockid_t.h new file mode 100644 index 0000000000..c3932eff31 --- /dev/null +++ b/abis/ironclad/clockid_t.h @@ -0,0 +1,7 @@ +#ifndef _ABIBITS_CLOCKID_T_H +#define _ABIBITS_CLOCKID_T_H + +typedef long clockid_t; + +#endif /* _ABIBITS_CLOCKID_T_H */ + diff --git a/abis/ironclad/dev_t.h b/abis/ironclad/dev_t.h new file mode 100644 index 0000000000..0b63fe5de3 --- /dev/null +++ b/abis/ironclad/dev_t.h @@ -0,0 +1,6 @@ +#ifndef _ABIBITS_DEV_T_H +#define _ABIBITS_DEV_T_H + +typedef unsigned long dev_t; + +#endif // _ABIBITS_DEV_T_H diff --git a/abis/ironclad/epoll.h b/abis/ironclad/epoll.h new file mode 100644 index 0000000000..49969d5f7f --- /dev/null +++ b/abis/ironclad/epoll.h @@ -0,0 +1,6 @@ +#ifndef _ABIBITS_EPOLL_H +#define _ABIBITS_EPOLL_H + +#define EPOLL_CLOEXEC 1 + +#endif // _ABIBITS_EPOLL_H diff --git a/abis/ironclad/errno.h b/abis/ironclad/errno.h new file mode 100644 index 0000000000..f8c720300f --- /dev/null +++ b/abis/ironclad/errno.h @@ -0,0 +1,126 @@ +#ifndef _ABIBITS_ERRNO_H +#define _ABIBITS_ERRNO_H + +#define EDOM 1 +#define EILSEQ 2 +#define ERANGE 3 + +#define E2BIG 1001 +#define EACCES 1002 +#define EADDRINUSE 1003 +#define EADDRNOTAVAIL 1004 +#define EAFNOSUPPORT 1005 +#define EAGAIN 1006 +#define EALREADY 1007 +#define EBADF 1008 +#define EBADMSG 1009 +#define EBUSY 1010 +#define ECANCELED 1011 +#define ECHILD 1012 +#define ECONNABORTED 1013 +#define ECONNREFUSED 1014 +#define ECONNRESET 1015 +#define EDEADLK 1016 +#define EDESTADDRREQ 1017 +#define EDQUOT 1018 +#define EEXIST 1019 +#define EFAULT 1020 +#define EFBIG 1021 +#define EHOSTUNREACH 1022 +#define EIDRM 1023 +#define EINPROGRESS 1024 +#define EINTR 1025 +#define EINVAL 1026 +#define EIO 1027 +#define EISCONN 1028 +#define EISDIR 1029 +#define ELOOP 1030 +#define EMFILE 1031 +#define EMLINK 1032 +#define EMSGSIZE 1034 +#define EMULTIHOP 1035 +#define ENAMETOOLONG 1036 +#define ENETDOWN 1037 +#define ENETRESET 1038 +#define ENETUNREACH 1039 +#define ENFILE 1040 +#define ENOBUFS 1041 +#define ENODEV 1042 +#define ENOENT 1043 +#define ENOEXEC 1044 +#define ENOLCK 1045 +#define ENOLINK 1046 +#define ENOMEM 1047 +#define ENOMSG 1048 +#define ENOPROTOOPT 1049 +#define ENOSPC 1050 +#define ENOSYS 1051 +#define ENOTCONN 1052 +#define ENOTDIR 1053 +#define ENOTEMPTY 1054 +#define ENOTRECOVERABLE 1055 +#define ENOTSOCK 1056 +#define ENOTSUP 1057 +#define ENOTTY 1058 +#define ENXIO 1059 +#define EOPNOTSUPP 1060 +#define EOVERFLOW 1061 +#define EOWNERDEAD 1062 +#define EPERM 1063 +#define EPIPE 1064 +#define EPROTO 1065 +#define EPROTONOSUPPORT 1066 +#define EPROTOTYPE 1067 +#define EROFS 1068 +#define ESPIPE 1069 +#define ESRCH 1070 +#define ESTALE 1071 +#define ETIMEDOUT 1072 +#define ETXTBSY 1073 +#define EWOULDBLOCK EAGAIN +#define EXDEV 1075 +#define ENODATA 1076 +#define ETIME 1077 +#define ENOKEY 1078 +#define ESHUTDOWN 1079 +#define EHOSTDOWN 1080 +#define EBADFD 1081 +#define ENOMEDIUM 1082 +#define ENOTBLK 1083 +#define ENONET 1084 +#define EPFNOSUPPORT 1085 +#define ESOCKTNOSUPPORT 1086 +#define ESTRPIPE 1087 +#define EREMOTEIO 1088 +#define ERFKILL 1089 +#define EBADR 1090 +#define EUNATCH 1091 +#define EMEDIUMTYPE 1092 +#define EREMOTE 1093 +#define EKEYREJECTED 1094 +#define EUCLEAN 1095 +#define EBADSLT 1096 +#define ENOANO 1097 +#define ENOCSI 1098 +#define ENOSTR 1099 +#define ETOOMANYREFS 1100 +#define ENOPKG 1101 +#define EKEYREVOKED 1102 +#define EXFULL 1103 +#define ELNRNG 1104 +#define ENOTUNIQ 1105 +#define ERESTART 1106 +#define EUSERS 1107 +#define ECHRNG 1108 +#define ELIBBAD 1109 +#define EL2HLT 1110 +#define EL3HLT 1111 +#define EKEYEXPIRED 1112 +#define ECOMM 1113 +#define EBADE 1114 +#define EHWPOISON 1115 +#define EBADRQC 1116 + +#define EIEIO 1524152434 + +#endif // _ABIBITS_ERRNO_H diff --git a/abis/ironclad/fcntl.h b/abis/ironclad/fcntl.h index d1e9f02a2d..10188deb1d 100644 --- a/abis/ironclad/fcntl.h +++ b/abis/ironclad/fcntl.h @@ -1,50 +1,58 @@ #ifndef _ABIBITS_FCNTL_H #define _ABIBITS_FCNTL_H -// reserve 3 bits for the access mode -#define O_ACCMODE 0x0007 -#define O_RDONLY 1 -#define O_WRONLY 2 -#define O_RDWR 3 -#define O_SEARCH 4 -#define O_EXEC 7 +// Flags supported by the kernel. +#define O_ACCMODE 0b000011 +#define O_RDONLY 00000001 +#define O_WRONLY 0b000010 +#define O_RDWR 0b000011 +#define O_APPEND 0b000100 +#define O_CLOEXEC 0b001000 +#define O_NOFOLLOW 0b010000 +#define O_NONBLOCK 0b100000 -// This flags are stubs. -#define O_APPEND 0x00008 -#define O_CREAT 0x00010 -#define O_DIRECTORY 0x00020 -#define O_EXCL 0x00040 -#define O_NOCTTY 0x00080 -#define O_NOFOLLOW 0x00100 -#define O_TRUNC 0x00200 -#define O_NONBLOCK 0x00400 -#define O_DSYNC 0x00800 -#define O_RSYNC 0x01000 -#define O_SYNC 0x02000 -#define O_CLOEXEC 0x04000 -#define O_PATH 0x08000 -#define O_LARGEFILE 0x10000 -#define O_NOATIME 0x20000 -#define O_TMPFILE 0x40000 +// Flags emulated by userland, we just have to make sure they dont overlap with +// kernel flags. +#define O_CREAT 0b0010000000 +#define O_EXCL 0b0100000000 +#define O_TRUNC 0b1000000000 -// The constants below are copied from abis/mlibc/fcntl.h. +// Stubbed flags, the value really doesnt matter as long as they dont overlap +// with usable ones. +// Implemented here as some software needs them to compile. +#define O_SEARCH 0b000000000010000000000 +#define O_EXEC 0b000000000100000000000 +#define O_NOCTTY 0b000000001000000000000 +#define O_DSYNC 0b000000010000000000000 +#define O_RSYNC 0b000000100000000000000 +#define O_SYNC 0b000001000000000000000 +#define O_PATH 0b000010000000000000000 +#define O_DIRECTORY 0b000100000000000000000 +#define O_LARGEFILE 0b001000000000000000000 +#define O_NOATIME 0b010000000000000000000 +#define O_TMPFILE 0b100000000000000000000 + +// Fcntl flags. +#define FD_CLOEXEC 1 #define F_DUPFD 1 #define F_DUPFD_CLOEXEC 2 -#define F_GETFD 3 -#define F_SETFD 4 -#define F_GETFL 5 -#define F_SETFL 6 -#define F_GETLK 7 -#define F_SETLK 8 -#define F_SETLKW 9 -#define F_GETOWN 10 -#define F_SETOWN 11 +#define F_GETFD 3 +#define F_SETFD 4 +#define F_GETFL 5 +#define F_SETFL 6 +#define F_GETPIPE_SZ 7 +#define F_SETPIPE_SZ 8 +#define F_GETLK 9 +#define F_SETLK 10 +#define F_SETLKW 11 #define F_RDLCK 1 #define F_UNLCK 2 #define F_WRLCK 3 -#define FD_CLOEXEC 1 +// Stubbed fcntl flags. +#define F_GETOWN 10 +#define F_SETOWN 11 #define F_SEAL_SHRINK 0x0002 #define F_SEAL_GROW 0x0004 @@ -53,12 +61,19 @@ #define F_ADD_SEALS 1033 #define F_GET_SEALS 1034 -#define AT_EMPTY_PATH 1 -#define AT_SYMLINK_FOLLOW 2 -#define AT_SYMLINK_NOFOLLOW 4 -#define AT_REMOVEDIR 8 -#define AT_EACCESS 512 +// At flags. +#define AT_REMOVEDIR 500 +#define AT_EACCESS 512 +#define AT_FDCWD 0x7FFFFFFF +#define AT_EMPTY_PATH 1 +#define AT_SYMLINK_FOLLOW 0 +#define AT_SYMLINK_NOFOLLOW 2 -#define AT_FDCWD -100 +#define POSIX_FADV_NORMAL 1 +#define POSIX_FADV_SEQUENTIAL 2 +#define POSIX_FADV_NOREUSE 3 +#define POSIX_FADV_DONTNEED 4 +#define POSIX_FADV_WILLNEED 5 +#define POSIX_FADV_RANDOM 6 #endif // _ABIBITS_FCNTL_H diff --git a/abis/ironclad/fsblkcnt_t.h b/abis/ironclad/fsblkcnt_t.h new file mode 100644 index 0000000000..0d7445619e --- /dev/null +++ b/abis/ironclad/fsblkcnt_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_FSBLKCNT_T_H +#define _ABIBITS_FSBLKCNT_T_H + +#include + +typedef __mlibc_uint64 fsblkcnt_t; + +#endif /* _ABIBITS_FSBLKCNT_T_H */ diff --git a/abis/ironclad/fsfilcnt_t.h b/abis/ironclad/fsfilcnt_t.h new file mode 100644 index 0000000000..1abda9a981 --- /dev/null +++ b/abis/ironclad/fsfilcnt_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_FSFILCNT_T_H +#define _ABIBITS_FSFILCNT_T_H + +#include + +typedef __mlibc_uint64 fsfilcnt_t; + +#endif /* _ABIBITS_FSFILCNT_T_H */ diff --git a/abis/ironclad/gid_t.h b/abis/ironclad/gid_t.h new file mode 100644 index 0000000000..252321f535 --- /dev/null +++ b/abis/ironclad/gid_t.h @@ -0,0 +1,6 @@ +#ifndef _ABIBITS_GID_T_H +#define _ABIBITS_GID_T_H + +typedef unsigned int gid_t; + +#endif // _ABIBITS_GID_T_H diff --git a/abis/ironclad/in.h b/abis/ironclad/in.h new file mode 100644 index 0000000000..3c736e3a31 --- /dev/null +++ b/abis/ironclad/in.h @@ -0,0 +1,168 @@ +#ifndef _ABIBITS_IN_H +#define _ABIBITS_IN_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct in_addr { + in_addr_t s_addr; +}; + +struct sockaddr_in { + sa_family_t sin_family; + in_port_t sin_port; + struct in_addr sin_addr; + uint8_t pad[8]; +}; +#define sin_zero pad /* for BSD Unix compatibility */ + +struct in6_addr { + union { + uint8_t __s6_addr[16]; + uint16_t __s6_addr16[8]; + uint32_t __s6_addr32[4]; + } __in6_union; +}; +#define s6_addr __in6_union.__s6_addr +#define s6_addr16 __in6_union.__s6_addr16 +#define s6_addr32 __in6_union.__s6_addr32 + +struct in6_pktinfo { + struct in6_addr ipi6_addr; + uint32_t ipi6_ifindex; +}; + +struct sockaddr_in6 { + sa_family_t sin6_family; + in_port_t sin6_port; + uint32_t sin6_flowinfo; + struct in6_addr sin6_addr; + uint32_t sin6_scope_id; +}; + +struct ipv6_mreq { + struct in6_addr ipv6mr_multiaddr; + unsigned ipv6mr_interface; +}; + +struct ip_mreq { + struct in_addr imr_multiaddr; + struct in_addr imr_interface; +}; + +struct ip_mreq_source { + struct in_addr imr_multiaddr; + struct in_addr imr_interface; + struct in_addr imr_sourceaddr; +}; + +struct ip_mreqn { + struct in_addr imr_multiaddr; + struct in_addr imr_address; + int imr_ifindex; +}; + +struct in_pktinfo { + unsigned int ipi_ifindex; + struct in_addr ipi_spec_dst; + struct in_addr ipi_addr; +}; + +struct group_source_req { + uint32_t gsr_interface; + struct sockaddr_storage gsr_group; + struct sockaddr_storage gsr_source; +}; + +#ifdef __cplusplus +} +#endif + +#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } +#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } + +#define IPPROTO_IP 1 +#define IPPROTO_IPV6 2 +#define IPPROTO_ICMP 3 +#define IPPROTO_RAW 4 +#define IPPROTO_TCP 5 +#define IPPROTO_UDP 6 +#define IPPROTO_IGMP 7 +#define IPPROTO_IPIP 8 +#define IPPROTO_DCCP 33 +#define IPPROTO_ROUTING 43 +#define IPPROTO_GRE 47 +#define IPPROTO_ESP 50 +#define IPPROTO_AH 51 +#define IPPROTO_ICMPV6 58 +#define IPPROTO_DSTOPTS 60 +#define IPPROTO_COMP 108 +#define IPPROTO_SCTP 132 +#define IPPROTO_UDPLITE 136 +#define IPPROTO_MAX 256 + +#define INADDR_ANY ((in_addr_t)0x00000000) +#define INADDR_BROADCAST ((in_addr_t)0xffffffff) +#define INADDR_LOOPBACK ((in_addr_t)0x7f000001) +#define INADDR_NONE ((in_addr_t)0xffffffff) + +#define INET_ADDRSTRLEN 16 + +#define INET6_ADDRSTRLEN 46 + +#define IPV6_JOIN_GROUP 1 +#define IPV6_LEAVE_GROUP 2 +#define IPV6_MULTICAST_HOPS 3 +#define IPV6_MULTICAST_IF 4 +#define IPV6_MULTICAST_LOOP 5 +#define IPV6_UNICAST_HOPS 6 +#define IPV6_V6ONLY 7 +#define IPV6_PMTUDISC_DONT 8 +#define IPV6_PMTUDISC_DO 9 +#define IPV6_MTU 10 +#define IPV6_2292PKTOPTIONS 11 +#define IPV6_MTU_DISCOVER 23 +#define IPV6_RECVERR 25 +#define IPV6_RECVPKTINFO 49 +#define IPV6_PKTINFO 50 +#define IPV6_RECVHOPLIMIT 51 +#define IPV6_HOPLIMIT 52 +#define IPV6_TCLASS 67 + +#define IP_TOS 1 +#define IP_TTL 2 +#define IP_OPTIONS 4 +#define IP_PMTUDISC_OMIT 5 +#define IP_PKTINFO 8 +#define IP_PKTOPTIONS 9 +#define IP_MTU_DISCOVER 10 +#define IP_RECVERR 11 +#define IP_RECVTTL 12 +#define IP_UNICAST_IF 13 +#define IP_MTU 14 + +#define IP_DEFAULT_MULTICAST_TTL 1 +#define IP_MULTICAST_IF 32 +#define IP_MULTICAST_TTL 33 +#define IP_MULTICAST_LOOP 34 +#define IP_ADD_MEMBERSHIP 35 +#define IP_DROP_MEMBERSHIP 36 +#define IP_UNBLOCK_SOURCE 37 +#define IP_BLOCK_SOURCE 38 +#define IP_ADD_SOURCE_MEMBERSHIP 39 +#define IP_DROP_SOURCE_MEMBERSHIP 40 +#define MCAST_JOIN_SOURCE_GROUP 46 +#define MCAST_LEAVE_SOURCE_GROUP 47 + +#define IP_PMTUDISC_DONT 0 +#define IP_PMTUDISC_DO 2 + +#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP +#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP + +#endif // _ABIBITS_IN_H diff --git a/abis/ironclad/ino_t.h b/abis/ironclad/ino_t.h new file mode 100644 index 0000000000..264d888f45 --- /dev/null +++ b/abis/ironclad/ino_t.h @@ -0,0 +1,7 @@ +#ifndef _ABIBITS_INO_T_H +#define _ABIBITS_INO_T_H + +// TODO: use (u)int64_t? +typedef long ino_t; + +#endif // _ABIBITS_INO_T_H diff --git a/abis/ironclad/inotify.h b/abis/ironclad/inotify.h new file mode 100644 index 0000000000..38c9c77da7 --- /dev/null +++ b/abis/ironclad/inotify.h @@ -0,0 +1,7 @@ +#ifndef _ABIBITS_INOTIFY_H +#define _ABIBITS_INOTIFY_H + +#define IN_CLOEXEC 1 +#define IN_NONBLOCK 2 + +#endif // _ABIBITS_INOTIFY_H diff --git a/abis/ironclad/ioctls.h b/abis/ironclad/ioctls.h new file mode 100644 index 0000000000..c39abb5065 --- /dev/null +++ b/abis/ironclad/ioctls.h @@ -0,0 +1,13 @@ +#ifndef _ABIBITS_IOCTLS_H +#define _ABIBITS_IOCTLS_H + +#define SIOCPROTOPRIVATE 0x89E0 +#define SIOCGIFNAME 0x8910 +#define SIOCGIFCONF 0x8912 +#define SIOCGIFFLAGS 0x8913 +#define SIOCSIFFLAGS 0x8914 +#define SIOCGIFINDEX 0x8933 +#define SIOCATMARK 0x8905 +#define SIOCGIFHWADDR 0x8927 + +#endif /* _ABIBITS_IOCTLS_H */ diff --git a/abis/ironclad/limits.h b/abis/ironclad/limits.h new file mode 100644 index 0000000000..6aac6221fd --- /dev/null +++ b/abis/ironclad/limits.h @@ -0,0 +1,14 @@ +#ifndef _ABIBITS_LIMITS_H +#define _ABIBITS_LIMITS_H + +#define IOV_MAX 1024 + +// Niceness related +#define NZERO 20 + +// Maximum hostname length, posix defines it as 255 +#define HOST_NAME_MAX 255 + +#define OPEN_MAX 256 + +#endif //_ABIBITS_LIMITS_H diff --git a/abis/ironclad/mode_t.h b/abis/ironclad/mode_t.h new file mode 100644 index 0000000000..77f75a9bd5 --- /dev/null +++ b/abis/ironclad/mode_t.h @@ -0,0 +1,6 @@ +#ifndef _ABIBITS_MODE_T_H +#define _ABIBITS_MODE_T_H + +typedef int mode_t; + +#endif // _ABIBITS_MODE_T_H diff --git a/abis/ironclad/mqueue.h b/abis/ironclad/mqueue.h new file mode 100644 index 0000000000..f18210ca71 --- /dev/null +++ b/abis/ironclad/mqueue.h @@ -0,0 +1,20 @@ +#ifndef _ABIBITS_MQUEUE_H +#define _ABIBITS_MQUEUE_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct mq_attr { + long mq_flags; + long mq_maxmsg; + long mq_msgsize; + long mq_curmsgs; + long __pad[4]; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _ABIBITS_MQUEUE_H */ diff --git a/abis/ironclad/msg.h b/abis/ironclad/msg.h new file mode 100644 index 0000000000..5e890c0687 --- /dev/null +++ b/abis/ironclad/msg.h @@ -0,0 +1,39 @@ +#ifndef _ABIBITS_MSG_H +#define _ABIBITS_MSG_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__i386__) +typedef __mlibc_uint64 msglen_t; +typedef __mlibc_uint64 msgqnum_t; +#else +typedef unsigned long msglen_t; +typedef unsigned long msgqnum_t; +#endif + +struct msqid_ds { + struct ipc_perm msg_perm; + time_t msg_stime; + time_t msg_rtime; + time_t msg_ctime; + unsigned long msg_cbytes; + msgqnum_t msg_qnum; + msglen_t msg_qbytes; + pid_t msg_lspid; + pid_t msg_lrpid; + unsigned long __unused[2]; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _ABIBITS_MSG_H */ + diff --git a/abis/ironclad/nlink_t.h b/abis/ironclad/nlink_t.h new file mode 100644 index 0000000000..30e178c707 --- /dev/null +++ b/abis/ironclad/nlink_t.h @@ -0,0 +1,6 @@ +#ifndef _ABIBITS_NLINK_T_H +#define _ABIBITS_NLINK_T_H + +typedef int nlink_t; + +#endif // _ABIBITS_NLINK_T_H diff --git a/abis/ironclad/packet.h b/abis/ironclad/packet.h new file mode 100644 index 0000000000..ee1a424f34 --- /dev/null +++ b/abis/ironclad/packet.h @@ -0,0 +1,6 @@ +#ifndef _ABIBITS_PACKET_H +#define _ABIBITS_PACKET_H + +#define PACKET_HOST 0 + +#endif // _ABIBITS_PACKET_H diff --git a/abis/ironclad/pid_t.h b/abis/ironclad/pid_t.h new file mode 100644 index 0000000000..5ffbd06b8b --- /dev/null +++ b/abis/ironclad/pid_t.h @@ -0,0 +1,6 @@ +#ifndef _ABIBITS_PID_T_H +#define _ABIBITS_PID_T_H + +typedef int pid_t; + +#endif // _ABIBITS_PID_T_H diff --git a/abis/ironclad/poll.h b/abis/ironclad/poll.h new file mode 100644 index 0000000000..e0fe1a57c7 --- /dev/null +++ b/abis/ironclad/poll.h @@ -0,0 +1,16 @@ +#ifndef _ABIBITS_POLL_H +#define _ABIBITS_POLL_H + +#define POLLIN 0x01 +#define POLLOUT 0x02 +#define POLLPRI 0x04 +#define POLLHUP 0x08 +#define POLLERR 0x10 +#define POLLRDHUP 0x20 +#define POLLNVAL 0x40 +#define POLLWRNORM 0x80 +#define POLLRDNORM 0x100 +#define POLLWRBAND 0x200 +#define POLLRDBAND 0x400 + +#endif // _ABIBITS_POLL_H diff --git a/abis/ironclad/ptrace.h b/abis/ironclad/ptrace.h new file mode 100644 index 0000000000..6f35eacc53 --- /dev/null +++ b/abis/ironclad/ptrace.h @@ -0,0 +1,56 @@ +#ifndef _ABIBITS_PTRACE_H +#define _ABIBITS_PTRACE_H + +#define PTRACE_PEEKTEXT 1 +#define PTRACE_PEEKDATA 2 +#define PTRACE_PEEKUSER 3 +#define PTRACE_POKETEXT 4 +#define PTRACE_POKEDATA 5 +#define PTRACE_CONT 7 +#define PTRACE_KILL 8 +#define PTRACE_SINGLESTEP 9 +#define PTRACE_GETREGS 14 +#define PTRACE_SETREGS 15 +#define PTRACE_ATTACH 16 +#define PTRACE_DETACH 17 +#define PTRACE_GETFPXREGS 18 +#define PTRACE_SETFPXREGS 19 +#define PTRACE_GETFPREGS 20 +#define PTRACE_SYSCALL 24 +#define PTRACE_SETOPTIONS 0x4200 +#define PTRACE_GETEVENTMSG 0x4201 +#define PTRACE_GETSIGINFO 0x4202 +#define PTRACE_SETSIGINFO 0x4203 +#define PTRACE_GETREGSET 0x4204 +#define PTRACE_SETREGSET 0x4205 +#define PTRACE_SEIZE 0x4206 +#define PTRACE_INTERRUPT 0x4207 +#define PTRACE_LISTEN 0x4208 +#define PTRACE_PEEKSIGINFO 0x4209 +#define PTRACE_GETSIGMASK 0x420A +#define PTRACE_SETSIGMASK 0x420B +#define PTRACE_SECCOMP_GET_FILTER 0x420C + +#define PTRACE_CE_O_TRACESYSGOOD 0x00000001 +#define PTRACE_O_TRACEFORK 0x00000002 +#define PTRACE_O_TRACEVFORK 0x00000004 +#define PTRACE_O_TRACECLONE 0x00000008 +#define PTRACE_O_TRACEEXEC 0x00000010 +#define PTRACE_O_TRACEVFORKDONE 0x00000020 +#define PTRACE_O_TRACEEXIT 0x00000040 +#define PTRACE_O_TRACESECCOMP 0x00000080 +#define PTRACE_O_EXITKILL 0x00100000 +#define PTRACE_O_SUSPEND_SECCOMP 0x00200000 +#define PTRACE_O_MASK 0x003000ff + +#define PTRACE_EVENT_FORK 1 +#define PTRACE_EVENT_VFORK 2 +#define PTRACE_EVENT_CLONE 3 +#define PTRACE_EVENT_EXEC 4 +#define PTRACE_EVENT_VFORK_DONE 5 +#define PTRACE_EVENT_EXIT 6 +#define PTRACE_EVENT_SECCOMP 7 + +#define PTRACE_PEEKSIGINFO_SHARED 1 + +#endif // _ABIBITS_PTRACE_H diff --git a/abis/ironclad/reboot.h b/abis/ironclad/reboot.h new file mode 100644 index 0000000000..aadc18f2e6 --- /dev/null +++ b/abis/ironclad/reboot.h @@ -0,0 +1,12 @@ +#ifndef _ABIBITS_REBOOT_H +#define _ABIBITS_REBOOT_H + +#define RB_AUTOBOOT 0x01234567 +#define RB_HALT_SYSTEM 0xcdef0123 +#define RB_ENABLE_CAD 0x89abcdef +#define RB_DISABLE_CAD 0 +#define RB_POWER_OFF 0x4321fedc +#define RB_SW_SUSPEND 0xd000fce2 +#define RB_KEXEC 0x45584543 + +#endif // _ABIBITS_REBOOT_H diff --git a/abis/ironclad/resource.h b/abis/ironclad/resource.h new file mode 100644 index 0000000000..927588b4b8 --- /dev/null +++ b/abis/ironclad/resource.h @@ -0,0 +1,53 @@ +#ifndef _ABIBITS_RESOURCE_H +#define _ABIBITS_RESOURCE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define RUSAGE_SELF 1 +#define RUSAGE_CHILDREN 2 + +#define RLIMIT_CORE 1 +#define RLIMIT_CPU 2 +#define RLIMIT_DATA 3 +#define RLIMIT_FSIZE 4 +#define RLIMIT_NOFILE 5 +#define RLIMIT_STACK 6 +#define RLIMIT_AS 7 +#define RLIMIT_MEMLOCK 8 +#define RLIMIT_RSS 9 +#define RLIMIT_NPROC 10 +#define RLIMIT_LOCKS 11 +#define RLIMIT_SIGPENDING 12 +#define RLIMIT_MSGQUEUE 13 +#define RLIMIT_NICE 14 +#define RLIMIT_RTPRIO 15 +#define RLIMIT_NLIMITS 16 + +struct rusage { + struct timeval ru_utime; + struct timeval ru_stime; + long int ru_maxrss; + long int ru_ixrss; + long int ru_idrss; + long int ru_isrss; + long int ru_minflt; + long int ru_majflt; + long int ru_nswap; + long int ru_inblock; + long int ru_oublock; + long int ru_msgsnd; + long int ru_msgrcv; + long int ru_nsignals; + long int ru_nvcsw; + long int ru_nivcsw; +}; + +#ifdef __cplusplus +} +#endif + +#endif // _ABIBITS_RESOURCE_H diff --git a/abis/ironclad/shm.h b/abis/ironclad/shm.h new file mode 100644 index 0000000000..93fb01bbc7 --- /dev/null +++ b/abis/ironclad/shm.h @@ -0,0 +1,21 @@ +#ifndef _ABIBITS_SHM_H +#define _ABIBITS_SHM_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct shm_info { + int used_ids; + unsigned long shm_tot; + unsigned long shm_rss; + unsigned long shm_swp; + unsigned long swap_attempts; + unsigned long swap_successes; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _ABIBITS_SHM_H */ diff --git a/abis/ironclad/signal.h b/abis/ironclad/signal.h new file mode 100644 index 0000000000..2d20315826 --- /dev/null +++ b/abis/ironclad/signal.h @@ -0,0 +1,192 @@ +#ifndef _ABIBITS_SIGNAL_H +#define _ABIBITS_SIGNAL_H + +#include +#include +#include + +union sigval { + int sival_int; + void *sival_ptr; +}; + +typedef struct { + int si_signo; + int si_code; + int si_errno; + pid_t si_pid; + uid_t si_uid; + void *si_addr; + int si_status; + union sigval si_value; +} siginfo_t; + +#ifdef __cplusplus +extern "C" { +#endif + +// Argument for signal() +typedef void (*__sighandler) (int); + +#define SIG_ERR ((__sighandler)(void *)(-1)) +#define SIG_DFL ((__sighandler)(void *)(-2)) +#define SIG_IGN ((__sighandler)(void *)(-3)) + +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGBUS 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGUSR1 10 +#define SIGSEGV 11 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGSTKFLT 16 +#define SIGCHLD 17 +#define SIGCONT 18 +#define SIGSTOP 19 +#define SIGTSTP 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGURG 23 +#define SIGXCPU 24 +#define SIGXFSZ 25 +#define SIGVTALRM 26 +#define SIGPROF 27 +#define SIGWINCH 28 +#define SIGIO 29 +#define SIGPOLL SIGIO +#define SIGPWR 30 +#define SIGSYS 31 +#define SIGRTMIN 32 +#define SIGRTMAX 33 +#define SIGCANCEL SIGSYS + +// siginfo->si_info constants +// SIGBUS +#define BUS_ADRALN 1 +#define BUS_ADRERR 2 +#define BUS_OBJERR 3 + +// SIGILL +#define ILL_ILLOPC 1 +#define ILL_ILLOPN 2 +#define ILL_ILLADR 3 +#define ILL_ILLTRP 4 +#define ILL_PRVOPC 5 +#define ILL_PRVREG 6 +#define ILL_COPROC 7 +#define ILL_BADSTK 8 +#define ILL_BADIADDR 9 + +// SIGSEGV +#define SEGV_MAPERR 1 +#define SEGV_ACCERR 2 + +// TODO: replace this by uint64_t +typedef long sigset_t; + +#define SIGUNUSED SIGSYS + +// constants for sigprocmask() +#define SIG_BLOCK 1 +#define SIG_UNBLOCK 2 +#define SIG_SETMASK 3 + +#define SA_NOCLDSTOP (1 << 0) +#define SA_ONSTACK (1 << 1) +#define SA_RESETHAND (1 << 2) +#define SA_RESTART (1 << 3) +#define SA_SIGINFO (1 << 4) +#define SA_NOCLDWAIT (1 << 5) +#define SA_NODEFER (1 << 6) + +#define MINSIGSTKSZ 2048 +#define SIGSTKSZ 8192 +#define SS_ONSTACK 1 +#define SS_DISABLE 2 + +typedef struct __stack { + void *ss_sp; + size_t ss_size; + int ss_flags; +} stack_t; + +// constants for sigev_notify of struct sigevent +#define SIGEV_NONE 1 +#define SIGEV_SIGNAL 2 +#define SIGEV_THREAD 3 + +#define SI_ASYNCNL (-60) +#define SI_TKILL (-6) +#define SI_SIGIO (-5) +#define SI_ASYNCIO (-4) +#define SI_MESGQ (-3) +#define SI_TIMER (-2) +#define SI_QUEUE (-1) +#define SI_USER 0 +#define SI_KERNEL 128 + +#define NSIG 65 +#define _NSIG NSIG + +#define CLD_EXITED 1 +#define CLD_KILLED 2 +#define CLD_DUMPED 3 +#define CLD_TRAPPED 4 +#define CLD_STOPPED 5 +#define CLD_CONTINUED 6 + +struct sigevent { + int sigev_notify; + int sigev_signo; + union sigval sigev_value; + void (*sigev_notify_function)(union sigval); + // MISSING: sigev_notify_attributes +}; + +struct sigaction { + union { + void (*sa_handler)(int); + void (*sa_sigaction)(int, siginfo_t *, void *); + }; + sigset_t sa_mask; + int sa_flags; +}; + +#if defined(__x86_64__) || defined(__aarch64__) +// TODO: This is wrong for AArch64. + +typedef struct { + unsigned long oldmask; + unsigned long gregs[16]; + unsigned long pc, pr, sr; + unsigned long gbr, mach, macl; + unsigned long fpregs[16]; + unsigned long xfpregs[16]; + unsigned int fpscr, fpul, ownedfp; +} mcontext_t; + +typedef struct __ucontext { + unsigned long uc_flags; + struct __ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + sigset_t uc_sigmask; +} ucontext_t; + +#else +#error "Missing architecture specific code." +#endif + +#ifdef __cplusplus +} +#endif + +#endif // _ABIBITS_SIGNAL_H diff --git a/abis/ironclad/socket.h b/abis/ironclad/socket.h new file mode 100644 index 0000000000..48b8178b91 --- /dev/null +++ b/abis/ironclad/socket.h @@ -0,0 +1,165 @@ +#ifndef _ABIBITS_SOCKET_H +#define _ABIBITS_SOCKET_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef unsigned int sa_family_t; + +struct msghdr { + void *msg_name; + socklen_t msg_namelen; + struct iovec *msg_iov; + int msg_iovlen; + void *msg_control; + socklen_t msg_controllen; + int msg_flags; +}; + +struct sockaddr_storage { + sa_family_t ss_family; + char __padding[128 - sizeof(sa_family_t)]; +}; + +struct mmsghdr { + struct msghdr msg_hdr; + unsigned int msg_len; +}; + +struct cmsghdr { + socklen_t cmsg_len; + int cmsg_level; + int cmsg_type; +}; + +#ifdef __cplusplus +} +#endif + +#define SCM_RIGHTS 1 +#define SCM_TIMESTAMP SO_TIMESTAMP +#define SCM_TIMESTAMPNS SO_TIMESTAMPNS + +//MISSING: CMSG_DATA, CMSG_NXTHDR, CMSG_FIRSTHDR + +#define SCM_CREDENTIALS 0x02 + +#define SOCK_DGRAM 1 +#define SOCK_RAW 2 +#define SOCK_SEQPACKET 3 +#define SOCK_STREAM 4 +#define SOCK_DCCP 5 +#define SOCK_NONBLOCK 0x10000 +#define SOCK_CLOEXEC 0x20000 +#define SOCK_RDM 0x40000 + +#define SOL_SOCKET 1 +#define SOL_IPV6 41 +#define SOL_PACKET 263 +#define SOL_NETLINK 270 + +#define SO_ACCEPTCONN 1 +#define SO_BROADCAST 2 +#define SO_DEBUG 3 +#define SO_DONTROUTE 4 +#define SO_ERROR 5 +#define SO_KEEPALIVE 6 +#define SO_LINGER 7 +#define SO_OOBINLINE 8 +#define SO_RCVBUF 9 +#define SO_RCVLOWAT 10 +#define SO_RCVTIMEO 11 +#define SO_REUSEADDR 12 +#define SO_SNDBUF 13 +#define SO_SNDLOWAT 14 +#define SO_SNDTIMEO 15 +#define SO_TYPE 16 +#define SO_SNDBUFFORCE 17 +#define SO_PEERCRED 18 +#define SO_ATTACH_FILTER 19 +#define SO_PASSCRED 20 +#define SO_RCVBUFFORCE 21 +#define SO_DETACH_FILTER 22 +#define SO_PROTOCOL 23 +#define SO_REUSEPORT 24 +#define SO_TIMESTAMP 25 +#define SO_PEERSEC 26 +#define SO_BINDTODEVICE 27 +#define SO_DOMAIN 28 +#define SO_PASSSEC 29 +#define SO_TIMESTAMPNS 30 +#define SO_PRIORITY 31 +#define SO_MARK 32 + +#define SOMAXCONN 1 + +#define MSG_CTRUNC 0x1 +#define MSG_DONTROUTE 0x2 +#define MSG_EOR 0x4 +#define MSG_OOB 0x8 +#define MSG_NOSIGNAL 0x10 +#define MSG_PEEK 0x20 +#define MSG_TRUNC 0x40 +#define MSG_WAITALL 0x80 +#define MSG_FIN 0x200 +#define MSG_CONFIRM 0x800 + +// Linux extensions. +#define MSG_DONTWAIT 0x1000 +#define MSG_CMSG_CLOEXEC 0x2000 +#define MSG_MORE 0x4000 +#define MSG_FASTOPEN 0x20000000 + +// GNU (?) extension: Protocol family constants. + +#define PF_INET 1 +#define PF_INET6 2 +#define PF_UNIX 3 +#define PF_LOCAL 3 +#define PF_UNSPEC 4 +#define PF_NETLINK 5 +#define PF_BRIDGE 6 +#define PF_APPLETALK 7 +#define PF_BLUETOOTH 8 +#define PF_DECnet 9 +#define PF_IPX 10 +#define PF_ISDN 11 +#define PF_SNA 12 +#define PF_PACKET 13 +#define PF_AX25 14 +#define PF_NETROM 15 +#define PF_ROSE 16 +#define PF_TIPC 30 +#define PF_ALG 38 +#define PF_MAX 46 + +#define AF_INET PF_INET +#define AF_INET6 PF_INET6 +#define AF_UNIX PF_UNIX +#define AF_LOCAL PF_LOCAL +#define AF_UNSPEC PF_UNSPEC +#define AF_NETLINK PF_NETLINK +#define AF_BRIDGE PF_BRIDGE +#define AF_APPLETALK PF_APPLETALK +#define AF_BLUETOOTH PF_BLUETOOTH +#define AF_DECnet PF_DECnet +#define AF_IPX PF_IPX +#define AF_ISDN PF_ISDN +#define AF_SNA PF_SNA +#define AF_PACKET PF_PACKET +#define AF_PACKET PF_PACKET +#define AF_AX25 PF_AX25 +#define AF_NETROM PF_NETROM +#define AF_ROSE PF_ROSE +#define AF_TIPC PF_TIPC +#define AF_ALG PF_ALG +#define AF_MAX PF_MAX + +#define SHUT_RD 1 +#define SHUT_RDWR 2 +#define SHUT_WR 3 +#endif diff --git a/abis/ironclad/socklen_t.h b/abis/ironclad/socklen_t.h new file mode 100644 index 0000000000..190e5f9f81 --- /dev/null +++ b/abis/ironclad/socklen_t.h @@ -0,0 +1,6 @@ +#ifndef _ABIBITS_SOCKLEN_T_H +#define _ABIBITS_SOCKLEN_T_H + +typedef unsigned socklen_t; + +#endif /* _ABIBITS_SOCKLEN_T_H */ diff --git a/abis/ironclad/stat.h b/abis/ironclad/stat.h new file mode 100644 index 0000000000..3f55970e07 --- /dev/null +++ b/abis/ironclad/stat.h @@ -0,0 +1,69 @@ +#ifndef _ABIBITS_STAT_H +#define _ABIBITS_STAT_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define S_IFMT 0x0F000 +#define S_IFBLK 0x06000 +#define S_IFCHR 0x02000 +#define S_IFIFO 0x01000 +#define S_IFREG 0x08000 +#define S_IFDIR 0x04000 +#define S_IFLNK 0x0A000 +#define S_IFSOCK 0x0C000 + +#define S_IRWXU 0700 +#define S_IRUSR 0400 +#define S_IWUSR 0200 +#define S_IXUSR 0100 +#define S_IRWXG 070 +#define S_IRGRP 040 +#define S_IWGRP 020 +#define S_IXGRP 010 +#define S_IRWXO 07 +#define S_IROTH 04 +#define S_IWOTH 02 +#define S_IXOTH 01 +#define S_ISUID 04000 +#define S_ISGID 02000 +#define S_ISVTX 01000 + +#define S_IREAD S_IRUSR +#define S_IWRITE S_IWUSR +#define S_IEXEC S_IXUSR + +#ifdef __cplusplus +extern "C" { +#endif + +struct stat { + dev_t st_dev; + ino_t st_ino; + mode_t st_mode; + nlink_t st_nlink; + uid_t st_uid; + gid_t st_gid; + dev_t st_rdev; + off_t st_size; + struct timespec st_atim; + struct timespec st_mtim; + struct timespec st_ctim; + blksize_t st_blksize; + blkcnt_t st_blocks; +}; + +#ifdef __cplusplus +} +#endif + +#endif // _ABIBITS_STAT_H diff --git a/abis/ironclad/statfs.h b/abis/ironclad/statfs.h new file mode 100644 index 0000000000..60c977f65f --- /dev/null +++ b/abis/ironclad/statfs.h @@ -0,0 +1,28 @@ +#ifndef _ABIBITS_STATFS_H +#define _ABIBITS_STATFS_H + +#include +#include + +typedef struct __mlibc_fsid { + int __val[2]; +} fsid_t; + +struct statfs { + unsigned long f_type; + unsigned long f_bsize; + fsblkcnt_t f_blocks; + fsblkcnt_t f_bfree; + fsblkcnt_t f_bavail; + + fsfilcnt_t f_files; + fsfilcnt_t f_ffree; + fsid_t f_fsid; + unsigned long f_namelen; + unsigned long f_frsize; + unsigned long f_flags; + unsigned long __f_spare[4]; +}; + +#endif /* _ABIBITS_STATFS_H */ + diff --git a/abis/ironclad/statvfs.h b/abis/ironclad/statvfs.h new file mode 100644 index 0000000000..7a75d3a4b1 --- /dev/null +++ b/abis/ironclad/statvfs.h @@ -0,0 +1,29 @@ +#ifndef _ABIBITS_STATVFS_H +#define _ABIBITS_STATVFS_H + +#include +#include + +#define ST_RDONLY 1 +#define ST_NOSUID 2 +#define ST_MANDLOCK 64 + +// On Linux, this struct is not directly used by the kernel. +struct statvfs { + unsigned long f_bsize; + unsigned long f_frsize; + fsblkcnt_t f_blocks; + fsblkcnt_t f_bfree; + fsblkcnt_t f_bavail; + + fsfilcnt_t f_files; + fsfilcnt_t f_ffree; + fsfilcnt_t f_favail; + + unsigned long f_fsid; + unsigned long f_flag; + unsigned long f_namemax; +}; + +#endif /* _ABIBITS_STATVFS_H */ + diff --git a/abis/ironclad/suseconds_t.h b/abis/ironclad/suseconds_t.h new file mode 100644 index 0000000000..723ddfaeb0 --- /dev/null +++ b/abis/ironclad/suseconds_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_SUSECONDS_T_H +#define _ABIBITS_SUSECONDS_T_H + +#include + +typedef __mlibc_int64 suseconds_t; + +#endif /* _ABIBITS_SUSECONDS_T_H */ diff --git a/abis/ironclad/termios.h b/abis/ironclad/termios.h new file mode 100644 index 0000000000..42784b7b63 --- /dev/null +++ b/abis/ironclad/termios.h @@ -0,0 +1,109 @@ +#ifndef _ABIBITS_TERMIOS_H +#define _ABIBITS_TERMIOS_H + +typedef unsigned int cc_t; +typedef unsigned int speed_t; +typedef unsigned int tcflag_t; + +// indices for the c_cc array in struct termios +#define NCCS 11 +#define VEOF 0 +#define VEOL 1 +#define VERASE 2 +#define VINTR 3 +#define VKILL 4 +#define VMIN 5 +#define VQUIT 6 +#define VSTART 7 +#define VSTOP 8 +#define VSUSP 9 +#define VTIME 10 + +// bitwise flags for c_iflag in struct termios +#define BRKINT 0x0001 +#define ICRNL 0x0002 +#define IGNBRK 0x0004 +#define IGNCR 0x0008 +#define IGNPAR 0x0010 +#define INLCR 0x0020 +#define INPCK 0x0040 +#define ISTRIP 0x0080 +#define IXANY 0x0100 +#define IXOFF 0x0200 +#define IXON 0x0400 +#define PARMRK 0x0800 + +// bitwise flags for c_oflag in struct termios +#define OPOST 0x0001 +#define ONLCR 0x0002 +#define OCRNL 0x0004 +#define ONOCR 0x0008 +#define ONLRET 0x0010 +#define OFDEL 0x0020 +#define OFILL 0x0040 + +#define NLDLY 0x0080 +#define NL0 0x0000 +#define NL1 0x0080 + +#define CRDLY 0x0300 +#define CR0 0x0000 +#define CR1 0x0100 +#define CR2 0x0200 +#define CR3 0x0300 + +#define TABDLY 0x0C00 +#define TAB0 0x0000 +#define TAB1 0x0400 +#define TAB2 0x0800 +#define TAB3 0x0C00 + +#define BSDLY 0x1000 +#define BS0 0x0000 +#define BS1 0x1000 + +#define VTDLY 0x2000 +#define VT0 0x0000 +#define VT1 0x2000 + +#define FFDLY 0x4000 +#define FF0 0x0000 +#define FF1 0x4000 + +// bitwise constants for c_cflag in struct termios +#define CSIZE 0x0003 +#define CS5 0x0000 +#define CS6 0x0001 +#define CS7 0x0002 +#define CS8 0x0003 + +#define CSTOPB 0x0004 +#define CREAD 0x0008 +#define PARENB 0x0010 +#define PARODD 0x0020 +#define HUPCL 0x0040 +#define CLOCAL 0x0080 + +// bitwise constants for c_lflag in struct termios +#define ECHO 0x0001 +#define ECHOE 0x0002 +#define ECHOK 0x0004 +#define ECHONL 0x0008 +#define ICANON 0x0010 +#define IEXTEN 0x0020 +#define ISIG 0x0040 +#define NOFLSH 0x0080 +#define TOSTOP 0x0100 +#define ECHOPRT 0x0200 + +struct termios { + tcflag_t c_iflag; + tcflag_t c_oflag; + tcflag_t c_cflag; + tcflag_t c_lflag; + cc_t c_cc[NCCS]; + speed_t ibaud; + speed_t obaud; +}; + +#endif diff --git a/abis/ironclad/time.h b/abis/ironclad/time.h new file mode 100644 index 0000000000..3f49db3c4a --- /dev/null +++ b/abis/ironclad/time.h @@ -0,0 +1,15 @@ +#ifndef _ABIBITS_TIME_H +#define _ABIBITS_TIME_H + +#include + +struct itimerval { + struct timeval it_interval; /* Interval for periodic timer */ + struct timeval it_value; /* Time until next expiration */ +}; + +#define ITIMER_REAL 0 +#define ITIMER_VIRTUAL 1 +#define ITIMER_PROF 2 + +#endif // _ABIBITS_TIME_H diff --git a/abis/ironclad/uid_t.h b/abis/ironclad/uid_t.h new file mode 100644 index 0000000000..1688d07f71 --- /dev/null +++ b/abis/ironclad/uid_t.h @@ -0,0 +1,6 @@ +#ifndef _ABIBITS_UID_T_H +#define _ABIBITS_UID_T_H + +typedef unsigned int uid_t; + +#endif // _ABIBITS_UID_T_H diff --git a/abis/ironclad/utsname.h b/abis/ironclad/utsname.h new file mode 100644 index 0000000000..2cd2226523 --- /dev/null +++ b/abis/ironclad/utsname.h @@ -0,0 +1,12 @@ +#ifndef _ABIBITS_UTSNAME_T_H +#define _ABIBITS_UTSNAME_T_H + +struct utsname { + char sysname[65]; + char nodename[65]; + char release[65]; + char version[65]; + char machine[65]; +}; + +#endif // _ABIBITS_UTSNAME_T_H diff --git a/abis/ironclad/vm-flags.h b/abis/ironclad/vm-flags.h new file mode 100644 index 0000000000..a686cd3c0d --- /dev/null +++ b/abis/ironclad/vm-flags.h @@ -0,0 +1,46 @@ +#ifndef _ABIBITS_MMAP_FLAGS_H +#define _ABIBITS_MMAP_FLAGS_H + +#define PROT_NONE 0x00 +#define PROT_READ 0x01 +#define PROT_WRITE 0x02 +#define PROT_EXEC 0x04 + +#define MAP_FAILED ((void *)(-1)) +#define MAP_FILE 0x00 +#define MAP_PRIVATE 0x01 +#define MAP_SHARED 0x02 +#define MAP_FIXED 0x04 +#define MAP_ANON 0x08 +#define MAP_ANONYMOUS 0x08 +#define MAP_NORESERVE 0x10 +#define MAP_WC 0b10000 + +#define MS_ASYNC 0x01 +#define MS_SYNC 0x02 +#define MS_INVALIDATE 0x04 + +#define MCL_CURRENT 0x01 +#define MCL_FUTURE 0x02 + +#define POSIX_MADV_NORMAL 1 +#define POSIX_MADV_SEQUENTIAL 2 +#define POSIX_MADV_RANDOM 3 +#define POSIX_MADV_DONTNEED 4 +#define POSIX_MADV_WILLNEED 5 + +#define MADV_NORMAL 0 +#define MADV_RANDOM 1 +#define MADV_SEQUENTIAL 2 +#define MADV_WILLNEED 3 +#define MADV_DONTNEED 4 +#define MADV_FREE 8 + +// Linux extensions: +#define MREMAP_MAYMOVE 1 +#define MREMAP_FIXED 2 + +#define MFD_CLOEXEC 1U +#define MFD_ALLOW_SEALING 2U + +#endif // _ABIBITS_MMAP_FLAGS_H diff --git a/abis/ironclad/wait.h b/abis/ironclad/wait.h new file mode 100644 index 0000000000..5aa6bb8202 --- /dev/null +++ b/abis/ironclad/wait.h @@ -0,0 +1,25 @@ +#ifndef _ABIBITS_WAIT_H +#define _ABIBITS_WAIT_H + +#define WCONTINUED 1 +#define WNOHANG 2 +#define WUNTRACED 4 +#define WEXITED 8 +#define WNOWAIT 16 +#define WSTOPPED 32 + +#define __WALL 0x40000000 +#define __WCLONE 0x80000000 + +#define WCOREFLAG 0x80 + +#define WEXITSTATUS(x) ((x) & 0x000000FF) +#define WIFCONTINUED(x) ((x) & 0x00000100) +#define WIFEXITED(x) ((x) & 0x00000200) +#define WIFSIGNALED(x) ((x) & 0x00000400) +#define WIFSTOPPED(x) ((x) & 0x00000800) +#define WSTOPSIG(x) (((x) & 0x00FF0000) >> 16) +#define WTERMSIG(x) (((x) & 0xFF000000) >> 24) +#define WCOREDUMP(x) ((x) & WCOREFLAG) + +#endif //_ABIBITS_WAIT_H diff --git a/abis/ironclad/xattr.h b/abis/ironclad/xattr.h new file mode 100644 index 0000000000..c0e7fbebde --- /dev/null +++ b/abis/ironclad/xattr.h @@ -0,0 +1,21 @@ +#ifndef MLIBC_ABIS_LINUX_XATTR_H +#define MLIBC_ABIS_LINUX_XATTR_H + +/* __USE_KERNEL_XATTR_DEFS is exported when XATTR_* are emitted, and + * __UAPI_DEF_XATTR is used to determine the behaviour of the + * header (through ), if it's set + * to 1, the header exports xattr defines and __USE_KERNEL_XATTR_DEFS. + * This applies for pretty much all other defines in libc-compat.h + * AFAICT. + */ +#ifndef __USE_KERNEL_XATTR_DEFS +enum { + XATTR_CREATE = 1, +#define XATTR_CREATE XATTR_CREATE + XATTR_REPLACE = 2, +#define XATTR_REPLACE XATTR_REPLACE +}; +# define __UAPI_DEF_XATTR 0 +#endif + +#endif /* MLIBC_ABIS_LINUX_XATTR_H */ diff --git a/meson.build b/meson.build index 08c9de6be4..1bb7c66642 100644 --- a/meson.build +++ b/meson.build @@ -139,7 +139,7 @@ elif host_machine.system() == 'managarm' internal_conf.set10('MLIBC_MAP_FILE_WINDOWS', true) subdir('sysdeps/managarm') elif host_machine.system() == 'ironclad' - # disable_linux_option = true + disable_linux_option = true rtdl_include_dirs += include_directories('sysdeps/ironclad/include') libc_include_dirs += include_directories('sysdeps/ironclad/include') subdir('sysdeps/ironclad') diff --git a/sysdeps/ironclad/crt-x86_64/crti.S b/sysdeps/ironclad/crt-x86_64/crti.S new file mode 100644 index 0000000000..911b078dce --- /dev/null +++ b/sysdeps/ironclad/crt-x86_64/crti.S @@ -0,0 +1,11 @@ +.section .init +.global _init +_init: + push %rax + +.section .fini +.global _fini +_fini: + push %rax +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/ironclad/crt-x86_64/crtn.S b/sysdeps/ironclad/crt-x86_64/crtn.S new file mode 100644 index 0000000000..0187e50f92 --- /dev/null +++ b/sysdeps/ironclad/crt-x86_64/crtn.S @@ -0,0 +1,9 @@ +.section .init + pop %rax + ret + +.section .fini + pop %rax + ret +.section .note.GNU-stack,"",%progbits + diff --git a/sysdeps/ironclad/generic/generic.cpp b/sysdeps/ironclad/generic/generic.cpp index d32864b9ad..71361500a1 100644 --- a/sysdeps/ironclad/generic/generic.cpp +++ b/sysdeps/ironclad/generic/generic.cpp @@ -10,24 +10,25 @@ #include #include #include +#include +#include +#include +#include +#include namespace mlibc { void sys_libc_log(const char *message) { - /* ssize_t unused; char new_line = '\n'; - sys_write(1, message, strlen(message), &unused); - sys_write(1, &new_line, 1, &unused); - */ - (void)message; - return; + sys_write(2, message, strlen(message), &unused); + sys_write(2, &new_line, 1, &unused); } void sys_libc_panic() { ssize_t unused; char const *message = "mlibc panicked unrecoverably\n"; - sys_write(1, message, strlen(message), &unused); + sys_write(2, message, strlen(message), &unused); sys_exit(1); } @@ -39,21 +40,68 @@ void sys_exit(int status) { int sys_tcb_set(void *pointer) { int ret, errno; - SYSCALL1(SYSCALL_SET_TCB, pointer); + SYSCALL2(SYSCALL_ARCH_PRCTL, 1, pointer); return errno; } int sys_open(const char *path, int flags, mode_t mode, int *fd) { + return sys_openat(AT_FDCWD, path, flags, mode, fd); +} + +int sys_openat(int dirfd, const char *path, int flags, mode_t mode, int *fd) { int ret, errno; - (void)mode; - SYSCALL2(SYSCALL_OPEN, path, flags); + int path_len = strlen (path); + SYSCALL4(SYSCALL_OPEN, dirfd, path, path_len, flags); + if (ret != -1 && (flags & O_EXCL)) { + SYSCALL1(SYSCALL_CLOSE, ret); + return EEXIST; + } + + if (ret == -1 && (flags & O_CREAT)) { + SYSCALL5(SYSCALL_MAKENODE, AT_FDCWD, path, path_len, mode, 0); + if (ret == -1) { + return errno; + } + SYSCALL4(SYSCALL_OPEN, AT_FDCWD, path, path_len, flags); + } else if (ret != -1 && (flags & O_TRUNC)) { + // If the file cannot be truncated, dont sweat it, some software + // depends on some things being truncate-able that ironclad does not + // allow. For example, some devices. + sys_ftruncate(ret, 0); + } else if (ret != -1 && (flags & O_DIRECTORY)) { + struct stat st; + sys_stat(fsfd_target::fd, ret, NULL, 0, &st); + if (!S_ISDIR (st.st_mode)) { + ret = -1; + errno = ENOTDIR; + } + } + *fd = ret; return errno; } int sys_open_dir(const char *path, int *handle) { - return sys_open(path, O_RDONLY, 0660, handle); + return sys_open(path, O_RDONLY | O_DIRECTORY, 0660, handle); +} + +int sys_read_entries(int handle, void *buffer, size_t max_size, size_t *bytes_read) { + size_t ret; + int errno; + SYSCALL3(SYSCALL_GETDENTS, handle, buffer, max_size); + if (errno != 0) { + return errno; + } else { + *bytes_read = ret; + return 0; + } +} + +void sys_thread_exit() { + int ret, errno; + SYSCALL0(SYSCALL_EXIT_THREAD); + __builtin_unreachable(); } int sys_close(int fd) { @@ -62,6 +110,26 @@ int sys_close(int fd) { return errno; } +void sys_sync() { + int ret, errno; + SYSCALL0(SYSCALL_SYNC); + if (ret != 0) { + sys_libc_log("mlibc: sync failed"); + } +} + +int sys_fsync(int fd) { + int ret, errno; + SYSCALL2(SYSCALL_FSYNC, fd, 0); + return errno; +} + +int sys_fdatasync(int fd) { + int ret, errno; + SYSCALL2(SYSCALL_FSYNC, fd, 1); + return errno; +} + int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read) { ssize_t ret; int errno; @@ -78,6 +146,22 @@ int sys_write(int fd, const void *buf, size_t count, ssize_t *bytes_written) { return errno; } +int sys_pread(int fd, void *buf, size_t n, off_t off, ssize_t *bytes_read) { + ssize_t ret; + int errno; + SYSCALL4(SYSCALL_PREAD, fd, buf, n, off); + *bytes_read = ret; + return errno; +} + +int sys_pwrite(int fd, const void *buf, size_t n, off_t off, ssize_t *bytes_written) { + ssize_t ret; + int errno; + SYSCALL4(SYSCALL_WRITE, fd, buf, n, off); + *bytes_written = ret; + return errno; +} + int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) { ssize_t ret; int errno; @@ -86,8 +170,52 @@ int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) { return errno; } +int sys_ftruncate (int fd, size_t size) { + int ret, errno; + SYSCALL2(SYSCALL_TRUNCATE, fd, size); + return errno; +} + +int sys_flock(int fd, int options) { + struct flock lock; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = (off_t)((uint64_t)-1); + lock.l_pid = sys_getpid(); + + switch (options) { + case LOCK_SH: + lock.l_type = F_RDLCK; + break; + case LOCK_EX: + lock.l_type = F_WRLCK; + break; + case LOCK_UN: + lock.l_type = F_UNLCK; + break; + default: + return -1; + } + + int ret, errno; + SYSCALL3(SYSCALL_FCNTL, fd, F_SETLK, &lock); + return errno; +} + +int sys_getrusage(int scope, struct rusage *usage) { + int ret, errno; + SYSCALL2(SYSCALL_GETRUSAGE, scope, usage); + + // Ironclad returns nanoseconds instead of microseconds for usage, so we + // have to compensate for that. + usage->ru_utime.tv_usec = usage->ru_utime.tv_usec / 1000; + usage->ru_stime.tv_usec = usage->ru_stime.tv_usec / 1000; + + return errno; +} + int sys_anon_allocate(size_t size, void **pointer) { - return sys_vm_map(NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON, 0, 0, pointer); + return sys_vm_map(NULL, size, PROT_READ | PROT_WRITE, MAP_ANON, 0, 0, pointer); } int sys_anon_free(void *pointer, size_t size) { @@ -102,6 +230,68 @@ int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd, off_t offse return errno; } +int sys_getsockopt(int fd, int layer, int number, void *__restrict buffer, socklen_t *__restrict size) { + (void)fd; + (void)size; + if (layer == SOL_SOCKET && number == SO_PEERCRED) { + mlibc::infoLogger() << "mlibc: getsockopt() call with SOL_SOCKET and SO_PEERCRED is unimplemented" << frg::endlog; + *(int *)buffer = 0; + return 0; + } else if (layer == SOL_SOCKET && number == SO_SNDBUF) { + mlibc::infoLogger() << "mlibc: getsockopt() call with SOL_SOCKET and SO_SNDBUF is unimplemented" << frg::endlog; + *(int *)buffer = 4096; + return 0; + } else if (layer == SOL_SOCKET && number == SO_TYPE) { + mlibc::infoLogger() << "mlibc: getsockopt() call with SOL_SOCKET and SO_TYPE is unimplemented, hardcoding SOCK_STREAM" << frg::endlog; + *(int *)buffer = SOCK_STREAM; + return 0; + } else if (layer == SOL_SOCKET && number == SO_ERROR) { + mlibc::infoLogger() << "mlibc: getsockopt() call with SOL_SOCKET and SO_ERROR is unimplemented, hardcoding 0" << frg::endlog; + *(int *)buffer = 0; + return 0; + } else if (layer == SOL_SOCKET && number == SO_KEEPALIVE) { + mlibc::infoLogger() << "mlibc: getsockopt() call with SOL_SOCKET and SO_KEEPALIVE is unimplemented, hardcoding 0" << frg::endlog; + *(int *)buffer = 0; + return 0; + } else { + mlibc::panicLogger() << "mlibc: Unexpected getsockopt() call, layer: " << layer << " number: " << number << frg::endlog; + } + + return 0; +} + +int sys_setsockopt(int fd, int layer, int number, const void *buffer, socklen_t size) { + (void)fd; + (void)buffer; + (void)size; + if (layer == SOL_SOCKET && number == SO_PASSCRED) { + mlibc::infoLogger() << "mlibc: setsockopt(SO_PASSCRED) is not implemented correctly" << frg::endlog; + return 0; + } else if (layer == SOL_SOCKET && number == SO_ATTACH_FILTER) { + mlibc::infoLogger() << "mlibc: setsockopt(SO_ATTACH_FILTER) is not implemented correctly" << frg::endlog; + return 0; + } else if (layer == SOL_SOCKET && number == SO_RCVBUFFORCE) { + mlibc::infoLogger() << "mlibc: setsockopt(SO_RCVBUFFORCE) is not implemented correctly" << frg::endlog; + return 0; + } else if (layer == SOL_SOCKET && number == SO_SNDBUF) { + mlibc::infoLogger() << "mlibc: setsockopt() call with SOL_SOCKET and SO_SNDBUF is unimplemented" << frg::endlog; + return 0; + } else if (layer == SOL_SOCKET && number == SO_KEEPALIVE) { + mlibc::infoLogger() << "mlibc: setsockopt() call with SOL_SOCKET and SO_KEEPALIVE is unimplemented" << frg::endlog; + return 0; + } else if (layer == SOL_SOCKET && number == SO_REUSEADDR) { + mlibc::infoLogger() << "mlibc: setsockopt() call with SOL_SOCKET and SO_REUSEADDR is unimplemented" << frg::endlog; + return 0; + } else if (layer == AF_NETLINK && number == SO_ACCEPTCONN) { + mlibc::infoLogger() << "mlibc: setsockopt() call with AF_NETLINK and SO_ACCEPTCONN is unimplemented" << frg::endlog; + return 0; + } else { + mlibc::panicLogger() << "mlibc: Unexpected setsockopt() call, layer: " << layer << " number: " << number << frg::endlog; + } + + return 0; +} + int sys_vm_unmap(void *pointer, size_t size) { int ret; int errno; @@ -113,6 +303,16 @@ int sys_vm_unmap(void *pointer, size_t size) { } } +int sys_vm_protect(void *pointer, size_t size, int prot) { + int ret; + int errno; + SYSCALL3(SYSCALL_MPROTECT, pointer, size, prot); + if (ret != 0) { + return errno; + } + return 0; +} + pid_t sys_getpid() { pid_t ret; int errno; @@ -128,123 +328,97 @@ pid_t sys_getppid() { } int sys_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { - (void)signum; - (void)act; - (void)oldact; - mlibc::infoLogger() << "sigaction() is a stub" << frg::endlog; return 0; } -int sys_fcntl(int fd, int request, va_list args, int *result) { - (void)fd; - (void)request; - (void)args; - (void)result; - mlibc::infoLogger() << "fcntl() is a stub!" << frg::endlog; - return 0; -} - -int sys_sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict retrieve) { - (void)how; - (void)set; - (void)retrieve; - mlibc::infoLogger() << "sigprocmask() is a stub!" << frg::endlog; - return ENOSYS; -} - -int sys_ttyname(int fd, char *buf, size_t size) { - (void)fd; - (void)buf; - (void)size; - mlibc::infoLogger() << "ttyname() is a stub!" << frg::endlog; - return ENOSYS; +int sys_ptrace(long req, pid_t pid, void *addr, void *data, long *out) { + int ret, errno; + SYSCALL4(SYSCALL_PTRACE, req, pid, addr, data); + *out = (long)ret; + return errno; } -int sys_setpgid(pid_t pid, pid_t pgid) { - (void)pid; - (void)pgid; - mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!" << frg::endlog; - return 0; +int sys_fcntl(int fd, int request, va_list args, int *result) { + int ret, errno; + SYSCALL3(SYSCALL_FCNTL, fd, request, va_arg(args, uint64_t)); + *result = ret; + return errno; } -int sys_pselect(int num_fds, fd_set *read_set, fd_set *write_set, fd_set *except_set, - const struct timespec *timeout, const sigset_t *sigmask, int *num_events) { - (void)num_fds; - (void)read_set; - (void)write_set; - (void)except_set; - (void)timeout; - (void)sigmask; - (void)num_events; - mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog; +int sys_sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict retrieve) { return 0; } int sys_isatty(int fd) { - (void)fd; - mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog; - return 0; -} - -uid_t sys_getuid() { - mlibc::infoLogger() << "getuid() is a stub" << frg::endlog; - return 0; -} - -uid_t sys_geteuid() { - mlibc::infoLogger() << "geteuid() is a stub" << frg::endlog; - return 0; + struct termios t; + if (sys_tcgetattr(fd, &t) == 0) { + return 0; + } else { + return ENOTTY; + } } gid_t sys_getgid() { - mlibc::infoLogger() << "getgid() is a stub" << frg::endlog; + // FIXME: Stub needed by mlibc. return 0; } gid_t sys_getegid() { - mlibc::infoLogger() << "getegid() is a stub" << frg::endlog; + // FIXME: Stub needed by mlibc. return 0; } int sys_getpgid(pid_t pid, pid_t *pgid) { (void)pid; - mlibc::infoLogger() << "getpgid() is a stub" << frg::endlog; + // FIXME: Stub needed by mlibc. *pgid = 0; return 0; } -int sys_clock_get(int clock, time_t *secs, long *nanos) { - (void)clock; - (void)secs; - (void)nanos; - mlibc::infoLogger() << "clock_get() is a stub" << frg::endlog; - return 0; -} - int sys_execve(const char *path, char *const argv[], char *const envp[]) { - int ret, errno; + int ret, errno, argv_len, envp_len; + for (argv_len = 0; argv[argv_len] != NULL; argv_len++); + for (envp_len = 0; envp[envp_len] != NULL; envp_len++); - SYSCALL3(SYSCALL_EXEC, path, argv, envp); + size_t path_len = strlen (path); + SYSCALL6(SYSCALL_EXEC, path, path_len, argv, argv_len, envp, envp_len); if (ret == -1) { return errno; - } + } return 0; } int sys_fork(pid_t *child) { - pid_t ret; - int errno; + pid_t ret; + int errno; - SYSCALL0(SYSCALL_FORK); + SYSCALL6(SYSCALL_CLONE, 0, 0, 0, 0, 0, 1); - if (ret == -1) { - return errno; - } + if (ret == -1) { + return errno; + } - *child = ret; - return 0; + if (child != NULL) { + *child = ret; + } + + return 0; +} + +int sys_getrlimit(int resource, struct rlimit *limit) { + uint64_t ret, errno; + SYSCALL1(SYSCALL_GETRLIMIT, resource); + limit->rlim_cur = ret; + limit->rlim_max = ret; + return errno; +} + +int sys_setrlimit(int resource, const struct rlimit *limit) { + int ret, errno; + SYSCALL2(SYSCALL_SETRLIMIT, resource, limit->rlim_cur); + return errno; } int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid) { @@ -263,13 +437,13 @@ int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret } *ret_pid = ret; - return 0; + return errno; } int sys_uname(struct utsname *buf) { int ret, errno; - SYSCALL1(SYSCALL_UNAME, buf); + SYSCALL3(SYSCALL_SYSCONF, 10, buf, sizeof(struct utsname)); if (ret == -1) { return errno; @@ -278,6 +452,19 @@ int sys_uname(struct utsname *buf) { return 0; } + + +int sys_setpgid(pid_t pid, pid_t pgid) { + (void)pid; + (void)pgid; + mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!" << frg::endlog; + return 0; +} + +int sys_ttyname(int, char *, size_t) { + return ENOSYS; +} + int sys_sethostname(const char *buff, size_t size) { int ret, errno; @@ -290,23 +477,28 @@ int sys_sethostname(const char *buff, size_t size) { return 0; } -int sys_getcwd(const char *buff, size_t size) { - char* ret; - int errno; +int sys_chdir(const char *buff) { + int ret, errno; - SYSCALL2(SYSCALL_GETCWD, buff, size); + size_t buff_len = strlen(buff); + SYSCALL4(SYSCALL_OPEN, AT_FDCWD, buff, buff_len, O_RDONLY); + if (ret == -1) { + return ENOENT; + } - if (ret == NULL) { + SYSCALL1(SYSCALL_CHDIR, ret); + + if (ret == -1) { return errno; } return 0; } -int sys_chdir(const char *buff) { +int sys_fchdir(int fd) { int ret, errno; - SYSCALL1(SYSCALL_CHDIR, buff); + SYSCALL1(SYSCALL_CHDIR, fd); if (ret == -1) { return errno; @@ -324,135 +516,474 @@ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) { return errno; } - *result = ret; + *result = ret; return 0; } -int sys_sched_yield(void) { +void sys_yield(void) { int ret, errno; - SYSCALL0(SYSCALL_SCHED_YIELD); +} - if (ret == -1) { - return errno; +int sys_kill(int pid, int sig) { + int ret, errno; + if (sig == SIGKILL) { + SYSCALL1(SYSCALL_ACTUALLY_KILL, pid); + } else { + SYSCALL2(SYSCALL_SEND_SIGNAL, pid, sig); } - return 0; + return errno; } int sys_dup(int fd, int flags, int *newfd) { - (void)flags; - int ret, errno; - - SYSCALL1(SYSCALL_DUP, fd); - - if (ret == -1) { - return errno; + if (flags & O_CLOEXEC) { + SYSCALL3(SYSCALL_FCNTL, fd, F_DUPFD_CLOEXEC, 0); + } else { + SYSCALL3(SYSCALL_FCNTL, fd, F_DUPFD, 0); } *newfd = ret; - return 0; + return errno; } int sys_dup2(int fd, int flags, int newfd) { - int ret, errno; + if (sys_close(newfd) != 0) { + return EBADFD; + } - if (flags) { - SYSCALL3(SYSCALL_DUP3, fd, newfd, flags); + int ret, errno; + if (flags & O_CLOEXEC) { + SYSCALL3(SYSCALL_FCNTL, fd, F_DUPFD_CLOEXEC, newfd); } else { - SYSCALL2(SYSCALL_DUP2, fd, newfd); + SYSCALL3(SYSCALL_FCNTL, fd, F_DUPFD, newfd); } - if (ret == -1) { - return errno; + if (ret != -1 && ret != newfd) { + return EBADFD; } else { - return 0; + return errno; } } int sys_tcgetattr(int fd, struct termios *attr) { - int ret; + int ret; - if (int r = sys_ioctl(fd, TCGETS, attr, &ret) != 0) { - return r; - } + if (int r = sys_ioctl(fd, TCGETS, attr, &ret) != 0) { + return r; + } - return 0; + return 0; } int sys_tcsetattr(int fd, int optional_action, const struct termios *attr) { - int ret; + int ret; + + switch (optional_action) { + case TCSANOW: + optional_action = TCSETS; break; + case TCSADRAIN: + optional_action = TCSETSW; break; + case TCSAFLUSH: + optional_action = TCSETSF; break; + default: + __ensure(!"Unsupported tcsetattr"); + } + + if (int r = sys_ioctl(fd, optional_action, (void *)attr, &ret) != 0) { + return r; + } + + return 0; +} + +int sys_access(const char *path, int mode) { + int ret, errno; + size_t len = strlen(path); + SYSCALL5(SYSCALL_ACCESS, AT_FDCWD, path, len, mode, 0); + return errno; +} - switch (optional_action) { - case TCSANOW: - optional_action = TCSETS; break; - case TCSADRAIN: - optional_action = TCSETSW; break; - case TCSAFLUSH: - optional_action = TCSETSF; break; - default: - __ensure(!"Unsupported tcsetattr"); - } +int sys_faccessat(int dirfd, const char *pathname, int mode, int flags) { + int ret, errno; + size_t len = strlen(pathname); + SYSCALL5(SYSCALL_ACCESS, dirfd, pathname, len, mode, flags); + return errno; +} + +struct futex_item { + uint64_t addr; + uint32_t expected; + uint32_t flags; +}; - if (int r = sys_ioctl(fd, optional_action, (void *)attr, &ret) != 0) { - return r; - } +int sys_futex_wait(int *pointer, int expected, const struct timespec *time) { + int ret, errno; + struct futex_item item = {.addr = (uint64_t)pointer, .expected = expected, .flags = 0}; + if (time == NULL) { + struct timespec t = {(time_t)-1, (time_t)-1}; + SYSCALL4(SYSCALL_FUTEX, 0b01, &item, 1, &t); + } else { + SYSCALL4(SYSCALL_FUTEX, 0b01, &item, 1, time); + } + return errno; +} - return 0; +int sys_futex_wake(int *pointer) { + int ret, errno; + struct futex_item item = {.addr = (uint64_t)pointer, .expected = 0, .flags = 0}; + struct timespec t = {(time_t)-1, (time_t)-1}; + SYSCALL4(SYSCALL_FUTEX, 0b10, &item, 1, &t); + return errno; } -int sys_access(const char *path, int mode) { +int sys_pipe(int *fds, int flags) { int ret, errno; + SYSCALL2(SYSCALL_PIPE, fds, flags); + return errno; +} - SYSCALL2(SYSCALL_ACCESS, path, mode); +int sys_getentropy(void *buffer, size_t length) { + ssize_t ret; + int errno; + SYSCALL2(SYSCALL_GETRANDOM, buffer, length); + return errno; +} - if (ret == -1) { - return errno; - } else { - return 0; - } +int sys_mkdir(const char *path, mode_t mode) { + return sys_mkdirat(AT_FDCWD, path, mode); } -int sys_getpriority(int which, id_t who, int *value) { +int sys_mkdirat(int dirfd, const char *path, mode_t mode) { int ret, errno; + size_t path_len = strlen (path); + SYSCALL5(SYSCALL_MAKENODE, dirfd, path, path_len, S_IFDIR | mode, 0); + return errno; +} - SYSCALL2(SYSCALL_GETPRIORITY, which, who); +int sys_rmdir(const char* path){ + int ret, errno; + size_t path_len = strlen (path); + SYSCALL3(SYSCALL_UNLINK, AT_FDCWD, path, path_len); + return errno; +} - if (ret == -1 && errno != 0) { - return errno; +int sys_unlinkat(int fd, const char *path, int flags) { + int ret, errno; + size_t path_len = strlen (path); + SYSCALL3(SYSCALL_UNLINK, fd, path, path_len); + return errno; +} + +int sys_link(const char* srcpath, const char* destpath) { + int ret, errno; + size_t src_len = strlen (srcpath); + size_t dst_len = strlen (destpath); + SYSCALL6(SYSCALL_LINK, AT_FDCWD, srcpath, src_len, AT_FDCWD, destpath, dst_len); + return errno; +} + +int sys_socket(int domain, int type, int protocol, int *fd) { + int ret, errno; + SYSCALL3(SYSCALL_SOCKET, domain, type, protocol); + if (ret != -1) { + *fd = ret; + return 0; } else { - *value = ret; - return 0; - } + return errno; + } } -int sys_setpriority(int which, id_t who, int prio) { +uid_t sys_getuid() { + uint64_t ret, errno; + SYSCALL0(SYSCALL_GETUID); + return (uid_t)ret; +} + +uid_t sys_geteuid() { + uint64_t ret, errno; + SYSCALL0(SYSCALL_GETEUID); + return (uid_t)ret; +} + +int sys_setuid(uid_t uid) { + int ret, errno; + if (uid == 0) { + SYSCALL2(SYSCALL_SETUIDS, uid, uid); + } else { + SYSCALL2(SYSCALL_SETUIDS, uid, ((uint64_t)-1)); + } + return ret; +} + +int sys_seteuid(uid_t euid) { int ret, errno; + SYSCALL2(SYSCALL_SETUIDS, ((uint64_t)-1), euid); + return ret; +} - SYSCALL3(SYSCALL_SETPRIORITY, which, who, prio); +#ifndef MLIBC_BUILDING_RTDL - if (ret == -1) { - return errno; +extern "C" void __mlibc_thread_entry(); + +int sys_clone(void *tcb, pid_t *tid_out, void *stack) { + int ret, errno; + SYSCALL6(SYSCALL_CLONE, (uintptr_t)__mlibc_thread_entry, 0, stack, 0b10, tcb, 1); + + if (ret == -1) { + return errno; + } + + *tid_out = (pid_t)ret; + return 0; +} + +int sys_prepare_stack(void **stack, void *entry, void *arg, void *tcb, size_t *stack_size, size_t *guard_size) { + // TODO guard + + mlibc::infoLogger() << "mlibc: sys_prepare_stack() does not setup a guard!" << frg::endlog; + + *guard_size = 0; + *stack_size = *stack_size ? *stack_size : 0x400000; + + if (!*stack) { + *stack = (void *)((char *)mmap(NULL, *stack_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0) + *stack_size); + if (*stack == MAP_FAILED) { + return errno; + } + } + + void **stack_it = (void **)*stack; + + *--stack_it = arg; + *--stack_it = tcb; + *--stack_it = entry; + + *stack = (void *)stack_it; + + return 0; +} + +int sys_clock_getres(int clock, time_t *secs, long *nanos) { + struct timespec time; + int ret, errno; + SYSCALL3(SYSCALL_CLOCK, 0, clock, &time); + *secs = time.tv_sec; + *nanos = time.tv_nsec; + return errno; +} + +int sys_clock_get(int clock, time_t *secs, long *nanos) { + struct timespec time; + int ret, errno; + SYSCALL3(SYSCALL_CLOCK, 1, clock, &time); + *secs = time.tv_sec; + *nanos = time.tv_nsec; + return errno; +} + +int sys_clock_set(int clock, time_t secs, long nanos) { + struct timespec time = {.tv_sec = secs, .tv_nsec = nanos }; + int ret, errno; + SYSCALL3(SYSCALL_CLOCK, 2, clock, &time); + return errno; +} + +int sys_bind(int fd, const struct sockaddr *addr_ptr, socklen_t addrlen) { + int ret, errno; + SYSCALL3(SYSCALL_BIND, fd, addr_ptr, addrlen); + return errno; +} + +int sys_connect(int fd, const struct sockaddr *addr_ptr, socklen_t addrlen) { + int ret, errno; + SYSCALL3(SYSCALL_CONNECT, fd, addr_ptr, addrlen); + return errno; +} + +int sys_listen(int fd, int backlog) { + int ret, errno; + SYSCALL2(SYSCALL_LISTEN, fd, backlog); + return errno; +} + +int sys_accept(int fd, int *newfd, struct sockaddr *addr_ptr, socklen_t *addr_length, int flags) { + int ret, errno; + SYSCALL4(SYSCALL_ACCEPT, fd, addr_ptr, addr_length, flags); + *newfd = ret; + return errno; +} + + +int sys_sockname(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, socklen_t *actual_length) { + int ret, errno; + SYSCALL3(SYSCALL_GETSOCKNAME, fd, addr_ptr, &max_addr_length); + *actual_length = max_addr_length; + return errno; +} + +int sys_peername(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, socklen_t *actual_length) { + int ret, errno; + SYSCALL3(SYSCALL_GETPEERNAME, fd, addr_ptr, &max_addr_length); + *actual_length = max_addr_length; + return errno; +} + +int sys_shutdown(int sockfd, int how) { + int ret, errno; + SYSCALL2(SYSCALL_SHUTDOWN, sockfd, how); + return errno; +} + +int sys_msg_recv(int fd, struct msghdr *hdr, int flags, ssize_t *length) { + if (hdr->msg_control != NULL) { + mlibc::infoLogger() << "mlibc: recv() msg_control not supported!" << frg::endlog; + return EINVAL; + } + + int ret; + size_t count = 0; + int errno; + + for (int i = 0; i < hdr->msg_iovlen; i++) { + SYSCALL6(SYSCALL_RECVFROM, fd, hdr->msg_iov->iov_base, hdr->msg_iov->iov_len, + hdr->msg_flags, hdr->msg_name, hdr->msg_namelen); + if (ret == -1) { + return errno; + } + count += ret; + } + + *length = count; + return 0; +} + +int sys_msg_send(int fd, const struct msghdr *hdr, int flags, ssize_t *length) { + if (hdr->msg_control != NULL) { + mlibc::infoLogger() << "mlibc: recv() msg_control not supported!" << frg::endlog; + return EINVAL; + } + + int ret; + size_t count = 0; + int errno; + + for (int i = 0; i < hdr->msg_iovlen; i++) { + SYSCALL6(SYSCALL_SENDTO, fd, hdr->msg_iov->iov_base, hdr->msg_iov->iov_len, + hdr->msg_flags, hdr->msg_name, hdr->msg_namelen); + if (ret == -1) { + return errno; + } + count += ret; + } + + *length = count; + return 0; +} + + +int sys_ppoll(struct pollfd *fds, int nfds, const struct timespec *timeout, const sigset_t *sigmask, int *num_events) { + // XXX: Ironclad has no sigprogmask so this is basically a weird ppoll poll + // chimeral abomination. + int ret, errno; + if (timeout == NULL) { + struct timespec t = {.tv_sec = (time_t)-1, .tv_nsec = (time_t)-1}; + SYSCALL3(SYSCALL_POLL, fds, nfds, &t); } else { - return 0; - } + SYSCALL3(SYSCALL_POLL, fds, nfds, timeout); + } + if (ret == -1) { + return errno; + } + + *num_events = ret; + return errno; } -int sys_futex_wait(int *pointer, int expected, const struct timespec *time) { - (void)pointer; - (void)expected; - (void)time; - __ensure(!"sys_futex is a stub!"); - __builtin_unreachable(); +int sys_poll(struct pollfd *fds, nfds_t count, int timeout, int *num_events) { + struct timespec ts; + ts.tv_sec = timeout / 1000; + ts.tv_nsec = (timeout % 1000) * 1000000; + return sys_ppoll(fds, count, timeout < 0 ? NULL : &ts, NULL, num_events); } -int sys_futex_wake(int *pointer) { - (void)pointer; - __ensure(!"sys_futex is a stub!"); - __builtin_unreachable(); +int sys_pselect(int nfds, fd_set *read_set, fd_set *write_set, + fd_set *except_set, const struct timespec *timeout, + const sigset_t *sigmask, int *num_events) { + struct pollfd *fds = (struct pollfd *)calloc(nfds, sizeof(struct pollfd)); + if (fds == NULL) { + return ENOMEM; + } + + for (int i = 0; i < nfds; i++) { + struct pollfd *fd = &fds[i]; + + if (read_set && FD_ISSET(i, read_set)) { + fd->events |= POLLIN; + } + if (write_set && FD_ISSET(i, write_set)) { + fd->events |= POLLOUT; + } + if (except_set && FD_ISSET(i, except_set)) { + fd->events |= POLLPRI; + } + + if (!fd->events) { + fd->fd = -1; + continue; + } + fd->fd = i; + } + + int ret = sys_ppoll(fds, nfds, timeout, sigmask, num_events); + if (ret != 0) { + free(fds); + return ret; + } + + fd_set res_read_set, res_write_set, res_except_set; + FD_ZERO(&res_read_set); + FD_ZERO(&res_write_set); + FD_ZERO(&res_except_set); + + for (int i = 0; i < nfds; i++) { + struct pollfd *fd = &fds[i]; + + if (read_set && FD_ISSET(i, read_set) && (fd->revents & (POLLIN | POLLERR | POLLHUP)) != 0) { + FD_SET(i, &res_read_set); + } + if (write_set && FD_ISSET(i, write_set) && (fd->revents & (POLLOUT | POLLERR | POLLHUP)) != 0) { + FD_SET(i, &res_write_set); + } + if (except_set && FD_ISSET(i, except_set) && (fd->revents & POLLPRI) != 0) { + FD_SET(i, &res_except_set); + } + } + + free(fds); + if (read_set) { + *read_set = res_read_set; + } + if (write_set) { + *write_set = res_write_set; + } + if (except_set) { + *except_set = res_except_set; + } + + return 0; } -#ifndef MLIBC_BUILDING_RTDL +int sys_sleep(time_t *secs, long *nanos) { + struct timespec time = {.tv_sec = *secs, .tv_nsec = *nanos}; + struct timespec rem = {.tv_sec = 0, .tv_nsec = 0}; + + int ret, errno; + SYSCALL4(SYSCALL_CLOCK_NANOSLEEP, CLOCK_MONOTONIC, 0, &time, &rem); + *secs = rem.tv_sec; + *nanos = rem.tv_nsec; + return errno; +} int sys_gethostname(char *buffer, size_t bufsize) { struct utsname buf; @@ -464,25 +995,79 @@ int sys_gethostname(char *buffer, size_t bufsize) { return 0; } +int sys_utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags) { + int ret, errno; + if (pathname == NULL) { + pathname = ""; + flags |= AT_EMPTY_PATH; + } + + size_t path_len = strlen (pathname); + if (times == NULL) { + time_t secs; + long nsec; + ret = sys_clock_get(CLOCK_REALTIME, &secs, &nsec); + if (ret) { + return ret; + } + struct timespec times2[2] = {0, 0}; + times2[0].tv_sec = secs; + times2[0].tv_nsec = nsec; + times2[1].tv_sec = secs; + times2[1].tv_nsec = nsec; + SYSCALL5(SYSCALL_UTIMES, dirfd, pathname, path_len, ×2[0], flags); + } else { + SYSCALL5(SYSCALL_UTIMES, dirfd, pathname, path_len, times, flags); + } + + return errno; +} + +int sys_sysconf(int num, long *rret) { + long ret, errno; + + // Translate the number for the POSIX compat of the sysconf. + int translated; + switch (num) { + case _SC_PAGE_SIZE: translated = 1; break; + case _SC_OPEN_MAX: translated = 2; break; + case _SC_HOST_NAME_MAX: translated = 3; break; + case _SC_NPROCESSORS_ONLN: translated = 6; break; + case _SC_PHYS_PAGES: translated = 7; break; + case _SC_CHILD_MAX: translated = 11; break; + + // These are values that mlibc technically has to provide itself, but + // I personally dont like how ugly the hardcoded warnings look, so I just + // harcode them myself :) + case _SC_LINE_MAX: *rret = 4096; return 0; + + // Default is for mlibc to handle it. + default: return EINVAL; + } + + SYSCALL3(SYSCALL_SYSCONF, translated, 0, 0); + *rret = ret; + return errno; +} + int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags, struct stat *statbuf) { int ret, errno; (void)flags; switch (fsfdt) { case fsfd_target::fd: { - // mlibc wants us to do a fstat. - SYSCALL2(SYSCALL_FSTAT, fd, statbuf); - return errno; + SYSCALL5(SYSCALL_STAT, fd, "", 0, statbuf, AT_EMPTY_PATH); + break; } case fsfd_target::path: { - // mlibc wants us to do a lstat. - SYSCALL2(SYSCALL_LSTAT, path, statbuf); - return errno; + size_t len = strlen(path); + SYSCALL5(SYSCALL_STAT, AT_FDCWD, path, len, statbuf, flags); + break; } case fsfd_target::fd_path: { - // mlibc wants us to do an fstatat - __ensure(!"stat: Invalid fstatat"); - __builtin_unreachable(); + size_t len = strlen(path); + SYSCALL5(SYSCALL_STAT, fd, path, len, statbuf, flags); + break; } default: { __ensure(!"stat: Invalid fsfdt"); @@ -490,7 +1075,94 @@ int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags, struct stat } } - __builtin_unreachable(); + return errno; +} + +int sys_chmod(const char *pathname, mode_t mode) { + int ret, errno; + size_t len = strlen(pathname); + SYSCALL5(SYSCALL_FCHMOD, AT_FDCWD, pathname, len, mode, 0); + return errno; +} + +int sys_fchmodat(int fd, const char *pathname, mode_t mode, int flags) { + int ret, errno; + size_t len = strlen(pathname); + SYSCALL5(SYSCALL_FCHMOD, fd, pathname, len, mode, flags); + return errno; +} + +int sys_fchmod(int fd, mode_t mode) { + int ret, errno; + SYSCALL5(SYSCALL_FCHMOD, fd, "", 0, mode, AT_EMPTY_PATH); + return errno; +} + +int sys_chown(const char *pathname, uid_t uid, gid_t gid) { + int ret, errno; + size_t len = strlen(pathname); + SYSCALL6(SYSCALL_FCHOWN, AT_FDCWD, pathname, len, uid, gid, 0); + return errno; +} + +int sys_fchownat(int fd, const char *pathname, uid_t uid, gid_t gid, int flags) { + int ret, errno; + size_t len = strlen(pathname); + SYSCALL6(SYSCALL_FCHOWN, fd, pathname, len, uid, gid, flags); + return errno; +} + +int sys_fchown(int fd, uid_t uid, gid_t gid) { + int ret, errno; + SYSCALL6(SYSCALL_FCHOWN, fd, "", 0, uid, gid, AT_EMPTY_PATH); + return errno; +} + +int sys_umask(mode_t mode, mode_t *old) { + mode_t ret; + int errno; + SYSCALL1(SYSCALL_UMASK, mode); + *old = (mode_t)ret; + return errno; +} + +int sys_readlink(const char *path, void *buffer, size_t max_size, ssize_t *length) { + ssize_t ret; + int errno; + size_t path_len = strlen(path); + SYSCALL5(SYSCALL_READLINK, AT_FDCWD, path, path_len, buffer, max_size); + if (ret == -1) { + return errno; + } else { + *length = ret; + return 0; + } +} + +int sys_rename(const char *path, const char *new_path) { + int ret; + int errno; + size_t old_len = strlen(path); + size_t new_len = strlen(new_path); + SYSCALL7(SYSCALL_RENAME, AT_FDCWD, path, old_len, AT_FDCWD, new_path, new_len, 0); + return errno; +} + +int sys_renameat(int olddirfd, const char *old_path, int newdirfd, const char *new_path) { + int ret; + int errno; + size_t old_len = strlen(old_path); + size_t new_len = strlen(new_path); + SYSCALL7(SYSCALL_RENAME, olddirfd, old_path, old_len, newdirfd, new_path, new_len, 0); + return errno; +} + +int sys_mknodat(int dirfd, const char *path, mode_t mode, dev_t dev) { + int ret; + int errno; + size_t len = strlen(path); + SYSCALL5(SYSCALL_MAKENODE, dirfd, path, len, mode, dev); + return errno; } #endif diff --git a/sysdeps/ironclad/generic/mac.cpp b/sysdeps/ironclad/generic/mac.cpp new file mode 100644 index 0000000000..a13e56f2e8 --- /dev/null +++ b/sysdeps/ironclad/generic/mac.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +extern "C" { + +unsigned long get_mac_capabilities(void) { + int ret, errn; + SYSCALL0(SYSCALL_GET_MAC_CAPABILITIES); + errno = errn; + return ret; +} + +int set_mac_capabilities(unsigned long request) { + int ret, errn; + SYSCALL1(SYSCALL_SET_MAC_CAPABILITIES, request); + errno = errn; + return ret; +} + +int add_mac_permissions(const char *path, int flags) { + int ret, errn; + SYSCALL3(SYSCALL_ADD_MAC_PERMISSIONS, path, strlen(path), flags); + errno = errn; + return ret; +} + +int set_mac_enforcement(unsigned long enforcement) { + int ret, errn; + SYSCALL1(SYSCALL_SET_MAC_ENFORCEMENT, enforcement); + errno = errn; + return ret; +} + +} diff --git a/sysdeps/ironclad/generic/mntent.cpp b/sysdeps/ironclad/generic/mntent.cpp new file mode 100644 index 0000000000..d064af3bdc --- /dev/null +++ b/sysdeps/ironclad/generic/mntent.cpp @@ -0,0 +1,97 @@ +#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/sysdeps/ironclad/generic/mount.cpp b/sysdeps/ironclad/generic/mount.cpp new file mode 100644 index 0000000000..ff060e005d --- /dev/null +++ b/sysdeps/ironclad/generic/mount.cpp @@ -0,0 +1,34 @@ +#include +#include +#include +#include +#include + +int mount(const char *source, const char *target, + const char *fstype, unsigned long flags, const void *data) { + int ret, errno; + size_t source_len = strlen(source); + size_t target_len = strlen(target); + int val; + if (!strcmp(fstype, "ext")) { + val = 1; + } else if (!strcmp(fstype, "fat32")) { + val = 2; + } else { + return EINVAL; + } + + SYSCALL6(SYSCALL_MOUNT, source, source_len, target, target_len, val, flags); + return errno; +} + +int umount(const char *target) { + return umount2(target, 0); +} + +int umount2(const char *target, int flags) { + int ret, errno; + size_t target_len = strlen(target); + SYSCALL3(SYSCALL_UMOUNT, target, target_len, flags); + return errno; +} diff --git a/sysdeps/ironclad/generic/ptrace.cpp b/sysdeps/ironclad/generic/ptrace.cpp new file mode 100644 index 0000000000..58a8dd2c93 --- /dev/null +++ b/sysdeps/ironclad/generic/ptrace.cpp @@ -0,0 +1,9 @@ +#include +#include +#include + +int ptrace(int request, pid_t pid, void *addr, void *data) { + int ret; + SYSCALL4(SYSCALL_PTRACE, request, pid, addr, data); + return ret; +} diff --git a/sysdeps/ironclad/generic/pty.cpp b/sysdeps/ironclad/generic/pty.cpp new file mode 100644 index 0000000000..7434daee6e --- /dev/null +++ b/sysdeps/ironclad/generic/pty.cpp @@ -0,0 +1,18 @@ +#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 errno, ret; + int fds[2]; + SYSCALL3(SYSCALL_OPENPTY, fds, ios, win); + *mfd = fds[0]; + *sfd = fds[1]; + return ret; +} diff --git a/sysdeps/ironclad/generic/reboot.cpp b/sysdeps/ironclad/generic/reboot.cpp new file mode 100644 index 0000000000..45e8f03282 --- /dev/null +++ b/sysdeps/ironclad/generic/reboot.cpp @@ -0,0 +1,9 @@ +#include +#include +#include + +int reboot(int what) { + int ret, errno; + SYSCALL2(SYSCALL_REBOOT, what, 0); + return ret; +} diff --git a/sysdeps/ironclad/generic/sched2.cpp b/sysdeps/ironclad/generic/sched2.cpp new file mode 100644 index 0000000000..9699517351 --- /dev/null +++ b/sysdeps/ironclad/generic/sched2.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +extern "C" { + +int get_thread_sched(void) { + return 0; +} + +int set_thread_sched(int flags) { + return 0; +} + +int set_deadlines(int runtime, int period) { + return 0; +} + +} diff --git a/sysdeps/ironclad/generic/thread.S b/sysdeps/ironclad/generic/thread.S new file mode 100644 index 0000000000..47ab6a9878 --- /dev/null +++ b/sysdeps/ironclad/generic/thread.S @@ -0,0 +1,9 @@ +.section .text +.global __mlibc_thread_entry +__mlibc_thread_entry: + pop %rdi + pop %rsi + pop %rdx + call __mlibc_thread_trampoline + +.section .note.GNU-stack,"",%progbits diff --git a/sysdeps/ironclad/generic/thread.cpp b/sysdeps/ironclad/generic/thread.cpp new file mode 100644 index 0000000000..1b2f040a63 --- /dev/null +++ b/sysdeps/ironclad/generic/thread.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include + +extern "C" void __mlibc_thread_trampoline(void *(*fn)(void *), Tcb *tcb, void *arg) { + while (__atomic_load_n(&tcb->tid, __ATOMIC_RELAXED) == 0) { + mlibc::sys_futex_wait(&tcb->tid, 0, nullptr); + } + + tcb->invokeThreadFunc(reinterpret_cast(fn), arg); + + __atomic_store_n(&tcb->didExit, 1, __ATOMIC_RELEASE); + mlibc::sys_futex_wake(&tcb->didExit); + + mlibc::sys_thread_exit(); +} + +#define DEFAULT_STACK 0x20000 + +namespace mlibc { + int sys_prepare_stack(void **stack, void *entry, void *arg, void *tcb, size_t *stack_size, size_t *guard_size, void **stack_base) { + // TODO guard + + mlibc::infoLogger() << "mlibc: sys_prepare_stack() does not setup a guard!" << frg::endlog; + + *guard_size = 0; + + *stack_size = *stack_size ? *stack_size : DEFAULT_STACK; + + if (!*stack) { + *stack_base = mmap(NULL, *stack_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (*stack_base == MAP_FAILED) { + return errno; + } + } else { + *stack_base = *stack; + } + + *stack = (void *)((char *)*stack_base + *stack_size); + + void **stack_it = (void **)*stack; + + *--stack_it = arg; + *--stack_it = tcb; + *--stack_it = entry; + + *stack = (void *)stack_it; + + return 0; + } +} diff --git a/sysdeps/ironclad/include/abi-bits/access.h b/sysdeps/ironclad/include/abi-bits/access.h index 171f75f81b..8f0556a21e 120000 --- a/sysdeps/ironclad/include/abi-bits/access.h +++ b/sysdeps/ironclad/include/abi-bits/access.h @@ -1 +1 @@ -../../../../abis/mlibc/access.h \ No newline at end of file +../../../../abis/ironclad/access.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/blkcnt_t.h b/sysdeps/ironclad/include/abi-bits/blkcnt_t.h index e9d9f1b4ea..02c7cf3bdc 120000 --- a/sysdeps/ironclad/include/abi-bits/blkcnt_t.h +++ b/sysdeps/ironclad/include/abi-bits/blkcnt_t.h @@ -1 +1 @@ -../../../../abis/mlibc/blkcnt_t.h \ No newline at end of file +../../../../abis/ironclad/blkcnt_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/blksize_t.h b/sysdeps/ironclad/include/abi-bits/blksize_t.h index c6dfb6e0f6..17453931b9 120000 --- a/sysdeps/ironclad/include/abi-bits/blksize_t.h +++ b/sysdeps/ironclad/include/abi-bits/blksize_t.h @@ -1 +1 @@ -../../../../abis/mlibc/blksize_t.h \ No newline at end of file +../../../../abis/ironclad/blksize_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/clockid_t.h b/sysdeps/ironclad/include/abi-bits/clockid_t.h index 71f37bb6bd..b05d507a79 120000 --- a/sysdeps/ironclad/include/abi-bits/clockid_t.h +++ b/sysdeps/ironclad/include/abi-bits/clockid_t.h @@ -1 +1 @@ -../../../../abis/mlibc/clockid_t.h \ No newline at end of file +../../../../abis/ironclad/clockid_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/dev_t.h b/sysdeps/ironclad/include/abi-bits/dev_t.h index 0c1143b935..e403f5bdb6 120000 --- a/sysdeps/ironclad/include/abi-bits/dev_t.h +++ b/sysdeps/ironclad/include/abi-bits/dev_t.h @@ -1 +1 @@ -../../../../abis/mlibc/dev_t.h \ No newline at end of file +../../../../abis/ironclad/dev_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/epoll.h b/sysdeps/ironclad/include/abi-bits/epoll.h index 9efc3a05b7..03645542d5 120000 --- a/sysdeps/ironclad/include/abi-bits/epoll.h +++ b/sysdeps/ironclad/include/abi-bits/epoll.h @@ -1 +1 @@ -../../../../abis/mlibc/epoll.h \ No newline at end of file +../../../../abis/ironclad/epoll.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/errno.h b/sysdeps/ironclad/include/abi-bits/errno.h index 589859fb9d..ec9b8f6dac 120000 --- a/sysdeps/ironclad/include/abi-bits/errno.h +++ b/sysdeps/ironclad/include/abi-bits/errno.h @@ -1 +1 @@ -../../../../abis/mlibc/errno.h \ No newline at end of file +../../../../abis/ironclad/errno.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/fsblkcnt_t.h b/sysdeps/ironclad/include/abi-bits/fsblkcnt_t.h index 898dfb2f32..c5e0d6a232 120000 --- a/sysdeps/ironclad/include/abi-bits/fsblkcnt_t.h +++ b/sysdeps/ironclad/include/abi-bits/fsblkcnt_t.h @@ -1 +1 @@ -../../../../abis/linux/fsblkcnt_t.h \ No newline at end of file +../../../../abis/ironclad/fsblkcnt_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/fsfilcnt_t.h b/sysdeps/ironclad/include/abi-bits/fsfilcnt_t.h index 791755c9c8..b8925b8fc7 120000 --- a/sysdeps/ironclad/include/abi-bits/fsfilcnt_t.h +++ b/sysdeps/ironclad/include/abi-bits/fsfilcnt_t.h @@ -1 +1 @@ -../../../../abis/linux/fsfilcnt_t.h \ No newline at end of file +../../../../abis/ironclad/fsfilcnt_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/gid_t.h b/sysdeps/ironclad/include/abi-bits/gid_t.h index 6a77218044..1ee967663c 120000 --- a/sysdeps/ironclad/include/abi-bits/gid_t.h +++ b/sysdeps/ironclad/include/abi-bits/gid_t.h @@ -1 +1 @@ -../../../../abis/mlibc/gid_t.h \ No newline at end of file +../../../../abis/ironclad/gid_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/in.h b/sysdeps/ironclad/include/abi-bits/in.h index b58c683f27..e10e01084f 120000 --- a/sysdeps/ironclad/include/abi-bits/in.h +++ b/sysdeps/ironclad/include/abi-bits/in.h @@ -1 +1 @@ -../../../../abis/mlibc/in.h \ No newline at end of file +../../../../abis/ironclad/in.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/ino_t.h b/sysdeps/ironclad/include/abi-bits/ino_t.h index 10d644e77e..8da8d60029 120000 --- a/sysdeps/ironclad/include/abi-bits/ino_t.h +++ b/sysdeps/ironclad/include/abi-bits/ino_t.h @@ -1 +1 @@ -../../../../abis/mlibc/ino_t.h \ No newline at end of file +../../../../abis/ironclad/ino_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/inotify.h b/sysdeps/ironclad/include/abi-bits/inotify.h index 3f19ef6e17..95578b06e7 120000 --- a/sysdeps/ironclad/include/abi-bits/inotify.h +++ b/sysdeps/ironclad/include/abi-bits/inotify.h @@ -1 +1 @@ -../../../../abis/mlibc/inotify.h \ No newline at end of file +../../../../abis/ironclad/inotify.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/ioctls.h b/sysdeps/ironclad/include/abi-bits/ioctls.h index 595106b6fd..d532c47097 120000 --- a/sysdeps/ironclad/include/abi-bits/ioctls.h +++ b/sysdeps/ironclad/include/abi-bits/ioctls.h @@ -1 +1 @@ -../../../../abis/linux/ioctls.h \ No newline at end of file +../../../../abis/ironclad/ioctls.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/limits.h b/sysdeps/ironclad/include/abi-bits/limits.h index 1aa589426a..9f4938ce69 120000 --- a/sysdeps/ironclad/include/abi-bits/limits.h +++ b/sysdeps/ironclad/include/abi-bits/limits.h @@ -1 +1 @@ -../../../../abis/mlibc/limits.h \ No newline at end of file +../../../../abis/ironclad/limits.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/mode_t.h b/sysdeps/ironclad/include/abi-bits/mode_t.h index 29d7733123..47764b7211 120000 --- a/sysdeps/ironclad/include/abi-bits/mode_t.h +++ b/sysdeps/ironclad/include/abi-bits/mode_t.h @@ -1 +1 @@ -../../../../abis/mlibc/mode_t.h \ No newline at end of file +../../../../abis/ironclad/mode_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/mqueue.h b/sysdeps/ironclad/include/abi-bits/mqueue.h index fa87b078ad..394c37d986 120000 --- a/sysdeps/ironclad/include/abi-bits/mqueue.h +++ b/sysdeps/ironclad/include/abi-bits/mqueue.h @@ -1 +1 @@ -../../../../abis/linux/mqueue.h \ No newline at end of file +../../../../abis/ironclad/mqueue.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/msg.h b/sysdeps/ironclad/include/abi-bits/msg.h index f402b49306..7c59866a29 120000 --- a/sysdeps/ironclad/include/abi-bits/msg.h +++ b/sysdeps/ironclad/include/abi-bits/msg.h @@ -1 +1 @@ -../../../../abis/linux/msg.h \ No newline at end of file +../../../../abis/ironclad/msg.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/nlink_t.h b/sysdeps/ironclad/include/abi-bits/nlink_t.h index 7618c27f51..a5c8e25b08 120000 --- a/sysdeps/ironclad/include/abi-bits/nlink_t.h +++ b/sysdeps/ironclad/include/abi-bits/nlink_t.h @@ -1 +1 @@ -../../../../abis/mlibc/nlink_t.h \ No newline at end of file +../../../../abis/ironclad/nlink_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/packet.h b/sysdeps/ironclad/include/abi-bits/packet.h index 47067e2149..5a7a3332b6 120000 --- a/sysdeps/ironclad/include/abi-bits/packet.h +++ b/sysdeps/ironclad/include/abi-bits/packet.h @@ -1 +1 @@ -../../../../abis/mlibc/packet.h \ No newline at end of file +../../../../abis/ironclad/packet.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/pid_t.h b/sysdeps/ironclad/include/abi-bits/pid_t.h index 3fd26a7f05..36e4068adb 120000 --- a/sysdeps/ironclad/include/abi-bits/pid_t.h +++ b/sysdeps/ironclad/include/abi-bits/pid_t.h @@ -1 +1 @@ -../../../../abis/mlibc/pid_t.h \ No newline at end of file +../../../../abis/ironclad/pid_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/poll.h b/sysdeps/ironclad/include/abi-bits/poll.h index ab989c75eb..156ddd9b20 120000 --- a/sysdeps/ironclad/include/abi-bits/poll.h +++ b/sysdeps/ironclad/include/abi-bits/poll.h @@ -1 +1 @@ -../../../../abis/mlibc/poll.h \ No newline at end of file +../../../../abis/ironclad/poll.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/ptrace.h b/sysdeps/ironclad/include/abi-bits/ptrace.h index f391fb72f8..1260bf7aa6 120000 --- a/sysdeps/ironclad/include/abi-bits/ptrace.h +++ b/sysdeps/ironclad/include/abi-bits/ptrace.h @@ -1 +1 @@ -../../../../abis/mlibc/ptrace.h \ No newline at end of file +../../../../abis/ironclad/ptrace.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/reboot.h b/sysdeps/ironclad/include/abi-bits/reboot.h index 77013a4162..23c9af30b2 120000 --- a/sysdeps/ironclad/include/abi-bits/reboot.h +++ b/sysdeps/ironclad/include/abi-bits/reboot.h @@ -1 +1 @@ -../../../../abis/linux/reboot.h \ No newline at end of file +../../../../abis/ironclad/reboot.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/resource.h b/sysdeps/ironclad/include/abi-bits/resource.h index 3e59c75080..e950420cbc 120000 --- a/sysdeps/ironclad/include/abi-bits/resource.h +++ b/sysdeps/ironclad/include/abi-bits/resource.h @@ -1 +1 @@ -../../../../abis/mlibc/resource.h \ No newline at end of file +../../../../abis/ironclad/resource.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/shm.h b/sysdeps/ironclad/include/abi-bits/shm.h index 067d8c4fa5..f20c4fcc54 120000 --- a/sysdeps/ironclad/include/abi-bits/shm.h +++ b/sysdeps/ironclad/include/abi-bits/shm.h @@ -1 +1 @@ -../../../../abis/linux/shm.h \ No newline at end of file +../../../../abis/ironclad/shm.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/signal.h b/sysdeps/ironclad/include/abi-bits/signal.h index b20e51192a..ae8aa10e72 120000 --- a/sysdeps/ironclad/include/abi-bits/signal.h +++ b/sysdeps/ironclad/include/abi-bits/signal.h @@ -1 +1 @@ -../../../../abis/mlibc/signal.h \ No newline at end of file +../../../../abis/ironclad/signal.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/socket.h b/sysdeps/ironclad/include/abi-bits/socket.h index 0e1d6be9d5..5ddea1c697 120000 --- a/sysdeps/ironclad/include/abi-bits/socket.h +++ b/sysdeps/ironclad/include/abi-bits/socket.h @@ -1 +1 @@ -../../../../abis/mlibc/socket.h \ No newline at end of file +../../../../abis/ironclad/socket.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/socklen_t.h b/sysdeps/ironclad/include/abi-bits/socklen_t.h index 41f3b11f38..7db34a48e9 120000 --- a/sysdeps/ironclad/include/abi-bits/socklen_t.h +++ b/sysdeps/ironclad/include/abi-bits/socklen_t.h @@ -1 +1 @@ -../../../../abis/linux/socklen_t.h \ No newline at end of file +../../../../abis/ironclad/socklen_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/stat.h b/sysdeps/ironclad/include/abi-bits/stat.h index 82642c3ce4..a307c322b4 120000 --- a/sysdeps/ironclad/include/abi-bits/stat.h +++ b/sysdeps/ironclad/include/abi-bits/stat.h @@ -1 +1 @@ -../../../../abis/mlibc/stat.h \ No newline at end of file +../../../../abis/ironclad/stat.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/statfs.h b/sysdeps/ironclad/include/abi-bits/statfs.h index e3d202f538..bc1f622046 120000 --- a/sysdeps/ironclad/include/abi-bits/statfs.h +++ b/sysdeps/ironclad/include/abi-bits/statfs.h @@ -1 +1 @@ -../../../../abis/linux/statfs.h \ No newline at end of file +../../../../abis/ironclad/statfs.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/statvfs.h b/sysdeps/ironclad/include/abi-bits/statvfs.h index 1fc80c2a76..e0b90f088a 120000 --- a/sysdeps/ironclad/include/abi-bits/statvfs.h +++ b/sysdeps/ironclad/include/abi-bits/statvfs.h @@ -1 +1 @@ -../../../../abis/linux/statvfs.h \ No newline at end of file +../../../../abis/ironclad/statvfs.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/suseconds_t.h b/sysdeps/ironclad/include/abi-bits/suseconds_t.h index 9ed659770e..88197dd2e6 120000 --- a/sysdeps/ironclad/include/abi-bits/suseconds_t.h +++ b/sysdeps/ironclad/include/abi-bits/suseconds_t.h @@ -1 +1 @@ -../../../../abis/linux/suseconds_t.h \ No newline at end of file +../../../../abis/ironclad/suseconds_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/termios.h b/sysdeps/ironclad/include/abi-bits/termios.h index cfcfe7636b..a6bacb3b53 120000 --- a/sysdeps/ironclad/include/abi-bits/termios.h +++ b/sysdeps/ironclad/include/abi-bits/termios.h @@ -1 +1 @@ -../../../../abis/mlibc/termios.h \ No newline at end of file +../../../../abis/ironclad/termios.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/time.h b/sysdeps/ironclad/include/abi-bits/time.h index 97f3d52dd7..fa8e48693d 120000 --- a/sysdeps/ironclad/include/abi-bits/time.h +++ b/sysdeps/ironclad/include/abi-bits/time.h @@ -1 +1 @@ -../../../../abis/mlibc/time.h \ No newline at end of file +../../../../abis/ironclad/time.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/uid_t.h b/sysdeps/ironclad/include/abi-bits/uid_t.h index 1113eba6e0..1aebbe3200 120000 --- a/sysdeps/ironclad/include/abi-bits/uid_t.h +++ b/sysdeps/ironclad/include/abi-bits/uid_t.h @@ -1 +1 @@ -../../../../abis/mlibc/uid_t.h \ No newline at end of file +../../../../abis/ironclad/uid_t.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/utsname.h b/sysdeps/ironclad/include/abi-bits/utsname.h index 17b993fe4b..0a5dbc837f 120000 --- a/sysdeps/ironclad/include/abi-bits/utsname.h +++ b/sysdeps/ironclad/include/abi-bits/utsname.h @@ -1 +1 @@ -../../../../abis/mlibc/utsname.h \ No newline at end of file +../../../../abis/ironclad/utsname.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/vm-flags.h b/sysdeps/ironclad/include/abi-bits/vm-flags.h index f1a985e6ac..6dc4788be1 120000 --- a/sysdeps/ironclad/include/abi-bits/vm-flags.h +++ b/sysdeps/ironclad/include/abi-bits/vm-flags.h @@ -1 +1 @@ -../../../../abis/mlibc/vm-flags.h \ No newline at end of file +../../../../abis/ironclad/vm-flags.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/wait.h b/sysdeps/ironclad/include/abi-bits/wait.h index 6d911c7fb2..a87457d70c 120000 --- a/sysdeps/ironclad/include/abi-bits/wait.h +++ b/sysdeps/ironclad/include/abi-bits/wait.h @@ -1 +1 @@ -../../../../abis/mlibc/wait.h \ No newline at end of file +../../../../abis/ironclad/wait.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/abi-bits/xattr.h b/sysdeps/ironclad/include/abi-bits/xattr.h index 66412d7061..99e5aa3e13 120000 --- a/sysdeps/ironclad/include/abi-bits/xattr.h +++ b/sysdeps/ironclad/include/abi-bits/xattr.h @@ -1 +1 @@ -../../../../abis/linux/xattr.h \ No newline at end of file +../../../../abis/ironclad/xattr.h \ No newline at end of file diff --git a/sysdeps/ironclad/include/asm/ioctls.h b/sysdeps/ironclad/include/asm/ioctls.h new file mode 100644 index 0000000000..aa9f0b4ed0 --- /dev/null +++ b/sysdeps/ironclad/include/asm/ioctls.h @@ -0,0 +1,102 @@ +#ifndef _ASM_IOCTLS_H +#define _ASM_IOCTLS_H + +// List of all the IOCTLs supported, for further explanation on the meanings +// please refer to documentation. If you did not get any, good luck! +// Some IOCTL codes may be the same, in which case the device they are used in +// gives them meaning. Cross-device IOCTLs have more distinct values. + +#define PS2MOUSE_2_1_SCALING 1 +#define PS2MOUSE_1_1_SCALING 2 +#define PS2MOUSE_SET_RES 3 +#define PS2MOUSE_SET_SAMPLE_RATE 4 +#define RTC_RD_TIME 1 +#define RTC_SET_TIME 2 +#define FIOQSIZE 0x5460 +#define TCGETS 0x5401 +#define TCSETS 0x5402 +#define TCSETSW 0x5403 +#define TCSETSF 0x5404 +#define TCGETA 0x5405 +#define TCSETA 0x5406 +#define TCSETAW 0x5407 +#define TCSETAF 0x5408 +#define TCSBRK 0x5409 +#define TCXONC 0x540A +#define TCFLSH 0x540B +#define TIOCEXCL 0x540C +#define TIOCNXCL 0x540D +#define TIOCSCTTY 0x540E +#define TIOCGPGRP 0x540F +#define TIOCSPGRP 0x5410 +#define TIOCOUTQ 0x5411 +#define TIOCSTI 0x5412 +#define TIOCGWINSZ 0x5413 +#define TIOCSWINSZ 0x5414 +#define TIOCMGET 0x5415 +#define TIOCMBIS 0x5416 +#define TIOCMBIC 0x5417 +#define TIOCMSET 0x5418 +#define TIOCGSOFTCAR 0x5419 +#define TIOCSSOFTCAR 0x541A +#define FIONREAD 0x541B +#define TIOCINQ FIONREAD +#define TIOCLINUX 0x541C +#define TIOCCONS 0x541D +#define TIOCGSERIAL 0x541E +#define TIOCSSERIAL 0x541F +#define TIOCPKT 0x5420 +#define FIONBIO 0x5421 +#define TIOCNOTTY 0x5422 +#define TIOCSETD 0x5423 +#define TIOCGETD 0x5424 +#define TCSBRKP 0x5425 +#define TIOCSBRK 0x5427 +#define TIOCCBRK 0x5428 +#define TIOCGSID 0x5429 +#define TCGETS2 3 +#define TCSETS2 3 +#define TCSETSW2 3 +#define TCSETSF2 3 +#define TIOCGRS485 0x542E +#define TIOCSRS485 0x542F +#define TIOCGPTN 3 +#define TIOCSPTLCK 3 +#define TIOCGDEV 3 +#define TCGETX 0x5432 +#define TCSETX 0x5433 +#define TCSETXF 0x5434 +#define TCSETXW 0x5435 +#define TIOCSIG 0x36 +#define TIOCVHANGUP 0x5437 +#define TIOCGPKT 3 +#define TIOCGPTLCK 3 +#define TIOCGEXCL 3 +#define TIOCGPTPEER 3 +#define TIOCGISO7816 3 +#define TIOCSISO7816 3 +#define FIONCLEX 0x5450 +#define FIOCLEX 0x5451 +#define FIOASYNC 0x5452 +#define TIOCSERCONFIG 0x5453 +#define TIOCSERGWILD 0x5454 +#define TIOCSERSWILD 0x5455 +#define TIOCGLCKTRMIOS 0x5456 +#define TIOCSLCKTRMIOS 0x5457 +#define TIOCSERGSTRUCT 0x5458 +#define TIOCSERGETLSR 0x5459 +#define TIOCSERGETMULTI 0x545A +#define TIOCSERSETMULTI 0x545B +#define TIOCMIWAIT 0x545C +#define TIOCGICOUNT 0x545D +#define TIOCPKT_DATA 0 +#define TIOCPKT_FLUSHREAD 1 +#define TIOCPKT_FLUSHWRITE 2 +#define TIOCPKT_STOP 4 +#define TIOCPKT_START 8 +#define TIOCPKT_NOSTOP 16 +#define TIOCPKT_DOSTOP 32 +#define TIOCPKT_IOCTL 64 +#define TIOCSER_TEMT 0x01 + +#endif /* _ASM_IOCTLS_H */ diff --git a/sysdeps/ironclad/include/linux/fb.h b/sysdeps/ironclad/include/linux/fb.h new file mode 100644 index 0000000000..563ce82a33 --- /dev/null +++ b/sysdeps/ironclad/include/linux/fb.h @@ -0,0 +1,397 @@ +#ifndef _SYS_FB_H +#define _SYS_FB_H + +#include + +/* Definitions of frame buffers */ + +#define FB_MAX 32 /* sufficient for now */ + +/* ioctls + 0x46 is 'F' */ +#define FBIOGET_VSCREENINFO 0x4600 +#define FBIOPUT_VSCREENINFO 0x4601 +#define FBIOGET_FSCREENINFO 0x4602 +#define FBIOGETCMAP 0x4604 +#define FBIOPUTCMAP 0x4605 +#define FBIOPAN_DISPLAY 0x4606 +#define FBIO_CURSOR _IOWR('F', 0x08, struct fb_cursor) +/* 0x4607-0x460B are defined below */ +/* #define FBIOGET_MONITORSPEC 0x460C */ +/* #define FBIOPUT_MONITORSPEC 0x460D */ +/* #define FBIOSWITCH_MONIBIT 0x460E */ +#define FBIOGET_CON2FBMAP 0x460F +#define FBIOPUT_CON2FBMAP 0x4610 +#define FBIOBLANK 0x4611 /* arg: 0 or vesa level + 1 */ +#define FBIOGET_VBLANK _IOR('F', 0x12, struct fb_vblank) +#define FBIO_ALLOC 0x4613 +#define FBIO_FREE 0x4614 +#define FBIOGET_GLYPH 0x4615 +#define FBIOGET_HWCINFO 0x4616 +#define FBIOPUT_MODEINFO 0x4617 +#define FBIOGET_DISPINFO 0x4618 + +#define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */ +#define FB_TYPE_PLANES 1 /* Non interleaved planes */ +#define FB_TYPE_INTERLEAVED_PLANES 2 /* Interleaved planes */ +#define FB_TYPE_TEXT 3 /* Text/attributes */ +#define FB_TYPE_VGA_PLANES 4 /* EGA/VGA planes */ +#define FB_TYPE_FOURCC 5 /* Type identified by a V4L2 FOURCC */ + +#define FB_AUX_TEXT_MDA 0 /* Monochrome text */ +#define FB_AUX_TEXT_CGA 1 /* CGA/EGA/VGA Color text */ +#define FB_AUX_TEXT_S3_MMIO 2 /* S3 MMIO fasttext */ +#define FB_AUX_TEXT_MGA_STEP16 3 /* MGA Millenium I: text, attr, 14 reserved bytes */ +#define FB_AUX_TEXT_MGA_STEP8 4 /* other MGAs: text, attr, 6 reserved bytes */ +#define FB_AUX_TEXT_SVGA_GROUP 8 /* 8-15: SVGA tileblit compatible modes */ +#define FB_AUX_TEXT_SVGA_MASK 7 /* lower three bits says step */ +#define FB_AUX_TEXT_SVGA_STEP2 8 /* SVGA text mode: text, attr */ +#define FB_AUX_TEXT_SVGA_STEP4 9 /* SVGA text mode: text, attr, 2 reserved bytes */ +#define FB_AUX_TEXT_SVGA_STEP8 10 /* SVGA text mode: text, attr, 6 reserved bytes */ +#define FB_AUX_TEXT_SVGA_STEP16 11 /* SVGA text mode: text, attr, 14 reserved bytes */ +#define FB_AUX_TEXT_SVGA_LAST 15 /* reserved up to 15 */ + +#define FB_AUX_VGA_PLANES_VGA4 0 /* 16 color planes (EGA/VGA) */ +#define FB_AUX_VGA_PLANES_CFB4 1 /* CFB4 in planes (VGA) */ +#define FB_AUX_VGA_PLANES_CFB8 2 /* CFB8 in planes (VGA) */ + +#define FB_VISUAL_MONO01 0 /* Monochr. 1=Black 0=White */ +#define FB_VISUAL_MONO10 1 /* Monochr. 1=White 0=Black */ +#define FB_VISUAL_TRUECOLOR 2 /* True color */ +#define FB_VISUAL_PSEUDOCOLOR 3 /* Pseudo color (like atari) */ +#define FB_VISUAL_DIRECTCOLOR 4 /* Direct color */ +#define FB_VISUAL_STATIC_PSEUDOCOLOR 5 /* Pseudo color readonly */ +#define FB_VISUAL_FOURCC 6 /* Visual identified by a V4L2 FOURCC */ + +#define FB_ACCEL_NONE 0 /* no hardware accelerator */ +#define FB_ACCEL_ATARIBLITT 1 /* Atari Blitter */ +#define FB_ACCEL_AMIGABLITT 2 /* Amiga Blitter */ +#define FB_ACCEL_S3_TRIO64 3 /* Cybervision64 (S3 Trio64) */ +#define FB_ACCEL_NCR_77C32BLT 4 /* RetinaZ3 (NCR 77C32BLT) */ +#define FB_ACCEL_S3_VIRGE 5 /* Cybervision64/3D (S3 ViRGE) */ +#define FB_ACCEL_ATI_MACH64GX 6 /* ATI Mach 64GX family */ +#define FB_ACCEL_DEC_TGA 7 /* DEC 21030 TGA */ +#define FB_ACCEL_ATI_MACH64CT 8 /* ATI Mach 64CT family */ +#define FB_ACCEL_ATI_MACH64VT 9 /* ATI Mach 64CT family VT class */ +#define FB_ACCEL_ATI_MACH64GT 10 /* ATI Mach 64CT family GT class */ +#define FB_ACCEL_SUN_CREATOR 11 /* Sun Creator/Creator3D */ +#define FB_ACCEL_SUN_CGSIX 12 /* Sun cg6 */ +#define FB_ACCEL_SUN_LEO 13 /* Sun leo/zx */ +#define FB_ACCEL_IMS_TWINTURBO 14 /* IMS Twin Turbo */ +#define FB_ACCEL_3DLABS_PERMEDIA2 15 /* 3Dlabs Permedia 2 */ +#define FB_ACCEL_MATROX_MGA2064W 16 /* Matrox MGA2064W (Millenium) */ +#define FB_ACCEL_MATROX_MGA1064SG 17 /* Matrox MGA1064SG (Mystique) */ +#define FB_ACCEL_MATROX_MGA2164W 18 /* Matrox MGA2164W (Millenium II) */ +#define FB_ACCEL_MATROX_MGA2164W_AGP 19 /* Matrox MGA2164W (Millenium II) */ +#define FB_ACCEL_MATROX_MGAG100 20 /* Matrox G100 (Productiva G100) */ +#define FB_ACCEL_MATROX_MGAG200 21 /* Matrox G200 (Myst, Mill, ...) */ +#define FB_ACCEL_SUN_CG14 22 /* Sun cgfourteen */ +#define FB_ACCEL_SUN_BWTWO 23 /* Sun bwtwo */ +#define FB_ACCEL_SUN_CGTHREE 24 /* Sun cgthree */ +#define FB_ACCEL_SUN_TCX 25 /* Sun tcx */ +#define FB_ACCEL_MATROX_MGAG400 26 /* Matrox G400 */ +#define FB_ACCEL_NV3 27 /* nVidia RIVA 128 */ +#define FB_ACCEL_NV4 28 /* nVidia RIVA TNT */ +#define FB_ACCEL_NV5 29 /* nVidia RIVA TNT2 */ +#define FB_ACCEL_CT_6555x 30 /* C&T 6555x */ +#define FB_ACCEL_3DFX_BANSHEE 31 /* 3Dfx Banshee */ +#define FB_ACCEL_ATI_RAGE128 32 /* ATI Rage128 family */ +#define FB_ACCEL_IGS_CYBER2000 33 /* CyberPro 2000 */ +#define FB_ACCEL_IGS_CYBER2010 34 /* CyberPro 2010 */ +#define FB_ACCEL_IGS_CYBER5000 35 /* CyberPro 5000 */ +#define FB_ACCEL_SIS_GLAMOUR 36 /* SiS 300/630/540 */ +#define FB_ACCEL_3DLABS_PERMEDIA3 37 /* 3Dlabs Permedia 3 */ +#define FB_ACCEL_ATI_RADEON 38 /* ATI Radeon family */ +#define FB_ACCEL_I810 39 /* Intel 810/815 */ +#define FB_ACCEL_SIS_GLAMOUR_2 40 /* SiS 315, 650, 740 */ +#define FB_ACCEL_SIS_XABRE 41 /* SiS 330 ("Xabre") */ +#define FB_ACCEL_I830 42 /* Intel 830M/845G/85x/865G */ +#define FB_ACCEL_NV_10 43 /* nVidia Arch 10 */ +#define FB_ACCEL_NV_20 44 /* nVidia Arch 20 */ +#define FB_ACCEL_NV_30 45 /* nVidia Arch 30 */ +#define FB_ACCEL_NV_40 46 /* nVidia Arch 40 */ +#define FB_ACCEL_XGI_VOLARI_V 47 /* XGI Volari V3XT, V5, V8 */ +#define FB_ACCEL_XGI_VOLARI_Z 48 /* XGI Volari Z7 */ +#define FB_ACCEL_OMAP1610 49 /* TI OMAP16xx */ +#define FB_ACCEL_TRIDENT_TGUI 50 /* Trident TGUI */ +#define FB_ACCEL_TRIDENT_3DIMAGE 51 /* Trident 3DImage */ +#define FB_ACCEL_TRIDENT_BLADE3D 52 /* Trident Blade3D */ +#define FB_ACCEL_TRIDENT_BLADEXP 53 /* Trident BladeXP */ +#define FB_ACCEL_CIRRUS_ALPINE 53 /* Cirrus Logic 543x/544x/5480 */ +#define FB_ACCEL_NEOMAGIC_NM2070 90 /* NeoMagic NM2070 */ +#define FB_ACCEL_NEOMAGIC_NM2090 91 /* NeoMagic NM2090 */ +#define FB_ACCEL_NEOMAGIC_NM2093 92 /* NeoMagic NM2093 */ +#define FB_ACCEL_NEOMAGIC_NM2097 93 /* NeoMagic NM2097 */ +#define FB_ACCEL_NEOMAGIC_NM2160 94 /* NeoMagic NM2160 */ +#define FB_ACCEL_NEOMAGIC_NM2200 95 /* NeoMagic NM2200 */ +#define FB_ACCEL_NEOMAGIC_NM2230 96 /* NeoMagic NM2230 */ +#define FB_ACCEL_NEOMAGIC_NM2360 97 /* NeoMagic NM2360 */ +#define FB_ACCEL_NEOMAGIC_NM2380 98 /* NeoMagic NM2380 */ +#define FB_ACCEL_PXA3XX 99 /* PXA3xx */ + +#define FB_ACCEL_SAVAGE4 0x80 /* S3 Savage4 */ +#define FB_ACCEL_SAVAGE3D 0x81 /* S3 Savage3D */ +#define FB_ACCEL_SAVAGE3D_MV 0x82 /* S3 Savage3D-MV */ +#define FB_ACCEL_SAVAGE2000 0x83 /* S3 Savage2000 */ +#define FB_ACCEL_SAVAGE_MX_MV 0x84 /* S3 Savage/MX-MV */ +#define FB_ACCEL_SAVAGE_MX 0x85 /* S3 Savage/MX */ +#define FB_ACCEL_SAVAGE_IX_MV 0x86 /* S3 Savage/IX-MV */ +#define FB_ACCEL_SAVAGE_IX 0x87 /* S3 Savage/IX */ +#define FB_ACCEL_PROSAVAGE_PM 0x88 /* S3 ProSavage PM133 */ +#define FB_ACCEL_PROSAVAGE_KM 0x89 /* S3 ProSavage KM133 */ +#define FB_ACCEL_S3TWISTER_P 0x8a /* S3 Twister */ +#define FB_ACCEL_S3TWISTER_K 0x8b /* S3 TwisterK */ +#define FB_ACCEL_SUPERSAVAGE 0x8c /* S3 Supersavage */ +#define FB_ACCEL_PROSAVAGE_DDR 0x8d /* S3 ProSavage DDR */ +#define FB_ACCEL_PROSAVAGE_DDRK 0x8e /* S3 ProSavage DDR-K */ + +#define FB_ACCEL_PUV3_UNIGFX 0xa0 /* PKUnity-v3 Unigfx */ + +#define FB_CAP_FOURCC 1 /* Device supports FOURCC-based formats */ + +struct fb_fix_screeninfo { + char id[16]; /* identification string eg "TT Builtin" */ + unsigned long smem_start; /* Start of frame buffer mem */ + /* (physical address) */ + uint32_t smem_len; /* Length of frame buffer mem */ + uint32_t type; /* see FB_TYPE_* */ + uint32_t type_aux; /* Interleave for interleaved Planes */ + uint32_t visual; /* see FB_VISUAL_* */ + uint16_t xpanstep; /* zero if no hardware panning */ + uint16_t ypanstep; /* zero if no hardware panning */ + uint16_t ywrapstep; /* zero if no hardware ywrap */ + uint32_t line_length; /* length of a line in bytes */ + unsigned long mmio_start; /* Start of Memory Mapped I/O */ + /* (physical address) */ + uint32_t mmio_len; /* Length of Memory Mapped I/O */ + uint32_t accel; /* Indicate to driver which */ + /* specific chip/card we have */ + uint16_t capabilities; /* see FB_CAP_* */ + uint16_t reserved[2]; /* Reserved for future compatibility */ +}; + +/* Interpretation of offset for color fields: All offsets are from the right, + * inside a "pixel" value, which is exactly 'bits_per_pixel' wide (means: you + * can use the offset as right argument to <<). A pixel afterwards is a bit + * stream and is written to video memory as that unmodified. + * + * For pseudocolor: offset and length should be the same for all color + * components. Offset specifies the position of the least significant bit + * of the palette index in a pixel value. Length indicates the number + * of available palette entries (i.e. # of entries = 1 << length). + */ +struct fb_bitfield { + uint32_t offset; /* beginning of bitfield */ + uint32_t length; /* length of bitfield */ + uint32_t msb_right; /* != 0 : Most significant bit is */ + /* right */ +}; + +#define FB_NONSTD_HAM 1 /* Hold-And-Modify (HAM) */ +#define FB_NONSTD_REV_PIX_IN_B 2 /* order of pixels in each byte is reversed */ + +#define FB_ACTIVATE_NOW 0 /* set values immediately (or vbl)*/ +#define FB_ACTIVATE_NXTOPEN 1 /* activate on next open */ +#define FB_ACTIVATE_TEST 2 /* don't set, round up impossible */ +#define FB_ACTIVATE_MASK 15 + /* values */ +#define FB_ACTIVATE_VBL 16 /* activate values on next vbl */ +#define FB_CHANGE_CMAP_VBL 32 /* change colormap on vbl */ +#define FB_ACTIVATE_ALL 64 /* change all VCs on this fb */ +#define FB_ACTIVATE_FORCE 128 /* force apply even when no change*/ +#define FB_ACTIVATE_INV_MODE 256 /* invalidate videomode */ +#define FB_ACTIVATE_KD_TEXT 512 /* for KDSET vt ioctl */ + +#define FB_ACCELF_TEXT 1 /* (OBSOLETE) see fb_info.flags and vc_mode */ + +#define FB_SYNC_HOR_HIGH_ACT 1 /* horizontal sync high active */ +#define FB_SYNC_VERT_HIGH_ACT 2 /* vertical sync high active */ +#define FB_SYNC_EXT 4 /* external sync */ +#define FB_SYNC_COMP_HIGH_ACT 8 /* composite sync high active */ +#define FB_SYNC_BROADCAST 16 /* broadcast video timings */ + /* vtotal = 144d/288n/576i => PAL */ + /* vtotal = 121d/242n/484i => NTSC */ +#define FB_SYNC_ON_GREEN 32 /* sync on green */ + +#define FB_VMODE_NONINTERLACED 0 /* non interlaced */ +#define FB_VMODE_INTERLACED 1 /* interlaced */ +#define FB_VMODE_DOUBLE 2 /* double scan */ +#define FB_VMODE_ODD_FLD_FIRST 4 /* interlaced: top line first */ +#define FB_VMODE_MASK 255 + +#define FB_VMODE_YWRAP 256 /* ywrap instead of panning */ +#define FB_VMODE_SMOOTH_XPAN 512 /* smooth xpan possible (internally used) */ +#define FB_VMODE_CONUPDATE 512 /* don't update x/yoffset */ + +/* + * Display rotation support + */ +#define FB_ROTATE_UR 0 +#define FB_ROTATE_CW 1 +#define FB_ROTATE_UD 2 +#define FB_ROTATE_CCW 3 + +#define PICOS2KHZ(a) (1000000000UL/(a)) +#define KHZ2PICOS(a) (1000000000UL/(a)) + +struct fb_var_screeninfo { + uint32_t xres; /* visible resolution */ + uint32_t yres; + uint32_t xres_virtual; /* virtual resolution */ + uint32_t yres_virtual; + uint32_t xoffset; /* offset from virtual to visible */ + uint32_t yoffset; /* resolution */ + + uint32_t bits_per_pixel; /* guess what */ + uint32_t grayscale; /* 0 = color, 1 = grayscale, */ + /* >1 = FOURCC */ + struct fb_bitfield red; /* bitfield in fb mem if true color, */ + struct fb_bitfield green; /* else only length is significant */ + struct fb_bitfield blue; + struct fb_bitfield transp; /* transparency */ + + uint32_t nonstd; /* != 0 Non standard pixel format */ + + uint32_t activate; /* see FB_ACTIVATE_* */ + + uint32_t height; /* height of picture in mm */ + uint32_t width; /* width of picture in mm */ + + uint32_t accel_flags; /* (OBSOLETE) see fb_info.flags */ + + /* Timing: All values in pixclocks, except pixclock (of course) */ + uint32_t pixclock; /* pixel clock in ps (pico seconds) */ + uint32_t left_margin; /* time from sync to picture */ + uint32_t right_margin; /* time from picture to sync */ + uint32_t upper_margin; /* time from sync to picture */ + uint32_t lower_margin; + uint32_t hsync_len; /* length of horizontal sync */ + uint32_t vsync_len; /* length of vertical sync */ + uint32_t sync; /* see FB_SYNC_* */ + uint32_t vmode; /* see FB_VMODE_* */ + uint32_t rotate; /* angle we rotate counter clockwise */ + uint32_t colorspace; /* colorspace for FOURCC-based modes */ + uint32_t reserved[4]; /* Reserved for future compatibility */ +}; + +struct fb_cmap { + uint32_t start; /* First entry */ + uint32_t len; /* Number of entries */ + uint16_t *red; /* Red values */ + uint16_t *green; + uint16_t *blue; + uint16_t *transp; /* transparency, can be NULL */ +}; + +struct fb_con2fbmap { + uint32_t console; + uint32_t framebuffer; +}; + +/* VESA Blanking Levels */ +#define VESA_NO_BLANKING 0 +#define VESA_VSYNC_SUSPEND 1 +#define VESA_HSYNC_SUSPEND 2 +#define VESA_POWERDOWN 3 + + +enum { + /* screen: unblanked, hsync: on, vsync: on */ + FB_BLANK_UNBLANK = VESA_NO_BLANKING, + + /* screen: blanked, hsync: on, vsync: on */ + FB_BLANK_NORMAL = VESA_NO_BLANKING + 1, + + /* screen: blanked, hsync: on, vsync: off */ + FB_BLANK_VSYNC_SUSPEND = VESA_VSYNC_SUSPEND + 1, + + /* screen: blanked, hsync: off, vsync: on */ + FB_BLANK_HSYNC_SUSPEND = VESA_HSYNC_SUSPEND + 1, + + /* screen: blanked, hsync: off, vsync: off */ + FB_BLANK_POWERDOWN = VESA_POWERDOWN + 1 +}; + +#define FB_VBLANK_VBLANKING 0x001 /* currently in a vertical blank */ +#define FB_VBLANK_HBLANKING 0x002 /* currently in a horizontal blank */ +#define FB_VBLANK_HAVE_VBLANK 0x004 /* vertical blanks can be detected */ +#define FB_VBLANK_HAVE_HBLANK 0x008 /* horizontal blanks can be detected */ +#define FB_VBLANK_HAVE_COUNT 0x010 /* global retrace counter is available */ +#define FB_VBLANK_HAVE_VCOUNT 0x020 /* the vcount field is valid */ +#define FB_VBLANK_HAVE_HCOUNT 0x040 /* the hcount field is valid */ +#define FB_VBLANK_VSYNCING 0x080 /* currently in a vsync */ +#define FB_VBLANK_HAVE_VSYNC 0x100 /* verical syncs can be detected */ + +struct fb_vblank { + uint32_t flags; /* FB_VBLANK flags */ + uint32_t count; /* counter of retraces since boot */ + uint32_t vcount; /* current scanline position */ + uint32_t hcount; /* current scandot position */ + uint32_t reserved[4]; /* reserved for future compatibility */ +}; + +/* Internal HW accel */ +#define ROP_COPY 0 +#define ROP_XOR 1 + +struct fb_copyarea { + uint32_t dx; + uint32_t dy; + uint32_t width; + uint32_t height; + uint32_t sx; + uint32_t sy; +}; + +struct fb_fillrect { + uint32_t dx; /* screen-relative */ + uint32_t dy; + uint32_t width; + uint32_t height; + uint32_t color; + uint32_t rop; +}; + +struct fb_image { + uint32_t dx; /* Where to place image */ + uint32_t dy; + uint32_t width; /* Size of image */ + uint32_t height; + uint32_t fg_color; /* Only used when a mono bitmap */ + uint32_t bg_color; + uint8_t depth; /* Depth of the image */ + const char *data; /* Pointer to image data */ + struct fb_cmap cmap; /* color map info */ +}; + +/* + * hardware cursor control + */ + +#define FB_CUR_SETIMAGE 0x01 +#define FB_CUR_SETPOS 0x02 +#define FB_CUR_SETHOT 0x04 +#define FB_CUR_SETCMAP 0x08 +#define FB_CUR_SETSHAPE 0x10 +#define FB_CUR_SETSIZE 0x20 +#define FB_CUR_SETALL 0xFF + +struct fbcurpos { + uint16_t x, y; +}; + +struct fb_cursor { + uint16_t set; /* what to set */ + uint16_t enable; /* cursor on/off */ + uint16_t rop; /* bitop operation */ + const char *mask; /* cursor mask bits */ + struct fbcurpos hot; /* cursor hot spot */ + struct fb_image image; /* Cursor image */ +}; + +/* Settings for the generic backlight code */ +#define FB_BACKLIGHT_LEVELS 128 +#define FB_BACKLIGHT_MAX 0xFF + + +#endif /* _SYS_FB_H */ diff --git a/sysdeps/ironclad/include/mntent.h b/sysdeps/ironclad/include/mntent.h new file mode 100644 index 0000000000..e5e49e71ef --- /dev/null +++ b/sysdeps/ironclad/include/mntent.h @@ -0,0 +1,46 @@ +#ifndef _MNTENT_H +#define _MNTENT_H + +#include + +// TODO: Refer to _PATH_MOUNTED +#define MOUNTED "/etc/mtab" + +/* Generic mount options */ +#define MNTOPT_DEFAULTS "defaults" /* Use all default options. */ +#define MNTOPT_RO "ro" /* Read only. */ +#define MNTOPT_RW "rw" /* Read/write. */ +#define MNTOPT_SUID "suid" /* Set uid allowed. */ +#define MNTOPT_NOSUID "nosuid" /* No set uid allowed. */ +#define MNTOPT_NOAUTO "noauto" /* Do not auto mount. */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct mntent { + char *mnt_fsname; + char *mnt_dir; + char *mnt_type; + char *mnt_opts; + int mnt_freq; + int mnt_passno; +}; + +FILE *setmntent(const char *, const char *); + +struct mntent *getmntent(FILE *); + +int addmntent(FILE *, const struct mntent *); + +int endmntent(FILE *); + +char *hasmntopt(const struct mntent *, const char *); + +struct mntent *getmntent_r(FILE *, struct mntent *, char *, int); + +#ifdef __cplusplus +} +#endif + +#endif // _MNTENT_H diff --git a/sysdeps/ironclad/include/pty.h b/sysdeps/ironclad/include/pty.h new file mode 100644 index 0000000000..0468b4661f --- /dev/null +++ b/sysdeps/ironclad/include/pty.h @@ -0,0 +1,16 @@ +#ifndef _PTY_H +#define _PTY_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const struct winsize *win); + +#ifdef __cplusplus +} +#endif + +#endif // _PTY_H diff --git a/sysdeps/ironclad/include/sys/ironclad.h b/sysdeps/ironclad/include/sys/ironclad.h deleted file mode 100644 index 89a3851ca0..0000000000 --- a/sysdeps/ironclad/include/sys/ironclad.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef _IRONCLAD_H -#define _IRONCLAD_H - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define FB_DIMENSIONS 1 - -struct ironclad_fb_dimensions { - uint16_t width; - uint16_t height; - uint16_t pitch; - uint16_t bpp; - uint8_t red_mask_size; - uint8_t red_mask_shift; - uint8_t green_mask_size; - uint8_t green_mask_shift; - uint8_t blue_mask_size; - uint8_t blue_mask_shift; -}; - -#define PS2MOUSE_2_1_SCALING 1 -#define PS2MOUSE_1_1_SCALING 2 -#define PS2MOUSE_SET_RES 3 -#define PS2MOUSE_SET_SAMPLE_RATE 4 - -struct ironclad_mouse_data { - int x_variation; - int y_variation; - bool is_left; - bool is_right; -}; -#ifdef __cplusplus -} -#endif - -#endif // _IRONCLAD_H diff --git a/sysdeps/ironclad/include/sys/ironclad_devices.h b/sysdeps/ironclad/include/sys/ironclad_devices.h new file mode 100644 index 0000000000..74f47f812b --- /dev/null +++ b/sysdeps/ironclad/include/sys/ironclad_devices.h @@ -0,0 +1,44 @@ +#ifndef _SYS_IRONCLAD_DEVICES_H +#define _SYS_IRONCLAD_DEVICES_H + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PS2MOUSE_2_1_SCALING 1 +#define PS2MOUSE_1_1_SCALING 2 +#define PS2MOUSE_SET_RES 3 +#define PS2MOUSE_SET_SAMPLE_RATE 4 + +struct ironclad_mouse_data { + int x_variation; + int y_variation; + bool is_left; + bool is_right; +}; + +#define RTC_RD_TIME 1 +#define RTC_SET_TIME 2 + +struct rtc_time { + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; /* unused */ + int tm_yday; /* unused */ + int tm_isdst; /* unused */ +}; + +#ifdef __cplusplus +} +#endif + +#endif // _SYS_IRONCLAD_DEVICES_H diff --git a/sysdeps/ironclad/include/sys/mac.h b/sysdeps/ironclad/include/sys/mac.h new file mode 100644 index 0000000000..d4cf76d65c --- /dev/null +++ b/sysdeps/ironclad/include/sys/mac.h @@ -0,0 +1,46 @@ +#ifndef _SYS_MAC_H +#define _SYS_MAC_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAC_CAP_SCHED 0b00000000001 +#define MAC_CAP_SPAWN 0b00000000010 +#define MAC_CAP_ENTROPY 0b00000000100 +#define MAC_CAP_SYS_MEM 0b00000001000 +#define MAC_CAP_USE_NET 0b00000010000 +#define MAC_CAP_SYS_NET 0b00000100000 +#define MAC_CAP_SYS_MNT 0b00001000000 +#define MAC_CAP_SYS_PWR 0b00010000000 +#define MAC_CAP_PTRACE 0b00100000000 +#define MAC_CAP_SETUID 0b01000000000 +#define MAC_CAP_SYS_MAC 0b10000000000 +#define MAC_CAP_CLOCK 0b100000000000 +#define MAC_CAP_SIGNALALL 0b1000000000000 +unsigned long get_mac_capabilities(void); +int set_mac_capabilities(unsigned long request); + +#define MAC_PERM_CONTENTS 0b0000001 +#define MAC_PERM_READ 0b0000010 +#define MAC_PERM_WRITE 0b0000100 +#define MAC_PERM_EXEC 0b0001000 +#define MAC_PERM_APPEND 0b0010000 +#define MAC_PERM_FLOCK 0b0100000 +#define MAC_PERM_DEV 0b1000000 +int add_mac_permissions(const char *path, int flags); + +#define MAC_DENY 0b001 +#define MAC_DENY_AND_SCREAM 0b010 +#define MAC_KILL 0b100 +int set_mac_enforcement(unsigned long enforcement); + +#ifdef __cplusplus +} +#endif + +#endif // _SYS_MAC_H diff --git a/sysdeps/ironclad/include/sys/mount.h b/sysdeps/ironclad/include/sys/mount.h new file mode 100644 index 0000000000..71ae64d730 --- /dev/null +++ b/sysdeps/ironclad/include/sys/mount.h @@ -0,0 +1,19 @@ +#ifndef _SYS_MOUNT_H +#define _SYS_MOUNT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define MNT_FORCE 1 + +int mount(const char *source, const char *target, + const char *fstype, unsigned long flags, const void *data); +int umount(const char *target); +int umount2(const char *target, int flags); + +#ifdef __cplusplus +} +#endif + +#endif // _SYS_MOUNT_H diff --git a/sysdeps/ironclad/include/sys/ptrace.h b/sysdeps/ironclad/include/sys/ptrace.h new file mode 100644 index 0000000000..3993753f10 --- /dev/null +++ b/sysdeps/ironclad/include/sys/ptrace.h @@ -0,0 +1,23 @@ +#ifndef _SYS_PTRACE_H +#define _SYS_PTRACE_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define PTRACE_ATTACH 1 +#define PTRACE_DETACH 2 +#define PTRACE_CONT 3 +#define PTRACE_SYSCALL 4 +#define PTRACE_GETREGS 5 +int ptrace(int request, pid_t pid, void *addr, void *data); + +#ifdef __cplusplus +} +#endif + +#endif // _SYS_PTRACE_H diff --git a/sysdeps/ironclad/include/sys/reboot.h b/sysdeps/ironclad/include/sys/reboot.h new file mode 100644 index 0000000000..c2dbbf2b66 --- /dev/null +++ b/sysdeps/ironclad/include/sys/reboot.h @@ -0,0 +1,16 @@ +#ifndef _SYS_REBOOT_H +#define _SYS_REBOOT_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int reboot(int arg); + +#ifdef __cplusplus +} +#endif + +#endif // _SYS_REBOOT_H diff --git a/sysdeps/ironclad/include/sys/sched2.h b/sysdeps/ironclad/include/sys/sched2.h new file mode 100644 index 0000000000..caeb86a269 --- /dev/null +++ b/sysdeps/ironclad/include/sys/sched2.h @@ -0,0 +1,24 @@ +#ifndef _SYS_SCHED2_H +#define _SYS_SCHED2_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define THREAD_RT 0b0001 +#define THREAD_MONO 0b0010 +#define THREAD_MLOCK 0b0100 +#define THREAD_BANNED 0b1000 +int get_thread_sched(void); +int set_thread_sched(int flags); +int set_deadlines(int runtime, int period); + +#ifdef __cplusplus +} +#endif + +#endif // _SYS_SCHED2_H diff --git a/sysdeps/ironclad/include/sys/syscall.h b/sysdeps/ironclad/include/sys/syscall.h index 28d233e2fa..b0227d57c5 100644 --- a/sysdeps/ironclad/include/sys/syscall.h +++ b/sysdeps/ironclad/include/sys/syscall.h @@ -1,80 +1,170 @@ -#ifndef _SYSCALL_H -#define _SYSCALL_H +#ifndef _SYS_SYSCALL_H +#define _SYS_SYSCALL_H #include #define SYSCALL0(NUM) ({ \ - asm volatile ("int $0x80" \ + asm volatile ("syscall" \ : "=a"(ret), "=d"(errno) \ : "a"(NUM) \ - : "memory"); \ + : "rcx", "r11", "memory"); \ }) #define SYSCALL1(NUM, ARG0) ({ \ - asm volatile ("int $0x80" \ + asm volatile ("syscall" \ : "=a"(ret), "=d"(errno) \ : "a"(NUM), "D"(ARG0) \ - : "memory"); \ + : "rcx", "r11", "memory"); \ }) #define SYSCALL2(NUM, ARG0, ARG1) ({ \ - asm volatile ("int $0x80" \ + asm volatile ("syscall" \ : "=a"(ret), "=d"(errno) \ : "a"(NUM), "D"(ARG0), "S"(ARG1) \ - : "memory"); \ + : "rcx", "r11", "memory"); \ }) #define SYSCALL3(NUM, ARG0, ARG1, ARG2) ({ \ - asm volatile ("int $0x80" \ + asm volatile ("syscall" \ : "=a"(ret), "=d"(errno) \ : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2) \ - : "memory"); \ + : "rcx", "r11", "memory"); \ }) #define SYSCALL4(NUM, ARG0, ARG1, ARG2, ARG3) ({ \ - asm volatile ("int $0x80" \ + register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \ + asm volatile ("syscall" \ : "=a"(ret), "=d"(errno) \ - : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), "c"(ARG3) \ - : "memory"); \ + : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \ + "r"(arg_r12) \ + : "rcx", "r11", "memory"); \ +}) + +#define SYSCALL5(NUM, ARG0, ARG1, ARG2, ARG3, ARG4) ({ \ + register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \ + register __typeof(ARG4) arg_r8 asm("r8") = ARG4; \ + asm volatile ("syscall" \ + : "=a"(ret), "=d"(errno) \ + : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \ + "r"(arg_r12), "r"(arg_r8) \ + : "rcx", "r11", "memory"); \ +}) + +#define SYSCALL6(NUM, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) ({ \ + register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \ + register __typeof(ARG4) arg_r8 asm("r8") = ARG4; \ + register __typeof(ARG5) arg_r9 asm("r9") = ARG5; \ + asm volatile ("syscall" \ + : "=a"(ret), "=d"(errno) \ + : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \ + "r"(arg_r12), "r"(arg_r8), "r"(arg_r9) \ + : "rcx", "r11", "memory"); \ }) #define SYSCALL6(NUM, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5) ({ \ - register uint64_t arg_r8 asm("r8") = (uint64_t)ARG4; \ - register uint64_t arg_r9 asm("r9") = (uint64_t)ARG5; \ - asm volatile ("int $0x80" \ + register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \ + register __typeof(ARG4) arg_r8 asm("r8") = ARG4; \ + register __typeof(ARG5) arg_r9 asm("r9") = ARG5; \ + asm volatile ("syscall" \ + : "=a"(ret), "=d"(errno) \ + : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \ + "r"(arg_r12), "r"(arg_r8), "r"(arg_r9) \ + : "rcx", "r11", "memory"); \ +}) + +#define SYSCALL7(NUM, ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) ({ \ + register __typeof(ARG3) arg_r12 asm("r12") = ARG3; \ + register __typeof(ARG4) arg_r8 asm("r8") = ARG4; \ + register __typeof(ARG5) arg_r9 asm("r9") = ARG5; \ + register __typeof(ARG6) arg_r10 asm("r10") = ARG6; \ + asm volatile ("syscall" \ : "=a"(ret), "=d"(errno) \ : "a"(NUM), "D"(ARG0), "S"(ARG1), "d"(ARG2), \ - "c"(ARG3), "r"(arg_r8), "r"(arg_r9) \ - : "memory"); \ + "r"(arg_r12), "r"(arg_r8), "r"(arg_r9), "r"(arg_r10) \ + : "rcx", "r11", "memory"); \ }) -#define SYSCALL_EXIT 0 -#define SYSCALL_SET_TCB 1 -#define SYSCALL_OPEN 2 -#define SYSCALL_CLOSE 3 -#define SYSCALL_READ 4 -#define SYSCALL_WRITE 5 -#define SYSCALL_SEEK 6 -#define SYSCALL_MMAP 7 -#define SYSCALL_MUNMAP 8 -#define SYSCALL_GETPID 9 -#define SYSCALL_GETPPID 10 -#define SYSCALL_EXEC 11 -#define SYSCALL_FORK 12 -#define SYSCALL_WAIT 13 -#define SYSCALL_UNAME 14 -#define SYSCALL_SETHOSTNAME 15 -#define SYSCALL_FSTAT 16 -#define SYSCALL_LSTAT 17 -#define SYSCALL_GETCWD 18 -#define SYSCALL_CHDIR 19 -#define SYSCALL_IOCTL 20 -#define SYSCALL_SCHED_YIELD 21 -#define SYSCALL_GETPRIORITY 22 -#define SYSCALL_SETPRIORITY 23 -#define SYSCALL_DUP 24 -#define SYSCALL_DUP2 25 -#define SYSCALL_DUP3 26 -#define SYSCALL_ACCESS 27 +#define SYSCALL_EXIT 0 +#define SYSCALL_ARCH_PRCTL 1 +#define SYSCALL_OPEN 2 +#define SYSCALL_CLOSE 3 +#define SYSCALL_READ 4 +#define SYSCALL_WRITE 5 +#define SYSCALL_SEEK 6 +#define SYSCALL_MMAP 7 +#define SYSCALL_MUNMAP 8 +#define SYSCALL_GETPID 9 +#define SYSCALL_GETPPID 10 +#define SYSCALL_EXEC 11 +#define SYSCALL_CLONE 12 +#define SYSCALL_WAIT 13 +#define SYSCALL_SOCKET 14 +#define SYSCALL_SETHOSTNAME 15 +#define SYSCALL_UNLINK 16 +#define SYSCALL_STAT 17 +#define SYSCALL_GETCWD 18 +#define SYSCALL_CHDIR 19 +#define SYSCALL_IOCTL 20 +#define SYSCALL_SCHED_YIELD 21 +#define SYSCALL_DELETE_TCLUSTER 22 +#define SYSCALL_PIPE 23 +#define SYSCALL_GETUID 24 +#define SYSCALL_RENAME 25 +#define SYSCALL_SYSCONF 26 +#define SYSCALL_SPAWN 27 +#define SYSCALL_GETTID 28 +#define SYSCALL_MANAGE_TCLUSTER 29 +#define SYSCALL_FCNTL 30 +#define SYSCALL_EXIT_THREAD 31 +#define SYSCALL_GETRANDOM 32 +#define SYSCALL_MPROTECT 33 +#define SYSCALL_SYNC 34 +#define SYSCALL_SET_MAC_CAPABILITIES 35 +#define SYSCALL_GET_MAC_CAPABILITIES 36 +#define SYSCALL_ADD_MAC_PERMISSIONS 37 +#define SYSCALL_SET_MAC_ENFORCEMENT 38 +#define SYSCALL_MOUNT 39 +#define SYSCALL_UMOUNT 40 +#define SYSCALL_READLINK 41 +#define SYSCALL_GETDENTS 42 +#define SYSCALL_MAKENODE 43 +#define SYSCALL_TRUNCATE 44 +#define SYSCALL_BIND 45 +#define SYSCALL_SYMLINK 46 +#define SYSCALL_CONNECT 47 +#define SYSCALL_OPENPTY 48 +#define SYSCALL_FSYNC 49 +#define SYSCALL_LINK 50 +#define SYSCALL_PTRACE 51 +#define SYSCALL_LISTEN 52 +#define SYSCALL_ACCEPT 53 +#define SYSCALL_GETRLIMIT 54 +#define SYSCALL_SETRLIMIT 55 +#define SYSCALL_ACCESS 56 +#define SYSCALL_POLL 57 +#define SYSCALL_GETEUID 58 +#define SYSCALL_SETUIDS 59 +#define SYSCALL_FCHMOD 60 +#define SYSCALL_UMASK 61 +#define SYSCALL_REBOOT 62 +#define SYSCALL_FCHOWN 63 +#define SYSCALL_PREAD 64 +#define SYSCALL_PWRITE 65 +#define SYSCALL_GETSOCKNAME 66 +#define SYSCALL_GETPEERNAME 67 +#define SYSCALL_SHUTDOWN 68 +#define SYSCALL_FUTEX 69 +#define SYSCALL_CLOCK 70 +#define SYSCALL_CLOCK_NANOSLEEP 71 +#define SYSCALL_GETRUSAGE 72 +#define SYSCALL_RECVFROM 73 +#define SYSCALL_SENDTO 74 +#define SYSCALL_CONFIG_NETINTER 75 +#define SYSCALL_UTIMES 76 +#define SYSCALL_CREATE_TCLUSTER 77 +#define SYSCALL_SWITCH_TCLUSTER 78 +#define SYSCALL_ACTUALLY_KILL 79 +#define SYSCALL_SIGNALPOST 80 +#define SYSCALL_SEND_SIGNAL 81 -#endif // _SYSCALL_H +#endif // _SYS_SYSCALL_H diff --git a/sysdeps/ironclad/meson.build b/sysdeps/ironclad/meson.build index a0b4f8d55d..d12e2e1ede 100644 --- a/sysdeps/ironclad/meson.build +++ b/sysdeps/ironclad/meson.build @@ -5,7 +5,16 @@ rtdl_sources += files( libc_sources += files( 'generic/entry.cpp', - 'generic/generic.cpp' + 'generic/ptrace.cpp', + 'generic/generic.cpp', + 'generic/mntent.cpp', + 'generic/mount.cpp', + 'generic/reboot.cpp', + 'generic/pty.cpp', + 'generic/thread.cpp', + 'generic/mac.cpp', + 'generic/sched2.cpp', + 'generic/thread.S' ) if not no_headers @@ -56,10 +65,30 @@ if not no_headers subdir: 'abi-bits' ) install_headers( - 'include/sys/ironclad.h', + 'include/sys/sched2.h', + 'include/sys/ironclad_devices.h', + 'include/sys/mac.h', 'include/sys/syscall.h', + 'include/sys/reboot.h', + 'include/sys/mount.h', + 'include/sys/ptrace.h', subdir: 'sys' ) + + install_headers( + 'include/asm/ioctls.h', + subdir: 'asm' + ) + + install_headers( + 'include/linux/fb.h', + subdir: 'linux' + ) + + install_headers( + 'include/mntent.h', + 'include/pty.h' + ) endif if not headers_only @@ -71,5 +100,23 @@ if not headers_only install: true, install_dir: get_option('libdir') ) + + custom_target('crti', + build_by_default: true, + command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], + input: 'crt-x86_64/crti.S', + output: 'crti.o', + install: true, + install_dir: get_option('libdir') + ) + + custom_target('crtn', + build_by_default: true, + command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], + input: 'crt-x86_64/crtn.S', + output: 'crtn.o', + install: true, + install_dir: get_option('libdir') + ) endif