BuildSystem: Move all userpace libraries under the userspace directory

As the number of libraries is increasing, root directory starts to
expand. This adds better organization for libraries
This commit is contained in:
2024-06-18 13:14:35 +03:00
parent 1b5a01a6c9
commit c69919738b
157 changed files with 46 additions and 30 deletions

View File

@@ -0,0 +1,48 @@
#ifndef _SYS_BANAN_OS_H
#define _SYS_BANAN_OS_H 1
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_size_t 1
#include <stddef.h>
#define TTY_CMD_SET 0x01
#define TTY_CMD_UNSET 0x02
#define TTY_FLAG_ENABLE_OUTPUT 1
#define TTY_FLAG_ENABLE_INPUT 2
#define POWEROFF_SHUTDOWN 0
#define POWEROFF_REBOOT 1
struct proc_meminfo_t
{
size_t page_size;
size_t virt_pages;
size_t phys_pages;
};
/*
fildes: refers to valid tty device
command: one of TTY_CMD_* definitions
flags: bitwise or of TTY_FLAG_* definitions
return value: 0 on success, -1 on failure and errno set to the error
*/
int tty_ctrl(int fildes, int command, int flags);
int poweroff(int command);
int load_keymap(const char* path);
// Create shared memory object and return its key or -1 on error
long smo_create(size_t size, int prot);
// Delete shared memory object such that it will be no longer accessible with smo_map(). Existing mappings are still valid
int smo_delete(long key);
// Map shared memory object defined by its key and return address or null on error. Mappings can be unmapped using munmap()
void* smo_map(long key);
__END_DECLS
#endif

View File

@@ -0,0 +1,14 @@
#ifndef _SYS_CDEFS_H
#define _SYS_CDEFS_H 1
#define __banan_libc 1
#ifdef __cplusplus
#define __BEGIN_DECLS extern "C" {
#define __END_DECLS }
#else
#define __BEGIN_DECLS
#define __END_DECLS
#endif
#endif

View File

@@ -0,0 +1,20 @@
#ifndef _FRAMEBUFFER_H
#define _FRAMEBUFFER_H 1
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <stdint.h>
#define BANAN_FB_BPP 32
struct framebuffer_info_t
{
uint32_t width;
uint32_t height;
};
__END_DECLS
#endif

View File

@@ -0,0 +1,37 @@
#ifndef _SYS_IPC_H
#define _SYS_IPC_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_ipc.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_uid_t
#define __need_gid_t
#define __need_mode_t
#define __need_key_t
#include <sys/types.h>
struct ipc_perm
{
uid_t uid; /* Owner's user ID. */
gid_t gid; /* Owner's group ID. */
uid_t cuid; /* Creator's user ID. */
gid_t cgid; /* Creator's group ID. */
mode_t mode; /* Read/write permission. */
};
#define IPC_CREAT 0x01
#define IPC_EXCL 0x02
#define IPC_NOWAIT 0x04
#define IPC_PRIVATE 0x08
#define IPC_RMID 0x10
#define IPC_SET 0x20
#define IPC_STAT 0x40
key_t ftok(const char* path, int id);
__END_DECLS
#endif

View File

@@ -0,0 +1,76 @@
#ifndef _SYS_MMAN_H
#define _SYS_MMAN_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_mman.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define PROT_EXEC 0x01
#define PROT_NONE 0x02
#define PROT_READ 0x04
#define PROT_WRITE 0x08
#define MAP_FIXED 0x01
#define MAP_PRIVATE 0x02
#define MAP_SHARED 0x04
#define MAP_ANONYMOUS 0x08
#define MS_ASYNC 0x01
#define MS_INVALIDATE 0x02
#define MS_SYNC 0x04
#define MCL_CURRENT 0x01
#define MCL_FUTURE 0x01
#define MAP_FAILED ((void*)0)
#define POSIX_MADV_DONTNEED 1
#define POSIX_MADV_NORMAL 2
#define POSIX_MADV_RANDOM 3
#define POSIX_MADV_SEQUENTIAL 4
#define POSIX_MADV_WILLNEED 5
#define POSIX_TYPED_MEM_ALLOCATE 0x01
#define POSIX_TYPED_MEM_ALLOCATE_CONTIG 0x02
#define POSIX_TYPED_MEM_MAP_ALLOCATABLE 0x04
#define __need_mode_t
#define __need_off_t
#define __need_size_t
#include <sys/types.h>
struct posix_typed_mem_info
{
size_t posix_tmi_length; /* Maximum length which may be allocated from a typed memory object. */
};
struct sys_mmap_t
{
void* addr;
size_t len;
int prot;
int flags;
int fildes;
off_t off;
};
int mlock(const void* addr, size_t len);
int mlockall(int flags);
void* mmap(void* addr, size_t len, int prot, int flags, int fildes, off_t off);
int mprotect(void* addr, size_t len, int prot);
int msync(void* addr, size_t len, int flags);
int munlock(const void* addr, size_t len);
int munlockall(void);
int munmap(void* addr, size_t len);
int posix_madvise(void* addr, size_t len, int advice);
int posix_mem_offset(const void* __restrict addr, size_t len, off_t* __restrict off, size_t* __restrict contig_len, int* __restrict fildes);
int posix_typed_mem_get_info(int fildes, struct posix_typed_mem_info* info);
int posix_typed_mem_open(const char* name, int oflag, int tflag);
int shm_open(const char* name, int oflag, mode_t mode);
int shm_unlink(const char* name);
__END_DECLS
#endif

View File

@@ -0,0 +1,42 @@
#ifndef _SYS_MSG_H
#define _SYS_MSG_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_msg.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_pid_t
#define __need_size_t
#define __need_ssize_t
#define __need_time_t
#include <sys/types.h>
#include <sys/ipc.h>
typedef unsigned int msgqnum_t;
typedef unsigned int msglen_t;
#define MSG_NOERROR 0
struct msqid_ds
{
struct ipc_perm msg_perm; /* Operation permission structure. */
msgqnum_t msg_qnum; /* Number of messages currently on queue. */
msglen_t msg_qbytes; /* Maximum number of bytes allowed on queue. */
pid_t msg_lspid; /* Process ID of last msgsnd(). */
pid_t msg_lrpid; /* Process ID of last msgrcv(). */
time_t msg_stime; /* Time of last msgsnd(). */
time_t msg_rtime; /* Time of last msgrcv(). */
time_t msg_ctime; /* Time of last change. */
};
int msgctl(int msqid, int cmd, struct msqid_ds* buf);
int msgget(key_t key, int msgflg);
ssize_t msgrcv(int msqid, void* msgp, size_t msgsz, long msgtyp, int msgflg);
int msgsnd(int msqid, const void* msgp, size_t msgsz, int msgflg);
__END_DECLS
#endif

View File

@@ -0,0 +1,56 @@
#ifndef _SYS_RESOURCE_H
#define _SYS_RESOURCE_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_resource.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_id_t
#include <sys/types.h>
#include <sys/time.h>
#define PRIO_PROCESS 0
#define PRIO_PGRP 1
#define PRIO_USER 2
typedef unsigned int rlim_t;
#define RLIM_INFINITY ((rlim_t)-1)
#define RLIM_SAVED_MAX RLIM_INFINITY
#define RLIM_SAVED_CUR RLIM_INFINITY
#define RUSAGE_SELF 0
#define RUSAGE_CHILDREN 1
struct rlimit
{
rlim_t rlim_cur; /* The current (soft) limit. */
rlim_t rlim_max; /* The hard limit. */
};
struct rusage
{
struct timeval ru_utime; /* User time used. */
struct timeval ru_stime; /* System time used. */
};
#define RLIMIT_CORE 0
#define RLIMIT_CPU 1
#define RLIMIT_DATA 2
#define RLIMIT_FSIZE 3
#define RLIMIT_NOFILE 4
#define RLIMIT_STACK 5
#define RLIMIT_AS 6
int getpriority(int which, id_t who);
int getrlimit(int resource, struct rlimit* rlp);
int getrusage(int who, struct rusage* r_usage);
int setpriority(int which, id_t who, int value);
int setrlimit(int resource, const struct rlimit* rlp);
__END_DECLS
#endif

View File

@@ -0,0 +1,66 @@
#ifndef _SYS_SELECT_H
#define _SYS_SELECT_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_select.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <bits/types/timeval.h>
#include <signal.h>
#include <time.h>
#define FD_SETSIZE 1024
typedef unsigned long __fd_mask;
#define __FD_MASK_SIZE (8 * sizeof(__fd_mask))
typedef struct {
__fd_mask __bits[FD_SETSIZE / __FD_MASK_SIZE];
} fd_set;
#define FD_CLR(fd, setp) \
do { \
__fd_mask off = (fd) / __FD_MASK_SIZE; \
__fd_mask bit = (fd) % __FD_MASK_SIZE; \
(setp)->__bits[off] &= ~((__fd_mask)1 << bit); \
} while (0)
#define FD_ISSET(fd, setp) \
({ \
__fd_mask off = (fd) / __FD_MASK_SIZE; \
__fd_mask bit = (fd) % __FD_MASK_SIZE; \
(setp)->__bits[off] & ((__fd_mask)1 << bit); \
})
#define FD_SET(fd, setp) \
do { \
__fd_mask off = (fd) / __FD_MASK_SIZE; \
__fd_mask bit = (fd) % __FD_MASK_SIZE; \
(setp)->__bits[off] |= ((__fd_mask)1 << bit); \
} while (0)
#define FD_ZERO(setp) \
do { \
for (int i = 0; i < FD_SETSIZE / __FD_MASK_SIZE; i++) \
(setp)->__bits[i] = (__fd_mask)0; \
} while (0)
struct sys_pselect_t
{
int nfds;
fd_set* readfds;
fd_set* writefds;
fd_set* errorfds;
const struct timespec* timeout;
const sigset_t* sigmask;
};
int pselect(int nfds, fd_set* __restrict readfds, fd_set* __restrict writefds, fd_set* __restrict errorfds, const struct timespec* __restrict timeout, const sigset_t* __restrict sigmask);
int select(int nfds, fd_set* __restrict readfds, fd_set* __restrict writefds, fd_set* __restrict errorfds, struct timeval* __restrict timeout);
__END_DECLS
#endif

View File

@@ -0,0 +1,54 @@
#ifndef _SYS_SEM_H
#define _SYS_SEM_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_sem.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_pid_t
#define __need_size_t
#define __need_time_t
#include <sys/types.h>
#include <sys/ipc.h>
#define SEM_UNDO 1
#define GETNCNT 0
#define GETPID 1
#define GETVAL 2
#define GETALL 3
#define GETZCNT 4
#define SETVAL 5
#define SETALL 6
struct semid_ds
{
struct ipc_perm sem_perm; /* Operation permission structure. */
unsigned short sem_nsems; /* Number of semaphores in set. */
time_t sem_otime; /* Last semop() time. */
time_t sem_ctime; /* Last time changed by semctl(). */
};
// FIXME: A semaphore shall be represented by an anonymous structure, which shall include the following members:
// unsigned short semval; /* Semaphore value. */
// pid_t sempid; /* Process ID of last operation. */
// unsigned short semncnt; /* Number of processes waiting for semval to become greater than current value. */
// unsigned short semzcnt; /* Number of processes waiting for semval to become 0. */
struct sembuf
{
unsigned short sem_num; /* Semaphore number. */
short sem_op; /* Semaphore operation. */
short sem_flg; /* Operation flags. */
};
int semctl(int, int, int, ...);
int semget(key_t, int, int);
int semop(int, struct sembuf *, size_t);
__END_DECLS
#endif

View File

@@ -0,0 +1,42 @@
#ifndef _SYS_SHM_H
#define _SYS_SHM_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_shm.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_pid_t
#define __need_size_t
#define __need_time_t
#include <sys/types.h>
#include <sys/ipc.h>
#define SHM_RDONLY 0x01
#define SHM_RDONLY 0x02
#define SHM_RDONLY 0x04
typedef unsigned int shmatt_t;
struct shmid_ds
{
struct ipc_perm shm_perm; /* Operation permission structure. */
size_t shm_segsz; /* Size of segment in bytes. */
pid_t shm_lpid; /* Process ID of last shared memory operation. */
pid_t shm_cpid; /* Process ID of creator. */
shmatt_t shm_nattch; /* Number of current attaches. */
time_t shm_atime; /* Time of last shmat(). */
time_t shm_dtime; /* Time of last shmdt(). */
time_t shm_ctime; /* Time of last change by shmctl().*/
};
void* shmat(int shmid, const void* shmaddr, int shmflg);
int shmctl(int shmid, int cmd, struct shmid_ds* buf);
int shmdt(const void* shmaddr);
int shmget(key_t key, size_t size, int shmflg);
__END_DECLS
#endif

View File

@@ -0,0 +1,160 @@
#ifndef _SYS_SOCKET_H
#define _SYS_SOCKET_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_size_t
#define __need_ssize_t
#include <sys/types.h>
#include <sys/uio.h>
#include <bits/types/sa_family_t.h>
typedef long socklen_t;
#if !defined(FILENAME_MAX)
#define FILENAME_MAX 256
#elif FILENAME_MAX != 256
#error "invalid FILENAME_MAX"
#endif
struct sockaddr
{
sa_family_t sa_family; /* Address family. */
char sa_data[]; /* Socket address (variable-length data). */
};
struct sockaddr_storage
{
sa_family_t ss_family;
char ss_storage[FILENAME_MAX];
};
struct msghdr
{
void* msg_name; /* Optional address. */
socklen_t msg_namelen; /* Size of address. */
struct iovec* msg_iov; /* Scatter/gather array. */
int msg_iovlen; /* Members in msg_iov. */
void* msg_control; /* Ancillary data; see below. */
socklen_t msg_controllen; /* Ancillary data buffer len. */
int msg_flags; /* Flags on received message. */
};
struct cmsghdr
{
socklen_t cmsg_len; /* Data byte count, including the cmsghdr. */
int cmsg_level; /* Originating protocol. */
int cmsg_type; /* Protocol-specific type. */
};
// FIXME
#if 0
#define SCM_RIGHTS
#define CMSG_DATA(cmsg)
#define CMSG_NXTHDR(mhdr, cmsg)
#define CMSG_FIRSTHDR(mhdr)
#endif
struct linger
{
int l_onoff; /* Indicates wheter linger option is enabled. */
int l_linger; /* Linger time, in seconds. */
};
#define SOCK_DGRAM 0
#define SOCK_RAW 1
#define SOCK_SEQPACKET 2
#define SOCK_STREAM 3
#define SOL_SOCKET 1
#define SO_ACCEPTCONN 0
#define SO_BROADCAST 1
#define SO_DEBUG 2
#define SO_DONTROUTE 3
#define SO_ERROR 4
#define SO_KEEPALIVE 5
#define SO_LINGER 6
#define SO_OOBINLINE 7
#define SO_RCVBUF 8
#define SO_RCVLOWAT 9
#define SO_RCVTIMEO 10
#define SO_REUSEADDR 11
#define SO_SNDBUF 12
#define SO_SNDLOWAT 13
#define SO_SNDTIMEO 14
#define SO_TYPE 15
#define SOMAXCONN 4096
#define MSG_CTRUNC 0x01
#define MSG_DONTROUTE 0x02
#define MSG_EOR 0x04
#define MSG_OOB 0x08
#define MSG_NOSIGNAL 0x10
#define MSG_PEEK 0x20
#define MSG_TRUNC 0x40
#define MSG_WAITALL 0x80
#define AF_UNSPEC 0
#define AF_INET 1
#define AF_INET6 2
#define AF_UNIX 3
#define PF_UNSPEC AF_UNSPEC
#define PF_INET AF_INET
#define PF_INET6 AF_INET6
#define PF_UNIX AF_UNIX
#define SHUT_RD 0x01
#define SHUT_WR 0x02
#define SHUT_RDWR (SHUT_RD | SHUT_WR)
struct sys_sendto_t
{
int socket;
const void* message;
size_t length;
int flags;
const struct sockaddr* dest_addr;
socklen_t dest_len;
};
struct sys_recvfrom_t
{
int socket;
void* buffer;
size_t length;
int flags;
struct sockaddr* address;
socklen_t* address_len;
};
int accept(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len);
int bind(int socket, const struct sockaddr* address, socklen_t address_len);
int connect(int socket, const struct sockaddr* address, socklen_t address_len);
int getpeername(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len);
int getsockname(int socket, struct sockaddr* __restrict address, socklen_t* __restrict address_len);
int getsockopt(int socket, int level, int option_name, void* __restrict option_value, socklen_t* __restrict option_len);
int listen(int socket, int backlog);
ssize_t recv(int socket, void* buffer, size_t length, int flags);
ssize_t recvfrom(int socket, void* __restrict buffer, size_t length, int flags, struct sockaddr* __restrict address, socklen_t* __restrict address_len);
ssize_t recvmsg(int socket, struct msghdr* message, int flags);
ssize_t send(int socket, const void* buffer, size_t length, int flags);
ssize_t sendmsg(int socket, const struct msghdr* message, int flags);
ssize_t sendto(int socket, const void* message, size_t length, int flags, const struct sockaddr* dest_addr, socklen_t dest_len);
int setsockopt(int socket, int level, int option_name, const void* option_value, socklen_t option_len);
int shutdown(int socket, int how);
int sockatmark(int s);
int socket(int domain, int type, int protocol);
int socketpair(int domain, int type, int protocol, int socket_vector[2]);
__END_DECLS
#endif

View File

@@ -0,0 +1,109 @@
#ifndef _SYS_STAT_H
#define _SYS_STAT_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_blkcnt_t
#define __need_blksize_t
#define __need_dev_t
#define __need_ino_t
#define __need_mode_t
#define __need_nlink_t
#define __need_uid_t
#define __need_gid_t
#define __need_off_t
#define __need_time_t
#include <sys/types.h>
#include <time.h>
struct stat
{
dev_t st_dev; /* Device ID of device containing file. */
ino_t st_ino; /* File serial number. */
mode_t st_mode; /* Mode of file (see below). */
nlink_t st_nlink; /* Number of hard links to the file. */
uid_t st_uid; /* User ID of file. */
gid_t st_gid; /* Group ID of file. */
dev_t st_rdev; /* Device ID (if file is character or block special). */
off_t st_size; /* For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. For a shared memory object, the length in bytes. For a typed memory object, the length in bytes. For other file types, the use of this field is unspecified. */
struct timespec st_atim; /* Last data access timestamp. */
struct timespec st_mtim; /* Last data modification timestamp. */
struct timespec st_ctim; /* Last file status change timestamp. */
blksize_t st_blksize; /* A file system-specific preferred I/O block size for this object. In some file system types, this may vary from file to file. */
blkcnt_t st_blocks; /* Number of blocks allocated for this object. */
};
#define st_atime st_atim.tv_sec
#define st_ctime st_ctim.tv_sec
#define st_mtime st_mtim.tv_sec
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
#define S_ISUID 04000
#define S_ISGID 02000
#define S_ISVTX 01000
#define S_IFIFO 0010000
#define S_IFCHR 0020000
#define S_IFDIR 0040000
#define S_IFBLK 0060000
#define S_IFREG 0100000
#define S_IFLNK 0120000
#define S_IFSOCK 0140000
#define S_IFMASK 0170000
#define S_IFMT S_IFMASK
#define S_ISBLK(mode) ((mode & S_IFMASK) == S_IFBLK)
#define S_ISCHR(mode) ((mode & S_IFMASK) == S_IFCHR)
#define S_ISDIR(mode) ((mode & S_IFMASK) == S_IFDIR)
#define S_ISFIFO(mode) ((mode & S_IFMASK) == S_IFIFO)
#define S_ISREG(mode) ((mode & S_IFMASK) == S_IFREG)
#define S_ISLNK(mode) ((mode & S_IFMASK) == S_IFLNK)
#define S_ISSOCK(mode) ((mode & S_IFMASK) == S_IFSOCK)
// FIXME
#if 0
#define S_TYPEISMQ(buf)
#define S_TYPEISSEM(buf)
#define S_TYPEISSHM(buf)
#define S_TYPEISTMO(buf)
#endif
#define UTIME_NOW 1000000001
#define UTIME_OMIT 1000000002
int chmod(const char* path, mode_t mode);
int fchmod(int fildes, mode_t mode);
int fchmodat(int fd, const char* path, mode_t mode, int flag);
int fstat(int fildes, struct stat* buf);
int fstatat(int fd, const char* __restrict path, struct stat* __restrict buf, int flag);
int futimens(int fd, const struct timespec times[2]);
int lstat(const char* __restrict path, struct stat* __restrict buf);
int mkdir(const char* path, mode_t mode);
int mkdirat(int fd, const char* path, mode_t mode);
int mkfifo(const char* path, mode_t mode);
int mkfifoat(int fd, const char* path, mode_t mode);
int mknod(const char* path, mode_t mode, dev_t dev);
int mknodat(int fd, const char* path, mode_t mode, dev_t dev);
int stat(const char* __restrict path, struct stat* __restrict buf);
mode_t umask(mode_t cmask);
int utimensat(int fd, const char* path, const struct timespec times[2], int flag);
__END_DECLS
#endif

View File

@@ -0,0 +1,37 @@
#ifndef _SYS_STATVFS_H
#define _SYS_STATVFS_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_statvfs.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_fsblkcnt_t
#define __need_fsfilcnt_t
#include <sys/types.h>
struct statvfs
{
unsigned long f_bsize; /* File system block size. */
unsigned long f_frsize; /* Fundamental file system block size. */
fsblkcnt_t f_blocks; /* Total number of blocks on file system in units of f_frsize. */
fsblkcnt_t f_bfree; /* Total number of free blocks. */
fsblkcnt_t f_bavail; /* Number of free blocks available to non-privileged process. */
fsfilcnt_t f_files; /* Total number of file serial numbers. */
fsfilcnt_t f_ffree; /* Total number of free file serial numbers. */
fsfilcnt_t f_favail; /* Number of file serial numbers available to non-privileged process. */
unsigned long f_fsid; /* File system ID. */
unsigned long f_flag; /* Bit mask of f_flag values. */
unsigned long f_namemax; /* Maximum filename length. */
};
#define ST_RDONLY 0x01
#define ST_NOSUID 0x02
int fstatvfs(int fildes, struct statvfs* buf);
int statvfs(const char* __restrict path, struct statvfs* __restrict buf);
__END_DECLS
#endif

View File

@@ -0,0 +1,95 @@
#ifndef _SYS_SYSCALL_H
#define _SYS_SYSCALL_H 1
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __SYSCALL_LIST(O) \
O(SYS_EXIT, exit) \
O(SYS_READ, read) \
O(SYS_WRITE, write) \
O(SYS_TERMID, termid) \
O(SYS_CLOSE, close) \
O(SYS_OPEN, open) \
O(SYS_OPENAT, openat) \
O(SYS_SEEK, seek) \
O(SYS_TELL, tell) \
O(SYS_GET_TERMIOS, gettermios) \
O(SYS_SET_TERMIOS, settermios) \
O(SYS_FORK, fork) \
O(SYS_EXEC, exec) \
O(SYS_SLEEP, sleep) \
O(SYS_WAIT, wait) \
O(SYS_FSTAT, fstat) \
O(SYS_READ_DIR, readdir) \
O(SYS_SET_UID, setuid) \
O(SYS_SET_GID, setgid) \
O(SYS_SET_EUID, seteuid) \
O(SYS_SET_EGID, setegid) \
O(SYS_SET_REUID, setreuid) \
O(SYS_SET_REGID, setregid) \
O(SYS_GET_UID, getuid) \
O(SYS_GET_GID, getgid) \
O(SYS_GET_EUID, geteuid) \
O(SYS_GET_EGID, getegid) \
O(SYS_GET_PWD, getpwd) \
O(SYS_SET_PWD, setpwd) \
O(SYS_CLOCK_GETTIME, clock_gettime) \
O(SYS_PIPE, pipe) \
O(SYS_DUP, dup) \
O(SYS_DUP2, dup2) \
O(SYS_KILL, kill) \
O(SYS_SIGNAL, signal) \
O(SYS_TCSETPGRP, tcsetpgrp) \
O(SYS_GET_PID, getpid) \
O(SYS_GET_PGID, getpgid) \
O(SYS_SET_PGID, setpgid) \
O(SYS_FCNTL, fcntl) \
O(SYS_NANOSLEEP, nanosleep) \
O(SYS_FSTATAT, fstatat) \
O(SYS_STAT, stat) \
O(SYS_SYNC, sync) \
O(SYS_MMAP, mmap) \
O(SYS_MUNMAP, munmap) \
O(SYS_TTY_CTRL, tty_ctrl) \
O(SYS_POWEROFF, poweroff) \
O(SYS_CHMOD, chmod) \
O(SYS_CREATE, create) \
O(SYS_CREATE_DIR, create_dir) \
O(SYS_UNLINK, unlink) \
O(SYS_READLINK, readlink) \
O(SYS_READLINKAT, readlinkat) \
O(SYS_MSYNC, msync) \
O(SYS_PREAD, pread) \
O(SYS_CHOWN, chown) \
O(SYS_LOAD_KEYMAP, load_keymap) \
O(SYS_SOCKET, socket) \
O(SYS_BIND, bind) \
O(SYS_SENDTO, sendto) \
O(SYS_RECVFROM, recvfrom) \
O(SYS_IOCTL, ioctl) \
O(SYS_ACCEPT, accept) \
O(SYS_CONNECT, connect) \
O(SYS_LISTEN, listen) \
O(SYS_PSELECT, pselect) \
O(SYS_TRUNCATE, truncate) \
O(SYS_SMO_CREATE, smo_create) \
O(SYS_SMO_DELETE, smo_delete) \
O(SYS_SMO_MAP, smo_map) \
O(SYS_ISATTY, isatty) \
O(SYS_GETSOCKNAME, getsockname) \
O(SYS_GETSOCKOPT, getsockopt) \
O(SYS_SETSOCKOPT, setsockopt) \
enum Syscall
{
#define O(enum, name) enum,
__SYSCALL_LIST(O)
#undef O
__SYSCALL_COUNT
};
__END_DECLS
#endif

View File

@@ -0,0 +1,18 @@
#ifndef _SYS_SYSMACROS_H
#define _SYS_SYSMACROS_H 1
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_pid_t
#include <sys/types.h>
#define makedev(maj, min) ((dev_t)(maj) << 32 | (dev_t)(min))
#define major(dev) (((dev) >> 32) & 0xFFFFFFFF)
#define minor(dev) ( (dev) & 0xFFFFFFFF)
__END_DECLS
#endif

View File

@@ -0,0 +1,32 @@
#ifndef _SYS_TIME_H
#define _SYS_TIME_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_time.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
// NOTE: select is declared from here
#include <sys/select.h>
#include <bits/types/timeval.h>
struct itimerval
{
struct timeval it_interval; /* Timer interval. */
struct timeval it_value; /* Current value. */
};
#define ITIMER_REAL 0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF 2
int getitimer(int which, struct itimerval* value);
int gettimeofday(struct timeval* __restrict tp, void* __restrict tzp);
int setitimer(int which, const struct itimerval* __restrict value, struct itimerval* __restrict ovalue);
int utimes(const char* path, const struct timeval times[2]);
__END_DECLS
#endif

View File

@@ -0,0 +1,25 @@
#ifndef _SYS_TIMES_H
#define _SYS_TIMES_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_times.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_clock_t
#include <sys/types.h>
struct tms
{
clock_t tms_utime; /* User CPU time. */
clock_t tms_stime; /* System CPU time. */
clock_t tms_cutime; /* User CPU time of terminated child processes. */
clock_t tms_cstime; /* System CPU time of terminated child processes. */
};
clock_t times(struct tms* buffer);
__END_DECLS
#endif

View File

@@ -0,0 +1,196 @@
#ifndef _SYS_TYPES_H
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#if !defined(__need_blkcnt_t) \
&& !defined(__need_blksize_t) \
&& !defined(__need_clock_t) \
&& !defined(__need_clockid_t) \
&& !defined(__need_dev_t) \
&& !defined(__need_fsblkcnt_t) \
&& !defined(__need_fsfilcnt_t) \
&& !defined(__need_gid_t) \
&& !defined(__need_id_t) \
&& !defined(__need_ino_t) \
&& !defined(__need_key_t) \
&& !defined(__need_mode_t) \
&& !defined(__need_nlink_t) \
&& !defined(__need_off_t) \
&& !defined(__need_pid_t) \
&& !defined(__need_pthread_attr_t) \
&& !defined(__need_pthread_barrier_t) \
&& !defined(__need_pthread_barrierattr_t) \
&& !defined(__need_pthread_cond_t) \
&& !defined(__need_pthread_condattr_t) \
&& !defined(__need_pthread_key_t) \
&& !defined(__need_pthread_mutex_t) \
&& !defined(__need_pthread_mutexattr_t) \
&& !defined(__need_pthread_once_t) \
&& !defined(__need_pthread_rwlock_t) \
&& !defined(__need_pthread_rwlockattr_t) \
&& !defined(__need_pthread_spinlock_t) \
&& !defined(__need_pthread_t) \
&& !defined(__need_size_t) \
&& !defined(__need_ssize_t) \
&& !defined(__need_suseconds_t) \
&& !defined(__need_time_t) \
&& !defined(__need_timer_t) \
&& !defined(__need_uid_t)
#define __need_all_types
#endif
#ifdef __need_all_types
#define _SYS_TYPES_H 1
#endif
#if !defined(__blkcnt_t_defined) && (defined(__need_all_types) || defined(__need_blkcnt_t))
#define __blkcnt_defined 1
typedef long blkcnt_t;
#endif
#undef __need_blkcnt_t
#if !defined(__blksize_t_defined) && (defined(__need_all_types) || defined(__need_blksize_t))
#define __blksize_t_defined 1
typedef long blksize_t;
#endif
#undef __need_blksize_t
#if !defined(__clock_t_defined) && (defined(__need_all_types) || defined(__need_clock_t))
#define __clock_t_defined 1
typedef long clock_t;
#endif
#undef __need_clock_t
#if !defined(__clockid_t_defined) && (defined(__need_all_types) || defined(__need_clockid_t))
#define __clockid_t_defined 1
typedef int clockid_t;
#endif
#undef __need_clockid_t
#if !defined(__dev_t_defined) && (defined(__need_all_types) || defined(__need_dev_t))
#define __dev_t_defined 1
typedef unsigned long dev_t;
#endif
#undef __need_dev_t
#if !defined(__fsblkcnt_t_defined) && (defined(__need_all_types) || defined(__need_fsblkcnt_t))
#define __fsblkcnt_t_defined 1
typedef unsigned long fsblkcnt_t;
#endif
#undef __need_fsblkcnt_t
#if !defined(__fsfilcnt_t_defined) && (defined(__need_all_types) || defined(__need_fsfilcnt_t))
#define __fsfilcnt_t_defined 1
typedef unsigned long fsfilcnt_t;
#endif
#undef __need_fsfilcnt_t
#if !defined(__gid_t_defined) && (defined(__need_all_types) || defined(__need_gid_t))
#define __gid_t_defined 1
typedef int gid_t;
#endif
#undef __need_gid_t
#if !defined(__id_t_defined) && (defined(__need_all_types) || defined(__need_id_t))
#define __id_t_defined 1
typedef int id_t;
#endif
#undef __need_id_t
#if !defined(__ino_t_defined) && (defined(__need_all_types) || defined(__need_ino_t))
#define __ino_t_defined 1
typedef unsigned long long ino_t;
#endif
#undef __need_ino_t
#if !defined(__key_t_defined) && (defined(__need_all_types) || defined(__need_key_t))
#define __key_t_defined 1
typedef int key_t;
#endif
#undef __need_key_t
#if !defined(__mode_t_defined) && (defined(__need_all_types) || defined(__need_mode_t))
#define __mode_t_defined 1
typedef unsigned int mode_t;
#endif
#undef __need_mode_t
#if !defined(__nlink_t_defined) && (defined(__need_all_types) || defined(__need_nlink_t))
#define __nlink_t_defined 1
typedef unsigned long nlink_t;
#endif
#undef __need_nlink_t
#if !defined(__off_t_defined) && (defined(__need_all_types) || defined(__need_off_t))
#define __off_t_defined 1
typedef long off_t;
#endif
#undef __need_off_t
#if !defined(__pid_t_defined) && (defined(__need_all_types) || defined(__need_pid_t))
#define __pid_t_defined 1
typedef int pid_t;
#endif
#undef __need_pid_t
#include <bits/pthread_types.h>
#if !defined(__size_t_defined) && (defined(__need_all_types) || defined(__need_size_t))
#define __size_t_defined 1
#define __need_size_t
#include <stddef.h>
#endif
#undef __need_size_t
#if !defined(__ssize_t_defined) && (defined(__need_all_types) || defined(__need_ssize_t))
#define __ssize_t_defined 1
#if __SIZEOF_SIZE_T__ == __SIZEOF_INT__
typedef int ssize_t;
#elif __SIZEOF_SIZE_T__ == __SIZEOF_LONG__
typedef long ssize_t;
#elif __SIZEOF_SIZE_T__ == __SIZEOF_LONG_LONG__
typedef long long ssize_t;
#else
#error "unsupported sizeof(size_t)"
#endif
#endif
#undef __need_ssize_t
#if !defined(__suseconds_t_defined) && (defined(__need_all_types) || defined(__need_suseconds_t))
#define __suseconds_t_defined 1
typedef long suseconds_t;
#endif
#undef __need_suseconds_t
#if !defined(__time_t_defined) && (defined(__need_all_types) || defined(__need_time_t))
#define __time_t_defined 1
typedef unsigned long long time_t;
#endif
#undef __need_time_t
#if !defined(__timer_t_defined) && (defined(__need_all_types) || defined(__need_timer_t))
#define __timer_t_defined 1
typedef void* timer_t;
#endif
#undef __need_timer_t
#if !defined(__uid_t_defined) && (defined(__need_all_types) || defined(__need_uid_t))
#define __uid_t_defined 1
typedef int uid_t;
#endif
#undef __need_uid_t
#ifdef __need_all_types
#include <stdint.h>
#endif
#undef __need_all_types
__END_DECLS
#endif

View File

@@ -0,0 +1,25 @@
#ifndef _SYS_UIO_H
#define _SYS_UIO_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_uio.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_size_t
#define __need_ssize_t
#include <sys/types.h>
struct iovec
{
void* iov_base; /* Base address of a memory region for input or output. */
size_t iov_len; /* The size of the memory pointed to by iov_base. */
};
ssize_t readv(int fildes, const struct iovec* iov, int iovcnt);
ssize_t writev(int fildes, const struct iovec* iov, int iovcnt);
__END_DECLS
#endif

View File

@@ -0,0 +1,20 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_un.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#include <bits/types/sa_family_t.h>
struct sockaddr_un
{
sa_family_t sun_family; /* Address family. */
char sun_path[FILENAME_MAX]; /* Socket pathname. */
};
__END_DECLS
#endif

View File

@@ -0,0 +1,23 @@
#ifndef _SYS_UTSNAME_H
#define _SYS_UTSNAME_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_utsname.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
struct utsname
{
char sysname[65]; /* Name of this implementation of the operating system. */
char nodename[65]; /* Name of this node within the communications network to which this node is attached, if any. */
char release[65]; /* Current release level of this implementation. */
char version[65]; /* Current version level of this release. */
char machine[65]; /* Name of the hardware type on which the system is running. */
};
int uname(struct utsname* name);
__END_DECLS
#endif

View File

@@ -0,0 +1,45 @@
#ifndef _SYS_WAIT_H
#define _SYS_WAIT_H 1
// https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_wait.h.html
#include <sys/cdefs.h>
__BEGIN_DECLS
#define __need_id_t
#define __need_pid_t
#include <sys/types.h>
#include <signal.h>
#define WCONTINUED 0x01
#define WNOHANG 0x02
#define WUNTRACED 0x04
#define WEXITED 0x08
#define WNOWAIT 0x10
#define WSTOPPED 0x20
#define WEXITSTATUS(status) (((status) >> 8) & 0xFF)
#define WSTOPSIG(status) WEXITSTATUS(status)
#define WTERMSIG(status) ((status) & 0x7F)
#define WIFEXITED(status) (WTERMSIG(status) == 0)
#define WIFSIGNALED(status) (((status) & 0x7F) > 0 && ((status) & 0x7F) < 0x7F)
#define WIFSTOPPED(status) (((status) & 0xFF) == 0x7F)
#define __WGENEXITCODE(ret, sig) (((ret) << 8) | (sig))
typedef enum
{
P_ALL,
P_PGID,
P_PID,
} idtype_t;
pid_t wait(int* stat_loc);
int waitid(idtype_t idtype, id_t id, siginfo_t* infop, int options);
pid_t waitpid(pid_t pid, int* stat_loc, int options);
__END_DECLS
#endif