Squash commits for public release
This commit is contained in:
23
libs/libc/include/assert.h
Normal file
23
libs/libc/include/assert.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef _LIBC_ASSERT_H
|
||||
#define _LIBC_ASSERT_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/_structs.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#ifndef assert
|
||||
#define assert(x) \
|
||||
if (!(x)) { \
|
||||
printf("Assertion failed: %s, function %s, file %s:%d\n", #x, __func__, __FILE__, __LINE__); \
|
||||
fflush(stdout); \
|
||||
abort(); \
|
||||
}
|
||||
#endif // assert
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_ASSERT_H
|
||||
135
libs/libc/include/bits/errno.h
Normal file
135
libs/libc/include/bits/errno.h
Normal file
@@ -0,0 +1,135 @@
|
||||
#ifndef _LIBC_BITS_ERRNO_H
|
||||
#define _LIBC_BITS_ERRNO_H
|
||||
|
||||
// clang-format off
|
||||
#define EPERM 1 /* Operation not permitted */
|
||||
#define ENOENT 2 /* No such file or directory */
|
||||
#define ESRCH 3 /* No such process */
|
||||
#define EINTR 4 /* Interrupted system call */
|
||||
#define EIO 5 /* I/O error */
|
||||
#define ENXIO 6 /* No such device or address */
|
||||
#define E2BIG 7 /* Arg list too long */
|
||||
#define ENOEXEC 8 /* Exec format error */
|
||||
#define EBADF 9 /* Bad file number */
|
||||
#define ECHILD 10 /* No child processes */
|
||||
#define EAGAIN 11 /* Try again */
|
||||
#define ENOMEM 12 /* Out of memory */
|
||||
#define EACCES 13 /* Permission denied */
|
||||
#define EFAULT 14 /* Bad address */
|
||||
#define ENOTBLK 15 /* Block device required */
|
||||
#define EBUSY 16 /* Device or resource busy */
|
||||
#define EEXIST 17 /* File exists */
|
||||
#define EXDEV 18 /* Cross-device link */
|
||||
#define ENODEV 19 /* No such device */
|
||||
#define ENOTDIR 20 /* Not a directory */
|
||||
#define EISDIR 21 /* Is a directory */
|
||||
#define EINVAL 22 /* Invalid argument */
|
||||
#define ENFILE 23 /* File table overflow */
|
||||
#define EMFILE 24 /* Too many open files */
|
||||
#define ENOTTY 25 /* Not a typewriter */
|
||||
#define ETXTBSY 26 /* Text file busy */
|
||||
#define EFBIG 27 /* File too large */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#define ESPIPE 29 /* Illegal seek */
|
||||
#define EROFS 30 /* Read-only file system */
|
||||
#define EMLINK 31 /* Too many links */
|
||||
#define EPIPE 32 /* Broken pipe */
|
||||
#define EDOM 33 /* Math argument out of domain of func */
|
||||
#define ERANGE 34 /* Math result not representable */
|
||||
#define EDEADLK 35 /* Resource deadlock would occur */
|
||||
#define ENAMETOOLONG 36 /* File name too long */
|
||||
#define ENOLCK 37 /* No record locks available */
|
||||
#define ENOSYS 38 /* Function not implemented */
|
||||
#define ENOTEMPTY 39 /* Directory not empty */
|
||||
#define ELOOP 40 /* Too many symbolic links encountered */
|
||||
#define EWOULDBLOCK EAGAIN /* Operation would block */
|
||||
#define ENOMSG 42 /* No message of desired type */
|
||||
#define EIDRM 43 /* Identifier removed */
|
||||
#define ECHRNG 44 /* Channel number out of range */
|
||||
#define EL2NSYNC 45 /* Level 2 not synchronized */
|
||||
#define EL3HLT 46 /* Level 3 halted */
|
||||
#define EL3RST 47 /* Level 3 reset */
|
||||
#define ELNRNG 48 /* Link number out of range */
|
||||
#define EUNATCH 49 /* Protocol driver not attached */
|
||||
#define ENOCSI 50 /* No CSI structure available */
|
||||
#define EL2HLT 51 /* Level 2 halted */
|
||||
#define EBADE 52 /* Invalid exchange */
|
||||
#define EBADR 53 /* Invalid request descriptor */
|
||||
#define EXFULL 54 /* Exchange full */
|
||||
#define ENOANO 55 /* No anode */
|
||||
#define EBADRQC 56 /* Invalid request code */
|
||||
#define EBADSLT 57 /* Invalid slot */
|
||||
|
||||
#define EDEADLOCK EDEADLK
|
||||
|
||||
#define EBFONT 59 /* Bad font file format */
|
||||
#define ENOSTR 60 /* Device not a stream */
|
||||
#define ENODATA 61 /* No data available */
|
||||
#define ETIME 62 /* Timer expired */
|
||||
#define ENOSR 63 /* Out of streams resources */
|
||||
#define ENONET 64 /* Machine is not on the network */
|
||||
#define ENOPKG 65 /* Package not installed */
|
||||
#define EREMOTE 66 /* Object is remote */
|
||||
#define ENOLINK 67 /* Link has been severed */
|
||||
#define EADV 68 /* Advertise error */
|
||||
#define ESRMNT 69 /* Srmount error */
|
||||
#define ECOMM 70 /* Communication error on send */
|
||||
#define EPROTO 71 /* Protocol error */
|
||||
#define EMULTIHOP 72 /* Multihop attempted */
|
||||
#define EDOTDOT 73 /* RFS specific error */
|
||||
#define EBADMSG 74 /* Not a data message */
|
||||
#define EOVERFLOW 75 /* Value too large for defined data type */
|
||||
#define ENOTUNIQ 76 /* Name not unique on network */
|
||||
#define EBADFD 77 /* File descriptor in bad state */
|
||||
#define EREMCHG 78 /* Remote address changed */
|
||||
#define ELIBACC 79 /* Can not access a needed shared library */
|
||||
#define ELIBBAD 80 /* Accessing a corrupted shared library */
|
||||
#define ELIBSCN 81 /* .lib section in a.out corrupted */
|
||||
#define ELIBMAX 82 /* Attempting to link in too many shared libraries */
|
||||
#define ELIBEXEC 83 /* Cannot exec a shared library directly */
|
||||
#define EILSEQ 84 /* Illegal byte sequence */
|
||||
#define ERESTART 85 /* Interrupted system call should be restarted */
|
||||
#define ESTRPIPE 86 /* Streams pipe error */
|
||||
#define EUSERS 87 /* Too many users */
|
||||
#define ENOTSOCK 88 /* Socket operation on non-socket */
|
||||
#define EDESTADDRREQ 89 /* Destination address required */
|
||||
#define EMSGSIZE 90 /* Message too long */
|
||||
#define EPROTOTYPE 91 /* Protocol wrong type for socket */
|
||||
#define ENOPROTOOPT 92 /* Protocol not available */
|
||||
#define EPROTONOSUPPORT 93 /* Protocol not supported */
|
||||
#define ESOCKTNOSUPPORT 94 /* Socket type not supported */
|
||||
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
|
||||
#define EPFNOSUPPORT 96 /* Protocol family not supported */
|
||||
#define EAFNOSUPPORT 97 /* Address family not supported by protocol */
|
||||
#define EADDRINUSE 98 /* Address already in use */
|
||||
#define EADDRNOTAVAIL 99 /* Cannot assign requested address */
|
||||
#define ENETDOWN 100 /* Network is down */
|
||||
#define ENETUNREACH 101 /* Network is unreachable */
|
||||
#define ENETRESET 102 /* Network dropped connection because of reset */
|
||||
#define ECONNABORTED 103 /* Software caused connection abort */
|
||||
#define ECONNRESET 104 /* Connection reset by peer */
|
||||
#define ENOBUFS 105 /* No buffer space available */
|
||||
#define EISCONN 106 /* Transport endpoint is already connected */
|
||||
#define ENOTCONN 107 /* Transport endpoint is not connected */
|
||||
#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
|
||||
#define ETOOMANYREFS 109 /* Too many references: cannot splice */
|
||||
#define ETIMEDOUT 110 /* Connection timed out */
|
||||
#define ECONNREFUSED 111 /* Connection refused */
|
||||
#define EHOSTDOWN 112 /* Host is down */
|
||||
#define EHOSTUNREACH 113 /* No route to host */
|
||||
#define EALREADY 114 /* Operation already in progress */
|
||||
#define EINPROGRESS 115 /* Operation now in progress */
|
||||
#define ESTALE 116 /* Stale NFS file handle */
|
||||
#define EUCLEAN 117 /* Structure needs cleaning */
|
||||
#define ENOTNAM 118 /* Not a XENIX named type file */
|
||||
#define ENAVAIL 119 /* No XENIX semaphores available */
|
||||
#define EISNAM 120 /* Is a named type file */
|
||||
#define EREMOTEIO 121 /* Remote I/O error */
|
||||
#define EDQUOT 122 /* Quota exceeded */
|
||||
|
||||
#define ENOMEDIUM 123 /* No medium found */
|
||||
#define EMEDIUMTYPE 124 /* Wrong medium type */
|
||||
#define EBADARCH 125 /* Bad arch */
|
||||
// clang-format on
|
||||
|
||||
#endif // _LIBC_BITS_ERRNO_H
|
||||
19
libs/libc/include/bits/fcntl.h
Normal file
19
libs/libc/include/bits/fcntl.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef _LIBC_BITS_FCNTL_H
|
||||
#define _LIBC_BITS_FCNTL_H
|
||||
|
||||
#define SEEK_SET 0x1
|
||||
#define SEEK_CUR 0x2
|
||||
#define SEEK_END 0x3
|
||||
|
||||
/* OPEN */
|
||||
#define O_RDONLY 0x1
|
||||
#define O_WRONLY 0x2
|
||||
#define O_RDWR (O_RDONLY | O_WRONLY)
|
||||
#define O_DIRECTORY 0x4
|
||||
#define O_CREAT 0x8
|
||||
#define O_TRUNC 0x10
|
||||
#define O_APPEND 0x20
|
||||
#define O_EXCL 0x40
|
||||
#define O_EXEC 0x80
|
||||
|
||||
#endif // _LIBC_BITS_FCNTL_H
|
||||
44
libs/libc/include/bits/signal.h
Normal file
44
libs/libc/include/bits/signal.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef _LIBC_BITS_SIGNAL_H
|
||||
#define _LIBC_BITS_SIGNAL_H
|
||||
|
||||
#define SIGHUP 1
|
||||
#define SIGINT 2
|
||||
#define SIGQUIT 3
|
||||
#define SIGILL 4
|
||||
#define SIGTRAP 5
|
||||
#define SIGABRT 6
|
||||
#define SIGIOT 6
|
||||
#define SIGBUS 7
|
||||
#define SIGFPE 8
|
||||
#define SIGKILL 9
|
||||
#define SIGUSR1 10
|
||||
#define SIGSEGV 11
|
||||
#define SIGUSR2 12
|
||||
#define SIGPIPE 13
|
||||
#define SIGALRM 14
|
||||
#define SIGTERM 15
|
||||
#define SIGSTKFLT 16
|
||||
#define SIGCHLD 17
|
||||
#define SIGCONT 18
|
||||
#define SIGSTOP 19
|
||||
#define SIGTSTP 20
|
||||
#define SIGTTIN 21
|
||||
#define SIGTTOU 22
|
||||
#define SIGURG 23
|
||||
#define SIGXCPU 24
|
||||
#define SIGXFSZ 25
|
||||
#define SIGVTALRM 26
|
||||
#define SIGPROF 27
|
||||
#define SIGWINCH 28
|
||||
#define SIGIO 29
|
||||
#define SIGPOLL SIGIO
|
||||
#define SIGPWR 30
|
||||
#define SIGSYS 31
|
||||
|
||||
typedef void (*sighandler_t)(int);
|
||||
|
||||
#define SIG_DFL ((sighandler_t)0)
|
||||
#define SIG_ERR ((sighandler_t)-1)
|
||||
#define SIG_IGN ((sighandler_t)1)
|
||||
|
||||
#endif // _LIBC_BITS_SIGNAL_H
|
||||
18
libs/libc/include/bits/sys/ioctls.h
Normal file
18
libs/libc/include/bits/sys/ioctls.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _LIBC_BITS_SYS_IOCTLS_H
|
||||
#define _LIBC_BITS_SYS_IOCTLS_H
|
||||
|
||||
/* TTY */
|
||||
#define TIOCGPGRP 0x0101
|
||||
#define TIOCSPGRP 0x0102
|
||||
#define TCGETS 0x0103
|
||||
#define TCSETS 0x0104
|
||||
#define TCSETSW 0x0105
|
||||
#define TCSETSF 0x0106
|
||||
|
||||
/* BGA */
|
||||
#define BGA_SWAP_BUFFERS 0x0101
|
||||
#define BGA_GET_HEIGHT 0x0102
|
||||
#define BGA_GET_WIDTH 0x0103
|
||||
#define BGA_GET_SCALE 0x0104
|
||||
|
||||
#endif // _LIBC_BITS_SYS_IOCTLS_H
|
||||
28
libs/libc/include/bits/sys/mman.h
Normal file
28
libs/libc/include/bits/sys/mman.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef _LIBC_BITS_SYS_MMAN_H
|
||||
#define _LIBC_BITS_SYS_MMAN_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define MAP_SHARED 0x01
|
||||
#define MAP_PRIVATE 0x02
|
||||
#define MAP_FIXED 0x10
|
||||
#define MAP_ANONYMOUS 0x20
|
||||
#define MAP_STACK 0x40
|
||||
|
||||
#define PROT_READ 0x1
|
||||
#define PROT_WRITE 0x2
|
||||
#define PROT_EXEC 0x4
|
||||
#define PROT_NONE 0x0
|
||||
|
||||
struct mmap_params {
|
||||
void* addr;
|
||||
size_t size;
|
||||
int prot;
|
||||
int flags;
|
||||
int fd;
|
||||
off_t offset;
|
||||
};
|
||||
typedef struct mmap_params mmap_params_t;
|
||||
|
||||
#endif // _LIBC_BITS_SYS_MMAN_H
|
||||
13
libs/libc/include/bits/sys/ptrace.h
Normal file
13
libs/libc/include/bits/sys/ptrace.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _LIBC_BITS_SYS_PTRACE_H
|
||||
#define _LIBC_BITS_SYS_PTRACE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef int ptrace_request_t;
|
||||
#define PTRACE_TRACEME (0x1)
|
||||
#define PTRACE_CONT (0x2)
|
||||
#define PTRACE_PEEKTEXT (0x3)
|
||||
#define PTRACE_PEEKDATA (0x4)
|
||||
|
||||
#endif // _LIBC_BITS_SYS_PTRACE_H
|
||||
18
libs/libc/include/bits/sys/select.h
Normal file
18
libs/libc/include/bits/sys/select.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _LIBC_BITS_SYS_SELECT_H
|
||||
#define _LIBC_BITS_SYS_SELECT_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define FD_SETSIZE 32
|
||||
|
||||
struct fd_set {
|
||||
uint8_t fds[FD_SETSIZE / 8];
|
||||
};
|
||||
typedef struct fd_set fd_set_t;
|
||||
|
||||
#define FD_SET(fd, fd_set_ptr) ((fd_set_ptr)->fds[fd / 8] |= (1 << (fd % 8)))
|
||||
#define FD_CLR(fd, fd_set_ptr) ((fd_set_ptr)->fds[fd / 8] &= ~(1 << (fd % 8)))
|
||||
#define FD_ZERO(fd_set_ptr) (memset((uint8_t*)(fd_set_ptr), 0, sizeof(fd_set_t)))
|
||||
#define FD_ISSET(fd, fd_set_ptr) ((fd_set_ptr)->fds[fd / 8] & (1 << (fd % 8)))
|
||||
|
||||
#endif // _LIBC_BITS_SYS_SELECT_H
|
||||
26
libs/libc/include/bits/sys/socket.h
Normal file
26
libs/libc/include/bits/sys/socket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _LIBC_BITS_SYS_SOCKET_H
|
||||
#define _LIBC_BITS_SYS_SOCKET_H
|
||||
|
||||
enum SOCK_DOMAINS {
|
||||
PF_LOCAL,
|
||||
PF_INET,
|
||||
PF_INET6,
|
||||
PF_IPX,
|
||||
PF_NETLINK,
|
||||
PF_X25,
|
||||
PF_AX25,
|
||||
PF_ATMPVC,
|
||||
PF_APPLETALK,
|
||||
PF_PACKET,
|
||||
};
|
||||
|
||||
enum SOCK_TYPES {
|
||||
SOCK_STREAM,
|
||||
SOCK_DGRAM,
|
||||
SOCK_SEQPACKET,
|
||||
SOCK_RAW,
|
||||
SOCK_RDM,
|
||||
SOCK_PACKET,
|
||||
};
|
||||
|
||||
#endif // _LIBC_BITS_SYS_SOCKET_H
|
||||
64
libs/libc/include/bits/sys/stat.h
Normal file
64
libs/libc/include/bits/sys/stat.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef _LIBC_BITS_SYS_STAT_H
|
||||
#define _LIBC_BITS_SYS_STAT_H
|
||||
|
||||
#include <bits/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define S_IFMT 0xF000
|
||||
|
||||
/* MODES */
|
||||
#define S_IFSOCK 0xC000 /* [XSI] socket */
|
||||
#define S_IFLNK 0xA000 /* [XSI] symbolic link */
|
||||
#define S_IFREG 0x8000 /* [XSI] regular */
|
||||
#define S_IFBLK 0x6000 /* [XSI] block special */
|
||||
#define S_IFDIR 0x4000 /* [XSI] directory */
|
||||
#define S_IFCHR 0x2000 /* [XSI] character special */
|
||||
#define S_IFIFO 0x1000 /* [XSI] named pipe (fifo) */
|
||||
|
||||
#define S_ISUID 0x0800
|
||||
#define S_ISGID 0x0400
|
||||
#define S_ISVTX 0x0200
|
||||
|
||||
/* Read, write, execute/search by owner */
|
||||
#define S_IRWXU 0x01c0
|
||||
#define S_IRUSR 0x0100
|
||||
#define S_IWUSR 0x0080
|
||||
#define S_IXUSR 0x0040
|
||||
/* Read, write, execute/search by group */
|
||||
#define S_IRWXG 0x0038
|
||||
#define S_IRGRP 0x0020
|
||||
#define S_IWGRP 0x0010
|
||||
#define S_IXGRP 0x0008
|
||||
/* Read, write, execute/search by others */
|
||||
#define S_IRWXO 0x0007
|
||||
#define S_IROTH 0x0004
|
||||
#define S_IWOTH 0x0002
|
||||
#define S_IXOTH 0x0001
|
||||
|
||||
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
|
||||
#define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR)
|
||||
#define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK)
|
||||
#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
|
||||
#define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO)
|
||||
#define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK)
|
||||
#define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK)
|
||||
|
||||
struct stat {
|
||||
dev_t st_dev; /* ID of device containing file */
|
||||
ino_t st_ino; /* Inode number */
|
||||
mode_t st_mode; /* File type and mode */
|
||||
nlink_t st_nlink; /* Number of hard links */
|
||||
uid_t st_uid; /* User ID of owner */
|
||||
gid_t st_gid; /* Group ID of owner */
|
||||
dev_t st_rdev; /* Device ID (if special file) */
|
||||
off_t st_size; /* Total size, in bytes */
|
||||
uint32_t st_blksize; /* Block size for filesystem I/O */
|
||||
uint32_t st_blocks; /* Number of 512B blocks allocated */
|
||||
|
||||
struct timespec st_atim; /* Time of last access */
|
||||
struct timespec st_mtim; /* Time of last modification */
|
||||
struct timespec st_ctim; /* Time of last status change */
|
||||
};
|
||||
typedef struct stat stat_t;
|
||||
|
||||
#endif // _LIBC_BITS_SYS_STAT_H
|
||||
15
libs/libc/include/bits/sys/utsname.h
Normal file
15
libs/libc/include/bits/sys/utsname.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _LIBC_BITS_SYS_UTSNAME_H
|
||||
#define _LIBC_BITS_SYS_UTSNAME_H
|
||||
|
||||
#define UTSNAME_ENTRY_LEN 65
|
||||
|
||||
struct utsname {
|
||||
char sysname[UTSNAME_ENTRY_LEN];
|
||||
char nodename[UTSNAME_ENTRY_LEN];
|
||||
char release[UTSNAME_ENTRY_LEN];
|
||||
char version[UTSNAME_ENTRY_LEN];
|
||||
char machine[UTSNAME_ENTRY_LEN];
|
||||
};
|
||||
typedef struct utsname utsname_t;
|
||||
|
||||
#endif // _LIBC_BITS_SYS_UTSNAME_H
|
||||
7
libs/libc/include/bits/sys/wait.h
Normal file
7
libs/libc/include/bits/sys/wait.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _LIBC_BITS_SYS_WAIT_H
|
||||
#define _LIBC_BITS_SYS_WAIT_H
|
||||
|
||||
#define WNOHANG 0x1
|
||||
#define WUNTRACED 0x2
|
||||
|
||||
#endif // _LIBC_BITS_SYS_WAIT_H
|
||||
1129
libs/libc/include/bits/syscalls.h
Normal file
1129
libs/libc/include/bits/syscalls.h
Normal file
File diff suppressed because it is too large
Load Diff
13
libs/libc/include/bits/thread.h
Normal file
13
libs/libc/include/bits/thread.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _LIBC_BITS_THREAD_H
|
||||
#define _LIBC_BITS_THREAD_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
struct thread_create_params {
|
||||
uint32_t entry_point;
|
||||
uint32_t stack_start;
|
||||
uint32_t stack_size;
|
||||
};
|
||||
typedef struct thread_create_params thread_create_params_t;
|
||||
|
||||
#endif // _LIBC_BITS_THREAD_H
|
||||
56
libs/libc/include/bits/time.h
Normal file
56
libs/libc/include/bits/time.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef _LIBC_BITS_TIME_H
|
||||
#define _LIBC_BITS_TIME_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
struct timeval {
|
||||
time_t tv_sec;
|
||||
uint32_t tv_usec;
|
||||
};
|
||||
typedef struct timeval timeval_t;
|
||||
|
||||
#define DST_NONE 0 /* not on dst */
|
||||
#define DST_USA 1 /* USA style dst */
|
||||
#define DST_AUST 2 /* Australian style dst */
|
||||
#define DST_WET 3 /* Western European dst */
|
||||
#define DST_MET 4 /* Middle European dst */
|
||||
#define DST_EET 5 /* Eastern European dst */
|
||||
#define DST_CAN 6 /* Canada */
|
||||
struct timezone {
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
typedef struct timezone timezone_t;
|
||||
|
||||
struct timespec {
|
||||
time_t tv_sec;
|
||||
uint32_t tv_nsec;
|
||||
};
|
||||
typedef struct timespec timespec_t;
|
||||
|
||||
struct tm {
|
||||
int tm_sec;
|
||||
int tm_min;
|
||||
int tm_hour;
|
||||
int tm_mday;
|
||||
int tm_mon;
|
||||
int tm_year;
|
||||
int tm_wday;
|
||||
int tm_yday;
|
||||
int tm_isdst;
|
||||
};
|
||||
typedef struct tm tm_t;
|
||||
|
||||
typedef enum {
|
||||
CLOCK_REALTIME,
|
||||
CLOCK_MONOTONIC,
|
||||
CLOCK_PROCESS_CPUTIME_ID,
|
||||
CLOCK_THREAD_CPUTIME_ID,
|
||||
} clockid_t;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_BITS_TIME_H
|
||||
43
libs/libc/include/bits/types.h
Normal file
43
libs/libc/include/bits/types.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef _LIBC_BITS_TYPES_H
|
||||
#define _LIBC_BITS_TYPES_H
|
||||
|
||||
typedef char __int8_t;
|
||||
typedef short __int16_t;
|
||||
typedef int __int32_t;
|
||||
typedef long long __int64_t;
|
||||
typedef unsigned char __uint8_t;
|
||||
typedef unsigned short __uint16_t;
|
||||
typedef unsigned int __uint32_t;
|
||||
typedef unsigned long long __uint64_t;
|
||||
|
||||
typedef __uint32_t __dev_t; /* Type of device numbers. */
|
||||
typedef __uint32_t __uid_t; /* Type of user identifications. */
|
||||
typedef __uint32_t __gid_t; /* Type of group identifications. */
|
||||
typedef __uint32_t __ino_t; /* Type of file serial numbers. */
|
||||
typedef __uint64_t __ino64_t; /* Type of file serial numbers (LFS).*/
|
||||
typedef __uint16_t __mode_t; /* Type of file attribute bitmasks. */
|
||||
typedef __uint32_t __nlink_t; /* Type of file link counts. */
|
||||
typedef __int64_t __off64_t; /* Type of file sizes and offsets (LFS). */
|
||||
typedef __uint32_t __pid_t; /* Type of process identifications. */
|
||||
typedef __uint32_t __fsid_t; /* Type of file system IDs. */
|
||||
typedef __uint32_t __time_t; /* Seconds since the Epoch. */
|
||||
|
||||
#if defined(__x86_64__) || defined(__aarch64__) || (defined(__riscv) && (__riscv_xlen == 64))
|
||||
#define BITS64
|
||||
typedef __int64_t __off_t; /* Type of file sizes and offsets. */
|
||||
|
||||
#ifndef LONG_TYPE_SIZE
|
||||
#define LONG_TYPE_SIZE (8)
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define BITS32
|
||||
typedef __int32_t __off_t; /* Type of file sizes and offsets. */
|
||||
|
||||
#ifndef LONG_TYPE_SIZE
|
||||
#define LONG_TYPE_SIZE (4)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _LIBC_BITS_TYPES_H
|
||||
38
libs/libc/include/ctype.h
Normal file
38
libs/libc/include/ctype.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef _LIBC_CTYPE_H
|
||||
#define _LIBC_CTYPE_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/_structs.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define _U 01
|
||||
#define _L 02
|
||||
#define _N 04
|
||||
#define _S 010
|
||||
#define _P 020
|
||||
#define _C 040
|
||||
#define _X 0100
|
||||
#define _B 0200
|
||||
|
||||
extern const char __ctypes[256];
|
||||
|
||||
static inline int isalnum(int c) { return __ctypes[(unsigned char)(c)] & (_U | _L | _N); }
|
||||
static inline int isalpha(int c) { return __ctypes[(unsigned char)(c)] & (_U | _L); }
|
||||
static inline int iscntrl(int c) { return __ctypes[(unsigned char)(c)] & (_C); }
|
||||
static inline int isdigit(int c) { return __ctypes[(unsigned char)(c)] & (_N); }
|
||||
static inline int isxdigit(int c) { return __ctypes[(unsigned char)(c)] & (_N | _X); }
|
||||
static inline int isspace(int c) { return __ctypes[(unsigned char)(c)] & (_S); }
|
||||
static inline int ispunct(int c) { return __ctypes[(unsigned char)(c)] & (_P); }
|
||||
static inline int isprint(int c) { return __ctypes[(unsigned char)(c)] & (_P | _U | _L | _N | _B); }
|
||||
static inline int isgraph(int c) { return __ctypes[(unsigned char)(c)] & (_P | _U | _L | _N); }
|
||||
static inline int islower(int c) { return (__ctypes[(unsigned char)(c)] & (_U | _L)) == _L; }
|
||||
static inline int isupper(int c) { return (__ctypes[(unsigned char)(c)] & (_U | _L)) == _U; }
|
||||
static inline int tolower(int c) { return isupper(c) ? (c) - 'a' + 'A' : c; }
|
||||
static inline int toupper(int c) { return islower(c) ? (c) - 'A' + 'a' : c; }
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _LIBC_CTYPE_H */
|
||||
31
libs/libc/include/dirent.h
Normal file
31
libs/libc/include/dirent.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _LIBC_DIRENT_H
|
||||
#define _LIBC_DIRENT_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/_structs.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
struct __dirstream {
|
||||
int fd;
|
||||
size_t size; /* size of dir data */
|
||||
size_t allocated; /* size of data holder block */
|
||||
size_t offset;
|
||||
};
|
||||
typedef struct __dirstream DIR;
|
||||
|
||||
struct __dirent {
|
||||
uint32_t d_ino; /* Inode number */
|
||||
uint32_t d_off; /* Offset to next linux_dirent */
|
||||
uint16_t d_reclen; /* Length of this linux_dirent */
|
||||
char d_name[]; /* Filename (null-terminated) */
|
||||
};
|
||||
typedef struct __dirent dirent_t;
|
||||
|
||||
ssize_t getdents(int fd, char* buf, size_t len);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _LIBC_DIRENT_H */
|
||||
10
libs/libc/include/errno.h
Normal file
10
libs/libc/include/errno.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _LIBC_ERRNO_H
|
||||
#define _LIBC_ERRNO_H
|
||||
|
||||
#include <bits/errno.h>
|
||||
|
||||
extern int errno;
|
||||
|
||||
#define set_errno(x) (errno = x)
|
||||
|
||||
#endif
|
||||
15
libs/libc/include/fcntl.h
Normal file
15
libs/libc/include/fcntl.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _LIBC_FCNTL_H
|
||||
#define _LIBC_FCNTL_H
|
||||
|
||||
#include <bits/fcntl.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int open(const char* pathname, int flags, ...);
|
||||
int creat(const char* path, mode_t mode);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_FCNTL_H
|
||||
98
libs/libc/include/limits.h
Normal file
98
libs/libc/include/limits.h
Normal file
@@ -0,0 +1,98 @@
|
||||
#ifndef _LIBC_LIMITS_H
|
||||
#define _LIBC_LIMITS_H
|
||||
|
||||
#include <bits/types.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#ifndef PAGE_SIZE
|
||||
#define PAGE_SIZE 4096
|
||||
#endif
|
||||
|
||||
#define HOST_NAME_MAX 64
|
||||
|
||||
#define PATH_MAX 4096
|
||||
#if !defined MAXPATHLEN && defined PATH_MAX
|
||||
#define MAXPATHLEN PATH_MAX
|
||||
#endif
|
||||
|
||||
#define NAME_MAX 255
|
||||
|
||||
#define TTY_NAME_MAX 32
|
||||
|
||||
#define PIPE_BUF 4096
|
||||
|
||||
#define INT_MAX INT32_MAX
|
||||
#define INT_MIN INT32_MIN
|
||||
|
||||
#define UINT_MAX UINT32_MAX
|
||||
|
||||
#define CHAR_BIT 8
|
||||
#define SCHAR_MIN (-128)
|
||||
#define SCHAR_MAX 127
|
||||
#define UCHAR_MAX 255
|
||||
|
||||
#define SHRT_MAX 32768
|
||||
#define SHRT_MIN (-SHRT_MAX - 1)
|
||||
|
||||
#define USHRT_MAX 65535
|
||||
|
||||
#if LONG_TYPE_SIZE == 4
|
||||
#define LONG_MAX 2147483647L
|
||||
#define LONG_MIN (-LONG_MAX - 1L)
|
||||
#define ULONG_MAX 4294967295UL
|
||||
#elif LONG_TYPE_SIZE == 8
|
||||
#define LONG_MAX 9223372036854775807L
|
||||
#define LONG_MIN (-LONG_MAX - 1L)
|
||||
#define ULONG_MAX 18446744073709551615UL
|
||||
#endif
|
||||
|
||||
#define LONG_LONG_MAX 9223372036854775807LL
|
||||
#define LONG_LONG_MIN (-LONG_LONG_MAX - 1LL)
|
||||
|
||||
#define LLONG_MAX LONG_LONG_MAX
|
||||
#define LLONG_MIN LONG_LONG_MIN
|
||||
|
||||
#define ULONG_LONG_MAX 18446744073709551615ULL
|
||||
#define ULLONG_MAX ULONG_LONG_MAX
|
||||
|
||||
#define CHAR_MIN SCHAR_MIN
|
||||
#define CHAR_MAX SCHAR_MAX
|
||||
|
||||
#define CHAR_WIDTH 8
|
||||
#define SCHAR_WIDTH 8
|
||||
#define UCHAR_WIDTH 8
|
||||
|
||||
#define SHRT_WIDTH 16
|
||||
#define USHRT_WIDTH 16
|
||||
|
||||
#define INT_WIDTH 32
|
||||
#define UINT_WIDTH 32
|
||||
|
||||
#if LONG_TYPE_SIZE == 4
|
||||
#define LONG_WIDTH 32
|
||||
#define ULONG_WIDTH 32
|
||||
#else
|
||||
#define LONG_WIDTH 64
|
||||
#define ULONG_WIDTH 64
|
||||
#endif
|
||||
|
||||
#define LLONG_WIDTH 64
|
||||
#define ULLONG_WIDTH 64
|
||||
|
||||
#define ARG_MAX 65536
|
||||
|
||||
#define PTHREAD_STACK_MIN 65536
|
||||
|
||||
#define SSIZE_MAX 2147483647
|
||||
|
||||
#define LINK_MAX 4096
|
||||
|
||||
#define TZNAME_MAX 64
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_LIMITS_H
|
||||
15
libs/libc/include/pthread.h
Normal file
15
libs/libc/include/pthread.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _LIBC_PTHREAD_H
|
||||
#define _LIBC_PTHREAD_H
|
||||
|
||||
#include <bits/thread.h>
|
||||
#include <sys/_structs.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int pthread_create(void* func);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _LIBC_PTHREAD_H */
|
||||
28
libs/libc/include/pwd.h
Normal file
28
libs/libc/include/pwd.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef _LIBC_PWD_H
|
||||
#define _LIBC_PWD_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
struct passwd {
|
||||
char* pw_name;
|
||||
char* pw_passwd;
|
||||
uid_t pw_uid;
|
||||
gid_t pw_gid;
|
||||
char* pw_gecos;
|
||||
char* pw_dir;
|
||||
char* pw_shell;
|
||||
};
|
||||
typedef struct passwd passwd_t;
|
||||
|
||||
void setpwent();
|
||||
void endpwent();
|
||||
passwd_t* getpwent();
|
||||
passwd_t* getpwuid(uid_t uid);
|
||||
passwd_t* getpwnam(const char* name);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_PWD_H
|
||||
13
libs/libc/include/sched.h
Normal file
13
libs/libc/include/sched.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _LIBC_SCHED_H
|
||||
#define _LIBC_SCHED_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
void sched_yield();
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SCHED_H
|
||||
60
libs/libc/include/setjmp.h
Normal file
60
libs/libc/include/setjmp.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#ifndef _LIBC_SETJMP_H
|
||||
#define _LIBC_SETJMP_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#ifdef __i386__
|
||||
/**
|
||||
* x86_32 (6 * 4):
|
||||
* - ebx
|
||||
* - esp
|
||||
* - ebp
|
||||
* - esi
|
||||
* - edi
|
||||
* - return address
|
||||
*/
|
||||
#define _jblen (6 * 4)
|
||||
#elif defined(__x86_64__)
|
||||
/**
|
||||
* x86_64 (8 * 8):
|
||||
* - rip, rbp, rsp, rbx, r12, r13, r14, r15
|
||||
*/
|
||||
#define _jblen (8 * 8)
|
||||
#elif defined(__arm__)
|
||||
/**
|
||||
* ARMv7 (11 * 4 + 8 * 8):
|
||||
* - r4 - r12, sp, lr
|
||||
* - d8-d15
|
||||
*/
|
||||
#define _jblen (11 * 4 + 8 * 8)
|
||||
#elif defined(__aarch64__)
|
||||
/**
|
||||
* ARMv8 (22 * 8):
|
||||
* - x19-x28, x29(fp), x30(lr), x31(sp), x4(alignment)
|
||||
* - d8-d15
|
||||
*/
|
||||
#define _jblen (22 * 8)
|
||||
#elif (defined(__riscv) && (__riscv_xlen == 64))
|
||||
/**
|
||||
* RISC-V 64bit (14 * 8):
|
||||
* - s0-s11, ra, sp
|
||||
*/
|
||||
#define _jblen (14 * 8)
|
||||
#endif
|
||||
|
||||
struct __jmp_buf {
|
||||
char regs[_jblen];
|
||||
};
|
||||
|
||||
typedef struct __jmp_buf jmp_buf[1];
|
||||
typedef struct __jmp_buf sigjmp_buf[1];
|
||||
|
||||
extern int setjmp(jmp_buf);
|
||||
extern void longjmp(jmp_buf, int val);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
30
libs/libc/include/shadow.h
Normal file
30
libs/libc/include/shadow.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef _LIBC_SHADOW_H
|
||||
#define _LIBC_SHADOW_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
struct spwd {
|
||||
char* sp_namp;
|
||||
char* sp_pwdp;
|
||||
int sp_lstchg;
|
||||
int sp_min;
|
||||
int sp_max;
|
||||
int sp_warn;
|
||||
int sp_inact;
|
||||
int sp_expire;
|
||||
uint32_t sp_flag;
|
||||
};
|
||||
|
||||
typedef struct spwd spwd_t;
|
||||
|
||||
void setspent();
|
||||
void endspent();
|
||||
spwd_t* getspent();
|
||||
spwd_t* getspnam(const char* name);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SHADOW_H
|
||||
17
libs/libc/include/signal.h
Normal file
17
libs/libc/include/signal.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _LIBC_SIGNAL_H
|
||||
#define _LIBC_SIGNAL_H
|
||||
|
||||
#include <bits/signal.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int kill(pid_t pid, int sig);
|
||||
int sigaction(int signo, sighandler_t callback);
|
||||
sighandler_t signal(int signo, sighandler_t callback);
|
||||
int raise(int sig);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SIGNAL_H
|
||||
15
libs/libc/include/stdarg.h
Normal file
15
libs/libc/include/stdarg.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _LIBC_STDARG_H
|
||||
#define _LIBC_STDARG_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define va_start(v, l) __builtin_va_start(v, l)
|
||||
#define va_end(v) __builtin_va_end(v)
|
||||
#define va_arg(v, l) __builtin_va_arg(v, l)
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_STDARG_H
|
||||
41
libs/libc/include/stdatomic.h
Normal file
41
libs/libc/include/stdatomic.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#ifndef _LIBC_STDATOMIC_H
|
||||
#define _LIBC_STDATOMIC_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
typedef enum {
|
||||
memory_order_relaxed = __ATOMIC_RELAXED,
|
||||
memory_order_consume = __ATOMIC_CONSUME,
|
||||
memory_order_acquire = __ATOMIC_ACQUIRE,
|
||||
memory_order_release = __ATOMIC_RELEASE,
|
||||
memory_order_acq_rel = __ATOMIC_ACQ_REL,
|
||||
memory_order_seq_cst = __ATOMIC_SEQ_CST
|
||||
} memory_order;
|
||||
|
||||
typedef _Atomic bool atomic_bool;
|
||||
typedef _Atomic char atomic_char;
|
||||
typedef _Atomic signed char atomic_schar;
|
||||
typedef _Atomic unsigned char atomic_uchar;
|
||||
typedef _Atomic short atomic_short;
|
||||
typedef _Atomic unsigned short atomic_ushort;
|
||||
typedef _Atomic int atomic_int;
|
||||
typedef _Atomic unsigned int atomic_uint;
|
||||
typedef _Atomic long atomic_long;
|
||||
typedef _Atomic unsigned long atomic_ulong;
|
||||
typedef _Atomic long long atomic_llong;
|
||||
typedef _Atomic unsigned long long atomic_ullong;
|
||||
|
||||
#define atomic_add_explicit(x, val, ord) (__atomic_add_fetch(x, val, ord))
|
||||
#define atomic_store_explicit(x, val, ord) (__atomic_store_n(x, val, ord))
|
||||
#define atomic_load_explicit(x, ord) (__atomic_load_n(x, ord))
|
||||
|
||||
#define atomic_add(x, val) (atomic_add_explicit(x, val, __ATOMIC_SEQ_CST))
|
||||
#define atomic_store(x, val) (atomic_store_explicit(x, val, __ATOMIC_SEQ_CST))
|
||||
#define atomic_load(x) (atomic_load_explicit(x, __ATOMIC_SEQ_CST))
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif //_LIBC_STDATOMIC_H
|
||||
17
libs/libc/include/stdbool.h
Normal file
17
libs/libc/include/stdbool.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _LIBC_STDBOOL_H
|
||||
#define _LIBC_STDBOOL_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#ifndef __bool_true_false_are_defined
|
||||
#define bool _Bool
|
||||
#define true (1)
|
||||
#define false (0)
|
||||
#define __bool_true_false_are_defined 1
|
||||
#endif // __bool_true_false_are_defined
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif //_LIBC_STDBOOL_H
|
||||
43
libs/libc/include/stddef.h
Normal file
43
libs/libc/include/stddef.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef _LIBC_STDDEF_H
|
||||
#define _LIBC_STDDEF_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#ifdef __i386__
|
||||
#if defined(__clang__)
|
||||
typedef unsigned int size_t;
|
||||
typedef int ssize_t;
|
||||
typedef int ptrdiff_t;
|
||||
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||
typedef unsigned long size_t;
|
||||
typedef long ssize_t;
|
||||
typedef long ptrdiff_t;
|
||||
#endif
|
||||
#elif __x86_64__
|
||||
typedef unsigned long size_t;
|
||||
typedef long long ssize_t;
|
||||
typedef long long ptrdiff_t;
|
||||
#elif __arm__
|
||||
typedef unsigned int size_t;
|
||||
typedef int ssize_t;
|
||||
typedef int ptrdiff_t;
|
||||
#elif __aarch64__
|
||||
typedef unsigned long size_t;
|
||||
typedef long long ssize_t;
|
||||
typedef long long ptrdiff_t;
|
||||
#elif defined(__riscv) && (__riscv_xlen == 64)
|
||||
typedef unsigned long size_t;
|
||||
typedef long long ssize_t;
|
||||
typedef long long ptrdiff_t;
|
||||
#endif
|
||||
|
||||
#define NULL ((void*)0)
|
||||
|
||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_STDDEF_H
|
||||
110
libs/libc/include/stdint.h
Normal file
110
libs/libc/include/stdint.h
Normal file
@@ -0,0 +1,110 @@
|
||||
#ifndef _LIBC_STDINT_H
|
||||
#define _LIBC_STDINT_H
|
||||
|
||||
#include <bits/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#ifndef __stdints_defined
|
||||
#define __stdints_defined
|
||||
typedef __int8_t int8_t;
|
||||
typedef __int16_t int16_t;
|
||||
typedef __int32_t int32_t;
|
||||
typedef __int64_t int64_t;
|
||||
typedef __uint8_t uint8_t;
|
||||
typedef __uint16_t uint16_t;
|
||||
typedef __uint32_t uint32_t;
|
||||
typedef __uint64_t uint64_t;
|
||||
#endif // __stdints_defined
|
||||
|
||||
#ifndef __stdleastints_defined
|
||||
#define __stdleastints_defined
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
#endif // __stdleastints_defined
|
||||
|
||||
#ifndef __stdfastints_defined
|
||||
#define __stdfastints_defined
|
||||
typedef int32_t int_fast8_t;
|
||||
typedef int32_t int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
typedef uint32_t uint_fast8_t;
|
||||
typedef uint32_t uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
#endif // __stdfastints_defined
|
||||
|
||||
#ifndef __stdptrints_defined
|
||||
#define __stdptrints_defined
|
||||
#ifdef BITS64
|
||||
typedef int64_t intptr_t;
|
||||
typedef uint64_t uintptr_t;
|
||||
#elif defined(BITS32)
|
||||
typedef int32_t intptr_t;
|
||||
typedef uint32_t uintptr_t;
|
||||
#else
|
||||
#error Unknown BITSx?
|
||||
#endif
|
||||
#endif // __stdptrints_defined
|
||||
|
||||
#ifndef __stdmaxints_defined
|
||||
#define __stdmaxints_defined
|
||||
typedef int64_t intmax_t;
|
||||
#endif // __stdmaxints_defined
|
||||
|
||||
#ifndef __stdintmacroses_defined
|
||||
#define __stdintmacroses_defined
|
||||
#define INT8_MAX 0x7f
|
||||
#define INT8_MIN (-INT8_MAX - 1)
|
||||
#define UINT8_MAX (INT8_MAX * 2 + 1)
|
||||
|
||||
#define INT16_MAX 0x7fff
|
||||
#define INT16_MIN (-INT16_MAX - 1)
|
||||
#define UINT16_MAX (INT16_MAX * 2U + 1U)
|
||||
|
||||
#define INT32_MAX 0x7fffffffL
|
||||
#define INT32_MIN (-INT32_MAX - 1L)
|
||||
#define UINT32_MAX (INT32_MAX * 2UL + 1UL)
|
||||
|
||||
#define INT64_MAX 0x7fffffffffffffffLL
|
||||
#define INT64_MIN (-INT64_MAX - 1LL)
|
||||
#define UINT64_MAX (INT64_MAX * 2ULL + 1ULL)
|
||||
|
||||
#define INT_LEAST8_MAX INT8_MAX
|
||||
#define INT_LEAST8_MIN INT8_MIN
|
||||
#define UINT_LEAST8_MAX UINT8_MAX
|
||||
#define INT_LEAST16_MAX INT16_MAX
|
||||
#define INT_LEAST16_MIN INT16_MIN
|
||||
#define UINT_LEAST16_MAX UINT16_MAX
|
||||
#define INT_LEAST32_MAX INT32_MAX
|
||||
#define INT_LEAST32_MIN INT32_MIN
|
||||
#define UINT_LEAST32_MAX UINT32_MAX
|
||||
#define INT_LEAST64_MAX INT64_MAX
|
||||
#define INT_LEAST64_MIN INT64_MIN
|
||||
#define UINT_LEAST64_MAX UINT64_MAX
|
||||
|
||||
#define INT_FAST8_MAX INT8_MAX
|
||||
#define INT_FAST8_MIN INT8_MIN
|
||||
#define UINT_FAST8_MAX UINT8_MAX
|
||||
#define INT_FAST16_MAX INT16_MAX
|
||||
#define INT_FAST16_MIN INT16_MIN
|
||||
#define UINT_FAST16_MAX UINT16_MAX
|
||||
#define INT_FAST32_MAX INT32_MAX
|
||||
#define INT_FAST32_MIN INT32_MIN
|
||||
#define UINT_FAST32_MAX UINT32_MAX
|
||||
#define INT_FAST64_MAX INT64_MAX
|
||||
#define INT_FAST64_MIN INT64_MIN
|
||||
#define UINT_FAST64_MAX UINT64_MAX
|
||||
#endif // __stdintmacroses_defined
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif //_LIBC_STDINT_H
|
||||
112
libs/libc/include/stdio.h
Normal file
112
libs/libc/include/stdio.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#ifndef _LIBC_STDIO_H
|
||||
#define _LIBC_STDIO_H
|
||||
|
||||
#include <bits/fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define _IOFBF 0 /* setvbuf should set fully buffered */
|
||||
#define _IOLBF 1 /* setvbuf should set line buffered */
|
||||
#define _IONBF 2 /* setvbuf should set unbuffered */
|
||||
#define BUFSIZ 1024 /* size of buffer used by setbuf */
|
||||
#define EOF (-1)
|
||||
#define UNGOTC_EMPTY (-0x400)
|
||||
|
||||
/* Define stdin, stdout and stderr macros for better readability. */
|
||||
#define STDIN 0
|
||||
#define STDOUT 1
|
||||
#define STDERR 2
|
||||
|
||||
typedef struct __fbuf __fbuf_t;
|
||||
typedef struct __rwbuf __rwbuf_t;
|
||||
typedef struct __file FILE;
|
||||
|
||||
extern FILE* stdin;
|
||||
extern FILE* stdout;
|
||||
extern FILE* stderr;
|
||||
|
||||
/* Open a file. Returns a struct representing an open file allocated on the
|
||||
heap. The possible mode combinations are: r, w, a, r+ and w+. Returns NULL
|
||||
if anything goes wrong. */
|
||||
FILE* fopen(const char* filename, const char* mode);
|
||||
|
||||
/* Deallocate the file and close it. Any remaining data is flushed. Returns 0
|
||||
on success, or EOF on failure. */
|
||||
int fclose(FILE* stream);
|
||||
|
||||
/* Read up to 'count' objects, each of 'size' size into 'buf' from 'stream' */
|
||||
size_t fread(void* buf, size_t size, size_t count, FILE* stream);
|
||||
|
||||
/* Write up to 'count' objects, each of 'size' size into 'stream' from 'buf'. */
|
||||
size_t fwrite(const void* buf, size_t size, size_t count, FILE* stream);
|
||||
|
||||
/* Set the file indicator to 'offset', starting from 'origin'. */
|
||||
int fseek(FILE* stream, uint32_t offset, int origin);
|
||||
|
||||
/* Flush all buffers, writing all stored data into the stored device/file. */
|
||||
int fflush(FILE* stream);
|
||||
|
||||
/* Put a single character to the given stream. 'putchar' will write the char
|
||||
to stdout. */
|
||||
int fputc(int c, FILE* stream);
|
||||
int putc(int c, FILE* stream) __use_instead("fputc");
|
||||
int putchar(int c);
|
||||
|
||||
/* Put a string to the given stream with a newline at the end, 'puts' writes
|
||||
to stdout by default. */
|
||||
int fputs(const char* s, FILE* stream);
|
||||
int puts(const char* s);
|
||||
|
||||
/* Read/place back a char from the given stream. 'getchar' will get a single
|
||||
char from stdin. */
|
||||
int fgetc(FILE* stream);
|
||||
int getc(FILE* stream) __use_instead("fgets");
|
||||
int getchar();
|
||||
int ungetc(int c, FILE* stream);
|
||||
|
||||
/* Get a string from the given stream, of max 'size'. */
|
||||
char* fgets(char* str, int size, FILE* stream);
|
||||
char* gets(char* str);
|
||||
|
||||
/* Checks whether the end-of-File indicator associated with stream is set,
|
||||
returning a value different from zero if it is. */
|
||||
int feof(FILE* stream);
|
||||
|
||||
/* Set the buffering mode of the stream. 'mode' can either be _IOFBF, _IOLBF
|
||||
or _IONBF. If 'buf' is NULL, resize the internal buffer to 'size'. If 'buf'
|
||||
is instead not NULL, it changes the internal buffer to the user provided
|
||||
one of size 'size'. Return -1 if something goes wrong. */
|
||||
int setvbuf(FILE* stream, char* buf, int mode, size_t size);
|
||||
|
||||
/* Set the buffering mode to full buffering if 'buf' is provided. The minimum
|
||||
size of the buffer should be BUFSIZ, or it could lead to a buffer overflow.
|
||||
If 'buf' is NULL, buffering it turned off. */
|
||||
void setbuf(FILE* stream, char* buf);
|
||||
|
||||
/* Set the buffering mode of the given stream to _IOLBF. */
|
||||
void setlinebuf(FILE* stream);
|
||||
|
||||
/* Works the same as the C standard says, check there. */
|
||||
int vsnprintf(char* buf, size_t n, const char* fmt, va_list arg);
|
||||
int vsprintf(char* buf, const char* fmt, va_list arg);
|
||||
int snprintf(char* buf, size_t n, const char* fmt, ...);
|
||||
int sprintf(char* buf, const char* fmt, ...);
|
||||
int fprintf(FILE* stream, const char* fmt, ...);
|
||||
int printf(const char* fmt, ...);
|
||||
|
||||
/* Scan a buffer for the provided values. Works similarly to printf, but it
|
||||
reads instead of writes. 'scanf' reads from stdin instead of a buffer. Note
|
||||
that using these functions may be unsafe. Never trust the user! */
|
||||
int vsscanf(const char* buf, const char* fmt, va_list arg);
|
||||
int sscanf(const char* buf, const char* fmt, ...);
|
||||
int scanf(const char* fmt, ...);
|
||||
|
||||
/* Dump information about the stream to stdout. */
|
||||
int __stream_info(FILE* stream);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_STDIO_H
|
||||
64
libs/libc/include/stdlib.h
Normal file
64
libs/libc/include/stdlib.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef _LIBC_STDLIB_H
|
||||
#define _LIBC_STDLIB_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/environ.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define EXIT_FAILURE 1
|
||||
#define EXIT_SUCCESS 0
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#ifndef max
|
||||
#define max(a, b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a > _b ? _a : _b; })
|
||||
#endif /* max */
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
__typeof__ (b) _b = (b); \
|
||||
_a < _b ? _a : _b; })
|
||||
#endif /* min */
|
||||
#endif /* NOMINMAX */
|
||||
|
||||
static inline int abs(int i)
|
||||
{
|
||||
return i < 0 ? -i : i;
|
||||
}
|
||||
|
||||
/* malloc */
|
||||
extern void* malloc(size_t);
|
||||
extern void free(void*);
|
||||
extern void* calloc(size_t, size_t);
|
||||
extern void* realloc(void*, size_t);
|
||||
|
||||
/* tools */
|
||||
int atoi(const char* s);
|
||||
|
||||
/* exit */
|
||||
void abort() __attribute__((noreturn));
|
||||
void exit(int status) __attribute__((noreturn));
|
||||
|
||||
/* pts */
|
||||
int posix_openpt(int flags);
|
||||
int ptsname_r(int fd, char* buf, size_t buflen);
|
||||
char* ptsname(int fd);
|
||||
|
||||
/* env */
|
||||
int putenv(char* string);
|
||||
char* getenv(const char* name);
|
||||
int setenv(const char* name, const char* value, int overwrite);
|
||||
int unsetenv(const char* name);
|
||||
|
||||
long strtol(const char* nptr, char** endptr, int base);
|
||||
void qsort(void* base, size_t nitems, size_t size, int (*compar)(const void*, const void*));
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_STDLIB_H
|
||||
57
libs/libc/include/string.h
Normal file
57
libs/libc/include/string.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef _LIBC_STRING_H
|
||||
#define _LIBC_STRING_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
/* Set 'nbytes' to 'fill' starting from 'dest'. */
|
||||
void* memset(void* dest, int fill, size_t nbytes);
|
||||
|
||||
/* Move 'nbytes' from 'src' to 'dest' */
|
||||
void* memmove(void* dest, const void* __restrict src, size_t nbytes);
|
||||
|
||||
/* Copy 'nbytes' from 'src' to 'dest'. See the comment in the source file
|
||||
about optimization and restricting pointers. */
|
||||
void* memcpy(void* __restrict dest, const void* __restrict src, size_t nbytes);
|
||||
|
||||
/* Copy 'nbytes' from 'src' to 'dest', stopping if the current byte matches
|
||||
'stop'. Note that the stop byte also gets copied over. */
|
||||
void* memccpy(void* dest, const void* __restrict src, int stop, size_t nbytes);
|
||||
|
||||
/* Compare 'nbytes' from 'src1' and 'src2'. Return 0 if all the bytes match,
|
||||
otherwise return the difference. */
|
||||
int memcmp(const void* src1, const void* src2, size_t nbytes);
|
||||
void* memchr(const void* ptr, int c, size_t size);
|
||||
|
||||
/* Calculate the string length starting from 'str'. */
|
||||
size_t strlen(const char* str);
|
||||
|
||||
/* Copy 'src' into 'dest' until it finds a null byte in the source string.
|
||||
Note that this is dangerous because it writes memory no matter the size
|
||||
the 'dest' buffer is. */
|
||||
char* strcpy(char* dest, const char* src);
|
||||
int strcmp(const char* a, const char* b);
|
||||
int strncmp(const char* a, const char* b, size_t nbytes);
|
||||
|
||||
/* Copy 'src' into 'dest' until it finds a null byte or reaches the 'nbytes'
|
||||
limit provided by the user. This is the recommended way of copying strings,
|
||||
instead of using regular strcpy. Note that this will fill the 'dest' buffer
|
||||
with null bytes if the amount of copied bytes is lower than 'nbytes'. */
|
||||
char* strncpy(char* dest, const char* src, size_t nbytes);
|
||||
|
||||
/* Returns a pointer to the first occurrence of character in the C string str. */
|
||||
char* strchr(const char* s, int c);
|
||||
|
||||
char* strtok_r(char* str, const char* delim, char** saveptr);
|
||||
char* strtok(char* str, const char* delim);
|
||||
|
||||
char* strstr(const char* haystack, const char* needle);
|
||||
char* strcat(char* dest, const char* src);
|
||||
char* strrchr(const char* str, int ch);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_STRING_H
|
||||
4
libs/libc/include/sys/_structs.h
Normal file
4
libs/libc/include/sys/_structs.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef _LIBC_SYS__STRUCTS_H
|
||||
#define _LIBC_SYS__STRUCTS_H
|
||||
|
||||
#endif
|
||||
10
libs/libc/include/sys/_types/_devs.h
Normal file
10
libs/libc/include/sys/_types/_devs.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _LIBC_SYS__TYPES__DEVS_H
|
||||
#define _LIBC_SYS__TYPES__DEVS_H
|
||||
|
||||
#define MINORBITS 20
|
||||
#define MINORMASK ((1U << MINORBITS) - 1)
|
||||
#define major(dev) ((unsigned int)((dev) >> MINORBITS))
|
||||
#define minor(dev) ((unsigned int)((dev)&MINORMASK))
|
||||
#define makedev(ma, mi) (((ma) << MINORBITS) | (mi))
|
||||
|
||||
#endif // _LIBC_SYS__TYPES__DEVS_H
|
||||
77
libs/libc/include/sys/_types/_ints.h
Normal file
77
libs/libc/include/sys/_types/_ints.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef _LIBC_SYS__TYPES__INTS_H
|
||||
#define _LIBC_SYS__TYPES__INTS_H
|
||||
|
||||
#include <bits/types.h>
|
||||
|
||||
#ifndef __stdints_defined
|
||||
#define __stdints_defined
|
||||
typedef __int8_t int8_t;
|
||||
typedef __int16_t int16_t;
|
||||
typedef __int32_t int32_t;
|
||||
typedef __int64_t int64_t;
|
||||
typedef __uint8_t uint8_t;
|
||||
typedef __uint16_t uint16_t;
|
||||
typedef __uint32_t uint32_t;
|
||||
typedef __uint64_t uint64_t;
|
||||
#endif // __stdints_defined
|
||||
|
||||
#ifndef __dev_t_defined
|
||||
#define __dev_t_defined
|
||||
typedef __dev_t dev_t;
|
||||
#endif // __dev_t_defined
|
||||
|
||||
#ifndef __uid_t_defined
|
||||
#define __uid_t_defined
|
||||
typedef __uid_t uid_t;
|
||||
#endif // __uid_t_defined
|
||||
|
||||
#ifndef __gid_t_defined
|
||||
#define __gid_t_defined
|
||||
typedef __gid_t gid_t;
|
||||
#endif // __gid_t_defined
|
||||
|
||||
#ifndef __ino_t_defined
|
||||
#define __ino_t_defined
|
||||
typedef __ino_t ino_t;
|
||||
#endif // __ino_t_defined
|
||||
|
||||
#ifndef __ino64_t_defined
|
||||
#define __ino64_t_defined
|
||||
typedef __ino64_t ino64_t;
|
||||
#endif // __ino64_t_defined
|
||||
|
||||
#ifndef __mode_t_defined
|
||||
#define __mode_t_defined
|
||||
typedef __mode_t mode_t;
|
||||
#endif // __mode_t_defined
|
||||
|
||||
#ifndef __nlink_t_defined
|
||||
#define __nlink_t_defined
|
||||
typedef __nlink_t nlink_t;
|
||||
#endif // __nlink_t_defined
|
||||
|
||||
#ifndef __off_t_defined
|
||||
#define __off_t_defined
|
||||
typedef __off_t off_t;
|
||||
#endif // __off_t_defined
|
||||
|
||||
#ifndef __off64_t_defined
|
||||
#define __off64_t_defined
|
||||
typedef __off64_t off64_t;
|
||||
#endif // __off64_t_defined
|
||||
|
||||
#ifndef __pid_t_defined
|
||||
#define __pid_t_defined
|
||||
typedef __pid_t pid_t;
|
||||
#endif // __pid_t_defined
|
||||
|
||||
#ifndef __fsid_t_defined
|
||||
#define __fsid_t_defined
|
||||
typedef __fsid_t fsid_t;
|
||||
#endif // __fsid_t_defined
|
||||
|
||||
#ifndef __time_t_defined
|
||||
#define __time_t_defined
|
||||
typedef __time_t time_t;
|
||||
#endif // __time_t_defined
|
||||
#endif // _LIBC_SYS__TYPES__INTS_H
|
||||
6
libs/libc/include/sys/_types/_va_list.h
Normal file
6
libs/libc/include/sys/_types/_va_list.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _LIBC_SYS__TYPES__VA_LIST_H
|
||||
#define _LIBC_SYS__TYPES__VA_LIST_H
|
||||
|
||||
typedef __builtin_va_list va_list;
|
||||
|
||||
#endif // _LIBC_SYS__TYPES__VA_LIST_H
|
||||
23
libs/libc/include/sys/cdefs.h
Normal file
23
libs/libc/include/sys/cdefs.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef _LIBC_SYS_CDEFS_H
|
||||
#define _LIBC_SYS_CDEFS_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#define __BEGIN_DECLS extern "C" {
|
||||
#define __END_DECLS }
|
||||
#else
|
||||
#define __BEGIN_DECLS
|
||||
#define __END_DECLS
|
||||
#endif
|
||||
|
||||
/* Define __use_instead macro for some functions so the user can be warned
|
||||
about better/faster functions. */
|
||||
#ifndef __use_instead
|
||||
#ifdef __clang__
|
||||
#define __use_instead(F) __attribute__((diagnose_if(1, "use " F " instead", \
|
||||
"warning")))
|
||||
#elif defined(__GNUC__)
|
||||
#define __use_instead(F) __attribute__((warning("use " F " instead")))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif // _LIBC_SYS_CDEFS_H
|
||||
12
libs/libc/include/sys/environ.h
Normal file
12
libs/libc/include/sys/environ.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _LIBC_SYS_ENVIRON_H
|
||||
#define _LIBC_SYS_ENVIRON_H
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
extern char** environ;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYS_ENVIRON_H
|
||||
16
libs/libc/include/sys/ioctl.h
Normal file
16
libs/libc/include/sys/ioctl.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _LIBC_SYS_IOCTL_H
|
||||
#define _LIBC_SYS_IOCTL_H
|
||||
|
||||
#include <bits/sys/ioctls.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int ioctl(int fd, uintptr_t cmd, uintptr_t arg);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYS_IOCTL_H
|
||||
16
libs/libc/include/sys/mman.h
Normal file
16
libs/libc/include/sys/mman.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _LIBC_SYS_MMAN_H
|
||||
#define _LIBC_SYS_MMAN_H
|
||||
|
||||
#include <bits/sys/mman.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset);
|
||||
int munmap(void* addr, size_t length);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYS_MMAN_H
|
||||
15
libs/libc/include/sys/ptrace.h
Normal file
15
libs/libc/include/sys/ptrace.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _LIBC_SYS_PTRACE_H
|
||||
#define _LIBC_SYS_PTRACE_H
|
||||
|
||||
#include <bits/sys/ptrace.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int ptrace(ptrace_request_t request, pid_t pid, void* addr, void* data);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYS_PTRACE_H
|
||||
16
libs/libc/include/sys/select.h
Normal file
16
libs/libc/include/sys/select.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef _LIBC_SYS_SELECT_H
|
||||
#define _LIBC_SYS_SELECT_H
|
||||
|
||||
#include <bits/sys/select.h>
|
||||
#include <bits/time.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int select(int nfds, fd_set_t* readfds, fd_set_t* writefds, fd_set_t* exceptfds, timeval_t* timeout);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYS_SELECT_H
|
||||
17
libs/libc/include/sys/socket.h
Normal file
17
libs/libc/include/sys/socket.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _LIBC_SYS_SOCKET_H
|
||||
#define _LIBC_SYS_SOCKET_H
|
||||
|
||||
#include <bits/sys/socket.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int socket(int domain, int type, int protocol);
|
||||
int bind(int sockfd, const char* name, int len);
|
||||
int connect(int sockfd, const char* name, int len);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYS_SOCKET_H
|
||||
15
libs/libc/include/sys/stat.h
Normal file
15
libs/libc/include/sys/stat.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _LIBC_SYS_STAT_H
|
||||
#define _LIBC_SYS_STAT_H
|
||||
|
||||
#include <bits/sys/stat.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int mkdir(const char* path);
|
||||
int fstat(int nfds, stat_t* stat);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
14
libs/libc/include/sys/time.h
Normal file
14
libs/libc/include/sys/time.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _LIBC_SYS_TIME_H
|
||||
#define _LIBC_SYS_TIME_H
|
||||
|
||||
#include <bits/time.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int gettimeofday(timeval_t* tv, timezone_t* tz);
|
||||
int settimeofday(const timeval_t* tv, const timezone_t* tz);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
8
libs/libc/include/sys/types.h
Normal file
8
libs/libc/include/sys/types.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _LIBC_SYS_TYPES_H
|
||||
#define _LIBC_SYS_TYPES_H
|
||||
|
||||
#include <sys/_types/_devs.h>
|
||||
#include <sys/_types/_ints.h>
|
||||
#include <sys/_types/_va_list.h>
|
||||
|
||||
#endif /* _LIBC_SYS_TYPES_H */
|
||||
13
libs/libc/include/sys/utsname.h
Normal file
13
libs/libc/include/sys/utsname.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _LIBC_SYS_UTSNAME_H
|
||||
#define _LIBC_SYS_UTSNAME_H
|
||||
|
||||
#include <bits/sys/utsname.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int uname(utsname_t* buf);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYS_UTSNAME_H
|
||||
17
libs/libc/include/sys/wait.h
Normal file
17
libs/libc/include/sys/wait.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _LIBC_SYS_WAIT_H
|
||||
#define _LIBC_SYS_WAIT_H
|
||||
|
||||
#include <bits/sys/wait.h>
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int wait(int pid);
|
||||
int waitpid(int pid, int* status, int options);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYS_WAIT_H
|
||||
94
libs/libc/include/sysdep.h
Normal file
94
libs/libc/include/sysdep.h
Normal file
@@ -0,0 +1,94 @@
|
||||
#ifndef _LIBC_SYSDEP_H
|
||||
#define _LIBC_SYSDEP_H
|
||||
|
||||
#include <bits/syscalls.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
static inline intptr_t _syscall_impl(sysid_t sysid, intptr_t p1, intptr_t p2, intptr_t p3, intptr_t p4, intptr_t p5)
|
||||
{
|
||||
intptr_t ret;
|
||||
#ifdef __i386__
|
||||
asm volatile("push %%ebx;movl %2,%%ebx;int $0x80;pop %%ebx"
|
||||
: "=a"(ret)
|
||||
: "0"(sysid), "r"((intptr_t)(p1)), "c"((intptr_t)(p2)), "d"((intptr_t)(p3)), "S"((intptr_t)(p4)), "D"((intptr_t)(p5))
|
||||
: "memory");
|
||||
#elif __x86_64__
|
||||
asm volatile(
|
||||
"movq %1, %%rax;\
|
||||
movq %2, %%rdi;\
|
||||
movq %3, %%rsi;\
|
||||
movq %4, %%rdx;\
|
||||
movq %5, %%r10;\
|
||||
movq %6, %%r8;\
|
||||
int $0x80;\
|
||||
movq %%rax, %0;"
|
||||
: "=r"(ret)
|
||||
: "r"(sysid), "r"((intptr_t)(p1)), "r"((intptr_t)(p2)), "r"((intptr_t)(p3)), "r"((intptr_t)(p4)), "r"((intptr_t)(p5))
|
||||
: "memory", "rax", "rdi", "rsi", "rdx", "r10", "r8");
|
||||
#elif __arm__
|
||||
asm volatile(
|
||||
"mov r7, %1;\
|
||||
mov r0, %2;\
|
||||
mov r1, %3;\
|
||||
mov r2, %4;\
|
||||
mov r3, %5;\
|
||||
mov r4, %6;\
|
||||
swi 1;\
|
||||
mov %0, r0;"
|
||||
: "=r"(ret)
|
||||
: "r"(sysid), "r"((intptr_t)(p1)), "r"((intptr_t)(p2)), "r"((intptr_t)(p3)), "r"((intptr_t)(p4)), "r"((intptr_t)(p5))
|
||||
: "memory", "r0", "r1", "r2", "r3", "r4", "r7");
|
||||
#elif __aarch64__
|
||||
asm volatile(
|
||||
"mov x8, %x1;\
|
||||
mov x0, %x2;\
|
||||
mov x1, %x3;\
|
||||
mov x2, %x4;\
|
||||
mov x3, %x5;\
|
||||
mov x4, %x6;\
|
||||
svc 1;\
|
||||
mov %x0, x0;"
|
||||
: "=r"(ret)
|
||||
: "r"(sysid), "r"((intptr_t)(p1)), "r"((intptr_t)(p2)), "r"((intptr_t)(p3)), "r"((intptr_t)(p4)), "r"((intptr_t)(p5))
|
||||
: "memory", "x0", "x1", "x2", "x3", "x4", "x8");
|
||||
#elif defined(__riscv) && (__riscv_xlen == 64)
|
||||
// TODO: Check copatability with Linux.
|
||||
asm volatile(
|
||||
"mv a7, %1;\
|
||||
mv a0, %2;\
|
||||
mv a1, %3;\
|
||||
mv a2, %4;\
|
||||
mv a3, %5;\
|
||||
mv a4, %6;\
|
||||
ecall;\
|
||||
mv %0, a0;"
|
||||
: "=r"(ret)
|
||||
: "r"(sysid), "r"((intptr_t)(p1)), "r"((intptr_t)(p2)), "r"((intptr_t)(p3)), "r"((intptr_t)(p4)), "r"((intptr_t)(p5))
|
||||
: "memory", "a0", "a1", "a2", "a3", "a4", "a7");
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define DO_SYSCALL_0(type) _syscall_impl(type, 0, 0, 0, 0, 0)
|
||||
#define DO_SYSCALL_1(type, a) _syscall_impl(type, (intptr_t)a, 0, 0, 0, 0)
|
||||
#define DO_SYSCALL_2(type, a, b) _syscall_impl(type, (intptr_t)a, (intptr_t)b, 0, 0, 0)
|
||||
#define DO_SYSCALL_3(type, a, b, c) _syscall_impl(type, (intptr_t)a, (intptr_t)b, (intptr_t)c, 0, 0)
|
||||
#define DO_SYSCALL_4(type, a, b, c, d) _syscall_impl(type, (intptr_t)a, (intptr_t)b, (intptr_t)c, (intptr_t)d, 0)
|
||||
#define DO_SYSCALL_5(type, a, b, c, d, e) _syscall_impl(type, (intptr_t)a, (intptr_t)b, (intptr_t)c, (intptr_t)d, (intptr_t)e);
|
||||
#define RETURN_WITH_ERRNO(res, on_suc, on_fail) \
|
||||
do { \
|
||||
if ((intptr_t)res < 0) { \
|
||||
set_errno(res); \
|
||||
return (on_fail); \
|
||||
} \
|
||||
set_errno(0); \
|
||||
return on_suc; \
|
||||
} while (0);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYSDEP_H
|
||||
75
libs/libc/include/termios.h
Normal file
75
libs/libc/include/termios.h
Normal file
@@ -0,0 +1,75 @@
|
||||
#ifndef _LIBC_TERMIOS_H
|
||||
#define _LIBC_TERMIOS_H
|
||||
|
||||
#include <sys/_structs.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
typedef unsigned char cc_t;
|
||||
typedef unsigned int speed_t;
|
||||
typedef unsigned int tcflag_t;
|
||||
|
||||
#define NCCS 32
|
||||
struct termios {
|
||||
tcflag_t c_iflag; /* input mode flags */
|
||||
tcflag_t c_oflag; /* output mode flags */
|
||||
tcflag_t c_cflag; /* control mode flags */
|
||||
tcflag_t c_lflag; /* local mode flags */
|
||||
cc_t c_cc[NCCS]; /* control characters */
|
||||
};
|
||||
typedef struct termios termios_t;
|
||||
|
||||
/* c_cc characters */
|
||||
#define VINTR 0
|
||||
#define VQUIT 1
|
||||
#define VERASE 2
|
||||
#define VKILL 3
|
||||
#define VEOF 4
|
||||
#define VTIME 5
|
||||
#define VMIN 6
|
||||
#define VSWTC 7
|
||||
#define VSTART 8
|
||||
#define VSTOP 9
|
||||
#define VSUSP 10
|
||||
#define VEOL 11
|
||||
#define VREPRINT 12
|
||||
#define VDISCARD 13
|
||||
#define VWERASE 14
|
||||
#define VLNEXT 15
|
||||
#define VEOL2 16
|
||||
|
||||
/* c_lflag bits */
|
||||
#define ISIG 0000001
|
||||
#define ICANON 0000002
|
||||
#define ECHO 0000010
|
||||
#define ECHOE 0000020
|
||||
#define ECHOK 0000040
|
||||
#define ECHONL 0000100
|
||||
#define NOFLSH 0000200
|
||||
#define TOSTOP 0000400
|
||||
#define IEXTEN 0100000
|
||||
|
||||
/* tcflow() and TCXONC use these */
|
||||
#define TCOOFF 0
|
||||
#define TCOON 1
|
||||
#define TCIOFF 2
|
||||
#define TCION 3
|
||||
|
||||
/* tcflush() and TCFLSH use these */
|
||||
#define TCIFLUSH 0
|
||||
#define TCOFLUSH 1
|
||||
#define TCIOFLUSH 2
|
||||
|
||||
/* tcsetattr uses these */
|
||||
#define TCSANOW 0
|
||||
#define TCSADRAIN 1
|
||||
#define TCSAFLUSH 2
|
||||
|
||||
int tcgetattr(int fd, termios_t* termios_p);
|
||||
int tcsetattr(int fd, int optional_actions, const termios_t* termios_p);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _LIBC_TERMIOS_H */
|
||||
36
libs/libc/include/time.h
Normal file
36
libs/libc/include/time.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef _LIBC_TIME_H
|
||||
#define _LIBC_TIME_H
|
||||
|
||||
#include <bits/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
time_t time(time_t* timep);
|
||||
char* asctime(const tm_t* tm);
|
||||
char* asctime_r(const tm_t* tm, char* buf);
|
||||
|
||||
char* ctime(const time_t* timep);
|
||||
char* ctime_r(const time_t* timep, char* buf);
|
||||
tm_t* gmtime(const time_t* timep);
|
||||
tm_t* gmtime_r(const time_t* timep, tm_t* result);
|
||||
|
||||
tm_t* localtime(const time_t* timep);
|
||||
tm_t* localtime_r(const time_t* timep, tm_t* result);
|
||||
|
||||
size_t strftime(char* s, size_t max, const char* format, const tm_t* tm);
|
||||
|
||||
time_t mktime(tm_t* tm);
|
||||
|
||||
int clock_getres(clockid_t clk_id, timespec_t* res);
|
||||
int clock_gettime(clockid_t clk_id, timespec_t* tp);
|
||||
int clock_settime(clockid_t clk_id, const timespec_t* tp);
|
||||
|
||||
int nanosleep(const timespec_t* req, timespec_t* rem);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_TIME_H
|
||||
58
libs/libc/include/unistd.h
Normal file
58
libs/libc/include/unistd.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef _LIBC_UNISTD_H
|
||||
#define _LIBC_UNISTD_H
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
#define STDIN_FILENO 0 // Standard input file descriptor
|
||||
#define STDOUT_FILENO 1 // Standard output file descriptor
|
||||
#define STDERR_FILENO 2 // Standard error file descriptor
|
||||
|
||||
/* tasking */
|
||||
int fork();
|
||||
int execve(const char* path, char* const argv[], char* const envp[]);
|
||||
int execvpe(const char* path, char* const argv[], char* const envp[]);
|
||||
int execvp(const char* path, char* const argv[]);
|
||||
int execlp(const char* path, const char* arg0, ...);
|
||||
pid_t getpid();
|
||||
int setpgid(pid_t cmd, pid_t arg);
|
||||
pid_t getpgid(pid_t arg);
|
||||
uint32_t sleep(uint32_t seconds);
|
||||
uint32_t usleep(uint32_t usec);
|
||||
|
||||
/* fs */
|
||||
int close(int fd);
|
||||
ssize_t read(int fd, char* buf, size_t count);
|
||||
ssize_t write(int fd, const void* buf, size_t count);
|
||||
int dup(int oldfd);
|
||||
int dup2(int oldfd, int newfd);
|
||||
int rmdir(const char* path);
|
||||
int chdir(const char* path);
|
||||
char* getcwd(char* buf, size_t size);
|
||||
int unlink(const char* path);
|
||||
off_t lseek(int fd, off_t off, int whence);
|
||||
|
||||
/* identity */
|
||||
uid_t getuid();
|
||||
int setuid(uid_t uid);
|
||||
int setgid(gid_t gid);
|
||||
int setreuid(uid_t ruid, uid_t euid);
|
||||
int setregid(gid_t rgid, gid_t egid);
|
||||
char* getlogin();
|
||||
|
||||
/* sched */
|
||||
int nice(int inc);
|
||||
|
||||
/* conf */
|
||||
#define _CS_GNU_LIBC_VERSION 1
|
||||
#define _CS_GNU_LIBPTHREAD_VERSION 2
|
||||
#define _CS_PATH 3
|
||||
size_t confstr(int name, char* buf, size_t len);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_UNISTD_H
|
||||
18
libs/libc/include/x/shared_buffer.h
Normal file
18
libs/libc/include/x/shared_buffer.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _LIBC_SYS_SHARED_BUFFER_H
|
||||
#define _LIBC_SYS_SHARED_BUFFER_H
|
||||
|
||||
#include <bits/sys/select.h>
|
||||
#include <bits/time.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int shared_buffer_create(uint8_t** buffer, size_t size);
|
||||
int shared_buffer_get(int id, uint8_t** buffer);
|
||||
int shared_buffer_free(int id);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif // _LIBC_SYS_SHARED_BUFFER_H
|
||||
Reference in New Issue
Block a user