diff --git a/abis/badgeros/blkcnt_t.h b/abis/badgeros/blkcnt_t.h new file mode 100644 index 0000000000..fbbb9b8b52 --- /dev/null +++ b/abis/badgeros/blkcnt_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_BLKCNT_T_H +#define _ABIBITS_BLKCNT_T_H + +#include + +typedef __mlibc_int64 blkcnt_t; + +#endif /* _ABIBITS_BLKCNT_T_H */ diff --git a/abis/badgeros/blksize_t.h b/abis/badgeros/blksize_t.h new file mode 100644 index 0000000000..982a6beaa7 --- /dev/null +++ b/abis/badgeros/blksize_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_BLKSIZE_T_H +#define _ABIBITS_BLKSIZE_T_H + +#include + +typedef __mlibc_int64 blksize_t; + +#endif /* _ABIBITS_BLKCNT_T_H */ diff --git a/abis/badgeros/clockid_t.h b/abis/badgeros/clockid_t.h new file mode 100644 index 0000000000..74555473c1 --- /dev/null +++ b/abis/badgeros/clockid_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_CLOCKID_T_H +#define _ABIBITS_CLOCKID_T_H + +#include + +typedef __mlibc_int64 clockid_t; + +#endif /* _ABIBITS_BLKCNT_T_H */ diff --git a/abis/badgeros/dev_t.h b/abis/badgeros/dev_t.h new file mode 100644 index 0000000000..c39ab67f49 --- /dev/null +++ b/abis/badgeros/dev_t.h @@ -0,0 +1,10 @@ + +#ifndef _ABIBITS_DEV_T_H +#define _ABIBITS_DEV_T_H + +#include + +typedef __mlibc_uint64 dev_t; + +#endif /* _ABIBITS_DEV_T_H */ + diff --git a/abis/badgeros/fcntl.h b/abis/badgeros/fcntl.h new file mode 100644 index 0000000000..a0887f3f48 --- /dev/null +++ b/abis/badgeros/fcntl.h @@ -0,0 +1,156 @@ +#ifndef _ABIBITS_FCNTL_H +#define _ABIBITS_FCNTL_H + +#include +#include + +// #define O_PATH + +#define O_ACCMODE 0x03 +// Note: If neither O_RDONLY nor O_WRONLY are specified, the kernel assumes read access was requested. +#define O_RDONLY 0x00000001 +#define O_WRONLY 0x00000002 +#define O_RDWR 0x00000003 + +#define O_CREAT 0x00000040 +#define O_EXCL 0x00000080 +#define O_NOCTTY 0x01000000 +#define O_TRUNC 0x00000100 +#define O_APPEND 0x00000004 +#define O_NONBLOCK 0x00000200 +#define O_CLOEXEC 0x00010000 +// For __syscall_fs_dup: Use fncntl(F_DUPFD)-style FD selection; choose the next available instead of overwriting. +#define DUP2_FCNTL 0x00000800 +// #define O_NOATIME + +// #define O_DIRECT +#define O_DIRECTORY 0x00000010 +#define O_NOFOLLOW 0x00000020 + +#define O_TMPFILE 0x00000400 + +// #define O_EXEC O_PATH +// #define O_SEARCH O_PATH +#define O_TTY_INIT 0 + +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 4 + +#define F_SETOWN 8 +#define F_GETOWN 9 +#define F_SETSIG 10 +#define F_GETSIG 11 + +#if __INTPTR_WIDTH__ == 64 + +#define F_GETLK64 5 +#define F_SETLK64 6 +#define F_SETLKW64 7 + +#else /* __INTPTR_WIDTH__ == 64 */ + +#define F_GETLK64 12 +#define F_SETLK64 13 +#define F_SETLKW64 14 + +#endif + +#define F_GETLK F_GETLK64 +#define F_SETLK F_SETLK64 +#define F_SETLKW F_SETLKW64 + +#define F_SETOWN_EX 15 +#define F_GETOWN_EX 16 + +#define F_GETOWNER_UIDS 17 + +#define F_SETLEASE 1024 +#define F_GETLEASE 1025 +#define F_NOTIFY 1026 +#define F_DUPFD_CLOEXEC 1030 +#define F_SETPIPE_SZ 1031 +#define F_GETPIPE_SZ 1032 +#define F_ADD_SEALS 1033 +#define F_GET_SEALS 1034 + +#define F_SEAL_SEAL 0x0001 +#define F_SEAL_SHRINK 0x0002 +#define F_SEAL_GROW 0x0004 +#define F_SEAL_WRITE 0x0008 + +#define F_OFD_GETLK 36 +#define F_OFD_SETLK 37 +#define F_OFD_SETLKW 38 + +#define F_RDLCK 0 +#define F_WRLCK 1 +#define F_UNLCK 2 + +#define FD_CLOEXEC 0x00010000 + +#define AT_FDCWD -100 +#define AT_SYMLINK_NOFOLLOW 0x100 +#define AT_REMOVEDIR 0x200 +#define AT_SYMLINK_FOLLOW 0x400 +#define AT_EACCESS 0x200 + +#if defined(_GNU_SOURCE) +#define AT_NO_AUTOMOUNT 0x800 +#define AT_EMPTY_PATH 0x1000 +#endif + +#if __MLIBC_LINUX_OPTION && defined(_GNU_SOURCE) + +#define DN_ACCESS 1 +#define DN_MODIFY 2 +#define DN_CREATE 4 +#define DN_DELETE 8 +#define DN_RENAME 16 +#define DN_ATTRIB 32 +#define DN_MULTISHOT 0x80000000 + +#define AT_STATX_SYNC_AS_STAT 0x0000 +#define AT_STATX_FORCE_SYNC 0x2000 +#define AT_STATX_DONT_SYNC 0x4000 +#define AT_STATX_SYNC_TYPE 0x6000 + +#endif /* __MLIBC_LINUX_OPTION && defined(_GNU_SOURCE) */ + +#if defined(_GNU_SOURCE) || __MLIBC_POSIX2024 +struct f_owner_ex { + int type; + pid_t pid; +}; +#endif /* defined(_GNU_SOURCE) || __MLIBC_POSIX2024 */ + +#define F_OWNER_TID 0 +#define F_OWNER_PID 1 +#define F_OWNER_PGRP 2 + +#define POSIX_FADV_NORMAL 0 +#define POSIX_FADV_RANDOM 1 +#define POSIX_FADV_SEQUENTIAL 2 +#define POSIX_FADV_WILLNEED 3 +#define POSIX_FADV_DONTNEED 4 +#define POSIX_FADV_NOREUSE 5 + +#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 + +#endif /* _ABIBITS_FCNTL_H */ diff --git a/abis/badgeros/fd_set.h b/abis/badgeros/fd_set.h new file mode 100644 index 0000000000..d5b1e2cbef --- /dev/null +++ b/abis/badgeros/fd_set.h @@ -0,0 +1,12 @@ +#ifndef _ABIBITS_FD_SET_H +#define _ABIBITS_FD_SET_H + +#include + +#define FD_SETSIZE 256 + +typedef struct { + __mlibc_uint8 fds_bits[FD_SETSIZE / 8]; +} fd_set; + +#endif /* _ABIBITS_FD_SET_H */ diff --git a/abis/badgeros/fsblkcnt_t.h b/abis/badgeros/fsblkcnt_t.h new file mode 100644 index 0000000000..0d7445619e --- /dev/null +++ b/abis/badgeros/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/badgeros/fsfilcnt_t.h b/abis/badgeros/fsfilcnt_t.h new file mode 100644 index 0000000000..1abda9a981 --- /dev/null +++ b/abis/badgeros/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/badgeros/getid.h b/abis/badgeros/getid.h new file mode 100644 index 0000000000..8ed233634f --- /dev/null +++ b/abis/badgeros/getid.h @@ -0,0 +1,21 @@ +#ifndef _ABIBITS_BADGEROS_GETID_T_H +#define _ABIBITS_BADGEROS_GETID_T_H + +#include + +/* ID of calling process. */ +#define _GETID_PID 0 +/* ID of calling process' parent. */ +#define _GETID_PPID 1 +/* ID of calling thread. */ +#define _GETID_TID 2 +/* User ID of calling process. */ +#define _GETID_UID 3 +/* Effective user ID of calling process. */ +#define _GETID_EUID 4 +/* Group ID of calling process. */ +#define _GETID_GID 5 +/* Effective group ID of calling process. */ +#define _GETID_EGID 6 + +#endif /* _ABIBITS_BADGEROS_GETID_T_H */ diff --git a/abis/badgeros/nlink_t.h b/abis/badgeros/nlink_t.h new file mode 100644 index 0000000000..b14178ddff --- /dev/null +++ b/abis/badgeros/nlink_t.h @@ -0,0 +1,9 @@ + +#ifndef _ABIBITS_NLINK_T_H +#define _ABIBITS_NLINK_T_H + +#include + +typedef __mlibc_uint64 nlink_t; + +#endif /* _ABIBITS_NLINK_T_H */ diff --git a/abis/badgeros/pid_t.h b/abis/badgeros/pid_t.h new file mode 100644 index 0000000000..8935a7907d --- /dev/null +++ b/abis/badgeros/pid_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_PID_T +#define _ABIBITS_PID_T + +#include + +typedef __mlibc_int64 pid_t; + +#endif diff --git a/abis/badgeros/sigset_t.h b/abis/badgeros/sigset_t.h new file mode 100644 index 0000000000..c61aca598b --- /dev/null +++ b/abis/badgeros/sigset_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_SIGSET_T_H +#define _ABIBITS_SIGSET_T_H + +typedef struct { + unsigned long __sig[1024 / (8 * sizeof(long))]; +} sigset_t; + +#endif /* _ABIBITS_SIGSET_T_H */ diff --git a/abis/badgeros/stat.h b/abis/badgeros/stat.h new file mode 100644 index 0000000000..c7c614cd27 --- /dev/null +++ b/abis/badgeros/stat.h @@ -0,0 +1,73 @@ +#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; + blksize_t st_blksize; + blkcnt_t st_blocks; + struct timespec st_atim; + struct timespec st_mtim; + struct timespec st_ctim; +}; + +#if defined(_DEFAULT_SOURCE) || defined(_LARGEFILE64_SOURCE) +#define stat64 stat +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _ABIBITS_STAT_H */ diff --git a/abis/badgeros/statvfs.h b/abis/badgeros/statvfs.h new file mode 100644 index 0000000000..05961778f0 --- /dev/null +++ b/abis/badgeros/statvfs.h @@ -0,0 +1,59 @@ +#ifndef _ABIBITS_STATVFS_H +#define _ABIBITS_STATVFS_H + +#include + +#include +#include + +#define ST_RDONLY 1 +#define ST_NOSUID 2 +#define ST_NODEV 4 +#define ST_NOEXEC 8 +#define ST_SYNCHRONOUS 16 +#define ST_MANDLOCK 64 +#define ST_WRITE 128 +#define ST_APPEND 256 +#define ST_IMMUTABLE 512 +#define ST_NOATIME 1024 +#define ST_NODIRATIME 2048 +#define ST_WAIT 4096 +#define ST_NOWAIT 8192 + +#define MNT_RDONLY ST_RDONLY +#define MNT_NOSUID ST_NOSUID +#define MNT_NODEV ST_NODEV +#define MNT_NOEXEC ST_NOEXEC +#define MNT_SYNCHRONOUS ST_SYNCHRONOUS +#define MNT_MANDLOCK ST_MANDLOCK +#define MNT_WRITE ST_WRITE +#define MNT_APPEND ST_APPEND +#define MNT_IMMUTABLE ST_IMMUTABLE +#define MNT_NOATIME ST_NOATIME +#define MNT_NODIRATIME ST_NODIRATIME +#define MNT_WAIT ST_WAIT +#define MNT_NOWAIT ST_NOWAIT + +#define _VFS_NAMELEN 32 +/* BadgerOS: Equal to PATH_MAX. */ +#define _VFS_MNAMELEN 4096 + +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; + + char f_fstypename[_VFS_NAMELEN]; + char f_mntonname[_VFS_MNAMELEN]; + char f_mntfromname[_VFS_NAMELEN]; +}; + +#endif /* _ABIBITS_STATVFS_H */ diff --git a/abis/badgeros/suseconds_t.h b/abis/badgeros/suseconds_t.h new file mode 100644 index 0000000000..723ddfaeb0 --- /dev/null +++ b/abis/badgeros/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/badgeros/syscall_defs.inc b/abis/badgeros/syscall_defs.inc new file mode 100644 index 0000000000..ce4c1d23cd --- /dev/null +++ b/abis/badgeros/syscall_defs.inc @@ -0,0 +1,201 @@ + +// SPDX-License-Identifier: MIT +// clang-format off + + + +/* ==== DEFAULT MACRO EXPANSIONS ==== */ + +// Normal syscall definition. +#ifndef _SYSCALL_DEF +#define _SYSCALL_DEF(__no, __enum, __name, __returns, ...) +#endif + +// Normal syscall definition (returning void). +#ifndef _SYSCALL_DEF_V +#define _SYSCALL_DEF_V(__no, __enum, __name, ...) _SYSCALL_DEF(__no, __enum, __name, void, __VA_ARGS__) +#endif + + + + +// Yield to other threads. +_SYSCALL_DEF_V(0, _SYSCALL_THREAD_YIELD, __syscall_thread_yield) + +// Sleep for a certain amount of time. +_SYSCALL_DEF_V(1, _SYSCALL_THREAD_SLEEP, __syscall_thread_sleep, __mlibc_uint64 __delay) + +// Create a new thread. +// Returns thread ID or -errno. +_SYSCALL_DEF(2, _SYSCALL_THREAD_CREATE, __syscall_thread_create, long, void *__entry, void *__arg, int __priority) + +// Detach a thread; the thread will be destroyed as soon as it exits. +// Returns 0 or -errno. +_SYSCALL_DEF(3, _SYSCALL_THREAD_DETACH, __syscall_thread_detach, int, long __thread_id) + +// Wait for a thread to stop and return its exit code. +// Returns the exit code of that thread or -errno. +_SYSCALL_DEF(4, _SYSCALL_THREAD_JOIN, __syscall_thread_join, int, long __thread_id) + +// Exit the current thread; exit code can be read unless destroyed or detached. +_SYSCALL_DEF_V(5, _SYSCALL_THREAD_EXIT, __syscall_thread_exit, int __code) + +// Exit the process; exit code can be read by parent process. +_SYSCALL_DEF_V(6, _SYSCALL_PROC_EXIT, __syscall_proc_exit, int __code) + +// Get the command-line arguments (i.e. argc+argv) of the current process. +// If memory is large enough, a NULL-terminated argv array of C-string pointers and their data is stored in `memory`. +// The function returns how many bytes would be needed to store the structure. +// If the memory was not large enough, it it not modified. +_SYSCALL_DEF(7, _SYSCALL_PROC_GETARGS, __syscall_proc_getargs, __mlibc_size, __mlibc_size __cap, void *__memory) + +// Create a copy of the running process and return its PID (to the parent) or -1 (to the child). +_SYSCALL_DEF(8, _SYSCALL_PROC_FORK, __syscall_proc_fork, __mlibc_int64) + +// Execute the program at `path`, replacing the calling program's code and data in the process. +_SYSCALL_DEF(9, _SYSCALL_PROC_EXEC, __syscall_proc_exec, int, char const *__path, char const *const *__argv, char const *const *__envp) + +// Set the signal handler for a specific signal number. +_SYSCALL_DEF(10, _SYSCALL_PROC_SIGACTION, __syscall_proc_sigaction, int, int __signum, struct sigaction const *__newhandler, struct sigaction *__oldhandler) + +// Return from a signal handler. +_SYSCALL_DEF_V(11, _SYSCALL_PROC_SIGRET, __syscall_proc_sigret) + +// Get child process status update. +_SYSCALL_DEF(12, _SYSCALL_PROC_WAITPID, __syscall_proc_waitpid, __mlibc_int64, __mlibc_int64 __pid, int *__wstatus, int __options) + +// Open a file, optionally relative to a directory. +// Returns -errno on error, file descriptor number on success. +_SYSCALL_DEF(13, _SYSCALL_FS_OPEN, __syscall_fs_open, int, int __at, char const *__path, int __oflags) + +// Flush and close a file. +_SYSCALL_DEF(14, _SYSCALL_FS_CLOSE, __syscall_fs_close, int, int __fd) + +// Read bytes from a file. +// Returns 0 on EOF, -errno on error, read count on success. +_SYSCALL_DEF(15, _SYSCALL_FS_READ, __syscall_fs_read, __mlibc_int64, int __fd, void *__read_buf, long read_len) + +// Write bytes to a file. +// Returns -errno on error, write count on success. +_SYSCALL_DEF(16, _SYSCALL_FS_WRITE, __syscall_fs_write, __mlibc_int64, int __fd, void const *__write_buf, long write_len) + +// Read directory entries from a directory handle. +// See `dirent_t` for the format. +// Returns -errno on error, read count on success. +_SYSCALL_DEF(17, _SYSCALL_FS_GETDENTS, __syscall_fs_getdents, __mlibc_ptrdiff, int __fd, void *__read_buf, __mlibc_size __read_len) + +// Rename and/or move a file to another path, optionally relative to one or two directories. +// Returns -errno on error, 0 on success. +_SYSCALL_DEF(18, _SYSCALL_FS_RENAME, __syscall_fs_rename, int, int __old_at, char const *__old_path, int __new_at, char const *__new_path, __mlibc_uint32 __flags) + +// Get file status given file handler or path, optionally following the final symlink. +// If `path` is specified, it is interpreted as relative to the working directory. +// If both `path` and `fd` are specified, `path` is relative to the directory that `fd` describes. +// If only `fd` is specified, the inode referenced by `fd` is stat'ed. +// If `follow_link` is false, the last symlink in the path is not followed. +_SYSCALL_DEF(19, _SYSCALL_FS_STAT, __syscall_fs_stat, int, int __fd, char const *__path, bool __follow_link, struct stat *__stat_out) + +// Create a new directory. +// Returns -errno on error, 0 on success. +_SYSCALL_DEF(20, _SYSCALL_FS_MKDIR, __syscall_fs_mkdir, int, int __at, char const *__path) + +// Delete a directory if it is empty. +// Returns -errno on error, 0 on success. +_SYSCALL_DEF(21, _SYSCALL_FS_RMDIR, __syscall_fs_rmdir, int, int __at, char const *__path) + +// Create a new link to an existing inode. +// Returns -errno on error, 0 on success. +_SYSCALL_DEF(22, _SYSCALL_FS_LINK, __syscall_fs_link, int, int __old_at, char const *__old_path, int __new_at, char const *__new_path, __mlibc_uint32 __flags) + +// Remove a link to an inode. If it is the last link, the file is deleted. +// Returns -errno on error, 0 on success. +_SYSCALL_DEF(23, _SYSCALL_FS_UNLINK, __syscall_fs_unlink, int, int __at, char const *__path) + +// Create a new FIFO / named pipe. +// Returns -errno on error, 0 on success. +_SYSCALL_DEF(24, _SYSCALL_FS_MKFIFO, __syscall_fs_mkfifo, int, int __at, char const *__path) + +// Create a new pipe. +// `fds[0]` will be written with the pointer to the read end, `fds[1]` the write end. +// Returns -errno on error, 0 on success. +_SYSCALL_DEF(25, _SYSCALL_FS_PIPE, __syscall_fs_pipe, int, int __fds[2], int __flags) + +_SYSCALL_DEF(26, _SYSCALL_FS_SEEK, __syscall_fs_seek, __mlibc_int64, int fd, __mlibc_int64 offset, int __whence) + +// Map a new range of memory at an arbitrary virtual address. +// This may round up to a multiple of the page size. +// Alignment may be less than `align` if the kernel doesn't support it. +_SYSCALL_DEF(27, _SYSCALL_MEM_MAP, __syscall_mem_map, void *, void *__address, __mlibc_size __size, int __prot, int __flags) + +// Unmap a range of memory previously allocated with `SYSCALL_MEM_MAP`. +// Returns whether a range of memory was unmapped. +_SYSCALL_DEF_V(28, _SYSCALL_MEM_UNMAP, __syscall_mem_unmap, void *__address, __mlibc_size __size) + +// Change the protection flags on a range of memory. +// May fail if the process does not have write access to mapped objects. +_SYSCALL_DEF(29, _SYSCALL_MEM_PROTECT, __syscall_mem_protect, int, void *__address, __mlibc_size size, int __prot) + +_SYSCALL_DEF_V(30, _SYSCALL_TEMP_WRITE, __syscall_temp_write, char const *__message, __mlibc_size __len) + +// Start the shutdown process. +_SYSCALL_DEF_V(31, _SYSCALL_SYS_SHUTDOWN, __syscall_sys_shutdown, bool __is_reboot) + +// Get the value of some clock. +_SYSCALL_DEF(32, _SYSCALL_TIME_GETTIME, __syscall_time_gettime, int, int __clkid, struct timespec *__time) + +// Send a signal to a thread in this process. +_SYSCALL_DEF(33, _SYSCALL_THREAD_KILL, __syscall_thread_kill, int, long __thread_id, int __signum) + +// Send a signal to an arbitrary thread in a specified process. See man kill(2). +_SYSCALL_DEF(34, _SYSCALL_PROC_KILL, __syscall_proc_kill, int, __mlibc_int64 __pid, int __signum) + +// Get an ID as specified by _GETID_* macros. +_SYSCALL_DEF(35, _SYSCALL_PROC_GETID, __syscall_proc_getid, int, int __getid_type) + +// Create a new directory. +// Returns -errno on error, 0 on success. +_SYSCALL_DEF(36, _SYSCALL_FS_SYMLINK, __syscall_fs_symlink, int, char const *__link_target, int __at, char const *__path) + +// Duplicate a file descriptor. +// If `__newfd` is `-1`, an arbitrary descriptor number is selected. +_SYSCALL_DEF(37, _SYSCALL_FS_DUP, __syscall_fs_dup, int, int __fd, int __flags, int __newfd) + +// Modify the signal mask for this thread. +_SYSCALL_DEF(38, _SYSCALL_THREAD_SIGMASK, __syscall_thread_sigmask, int, int __how, sigset_t const *__set, sigset_t *__oldset) + +// Get system information. +_SYSCALL_DEF(39, _SYSCALL_SYS_UNAME, __syscall_sys_uname, int, struct utsname *__name) + +// Succeed if `__fd` is a TTY, fail otherwise. +_SYSCALL_DEF(40, _SYSCALL_FS_ISATTY, __syscall_fs_isatty, int, int __fd) + +// Get TTY attributes. +_SYSCALL_DEF(41, _SYSCALL_FS_TCGETATTR, __syscall_fs_tcgetattr, int, int __fd, struct termios *__attr) + +// Set TTY attributes. +_SYSCALL_DEF(42, _SYSCALL_FS_TCSETATTR, __syscall_fs_tcsetattr, int, int __fd, struct termios const *__attr) + +// Get the absolute path path of the current working directory. +// May be outdated if the directory was moved. +_SYSCALL_DEF(43, _SYSCALL_FS_GETCWD, __syscall_fs_getcwd, int, void *__buf, __mlibc_size __buflen) + +// Change the working directory. +// Since setting both `at` and `path` is non-standard, it is currently unsupported. +_SYSCALL_DEF(44, _SYSCALL_FS_CHDIR, __syscall_fs_chdir, int, int __at, char const *__path) + +// Get file descriptor flags. +_SYSCALL_DEF(45, _SYSCALL_FS_GETFD, __syscall_fs_getfd, int, int __fd) + +// Set file descriptor flags. +_SYSCALL_DEF(46, _SYSCALL_FS_SETFD, __syscall_fs_setfd, int, int __fd, int __flags) + +// Get file status flags. +_SYSCALL_DEF(47, _SYSCALL_FS_GETFL, __syscall_fs_getfl, int, int __fd) + +// Set file status flags. +_SYSCALL_DEF(48, _SYSCALL_FS_SETFL, __syscall_fs_setfl, int, int __fd, int __flags) + + + +#undef _SYSCALL_DEF +#undef _SYSCALL_DEF_V diff --git a/abis/badgeros/useconds_t.h b/abis/badgeros/useconds_t.h new file mode 100644 index 0000000000..beaa015b22 --- /dev/null +++ b/abis/badgeros/useconds_t.h @@ -0,0 +1,8 @@ +#ifndef _ABIBITS_SUSECONDS_T_H +#define _ABIBITS_SUSECONDS_T_H + +#include + +typedef __mlibc_uint64 useconds_t; + +#endif /* _ABIBITS_SUSECONDS_T_H */ diff --git a/abis/badgeros/wait.h b/abis/badgeros/wait.h new file mode 100644 index 0000000000..4db083ae22 --- /dev/null +++ b/abis/badgeros/wait.h @@ -0,0 +1,42 @@ +#ifndef _ABIBITS_WAIT_H +#define _ABIBITS_WAIT_H + +#include + +#define WNOHANG 1 +#define WUNTRACED 2 +#define WSTOPPED 2 +#define WEXITED 4 +#define WCONTINUED 8 +#define WNOWAIT 0x01000000 + +#define __WCOREFLAG 0x80 + +#define WEXITSTATUS(x) (((x) & 0xff00) >> 8) +#define WTERMSIG(x) (((x) & 0xff0000) >> 16) +#define WSTOPSIG(x) (((x) & 0xff0000) >> 16) + +/* Whether the child exited normally (by means of `SYSCALL_PROC_EXIT`). */ +#define WIFEXITED(x) (((x) & 0xff) == 0) +/* Whether the child was killed by a signal. */ +#define WIFSIGNALED(x) ((x) & 0x40) +/* Whether the child was suspended by a signal. */ +#define WIFSTOPPED(x) ((x) & 0x20) +/* Whether the child was resumed by `SIGCONT`. */ +#define WIFCONTINUED(x) ((x) & 0x10) + +#if defined(_DEFAULT_SOURCE) +#define WCOREFLAG __WCOREFLAG +#endif + +#if defined(_DEFAULT_SOURCE) || __MLIBC_POSIX2024 +/* Whether the child dumped core. */ +#define WCOREDUMP(x) ((x) & __WCOREFLAG) +#endif /* defined(_DEFAULT_SOURCE) || __MLIBC_POSIX2024 */ + +/* glibc extension, but also useful for kernels */ +#if defined(_DEFAULT_SOURCE) +#define W_EXITCODE(ret, sig) (((ret) << 8) | ((sig) << 16)) +#endif /* defined(_DEFAULT_SOURCE) */ + +#endif /*_ABIBITS_WAIT_H */ diff --git a/meson.build b/meson.build index f0cce792bd..b594e008af 100644 --- a/meson.build +++ b/meson.build @@ -286,6 +286,10 @@ elif host_machine.system() == 'menix' internal_conf.set10('MLIBC_MMAP_ALLOCATE_DSO', true) internal_conf.set10('MLIBC_MAP_FILE_WINDOWS', true) subdir('sysdeps/menix') +elif host_machine.system() == 'badgeros' + rtld_include_dirs += include_directories('sysdeps/badgeros/include') + libc_include_dirs += include_directories('sysdeps/badgeros/include') + subdir('sysdeps/badgeros') # ANCHOR: demo-sysdeps elif host_machine.system() == 'demo' subdir('sysdeps/demo') diff --git a/options/bsd/generic/sys-statvfs.cpp b/options/bsd/generic/sys-statvfs.cpp new file mode 100644 index 0000000000..a0d5d157df --- /dev/null +++ b/options/bsd/generic/sys-statvfs.cpp @@ -0,0 +1,43 @@ +/* +Copyright © 2026, __robot@PLT +SPDX-Licence-Identifier: MIT OR CC0 +*/ + +#include +#include +#include +#include +#include + +// Known bug from NetBSD implementation: A concurrency-safe implementation would allocate on each +// call so the application may call `free`. However, to implement NetBSD semantics, the allocation +// is stored here. +static struct statvfs *mounts_buffer = nullptr; + +int getmntinfo(struct statvfs **mntbufp, int mode) { + auto sysdep = MLIBC_CHECK_OR_ENOSYS(mlibc::sys_getvfsstat, -1); + + // Check how much capacity is needed. + int cap = 0; + sysdep(nullptr, 0, mode, &cap); + + int actual = cap; + do { + cap = actual; + free(mounts_buffer); + mounts_buffer = (struct statvfs *)calloc(cap, sizeof(struct statvfs)); + + if (int e = sysdep(mounts_buffer, cap, mode, &actual); e) { + mounts_buffer = nullptr; + errno = e; + return -1; + } + + // Retry in a loop on the off chance a new FS just mounted, + // though we can only care so much about concurrency due to NetBSD bugs. + } while (cap < actual); + + *mntbufp = mounts_buffer; + + return actual; +} diff --git a/options/bsd/include/mlibc/bsd-sysdeps.hpp b/options/bsd/include/mlibc/bsd-sysdeps.hpp index 1ad202f8ed..73880881ad 100644 --- a/options/bsd/include/mlibc/bsd-sysdeps.hpp +++ b/options/bsd/include/mlibc/bsd-sysdeps.hpp @@ -1,6 +1,8 @@ #ifndef MLIBC_BSD_SYSDEPS #define MLIBC_BSD_SYSDEPS +#include +#include #include namespace [[gnu::visibility("hidden")]] mlibc { @@ -9,7 +11,10 @@ namespace [[gnu::visibility("hidden")]] mlibc { [[gnu::weak]] int sys_getloadavg(double *samples); -[[gnu::weak]] int sys_openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const struct winsize *win); +[[gnu::weak]] int +sys_openpty(int *mfd, int *sfd, char *name, const struct termios *ios, const struct winsize *win); + +[[gnu::weak]] int sys_getvfsstat(struct statvfs *buf, size_t bufsize, int flags, int *out_fs_count); } // namespace mlibc diff --git a/options/bsd/include/sys/mount.h b/options/bsd/include/sys/mount.h new file mode 100644 index 0000000000..b920ee1c5c --- /dev/null +++ b/options/bsd/include/sys/mount.h @@ -0,0 +1,12 @@ +/* +Copyright © 2026, __robot@PLT +SPDX-Licence-Identifier: MIT OR CC0 +*/ + +#ifndef _SYS_MOUNT_H +#define _SYS_MOUNT_H + +#define MNT_WAIT 1 +#define MNT_NOWAIT 2 + +#endif /* _SYS_MOUNT_H */ diff --git a/options/bsd/meson.build b/options/bsd/meson.build index f70e95aed2..d9d108fc85 100644 --- a/options/bsd/meson.build +++ b/options/bsd/meson.build @@ -8,6 +8,7 @@ libc_sources += files( 'generic/getopt.cpp', 'generic/bsd_stdlib.cpp', 'generic/pty.cpp', + 'generic/sys-statvfs.cpp', ) if not no_headers @@ -23,6 +24,7 @@ if not no_headers subdir: 'arpa' ) install_headers( + 'include/sys/mount.h', 'include/sys/queue.h', subdir: 'sys' ) diff --git a/options/posix/include/sys/statvfs.h b/options/posix/include/sys/statvfs.h index e2302ea7df..40094902c8 100644 --- a/options/posix/include/sys/statvfs.h +++ b/options/posix/include/sys/statvfs.h @@ -11,6 +11,12 @@ extern "C" { #ifndef __MLIBC_ABI_ONLY +#if __MLIBC_BSD_OPTION +/* This corresponds to the NetBSD version of getmntinfo. + FreeBSD and OpenBSD are known to have a different declaration (in a different header file). */ +int getmntinfo(struct statvfs **__mntbufp, int __mode); +#endif + int statvfs(const char *__restrict __pathname, struct statvfs *__restrict __buf); int fstatvfs(int __fd, struct statvfs *__buf); @@ -26,4 +32,3 @@ int fstatvfs64(int __fd, struct statvfs64 *__buf); #endif #endif /* _SYS_STATVFS_H */ - diff --git a/sysdeps/badgeros/generic/entry.cpp b/sysdeps/badgeros/generic/entry.cpp new file mode 100644 index 0000000000..679dc066a6 --- /dev/null +++ b/sysdeps/badgeros/generic/entry.cpp @@ -0,0 +1,15 @@ +#include +#include +#include + +extern "C" void __dlapi_enter(uintptr_t *); + +extern char **environ; + +extern "C" void +__mlibc_entry(uintptr_t *entry_stack, int (*main_fn)(int argc, char *argv[], char *env[])) { + __dlapi_enter(entry_stack); + + auto result = main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ); + exit(result); +} diff --git a/sysdeps/badgeros/generic/syscall.cpp b/sysdeps/badgeros/generic/syscall.cpp new file mode 100644 index 0000000000..09c83f0519 --- /dev/null +++ b/sysdeps/badgeros/generic/syscall.cpp @@ -0,0 +1,8 @@ + +extern "C" { +#ifdef __riscv +#define _SYSCALL_DEF(__num, __enum, __name, __returns, ...) \ + __attribute__((naked)) void __name() { asm volatile("li a7, %0; ecall; ret" ::"i"(__num)); } +#include +#endif +} diff --git a/sysdeps/badgeros/generic/sysdeps-posix.cpp b/sysdeps/badgeros/generic/sysdeps-posix.cpp new file mode 100644 index 0000000000..98b23cd40c --- /dev/null +++ b/sysdeps/badgeros/generic/sysdeps-posix.cpp @@ -0,0 +1,312 @@ +#include "mlibc/tcb.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ANCHOR: stub +#define STUB() \ + ({ \ + __ensure(!"STUB function was called"); \ + __builtin_unreachable(); \ + }) +// ANCHOR_END: stub + +namespace mlibc { + +void sys_libc_panic() { + sys_libc_log("!!! mlibc panic !!!"); + sys_exit(-1); + __builtin_trap(); +} + +void sys_libc_log(const char *msg) { + __syscall_fs_write(2, msg, strlen(msg)); + __syscall_fs_write(2, "\n", 1); +} + +int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags, struct stat *statbuf) { + if (fsfdt == fsfd_target::path) { + fd = AT_FDCWD; + } else if (fsfdt == fsfd_target::fd) { + path = nullptr; + } else { + __ensure(fsfdt == fsfd_target::fd_path); + } + // TODO: This syscall subject to change. + return -__syscall_fs_stat(fd, path, (flags & AT_SYMLINK_NOFOLLOW) == 0, statbuf); +} + +int sys_write(int fd, void const *buf, size_t size, ssize_t *ret) { + *ret = __syscall_fs_write(fd, buf, size); + return *ret >= 0 ? 0 : -*ret; +} + +int sys_tcb_set(void *pointer) { + uintptr_t thread_data = reinterpret_cast(pointer) + sizeof(Tcb); + asm volatile("mv tp, %0" ::"r"(thread_data)); + return 0; +} + +int sys_anon_allocate(size_t size, void **pointer) { + auto res = + __syscall_mem_map(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS); + *pointer = (void *)res; + ssize_t errno = reinterpret_cast(res); + return errno < 0 ? -errno : 0; +} + +int sys_anon_free(void *pointer, unsigned long size) { + __syscall_mem_unmap(pointer, size); + return 0; +} + +int sys_seek(int fd, off_t offset, int whence, off_t *ret) { + auto res = __syscall_fs_seek(fd, offset, whence); + *ret = res; + return res < 0 ? -res : 0; +} + +void sys_exit(int status) { + __syscall_proc_exit(status); + __builtin_unreachable(); +} + +int sys_close(int fd) { return -__syscall_fs_close(fd); } + +int sys_futex_wake(int *, bool) { STUB(); } + +int sys_futex_wait(int *, int, timespec const *) { STUB(); } + +int sys_open_dir(const char *path, int *ret) { + // TODO: Mode currently ignored. + auto res = __syscall_fs_open(AT_FDCWD, path, O_DIRECTORY); + *ret = res; + return res < 0 ? -res : 0; +} + +int sys_read_entries(int fd, void *buffer, size_t max_size, size_t *bytes_read) { + auto res = __syscall_fs_getdents(fd, buffer, max_size); + *bytes_read = res; + return res < 0 ? -res : 0; +} + +int sys_read(int fd, void *read_buf, unsigned long read_len, long *ret) { + auto res = __syscall_fs_read(fd, read_buf, read_len); + *ret = res; + return res < 0 ? -res : 0; +} + +int sys_open(const char *path, int oflags, unsigned int mode, int *ret) { + (void)mode; + // TODO: Mode currently ignored. + auto res = __syscall_fs_open(AT_FDCWD, path, oflags); + *ret = res; + return res < 0 ? -res : 0; +} + +int sys_vm_map(void *hint, size_t size, int prot, int flags, int, off_t, void **pointer) { + auto res = __syscall_mem_map(hint, size, prot, flags); + *pointer = (void *)res; + ssize_t errno = reinterpret_cast(res); + return errno < 0 ? -errno : 0; +} + +int sys_vm_protect(void *pointer, size_t size, int prot) { + return -__syscall_mem_protect(pointer, size, prot); +} + +int sys_vm_unmap(void *address, size_t size) { + __syscall_mem_unmap(address, size); + return 0; +} + +int sys_clock_get(int clkid, time_t *secs, long *nanos) { + struct timespec ts; + auto res = __syscall_time_gettime(clkid, &ts); + *secs = ts.tv_sec; + *nanos = ts.tv_nsec; + return -res; +} + +int sys_fork(pid_t *child) { + pid_t res = __syscall_proc_fork(); + if (res < 0) { + return -res; + } else { + *child = res; + return 0; + } +} + +int sys_execve(const char *path, char *const argv[], char *const envp[]) { + return -__syscall_proc_exec(path, argv, envp); +} + +gid_t sys_getgid() { return __syscall_proc_getid(_GETID_GID); } +gid_t sys_getegid() { return __syscall_proc_getid(_GETID_EGID); } +uid_t sys_getuid() { return __syscall_proc_getid(_GETID_UID); } +uid_t sys_geteuid() { return __syscall_proc_getid(_GETID_EUID); } +pid_t sys_getpid() { return __syscall_proc_getid(_GETID_PID); } +pid_t sys_gettid() { return __syscall_proc_getid(_GETID_TID); } +pid_t sys_getppid() { return __syscall_proc_getid(_GETID_PPID); } +int sys_getpgid(pid_t pid, pid_t *pgid) { + *pgid = 1; + return 0; +} +int sys_getsid(pid_t pid, pid_t *sid) { + *sid = 1; + return 0; +} + +int sys_sigaction( + int signum, + const struct sigaction *__restrict newhandler, + struct sigaction *__restrict oldhandler +) { + if (newhandler) { + struct sigaction tmp = *newhandler; + tmp.sa_restorer = __syscall_proc_sigret; + return -__syscall_proc_sigaction(signum, &tmp, oldhandler); + } else { + return -__syscall_proc_sigaction(signum, nullptr, oldhandler); + } +} + +int sys_kill(pid_t pid, int signo) { return -__syscall_proc_kill(pid, signo); } + +int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid) { + if (ru) { + memset(ru, 0, sizeof(struct rusage)); + } + auto res = __syscall_proc_waitpid(pid, status, flags | WEXITED); + if (ret_pid) { + *ret_pid = res; + } + return res < 0 ? -res : 0; +} + +int sys_mkdir(const char *path, mode_t mode) { + (void)mode; + // TODO: Mode currently ignored. + return -__syscall_fs_mkdir(AT_FDCWD, path); +} + +int sys_mkdirat(int dirfd, const char *path, mode_t mode) { + (void)mode; + // TODO: Mode currently ignored. + return -__syscall_fs_mkdir(dirfd, path); +} + +int sys_link(const char *old_path, const char *new_path) { + return -__syscall_fs_link(AT_FDCWD, old_path, AT_FDCWD, new_path, 0); +} + +int sys_linkat(int olddirfd, const char *old_path, int newdirfd, const char *new_path, int flags) { + return -__syscall_fs_link(olddirfd, old_path, newdirfd, new_path, flags); +} + +int sys_symlink(const char *target_path, const char *link_path) { + return -__syscall_fs_symlink(target_path, AT_FDCWD, link_path); +} + +int sys_symlinkat(const char *target_path, int dirfd, const char *link_path) { + return -__syscall_fs_symlink(target_path, dirfd, link_path); +} + +int sys_rename(const char *old_path, const char *new_path) { + return -__syscall_fs_rename(AT_FDCWD, old_path, AT_FDCWD, new_path, 0); +} + +int sys_renameat(int olddirfd, const char *old_path, int newdirfd, const char *new_path) { + return -__syscall_fs_rename(olddirfd, old_path, newdirfd, new_path, 0); +} + +int sys_unlinkat(int fd, const char *path, int flags) { + if (flags & AT_REMOVEDIR) { + return -__syscall_fs_rmdir(fd, path); + } else { + return -__syscall_fs_unlink(fd, path); + } +} + +int sys_rmdir(const char *path) { return -__syscall_fs_rmdir(AT_FDCWD, path); } + +int sys_dup(int fd, int flags, int *newfd) { + auto res = __syscall_fs_dup(fd, flags, -1); + *newfd = res; + return res < 0 ? -res : 0; +} + +int sys_dup2(int fd, int flags, int newfd) { + auto res = __syscall_fs_dup(fd, flags, newfd); + return res < 0 ? -res : 0; +} + +int sys_sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict retrieve) { + return -__syscall_thread_sigmask(how, set, retrieve); +} + +int sys_thread_sigmask(int how, const sigset_t *__restrict set, sigset_t *__restrict retrieve) { + return -__syscall_thread_sigmask(how, set, retrieve); +} + +int sys_uname(struct utsname *buf) { return -__syscall_sys_uname(buf); } + +int sys_isatty(int fd) { return -__syscall_fs_isatty(fd); } + +int sys_tcgetattr(int fd, struct termios *attr) { return -__syscall_fs_tcgetattr(fd, attr); } + +int sys_tcsetattr(int fd, int act, const struct termios *attr) { + (void)act; + return -__syscall_fs_tcsetattr(fd, attr); +} + +int sys_getcwd(char *buffer, size_t size) { return -__syscall_fs_getcwd(buffer, size); } + +int sys_chdir(const char *path) { return -__syscall_fs_chdir(-1, path); } + +int sys_fchdir(int fd) { return -__syscall_fs_chdir(fd, nullptr); } + +int sys_fcntl(int fd, int request, va_list args, int *result) { + switch (request) { + case F_DUPFD: { + int minfd = va_arg(args, int); + auto res = __syscall_fs_dup(fd, DUP2_FCNTL, minfd); + *result = res; + return res < 0 ? -res : 0; + } + case F_DUPFD_CLOEXEC: { + int minfd = va_arg(args, int); + auto res = __syscall_fs_dup(fd, DUP2_FCNTL | O_CLOEXEC, minfd); + *result = res; + return res < 0 ? -res : 0; + } + case F_GETFD: { + auto res = __syscall_fs_getfd(fd); + *result = res; + return res < 0 ? -res : 0; + } + case F_SETFD: { + return -__syscall_fs_setfd(fd, va_arg(args, int)); + } + case F_GETFL: { + auto res = __syscall_fs_getfl(fd); + *result = res; + return res < 0 ? -res : 0; + } + case F_SETFL: { + return -__syscall_fs_setfl(fd, va_arg(args, int)); + } + default: + return EINVAL; + } +} + +} // namespace mlibc diff --git a/sysdeps/badgeros/include/abi-bits/access.h b/sysdeps/badgeros/include/abi-bits/access.h new file mode 120000 index 0000000000..cb83931670 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/access.h @@ -0,0 +1 @@ +../../../../abis/linux/access.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/auxv.h b/sysdeps/badgeros/include/abi-bits/auxv.h new file mode 120000 index 0000000000..c43f878641 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/auxv.h @@ -0,0 +1 @@ +../../../../abis/linux/auxv.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/blkcnt_t.h b/sysdeps/badgeros/include/abi-bits/blkcnt_t.h new file mode 120000 index 0000000000..ca20484c5c --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/blkcnt_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/blkcnt_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/blksize_t.h b/sysdeps/badgeros/include/abi-bits/blksize_t.h new file mode 120000 index 0000000000..da4525b042 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/blksize_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/blksize_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/clockid_t.h b/sysdeps/badgeros/include/abi-bits/clockid_t.h new file mode 120000 index 0000000000..a7932e4d33 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/clockid_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/clockid_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/dev_t.h b/sysdeps/badgeros/include/abi-bits/dev_t.h new file mode 120000 index 0000000000..fb5c77aeb5 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/dev_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/dev_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/epoll.h b/sysdeps/badgeros/include/abi-bits/epoll.h new file mode 120000 index 0000000000..eb4b76dcfc --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/epoll.h @@ -0,0 +1 @@ +../../../../abis/linux/epoll.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/errno.h b/sysdeps/badgeros/include/abi-bits/errno.h new file mode 120000 index 0000000000..6e507deff2 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/errno.h @@ -0,0 +1 @@ +../../../../abis/linux/errno.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/fcntl.h b/sysdeps/badgeros/include/abi-bits/fcntl.h new file mode 120000 index 0000000000..e1fae90efc --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/fcntl.h @@ -0,0 +1 @@ +../../../../abis/badgeros/fcntl.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/fd_set.h b/sysdeps/badgeros/include/abi-bits/fd_set.h new file mode 120000 index 0000000000..92551ee78e --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/fd_set.h @@ -0,0 +1 @@ +../../../../abis/badgeros/fd_set.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/fsblkcnt_t.h b/sysdeps/badgeros/include/abi-bits/fsblkcnt_t.h new file mode 120000 index 0000000000..4327b0f7f9 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/fsblkcnt_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/fsblkcnt_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/fsfilcnt_t.h b/sysdeps/badgeros/include/abi-bits/fsfilcnt_t.h new file mode 120000 index 0000000000..4b48a5aa75 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/fsfilcnt_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/fsfilcnt_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/getid.h b/sysdeps/badgeros/include/abi-bits/getid.h new file mode 120000 index 0000000000..c033524f91 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/getid.h @@ -0,0 +1 @@ +../../../../abis/badgeros/getid.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/gid_t.h b/sysdeps/badgeros/include/abi-bits/gid_t.h new file mode 120000 index 0000000000..abce6d69ad --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/gid_t.h @@ -0,0 +1 @@ +../../../../abis/linux/gid_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/in.h b/sysdeps/badgeros/include/abi-bits/in.h new file mode 120000 index 0000000000..418d1d5c04 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/in.h @@ -0,0 +1 @@ +../../../../abis/linux/in.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/ino_t.h b/sysdeps/badgeros/include/abi-bits/ino_t.h new file mode 120000 index 0000000000..4c20aca26a --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/ino_t.h @@ -0,0 +1 @@ +../../../../abis/linux/ino_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/inotify.h b/sysdeps/badgeros/include/abi-bits/inotify.h new file mode 120000 index 0000000000..b5cb28237a --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/inotify.h @@ -0,0 +1 @@ +../../../../abis/linux/inotify.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/ioctls.h b/sysdeps/badgeros/include/abi-bits/ioctls.h new file mode 120000 index 0000000000..595106b6fd --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/ioctls.h @@ -0,0 +1 @@ +../../../../abis/linux/ioctls.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/ipc.h b/sysdeps/badgeros/include/abi-bits/ipc.h new file mode 120000 index 0000000000..2c7ffc4c92 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/ipc.h @@ -0,0 +1 @@ +../../../../abis/linux/ipc.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/limits.h b/sysdeps/badgeros/include/abi-bits/limits.h new file mode 120000 index 0000000000..6c88db2ed6 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/limits.h @@ -0,0 +1 @@ +../../../../abis/linux/limits.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/mode_t.h b/sysdeps/badgeros/include/abi-bits/mode_t.h new file mode 120000 index 0000000000..5d78fdfc3b --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/mode_t.h @@ -0,0 +1 @@ +../../../../abis/linux/mode_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/mqueue.h b/sysdeps/badgeros/include/abi-bits/mqueue.h new file mode 120000 index 0000000000..fa87b078ad --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/mqueue.h @@ -0,0 +1 @@ +../../../../abis/linux/mqueue.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/msg.h b/sysdeps/badgeros/include/abi-bits/msg.h new file mode 120000 index 0000000000..f402b49306 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/msg.h @@ -0,0 +1 @@ +../../../../abis/linux/msg.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/nlink_t.h b/sysdeps/badgeros/include/abi-bits/nlink_t.h new file mode 120000 index 0000000000..6230ac736f --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/nlink_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/nlink_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/packet.h b/sysdeps/badgeros/include/abi-bits/packet.h new file mode 120000 index 0000000000..998ef1ab03 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/packet.h @@ -0,0 +1 @@ +../../../../abis/linux/packet.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/pid_t.h b/sysdeps/badgeros/include/abi-bits/pid_t.h new file mode 120000 index 0000000000..dae245cdf9 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/pid_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/pid_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/poll.h b/sysdeps/badgeros/include/abi-bits/poll.h new file mode 120000 index 0000000000..8ea6a0a39c --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/poll.h @@ -0,0 +1 @@ +../../../../abis/linux/poll.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/ptrace.h b/sysdeps/badgeros/include/abi-bits/ptrace.h new file mode 120000 index 0000000000..b2517b2cf1 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/ptrace.h @@ -0,0 +1 @@ +../../../../abis/linux/ptrace.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/random.h b/sysdeps/badgeros/include/abi-bits/random.h new file mode 120000 index 0000000000..83fc3d9618 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/random.h @@ -0,0 +1 @@ +../../../../abis/linux/random.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/reboot.h b/sysdeps/badgeros/include/abi-bits/reboot.h new file mode 120000 index 0000000000..77013a4162 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/reboot.h @@ -0,0 +1 @@ +../../../../abis/linux/reboot.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/resource.h b/sysdeps/badgeros/include/abi-bits/resource.h new file mode 120000 index 0000000000..88d74025fa --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/resource.h @@ -0,0 +1 @@ +../../../../abis/linux/resource.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/riscv-hwprobe.h b/sysdeps/badgeros/include/abi-bits/riscv-hwprobe.h new file mode 120000 index 0000000000..e65132501b --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/riscv-hwprobe.h @@ -0,0 +1 @@ +../../../../abis/linux/riscv-hwprobe.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/rlim_t.h b/sysdeps/badgeros/include/abi-bits/rlim_t.h new file mode 120000 index 0000000000..e92eb5fb87 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/rlim_t.h @@ -0,0 +1 @@ +../../../../abis/linux/rlim_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/route.h b/sysdeps/badgeros/include/abi-bits/route.h new file mode 120000 index 0000000000..313ead67b7 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/route.h @@ -0,0 +1 @@ +../../../../abis/linux/route.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/sa_family_t.h b/sysdeps/badgeros/include/abi-bits/sa_family_t.h new file mode 120000 index 0000000000..a75e229670 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/sa_family_t.h @@ -0,0 +1 @@ +../../../../abis/linux/sa_family_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/seek-whence.h b/sysdeps/badgeros/include/abi-bits/seek-whence.h new file mode 120000 index 0000000000..df7bccf02c --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/seek-whence.h @@ -0,0 +1 @@ +../../../../abis/linux/seek-whence.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/sem.h b/sysdeps/badgeros/include/abi-bits/sem.h new file mode 120000 index 0000000000..699d7afa50 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/sem.h @@ -0,0 +1 @@ +../../../../abis/linux/sem.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/shm.h b/sysdeps/badgeros/include/abi-bits/shm.h new file mode 120000 index 0000000000..067d8c4fa5 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/shm.h @@ -0,0 +1 @@ +../../../../abis/linux/shm.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/sig-limits.h b/sysdeps/badgeros/include/abi-bits/sig-limits.h new file mode 120000 index 0000000000..f829738ed9 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/sig-limits.h @@ -0,0 +1 @@ +../../../../abis/linux/sig-limits.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/sigevent.h b/sysdeps/badgeros/include/abi-bits/sigevent.h new file mode 120000 index 0000000000..83d069b5b3 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/sigevent.h @@ -0,0 +1 @@ +../../../../abis/linux/sigevent.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/signal.h b/sysdeps/badgeros/include/abi-bits/signal.h new file mode 120000 index 0000000000..4dcb0b7ce5 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/signal.h @@ -0,0 +1 @@ +../../../../abis/linux/signal.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/sigset_t.h b/sysdeps/badgeros/include/abi-bits/sigset_t.h new file mode 120000 index 0000000000..ce6aa216b8 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/sigset_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/sigset_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/sigval.h b/sysdeps/badgeros/include/abi-bits/sigval.h new file mode 120000 index 0000000000..ccd43a550b --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/sigval.h @@ -0,0 +1 @@ +../../../../abis/linux/sigval.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/sockaddr_storage.h b/sysdeps/badgeros/include/abi-bits/sockaddr_storage.h new file mode 120000 index 0000000000..b3748654f0 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/sockaddr_storage.h @@ -0,0 +1 @@ +../../../../abis/linux/sockaddr_storage.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/socket.h b/sysdeps/badgeros/include/abi-bits/socket.h new file mode 120000 index 0000000000..f1dc016e6d --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/socket.h @@ -0,0 +1 @@ +../../../../abis/linux/socket.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/socklen_t.h b/sysdeps/badgeros/include/abi-bits/socklen_t.h new file mode 120000 index 0000000000..41f3b11f38 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/socklen_t.h @@ -0,0 +1 @@ +../../../../abis/linux/socklen_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/stat.h b/sysdeps/badgeros/include/abi-bits/stat.h new file mode 120000 index 0000000000..077080807c --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/stat.h @@ -0,0 +1 @@ +../../../../abis/badgeros/stat.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/statfs.h b/sysdeps/badgeros/include/abi-bits/statfs.h new file mode 120000 index 0000000000..e3d202f538 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/statfs.h @@ -0,0 +1 @@ +../../../../abis/linux/statfs.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/statvfs.h b/sysdeps/badgeros/include/abi-bits/statvfs.h new file mode 120000 index 0000000000..a78e03f648 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/statvfs.h @@ -0,0 +1 @@ +../../../../abis/badgeros/statvfs.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/statx.h b/sysdeps/badgeros/include/abi-bits/statx.h new file mode 120000 index 0000000000..8702a1d000 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/statx.h @@ -0,0 +1 @@ +../../../../abis/linux/statx.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/suseconds_t.h b/sysdeps/badgeros/include/abi-bits/suseconds_t.h new file mode 120000 index 0000000000..8a7eabc900 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/suseconds_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/suseconds_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/syscall_defs.inc b/sysdeps/badgeros/include/abi-bits/syscall_defs.inc new file mode 120000 index 0000000000..85ef313996 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/syscall_defs.inc @@ -0,0 +1 @@ +../../../../abis/badgeros/syscall_defs.inc \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/termios.h b/sysdeps/badgeros/include/abi-bits/termios.h new file mode 120000 index 0000000000..ee8f0b091a --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/termios.h @@ -0,0 +1 @@ +../../../../abis/linux/termios.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/time.h b/sysdeps/badgeros/include/abi-bits/time.h new file mode 120000 index 0000000000..2a02625743 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/time.h @@ -0,0 +1 @@ +../../../../abis/linux/time.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/uid_t.h b/sysdeps/badgeros/include/abi-bits/uid_t.h new file mode 120000 index 0000000000..b306777852 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/uid_t.h @@ -0,0 +1 @@ +../../../../abis/linux/uid_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/useconds_t.h b/sysdeps/badgeros/include/abi-bits/useconds_t.h new file mode 120000 index 0000000000..bb27dea6c4 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/useconds_t.h @@ -0,0 +1 @@ +../../../../abis/badgeros/useconds_t.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/utmp-defines.h b/sysdeps/badgeros/include/abi-bits/utmp-defines.h new file mode 120000 index 0000000000..861764359e --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/utmp-defines.h @@ -0,0 +1 @@ +../../../../abis/linux/utmp-defines.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/utmpx.h b/sysdeps/badgeros/include/abi-bits/utmpx.h new file mode 120000 index 0000000000..c6a26774fc --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/utmpx.h @@ -0,0 +1 @@ +../../../../abis/linux/utmpx.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/utsname.h b/sysdeps/badgeros/include/abi-bits/utsname.h new file mode 120000 index 0000000000..b28575474a --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/utsname.h @@ -0,0 +1 @@ +../../../../abis/linux/utsname.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/vm-flags.h b/sysdeps/badgeros/include/abi-bits/vm-flags.h new file mode 120000 index 0000000000..bbe258cff1 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/vm-flags.h @@ -0,0 +1 @@ +../../../../abis/linux/vm-flags.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/vt.h b/sysdeps/badgeros/include/abi-bits/vt.h new file mode 120000 index 0000000000..5798a4ac96 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/vt.h @@ -0,0 +1 @@ +../../../../abis/linux/vt.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/wait.h b/sysdeps/badgeros/include/abi-bits/wait.h new file mode 120000 index 0000000000..36dc359776 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/wait.h @@ -0,0 +1 @@ +../../../../abis/badgeros/wait.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/abi-bits/xattr.h b/sysdeps/badgeros/include/abi-bits/xattr.h new file mode 120000 index 0000000000..66412d7061 --- /dev/null +++ b/sysdeps/badgeros/include/abi-bits/xattr.h @@ -0,0 +1 @@ +../../../../abis/linux/xattr.h \ No newline at end of file diff --git a/sysdeps/badgeros/include/sys/syscall.h b/sysdeps/badgeros/include/sys/syscall.h new file mode 100644 index 0000000000..4b420717cf --- /dev/null +++ b/sysdeps/badgeros/include/sys/syscall.h @@ -0,0 +1,27 @@ + +// SPDX-License-Identifier: MIT + +#pragma once + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +// C enum. +typedef enum { +#define _SYSCALL_DEF(__num, __enum, __name, __returns, ...) __enum = __num, +#include +} __syscall_t; + +// C declarations. +#define _SYSCALL_DEF(__num, __enum, __name, __returns, ...) __returns __name(__VA_ARGS__); +#include + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/sysdeps/badgeros/include/sys/sysmacros.h b/sysdeps/badgeros/include/sys/sysmacros.h new file mode 100644 index 0000000000..0b3c114f74 --- /dev/null +++ b/sysdeps/badgeros/include/sys/sysmacros.h @@ -0,0 +1,18 @@ +#ifndef _SYS_SYSMACROS_H +#define _SYS_SYSMACROS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define major(__dev) ((__mlibc_uint32)(__dev)) +#define minor(__dev) ((__mlibc_uint32)((__dev) >> 32)) +#define makedev(__major, __minor) ((__mlibc_uint64)(__major) | ((__mlibc_uint64)(__minor) << 32)) + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS_SYSMACROS_H */ diff --git a/sysdeps/badgeros/meson.build b/sysdeps/badgeros/meson.build new file mode 100644 index 0000000000..b0c84ac834 --- /dev/null +++ b/sysdeps/badgeros/meson.build @@ -0,0 +1,126 @@ +sysdep_supported_options = { + 'posix': true, + 'glibc': true, + 'bsd': true, +} + +rtld_sources += files( + 'generic/sysdeps-posix.cpp', + 'generic/syscall.cpp', +) + +libc_sources += files( + 'generic/entry.cpp', + 'generic/sysdeps-posix.cpp', + 'generic/syscall.cpp', +) + +if not no_headers + install_headers( + 'include/abi-bits/gid_t.h', + 'include/abi-bits/auxv.h', + 'include/abi-bits/stat.h', + 'include/abi-bits/utsname.h', + 'include/abi-bits/statvfs.h', + 'include/abi-bits/wait.h', + 'include/abi-bits/in.h', + 'include/abi-bits/syscall_defs.inc', + 'include/abi-bits/fsfilcnt_t.h', + 'include/abi-bits/time.h', + 'include/abi-bits/signal.h', + 'include/abi-bits/termios.h', + 'include/abi-bits/seek-whence.h', + 'include/abi-bits/ipc.h', + 'include/abi-bits/vt.h', + 'include/abi-bits/limits.h', + 'include/abi-bits/resource.h', + 'include/abi-bits/socket.h', + 'include/abi-bits/fsblkcnt_t.h', + 'include/abi-bits/statfs.h', + 'include/abi-bits/sockaddr_storage.h', + 'include/abi-bits/fd_set.h', + 'include/abi-bits/mqueue.h', + 'include/abi-bits/access.h', + 'include/abi-bits/errno.h', + 'include/abi-bits/shm.h', + 'include/abi-bits/sem.h', + 'include/abi-bits/ioctls.h', + 'include/abi-bits/utmpx.h', + 'include/abi-bits/statx.h', + 'include/abi-bits/ptrace.h', + 'include/abi-bits/poll.h', + 'include/abi-bits/blkcnt_t.h', + 'include/abi-bits/route.h', + 'include/abi-bits/socklen_t.h', + 'include/abi-bits/utmp-defines.h', + 'include/abi-bits/sig-limits.h', + 'include/abi-bits/msg.h', + 'include/abi-bits/nlink_t.h', + 'include/abi-bits/reboot.h', + 'include/abi-bits/sa_family_t.h', + 'include/abi-bits/uid_t.h', + 'include/abi-bits/epoll.h', + 'include/abi-bits/xattr.h', + 'include/abi-bits/suseconds_t.h', + 'include/abi-bits/riscv-hwprobe.h', + 'include/abi-bits/packet.h', + 'include/abi-bits/ino_t.h', + 'include/abi-bits/dev_t.h', + 'include/abi-bits/blksize_t.h', + 'include/abi-bits/useconds_t.h', + 'include/abi-bits/clockid_t.h', + 'include/abi-bits/random.h', + 'include/abi-bits/sigset_t.h', + 'include/abi-bits/mode_t.h', + 'include/abi-bits/pid_t.h', + 'include/abi-bits/rlim_t.h', + 'include/abi-bits/sigval.h', + 'include/abi-bits/sigevent.h', + 'include/abi-bits/vm-flags.h', + 'include/abi-bits/inotify.h', + 'include/abi-bits/fcntl.h', + subdir: 'abi-bits', + follow_symlinks: true + ) + install_headers( + 'include/sys/syscall.h', + 'include/sys/sysmacros.h', + subdir: 'sys', + follow_symlinks: true + ) +endif + +if not headers_only + crt = custom_target('Scrt0', + build_by_default: true, + command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], + input: 'riscv64/Scrt0.S', + output: 'Scrt0.o', + install: true, + install_dir: get_option('libdir') + ) + crt = custom_target('crt0', + build_by_default: true, + command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], + input: 'riscv64/crt0.S', + output: 'crt0.o', + install: true, + install_dir: get_option('libdir') + ) + crt = custom_target('crti', + build_by_default: true, + command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], + input: 'riscv64/crti.S', + output: 'crti.o', + install: true, + install_dir: get_option('libdir') + ) + crt = custom_target('crtn', + build_by_default: true, + command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'], + input: 'riscv64/crtn.S', + output: 'crtn.o', + install: true, + install_dir: get_option('libdir') + ) +endif diff --git a/sysdeps/badgeros/riscv64/Scrt0.S b/sysdeps/badgeros/riscv64/Scrt0.S new file mode 100644 index 0000000000..17cc3fd1a8 --- /dev/null +++ b/sysdeps/badgeros/riscv64/Scrt0.S @@ -0,0 +1,30 @@ +.weak __global_pointer$ +.hidden __global_pointer$ + +.section .text +.global _start +_start: + # Load gp. +.option push +.option norelax + lla gp, __global_pointer$ +.option pop + + mv a0, sp + la a1, main + call __mlibc_entry@plt + unimp + +# Load gp from .preinit_array since it may be used by the executable's .init_array. +# We still load it in _start to account for static binaries. This matches glibc's behavior. +load_gp: +.option push +.option norelax + lla gp, __global_pointer$ +.option pop + ret + +.section .preinit_array,"aw" + .dword load_gp + +.section .note.GNU-stack,"",%progbits diff --git a/sysdeps/badgeros/riscv64/crt0.S b/sysdeps/badgeros/riscv64/crt0.S new file mode 100644 index 0000000000..faaf407ee4 --- /dev/null +++ b/sysdeps/badgeros/riscv64/crt0.S @@ -0,0 +1,30 @@ +.weak __global_pointer$ +.hidden __global_pointer$ + +.section .text +.global _start +_start: + # Load gp. +.option push +.option norelax + lla gp, __global_pointer$ +.option pop + + mv a0, sp + la a1, main + call __mlibc_entry + unimp + +# Load gp from .preinit_array since it may be used by the executable's .init_array. +# We still load it in _start to account for static binaries. This matches glibc's behavior. +load_gp: +.option push +.option norelax + lla gp, __global_pointer$ +.option pop + ret + +.section .preinit_array,"aw" + .dword load_gp + +.section .note.GNU-stack,"",%progbits diff --git a/sysdeps/badgeros/riscv64/crti.S b/sysdeps/badgeros/riscv64/crti.S new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sysdeps/badgeros/riscv64/crtn.S b/sysdeps/badgeros/riscv64/crtn.S new file mode 100644 index 0000000000..e69de29bb2