Squash commits for public release
This commit is contained in:
6
kernel/include/libkern/_types/_va_list.h
Normal file
6
kernel/include/libkern/_types/_va_list.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _KERNEL_LIBKERN__TYPES__VA_LIST_H
|
||||
#define _KERNEL_LIBKERN__TYPES__VA_LIST_H
|
||||
|
||||
typedef __builtin_va_list va_list;
|
||||
|
||||
#endif // _KERNEL_LIBKERN__TYPES__VA_LIST_H
|
||||
12
kernel/include/libkern/atomic.h
Normal file
12
kernel/include/libkern/atomic.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _KERNEL_LIBKERN_ATOMIC_H
|
||||
#define _KERNEL_LIBKERN_ATOMIC_H
|
||||
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/kassert.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
#define atomic_add(x, val) (__atomic_add_fetch(x, val, __ATOMIC_SEQ_CST))
|
||||
#define atomic_store(x, val) (__atomic_store_n(x, val, __ATOMIC_SEQ_CST))
|
||||
#define atomic_load(x) (__atomic_load_n(x, __ATOMIC_SEQ_CST))
|
||||
|
||||
#endif // _KERNEL_LIBKERN_LOCK_H
|
||||
135
kernel/include/libkern/bits/errno.h
Normal file
135
kernel/include/libkern/bits/errno.h
Normal file
@@ -0,0 +1,135 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_ERRNO_H
|
||||
#define _KERNEL_LIBKERN_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 // _KERNEL_LIBKERN_BITS_ERRNO_H
|
||||
19
kernel/include/libkern/bits/fcntl.h
Normal file
19
kernel/include/libkern/bits/fcntl.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_FCNTL_H
|
||||
#define _KERNEL_LIBKERN_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 // _KERNEL_LIBKERN_BITS_FCNTL_H
|
||||
44
kernel/include/libkern/bits/signal.h
Normal file
44
kernel/include/libkern/bits/signal.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_SIGNAL_H
|
||||
#define _KERNEL_LIBKERN_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 // _KERNEL_LIBKERN_BITS_SIGNAL_H
|
||||
18
kernel/include/libkern/bits/sys/ioctls.h
Normal file
18
kernel/include/libkern/bits/sys/ioctls.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_SYS_IOCTLS_H
|
||||
#define _KERNEL_LIBKERN_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 // _KERNEL_LIBKERN_BITS_SYS_IOCTLS_H
|
||||
27
kernel/include/libkern/bits/sys/mman.h
Normal file
27
kernel/include/libkern/bits/sys/mman.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_SYS_MMAN_H
|
||||
#define _KERNEL_LIBKERN_BITS_SYS_MMAN_H
|
||||
|
||||
#include <libkern/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 // _KERNEL_LIBKERN_BITS_SYS_MMAN_H
|
||||
12
kernel/include/libkern/bits/sys/ptrace.h
Normal file
12
kernel/include/libkern/bits/sys/ptrace.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_SYS_PTRACE_H
|
||||
#define _KERNEL_LIBKERN_BITS_SYS_PTRACE_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
typedef int ptrace_request_t;
|
||||
#define PTRACE_TRACEME (0x1)
|
||||
#define PTRACE_CONT (0x2)
|
||||
#define PTRACE_PEEKTEXT (0x3)
|
||||
#define PTRACE_PEEKDATA (0x4)
|
||||
|
||||
#endif // _KERNEL_LIBKERN_BITS_SYS_PTRACE_H
|
||||
18
kernel/include/libkern/bits/sys/select.h
Normal file
18
kernel/include/libkern/bits/sys/select.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_SYS_SELECT_H
|
||||
#define _KERNEL_LIBKERN_BITS_SYS_SELECT_H
|
||||
|
||||
#include <libkern/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 // _KERNEL_LIBKERN_BITS_SYS_SELECT_H
|
||||
26
kernel/include/libkern/bits/sys/socket.h
Normal file
26
kernel/include/libkern/bits/sys/socket.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_SYS_SOCKET_H
|
||||
#define _KERNEL_LIBKERN_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 // _KERNEL_LIBKERN_BITS_SYS_SOCKET_H
|
||||
64
kernel/include/libkern/bits/sys/stat.h
Normal file
64
kernel/include/libkern/bits/sys/stat.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_SYS_STAT_H
|
||||
#define _KERNEL_LIBKERN_BITS_SYS_STAT_H
|
||||
|
||||
#include <libkern/bits/time.h>
|
||||
#include <libkern/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 // _KERNEL_LIBKERN_BITS_SYS_STAT_H
|
||||
15
kernel/include/libkern/bits/sys/utsname.h
Normal file
15
kernel/include/libkern/bits/sys/utsname.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_SYS_UTSNAME_H
|
||||
#define _KERNEL_LIBKERN_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 // _KERNEL_LIBKERN_BITS_SYS_UTSNAME_H
|
||||
7
kernel/include/libkern/bits/sys/wait.h
Normal file
7
kernel/include/libkern/bits/sys/wait.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_SYS_WAIT_H
|
||||
#define _KERNEL_LIBKERN_BITS_SYS_WAIT_H
|
||||
|
||||
#define WNOHANG 0x1
|
||||
#define WUNTRACED 0x2
|
||||
|
||||
#endif // _KERNEL_LIBKERN_BITS_SYS_WAIT_H
|
||||
1129
kernel/include/libkern/bits/syscalls.h
Normal file
1129
kernel/include/libkern/bits/syscalls.h
Normal file
File diff suppressed because it is too large
Load Diff
13
kernel/include/libkern/bits/thread.h
Normal file
13
kernel/include/libkern/bits/thread.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_THREAD_H
|
||||
#define _KERNEL_LIBKERN_BITS_THREAD_H
|
||||
|
||||
#include <libkern/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 // _KERNEL_LIBKERN_BITS_THREAD_H
|
||||
51
kernel/include/libkern/bits/time.h
Normal file
51
kernel/include/libkern/bits/time.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_TIME_H
|
||||
#define _KERNEL_LIBKERN_BITS_TIME_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
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;
|
||||
|
||||
#endif // _KERNEL_LIBKERN_BITS_TIME_H
|
||||
31
kernel/include/libkern/bits/types.h
Normal file
31
kernel/include/libkern/bits/types.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _KERNEL_LIBKERN_BITS_TYPES_H
|
||||
#define _KERNEL_LIBKERN_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))
|
||||
typedef __int64_t __off_t; /* Type of file sizes and offsets. */
|
||||
#else
|
||||
typedef __int32_t __off_t; /* Type of file sizes and offsets. */
|
||||
#endif
|
||||
|
||||
#endif // _KERNEL_LIBKERN_BITS_TYPES_H
|
||||
24
kernel/include/libkern/c_attrs.h
Normal file
24
kernel/include/libkern/c_attrs.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef _KERNEL_LIBKERN_C_ATTRS_H
|
||||
#define _KERNEL_LIBKERN_C_ATTRS_H
|
||||
|
||||
#ifndef PACKED
|
||||
#define PACKED __attribute__((packed))
|
||||
#endif // PACKED
|
||||
|
||||
#ifndef MAYBE_UNUSED
|
||||
#define MAYBE_UNUSED __attribute__((__unused__))
|
||||
#endif // MAYBE_UNUSED
|
||||
|
||||
#ifndef ALWAYS_INLINE
|
||||
#define ALWAYS_INLINE __attribute__((always_inline)) inline
|
||||
#endif // ALWAYS_INLINE
|
||||
|
||||
#ifndef NORETURN
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
#endif // NORETURN
|
||||
|
||||
#ifndef WARN_UNUSED_RESULT
|
||||
#define WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
|
||||
#endif // WARN_UNUSED_RESULT
|
||||
|
||||
#endif // _KERNEL_LIBKERN_C_ATTRS_H
|
||||
31
kernel/include/libkern/ctype.h
Normal file
31
kernel/include/libkern/ctype.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _KERNEL_LIBKERN_CTYPE_H
|
||||
#define _KERNEL_LIBKERN_CTYPE_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
#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 __kern_ctypes[256];
|
||||
|
||||
static inline int isalnum(int c) { return __kern_ctypes[(unsigned char)(c)] & (_U | _L | _N); }
|
||||
static inline int isalpha(int c) { return __kern_ctypes[(unsigned char)(c)] & (_U | _L); }
|
||||
static inline int iscntrl(int c) { return __kern_ctypes[(unsigned char)(c)] & (_C); }
|
||||
static inline int isdigit(int c) { return __kern_ctypes[(unsigned char)(c)] & (_N); }
|
||||
static inline int isxdigit(int c) { return __kern_ctypes[(unsigned char)(c)] & (_N | _X); }
|
||||
static inline int isspace(int c) { return __kern_ctypes[(unsigned char)(c)] & (_S); }
|
||||
static inline int ispunct(int c) { return __kern_ctypes[(unsigned char)(c)] & (_P); }
|
||||
static inline int isprint(int c) { return __kern_ctypes[(unsigned char)(c)] & (_P | _U | _L | _N | _B); }
|
||||
static inline int isgraph(int c) { return __kern_ctypes[(unsigned char)(c)] & (_P | _U | _L | _N); }
|
||||
static inline int islower(int c) { return (__kern_ctypes[(unsigned char)(c)] & (_U | _L)) == _L; }
|
||||
static inline int isupper(int c) { return (__kern_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; }
|
||||
|
||||
#endif /* _KERNEL_LIBKERN_CTYPE_H */
|
||||
152
kernel/include/libkern/font/font.h
Normal file
152
kernel/include/libkern/font/font.h
Normal file
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* 8x8 monochrome bitmap fonts for rendering
|
||||
* Author: Daniel Hepper <daniel@hepper.net>
|
||||
*
|
||||
* License: Public Domain
|
||||
*
|
||||
* Based on:
|
||||
* // Summary: font8x8.h
|
||||
* // 8x8 monochrome bitmap fonts for rendering
|
||||
* //
|
||||
* // Author:
|
||||
* // Marcel Sondaar
|
||||
* // International Business Machines (public domain VGA fonts)
|
||||
* //
|
||||
* // License:
|
||||
* // Public Domain
|
||||
*
|
||||
* Fetched from: http://dimensionalrift.homelinux.net/combuster/mos3/?p=viewsource&file=/modules/gfx/font8_8.asm
|
||||
**/
|
||||
|
||||
// Constant: font8x8_basic
|
||||
// Contains an 8x8 font map for unicode points U+0000 - U+007F (basic latin)
|
||||
static char font8x8_basic[128][8] = {
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0000 (nul)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0001
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0002
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0003
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0004
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0005
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0006
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0007
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0008
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0009
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000A
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000B
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000C
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000D
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000E
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+000F
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0010
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0011
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0012
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0013
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0014
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0015
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0016
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0017
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0018
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0019
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001A
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001B
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001C
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001D
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001E
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+001F
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0020 (space)
|
||||
{ 0x18, 0x3C, 0x3C, 0x18, 0x18, 0x00, 0x18, 0x00 }, // U+0021 (!)
|
||||
{ 0x36, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0022 (")
|
||||
{ 0x36, 0x36, 0x7F, 0x36, 0x7F, 0x36, 0x36, 0x00 }, // U+0023 (#)
|
||||
{ 0x0C, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x0C, 0x00 }, // U+0024 ($)
|
||||
{ 0x00, 0x63, 0x33, 0x18, 0x0C, 0x66, 0x63, 0x00 }, // U+0025 (%)
|
||||
{ 0x1C, 0x36, 0x1C, 0x6E, 0x3B, 0x33, 0x6E, 0x00 }, // U+0026 (&)
|
||||
{ 0x06, 0x06, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0027 (')
|
||||
{ 0x18, 0x0C, 0x06, 0x06, 0x06, 0x0C, 0x18, 0x00 }, // U+0028 (()
|
||||
{ 0x06, 0x0C, 0x18, 0x18, 0x18, 0x0C, 0x06, 0x00 }, // U+0029 ())
|
||||
{ 0x00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0x00, 0x00 }, // U+002A (*)
|
||||
{ 0x00, 0x0C, 0x0C, 0x3F, 0x0C, 0x0C, 0x00, 0x00 }, // U+002B (+)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x06 }, // U+002C (,)
|
||||
{ 0x00, 0x00, 0x00, 0x3F, 0x00, 0x00, 0x00, 0x00 }, // U+002D (-)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00 }, // U+002E (.)
|
||||
{ 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0x00 }, // U+002F (/)
|
||||
{ 0x3E, 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x3E, 0x00 }, // U+0030 (0)
|
||||
{ 0x0C, 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x3F, 0x00 }, // U+0031 (1)
|
||||
{ 0x1E, 0x33, 0x30, 0x1C, 0x06, 0x33, 0x3F, 0x00 }, // U+0032 (2)
|
||||
{ 0x1E, 0x33, 0x30, 0x1C, 0x30, 0x33, 0x1E, 0x00 }, // U+0033 (3)
|
||||
{ 0x38, 0x3C, 0x36, 0x33, 0x7F, 0x30, 0x78, 0x00 }, // U+0034 (4)
|
||||
{ 0x3F, 0x03, 0x1F, 0x30, 0x30, 0x33, 0x1E, 0x00 }, // U+0035 (5)
|
||||
{ 0x1C, 0x06, 0x03, 0x1F, 0x33, 0x33, 0x1E, 0x00 }, // U+0036 (6)
|
||||
{ 0x3F, 0x33, 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x00 }, // U+0037 (7)
|
||||
{ 0x1E, 0x33, 0x33, 0x1E, 0x33, 0x33, 0x1E, 0x00 }, // U+0038 (8)
|
||||
{ 0x1E, 0x33, 0x33, 0x3E, 0x30, 0x18, 0x0E, 0x00 }, // U+0039 (9)
|
||||
{ 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x00 }, // U+003A (:)
|
||||
{ 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x0C, 0x0C, 0x06 }, // U+003B (;)
|
||||
{ 0x18, 0x0C, 0x06, 0x03, 0x06, 0x0C, 0x18, 0x00 }, // U+003C (<)
|
||||
{ 0x00, 0x00, 0x3F, 0x00, 0x00, 0x3F, 0x00, 0x00 }, // U+003D (=)
|
||||
{ 0x06, 0x0C, 0x18, 0x30, 0x18, 0x0C, 0x06, 0x00 }, // U+003E (>)
|
||||
{ 0x1E, 0x33, 0x30, 0x18, 0x0C, 0x00, 0x0C, 0x00 }, // U+003F (?)
|
||||
{ 0x3E, 0x63, 0x7B, 0x7B, 0x7B, 0x03, 0x1E, 0x00 }, // U+0040 (@)
|
||||
{ 0x0C, 0x1E, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x00 }, // U+0041 (A)
|
||||
{ 0x3F, 0x66, 0x66, 0x3E, 0x66, 0x66, 0x3F, 0x00 }, // U+0042 (B)
|
||||
{ 0x3C, 0x66, 0x03, 0x03, 0x03, 0x66, 0x3C, 0x00 }, // U+0043 (C)
|
||||
{ 0x1F, 0x36, 0x66, 0x66, 0x66, 0x36, 0x1F, 0x00 }, // U+0044 (D)
|
||||
{ 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x46, 0x7F, 0x00 }, // U+0045 (E)
|
||||
{ 0x7F, 0x46, 0x16, 0x1E, 0x16, 0x06, 0x0F, 0x00 }, // U+0046 (F)
|
||||
{ 0x3C, 0x66, 0x03, 0x03, 0x73, 0x66, 0x7C, 0x00 }, // U+0047 (G)
|
||||
{ 0x33, 0x33, 0x33, 0x3F, 0x33, 0x33, 0x33, 0x00 }, // U+0048 (H)
|
||||
{ 0x1E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0049 (I)
|
||||
{ 0x78, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E, 0x00 }, // U+004A (J)
|
||||
{ 0x67, 0x66, 0x36, 0x1E, 0x36, 0x66, 0x67, 0x00 }, // U+004B (K)
|
||||
{ 0x0F, 0x06, 0x06, 0x06, 0x46, 0x66, 0x7F, 0x00 }, // U+004C (L)
|
||||
{ 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0x00 }, // U+004D (M)
|
||||
{ 0x63, 0x67, 0x6F, 0x7B, 0x73, 0x63, 0x63, 0x00 }, // U+004E (N)
|
||||
{ 0x1C, 0x36, 0x63, 0x63, 0x63, 0x36, 0x1C, 0x00 }, // U+004F (O)
|
||||
{ 0x3F, 0x66, 0x66, 0x3E, 0x06, 0x06, 0x0F, 0x00 }, // U+0050 (P)
|
||||
{ 0x1E, 0x33, 0x33, 0x33, 0x3B, 0x1E, 0x38, 0x00 }, // U+0051 (Q)
|
||||
{ 0x3F, 0x66, 0x66, 0x3E, 0x36, 0x66, 0x67, 0x00 }, // U+0052 (R)
|
||||
{ 0x1E, 0x33, 0x07, 0x0E, 0x38, 0x33, 0x1E, 0x00 }, // U+0053 (S)
|
||||
{ 0x3F, 0x2D, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0054 (T)
|
||||
{ 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x3F, 0x00 }, // U+0055 (U)
|
||||
{ 0x33, 0x33, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00 }, // U+0056 (V)
|
||||
{ 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0x00 }, // U+0057 (W)
|
||||
{ 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0x00 }, // U+0058 (X)
|
||||
{ 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0059 (Y)
|
||||
{ 0x7F, 0x63, 0x31, 0x18, 0x4C, 0x66, 0x7F, 0x00 }, // U+005A (Z)
|
||||
{ 0x1E, 0x06, 0x06, 0x06, 0x06, 0x06, 0x1E, 0x00 }, // U+005B ([)
|
||||
{ 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0x00 }, // U+005C (\)
|
||||
{ 0x1E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x00 }, // U+005D (])
|
||||
{ 0x08, 0x1C, 0x36, 0x63, 0x00, 0x00, 0x00, 0x00 }, // U+005E (^)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }, // U+005F (_)
|
||||
{ 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+0060 (`)
|
||||
{ 0x00, 0x00, 0x1E, 0x30, 0x3E, 0x33, 0x6E, 0x00 }, // U+0061 (a)
|
||||
{ 0x07, 0x06, 0x06, 0x3E, 0x66, 0x66, 0x3B, 0x00 }, // U+0062 (b)
|
||||
{ 0x00, 0x00, 0x1E, 0x33, 0x03, 0x33, 0x1E, 0x00 }, // U+0063 (c)
|
||||
{ 0x38, 0x30, 0x30, 0x3e, 0x33, 0x33, 0x6E, 0x00 }, // U+0064 (d)
|
||||
{ 0x00, 0x00, 0x1E, 0x33, 0x3f, 0x03, 0x1E, 0x00 }, // U+0065 (e)
|
||||
{ 0x1C, 0x36, 0x06, 0x0f, 0x06, 0x06, 0x0F, 0x00 }, // U+0066 (f)
|
||||
{ 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x1F }, // U+0067 (g)
|
||||
{ 0x07, 0x06, 0x36, 0x6E, 0x66, 0x66, 0x67, 0x00 }, // U+0068 (h)
|
||||
{ 0x0C, 0x00, 0x0E, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+0069 (i)
|
||||
{ 0x30, 0x00, 0x30, 0x30, 0x30, 0x33, 0x33, 0x1E }, // U+006A (j)
|
||||
{ 0x07, 0x06, 0x66, 0x36, 0x1E, 0x36, 0x67, 0x00 }, // U+006B (k)
|
||||
{ 0x0E, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x1E, 0x00 }, // U+006C (l)
|
||||
{ 0x00, 0x00, 0x33, 0x7F, 0x7F, 0x6B, 0x63, 0x00 }, // U+006D (m)
|
||||
{ 0x00, 0x00, 0x1F, 0x33, 0x33, 0x33, 0x33, 0x00 }, // U+006E (n)
|
||||
{ 0x00, 0x00, 0x1E, 0x33, 0x33, 0x33, 0x1E, 0x00 }, // U+006F (o)
|
||||
{ 0x00, 0x00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F }, // U+0070 (p)
|
||||
{ 0x00, 0x00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78 }, // U+0071 (q)
|
||||
{ 0x00, 0x00, 0x3B, 0x6E, 0x66, 0x06, 0x0F, 0x00 }, // U+0072 (r)
|
||||
{ 0x00, 0x00, 0x3E, 0x03, 0x1E, 0x30, 0x1F, 0x00 }, // U+0073 (s)
|
||||
{ 0x08, 0x0C, 0x3E, 0x0C, 0x0C, 0x2C, 0x18, 0x00 }, // U+0074 (t)
|
||||
{ 0x00, 0x00, 0x33, 0x33, 0x33, 0x33, 0x6E, 0x00 }, // U+0075 (u)
|
||||
{ 0x00, 0x00, 0x33, 0x33, 0x33, 0x1E, 0x0C, 0x00 }, // U+0076 (v)
|
||||
{ 0x00, 0x00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0x00 }, // U+0077 (w)
|
||||
{ 0x00, 0x00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0x00 }, // U+0078 (x)
|
||||
{ 0x00, 0x00, 0x33, 0x33, 0x33, 0x3E, 0x30, 0x1F }, // U+0079 (y)
|
||||
{ 0x00, 0x00, 0x3F, 0x19, 0x0C, 0x26, 0x3F, 0x00 }, // U+007A (z)
|
||||
{ 0x38, 0x0C, 0x0C, 0x07, 0x0C, 0x0C, 0x38, 0x00 }, // U+007B ({)
|
||||
{ 0x18, 0x18, 0x18, 0x00, 0x18, 0x18, 0x18, 0x00 }, // U+007C (|)
|
||||
{ 0x07, 0x0C, 0x0C, 0x38, 0x0C, 0x0C, 0x07, 0x00 }, // U+007D (})
|
||||
{ 0x6E, 0x3B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // U+007E (~)
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } // U+007F
|
||||
};
|
||||
26
kernel/include/libkern/kasan.h
Normal file
26
kernel/include/libkern/kasan.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef _KERNEL_LIBKERN_KASAN_H
|
||||
#define _KERNEL_LIBKERN_KASAN_H
|
||||
|
||||
#ifdef KASAN_ENABLED
|
||||
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/log.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
#define KASAN_FREED_OBJECT (0xfb)
|
||||
#define KASAN_KMALLOC_REDZONE (0xfe)
|
||||
#define KASAN_FREED_PAGE (0xff)
|
||||
|
||||
void kasan_init(uintptr_t shadow_base, size_t shadow_size);
|
||||
bool kasan_is_enabled();
|
||||
void kasan_enable();
|
||||
void kasan_disable();
|
||||
|
||||
uintptr_t kasan_mem_to_shadow(uintptr_t addr);
|
||||
int kasan_poison(uintptr_t addr, size_t size, int value);
|
||||
int kasan_unpoison(uintptr_t addr, size_t size, int value);
|
||||
int kasan_poison_kmalloc(uintptr_t addr, size_t size);
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _KERNEL_LIBKERN_KASAN_H
|
||||
35
kernel/include/libkern/kassert.h
Normal file
35
kernel/include/libkern/kassert.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef _KERNEL_LIBKERN_KASSERT_H
|
||||
#define _KERNEL_LIBKERN_KASSERT_H
|
||||
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/log.h>
|
||||
#include <libkern/types.h>
|
||||
#include <platform/generic/system.h>
|
||||
#include <platform/generic/tasking/trapframe.h>
|
||||
|
||||
void assert_handler(const char* cond, const char* func, const char* file, int line) NORETURN;
|
||||
#define ASSERT(x) \
|
||||
if (unlikely(!(x))) { \
|
||||
assert_handler(#x, __func__, __FILE__, __LINE__); \
|
||||
}
|
||||
|
||||
#ifdef DEBUG_KERNEL
|
||||
#define DEBUG_ASSERT(x) \
|
||||
if (unlikely(!(x))) { \
|
||||
assert_handler(#x, __func__, __FILE__, __LINE__); \
|
||||
}
|
||||
#else
|
||||
#undef DEBUG_ASSERT
|
||||
#define DEBUG_ASSERT(x)
|
||||
#endif
|
||||
|
||||
#define __IMPL_SASSERT_PASTE(a, b) a##b
|
||||
#define __IMPL_SASSERT_LINE(predicate, line, file) \
|
||||
typedef char __IMPL_SASSERT_PASTE(assertion_failed_##file##_, line)[2 * !!(predicate)-1]
|
||||
|
||||
#define STATIC_ASSERT(predicate, file) __IMPL_SASSERT_LINE(predicate, __LINE__, file)
|
||||
|
||||
void kpanic(const char* msg) NORETURN;
|
||||
void kpanic_tf(const char* err_msg, trapframe_t* tf) NORETURN;
|
||||
|
||||
#endif // _KERNEL_LIBKERN_KASSERT_H
|
||||
9
kernel/include/libkern/kernel_self_test.h
Normal file
9
kernel/include/libkern/kernel_self_test.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _KERNEL_LIBKERN_KERNEL_SELF_TEST_H
|
||||
#define _KERNEL_LIBKERN_KERNEL_SELF_TEST_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
void kpanic_at_test(char* t_err_msg, uint16_t test_no);
|
||||
bool kernel_self_test(bool throw_kernel_panic);
|
||||
|
||||
#endif // _KERNEL_LIBKERN_KERNEL_SELF_TEST_H
|
||||
45
kernel/include/libkern/libkern.h
Normal file
45
kernel/include/libkern/libkern.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef _KERNEL_LIBKERN_LIBKERN_H
|
||||
#define _KERNEL_LIBKERN_LIBKERN_H
|
||||
|
||||
#include <libkern/kassert.h>
|
||||
#include <libkern/mem.h>
|
||||
#include <libkern/types.h>
|
||||
#include <libkern/umem.h>
|
||||
|
||||
#define KB (1024)
|
||||
#define MB (1024 * 1024)
|
||||
|
||||
/**
|
||||
* SHORTCUTS
|
||||
*/
|
||||
|
||||
#define TEST_FLAG(val, flag) (((val) & (flag)) == (flag))
|
||||
#define TEST_BIT(val, bitnum) (((val) & (1 << bitnum)) == (1 << bitnum))
|
||||
|
||||
int stoi(void* str, int len);
|
||||
void htos(uintptr_t hex, char str[]);
|
||||
void dtos(uintptr_t dec, char str[]);
|
||||
void reverse(char s[]);
|
||||
size_t strlen(const char* s);
|
||||
int strcmp(const char* a, const char* b);
|
||||
int strncmp(const char* a, const char* b, size_t num);
|
||||
size_t ptrarray_len(const void** s);
|
||||
|
||||
#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 */
|
||||
|
||||
#define ROUND_CEIL(a, b) (((a) + ((b)-1)) & ~((b)-1))
|
||||
#define ROUND_FLOOR(a, b) ((a) & ~((b)-1))
|
||||
|
||||
#endif // _KERNEL_LIBKERN_LIBKERN_H
|
||||
69
kernel/include/libkern/lock.h
Normal file
69
kernel/include/libkern/lock.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef _KERNEL_LIBKERN_LOCK_H
|
||||
#define _KERNEL_LIBKERN_LOCK_H
|
||||
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/kassert.h>
|
||||
#include <libkern/log.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
// #define DEBUG_SPINLOCK
|
||||
|
||||
struct spinlock {
|
||||
int status;
|
||||
#ifdef DEBUG_SPINLOCK
|
||||
|
||||
#endif // DEBUG_SPINLOCK
|
||||
};
|
||||
typedef struct spinlock spinlock_t;
|
||||
|
||||
static ALWAYS_INLINE void spinlock_init(spinlock_t* lock)
|
||||
{
|
||||
__atomic_store_n(&lock->status, 0, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void spinlock_acquire(spinlock_t* lock)
|
||||
{
|
||||
int counter = 16;
|
||||
while (__atomic_exchange_n(&lock->status, 1, __ATOMIC_ACQUIRE) == 1) {
|
||||
extern bool system_can_preempt_kernel();
|
||||
if (system_can_preempt_kernel()) {
|
||||
if (!(--counter)) {
|
||||
extern void resched();
|
||||
resched();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void spinlock_release(spinlock_t* lock)
|
||||
{
|
||||
ASSERT(lock->status == 1);
|
||||
__atomic_store_n(&lock->status, 0, __ATOMIC_RELEASE);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE bool spinlock_try_acquire(spinlock_t* lock)
|
||||
{
|
||||
return !__atomic_exchange_n(&lock->status, 1, __ATOMIC_ACQUIRE);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_SPINLOCK
|
||||
#define spinlock_acquire(x) \
|
||||
system_disable_interrupts(); \
|
||||
extern int vmm_init_setup_finished; \
|
||||
if (vmm_init_setup_finished) { \
|
||||
log("acquire lock[%d] %s %s:%d", system_cpu_id(), #x, __FILE__, __LINE__); \
|
||||
} \
|
||||
system_enable_interrupts(); \
|
||||
spinlock_acquire(x);
|
||||
|
||||
#define spinlock_release(x) \
|
||||
system_disable_interrupts(); \
|
||||
extern int vmm_init_setup_finished; \
|
||||
if (vmm_init_setup_finished) { \
|
||||
log("release lock[%d] %s %s:%d ", system_cpu_id(), #x, __FILE__, __LINE__); \
|
||||
} \
|
||||
system_enable_interrupts(); \
|
||||
spinlock_release(x);
|
||||
#endif
|
||||
|
||||
#endif // _KERNEL_LIBKERN_LOCK_H
|
||||
15
kernel/include/libkern/log.h
Normal file
15
kernel/include/libkern/log.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _KERNEL_LIBKERN_LOG_H
|
||||
#define _KERNEL_LIBKERN_LOG_H
|
||||
|
||||
#include <libkern/printf.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
struct boot_args;
|
||||
void logger_setup(struct boot_args* boot_args);
|
||||
|
||||
int log(const char* format, ...);
|
||||
int log_warn(const char* format, ...);
|
||||
int log_error(const char* format, ...);
|
||||
int log_not_formatted(const char* format, ...);
|
||||
|
||||
#endif // _KERNEL_LIBKERN_LOG_H
|
||||
13
kernel/include/libkern/mask.h
Normal file
13
kernel/include/libkern/mask.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _KERNEL_LIBKERN_MASK_H
|
||||
#define _KERNEL_LIBKERN_MASK_H
|
||||
|
||||
#define MASKDEFINE(N, P, S) \
|
||||
N##_POS = (P), \
|
||||
N##_SIZE = (S), \
|
||||
N##_MASK = ((~(~0 << (S))) << (P))
|
||||
|
||||
#define TOKEN_PASTE_IMPL(x, y) x##y
|
||||
#define TOKEN_PASTE(x, y) TOKEN_PASTE_IMPL(x, y)
|
||||
#define SKIP(x, y) char TOKEN_PASTE(prefix, __LINE__)[y - x - 8]
|
||||
|
||||
#endif // _KERNEL_LIBKERN_MASK_H
|
||||
15
kernel/include/libkern/mem.h
Normal file
15
kernel/include/libkern/mem.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _KERNEL_LIBKERN_MEM_H
|
||||
#define _KERNEL_LIBKERN_MEM_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
void* memset(void* dest, uint8_t fll, size_t nbytes);
|
||||
void* memcpy(void* dest, const void* src, size_t nbytes);
|
||||
void* memccpy(void* dest, const void* src, uint8_t stop, size_t nbytes);
|
||||
void* memmove(void* dest, const void* src, size_t nbytes);
|
||||
int memcmp(const void* src1, const void* src2, size_t nbytes);
|
||||
|
||||
char* kmem_bring_to_kernel(const char* data, size_t size);
|
||||
char** kmem_bring_to_kernel_ptrarr(const char** data, size_t size);
|
||||
|
||||
#endif // _KERNEL_LIBKERN_MEM_H
|
||||
11
kernel/include/libkern/platform.h
Normal file
11
kernel/include/libkern/platform.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _KERNEL_LIBKERN_PLATFORM_H
|
||||
#define _KERNEL_LIBKERN_PLATFORM_H
|
||||
|
||||
#include <libkern/c_attrs.h>
|
||||
|
||||
ALWAYS_INLINE int ctz32(unsigned int val)
|
||||
{
|
||||
return __builtin_ctz(val);
|
||||
}
|
||||
|
||||
#endif // _KERNEL_LIBKERN_PLATFORM_H
|
||||
15
kernel/include/libkern/printf.h
Normal file
15
kernel/include/libkern/printf.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef _KERNEL_LIBKERN_PRINTF_H
|
||||
#define _KERNEL_LIBKERN_PRINTF_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
typedef int (*printf_putch_callback)(char ch, char* buf_base, size_t* written, void* callback_params);
|
||||
|
||||
int vsnprintf(char* s, size_t n, const char* format, va_list arg);
|
||||
int vsprintf(char* s, const char* format, va_list arg);
|
||||
int snprintf(char* s, size_t n, const char* format, ...);
|
||||
int sprintf(char* s, const char* format, ...);
|
||||
|
||||
int printf_engine(char* buf, const char* format, printf_putch_callback callback, void* callback_params, va_list arg);
|
||||
|
||||
#endif // _KERNEL_LIBKERN_PRINTF_H
|
||||
74
kernel/include/libkern/rwlock.h
Normal file
74
kernel/include/libkern/rwlock.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef _KERNEL_LIBKERN_RWLOCK_H
|
||||
#define _KERNEL_LIBKERN_RWLOCK_H
|
||||
|
||||
#include <libkern/atomic.h>
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/kassert.h>
|
||||
#include <libkern/lock.h>
|
||||
#include <libkern/log.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
struct rwlock {
|
||||
int readers;
|
||||
spinlock_t lock;
|
||||
#ifdef DEBUG_SPINLOCK
|
||||
|
||||
#endif // DEBUG_SPINLOCK
|
||||
};
|
||||
typedef struct rwlock rwspinlock_t;
|
||||
|
||||
static ALWAYS_INLINE void rwspinlock_init(rwspinlock_t* rwlock)
|
||||
{
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void rwlock_r_acquire(rwspinlock_t* rwlock)
|
||||
{
|
||||
spinlock_acquire(&rwlock->lock);
|
||||
rwlock->readers++;
|
||||
spinlock_release(&rwlock->lock);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void rwlock_r_release(rwspinlock_t* rwlock)
|
||||
{
|
||||
spinlock_acquire(&rwlock->lock);
|
||||
ASSERT(rwlock->readers >= 0);
|
||||
rwlock->readers--;
|
||||
spinlock_release(&rwlock->lock);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void rwlock_w_acquire(rwspinlock_t* rwlock)
|
||||
{
|
||||
for (;;) {
|
||||
spinlock_acquire(&rwlock->lock);
|
||||
if (!rwlock->readers) {
|
||||
return;
|
||||
}
|
||||
spinlock_release(&rwlock->lock);
|
||||
}
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void rwlock_w_release(rwspinlock_t* rwlock)
|
||||
{
|
||||
spinlock_release(&rwlock->lock);
|
||||
}
|
||||
|
||||
// #define DEBUG_SPINLOCK
|
||||
#ifdef DEBUG_SPINLOCK
|
||||
#define rwlock_r_acquire(x) \
|
||||
log("acquire r rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
|
||||
rwlock_r_acquire(x);
|
||||
|
||||
#define rwlock_r_release(x) \
|
||||
log("release r rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
|
||||
rwlock_r_release(x);
|
||||
|
||||
#define rwlock_w_acquire(x) \
|
||||
log("acquire w rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
|
||||
rwlock_w_acquire(x);
|
||||
|
||||
#define rwlock_w_release(x) \
|
||||
log("release w rwlock %s %s:%d ", #x, __FILE__, __LINE__); \
|
||||
rwlock_w_release(x);
|
||||
#endif
|
||||
|
||||
#endif // _KERNEL_LIBKERN_RWLOCK_H
|
||||
17
kernel/include/libkern/scanf.h
Normal file
17
kernel/include/libkern/scanf.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _KERNEL_LIBKERN_SCANF_H
|
||||
#define _KERNEL_LIBKERN_SCANF_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
#define EOF (-1)
|
||||
|
||||
typedef int (*scanf_lookupch_callback)(void* callback_params);
|
||||
typedef int (*scanf_getch_callback)(void* callback_params);
|
||||
typedef int (*scanf_putch_callback)(char ch, char* buf_base, size_t* written, void* callback_params);
|
||||
|
||||
int vsscanf(const char* buf, const char* fmt, va_list arg);
|
||||
int sscanf(const char* buf, const char* fmt, ...);
|
||||
|
||||
int scanf_engine(const char* format, scanf_lookupch_callback lookupch, scanf_getch_callback getch, void* callback_params, va_list arg);
|
||||
|
||||
#endif // _KERNEL_LIBKERN_SCANF_H
|
||||
8
kernel/include/libkern/stdarg.h
Normal file
8
kernel/include/libkern/stdarg.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _KERNEL_LIBKERN_STDARG_H
|
||||
#define _KERNEL_LIBKERN_STDARG_H
|
||||
|
||||
#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)
|
||||
|
||||
#endif // _KERNEL_LIBKERN_STDARG_H
|
||||
14
kernel/include/libkern/syscall_structs.h
Normal file
14
kernel/include/libkern/syscall_structs.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _KERNEL_LIBKERN_SYSCALL_STRUCTS_H
|
||||
#define _KERNEL_LIBKERN_SYSCALL_STRUCTS_H
|
||||
|
||||
#include <libkern/bits/fcntl.h>
|
||||
#include <libkern/bits/sys/ioctls.h>
|
||||
#include <libkern/bits/sys/mman.h>
|
||||
#include <libkern/bits/sys/select.h>
|
||||
#include <libkern/bits/sys/socket.h>
|
||||
#include <libkern/bits/sys/stat.h>
|
||||
#include <libkern/bits/sys/utsname.h>
|
||||
#include <libkern/bits/syscalls.h>
|
||||
#include <libkern/bits/thread.h>
|
||||
|
||||
#endif /* _KERNEL_LIBKERN_SYSCALL_STRUCTS_H */
|
||||
65
kernel/include/libkern/time.h
Normal file
65
kernel/include/libkern/time.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#ifndef _KERNEL_LIBKERN_TIME_H
|
||||
#define _KERNEL_LIBKERN_TIME_H
|
||||
|
||||
#include <libkern/bits/time.h>
|
||||
#include <libkern/kassert.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
static inline void timespec_add_nsec(timespec_t* time, int nsec)
|
||||
{
|
||||
ASSERT(-1000000000 < nsec && nsec < 1000000000);
|
||||
|
||||
time->tv_nsec += nsec;
|
||||
if (time->tv_nsec >= 1000000000) {
|
||||
time->tv_nsec -= 1000000000;
|
||||
time->tv_sec++;
|
||||
}
|
||||
if (time->tv_nsec < 0) {
|
||||
time->tv_nsec += 1000000000;
|
||||
time->tv_sec--;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void timespec_add_usec(timespec_t* time, int usec)
|
||||
{
|
||||
int sec = usec / 1000000;
|
||||
int nsec = (usec % 1000000) * 1000;
|
||||
timespec_add_nsec(time, nsec);
|
||||
time->tv_sec += sec;
|
||||
}
|
||||
|
||||
static inline void timespec_add_sec(timespec_t* time, int sec)
|
||||
{
|
||||
time->tv_sec += sec;
|
||||
}
|
||||
|
||||
static inline void timespec_add_timespec(timespec_t* lhs, const timespec_t* rhs)
|
||||
{
|
||||
timespec_add_nsec(lhs, rhs->tv_nsec);
|
||||
lhs->tv_sec += rhs->tv_sec;
|
||||
}
|
||||
|
||||
static inline void timespec_add_timeval(timespec_t* lhs, const timeval_t* rhs)
|
||||
{
|
||||
timespec_add_usec(lhs, rhs->tv_usec);
|
||||
lhs->tv_sec += rhs->tv_sec;
|
||||
}
|
||||
|
||||
static inline int timespec_cmp(const timespec_t* a, const timespec_t* b)
|
||||
{
|
||||
if (a->tv_sec == b->tv_sec) {
|
||||
if (a->tv_nsec == b->tv_nsec) {
|
||||
return 0;
|
||||
}
|
||||
if (a->tv_nsec < b->tv_nsec) {
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
if (a->tv_sec < b->tv_sec) {
|
||||
return -2;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
#endif // _KERNEL_LIBKERN_TIME_H
|
||||
139
kernel/include/libkern/types.h
Normal file
139
kernel/include/libkern/types.h
Normal file
@@ -0,0 +1,139 @@
|
||||
#ifndef _KERNEL_LIBKERN_TYPES_H
|
||||
#define _KERNEL_LIBKERN_TYPES_H
|
||||
|
||||
#include <libkern/_types/_va_list.h>
|
||||
#include <libkern/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
|
||||
|
||||
#ifdef __i386__
|
||||
typedef int32_t intptr_t;
|
||||
typedef uint32_t uintptr_t;
|
||||
typedef off_t off_t;
|
||||
#if defined(__clang__)
|
||||
typedef unsigned int size_t;
|
||||
typedef int ssize_t;
|
||||
#elif defined(__GNUC__) || defined(__GNUG__)
|
||||
typedef unsigned long size_t;
|
||||
typedef long ssize_t;
|
||||
#endif
|
||||
#define BITS32
|
||||
#elif __x86_64__
|
||||
typedef uint64_t size_t;
|
||||
typedef int64_t ssize_t;
|
||||
typedef int64_t intptr_t;
|
||||
typedef uint64_t uintptr_t;
|
||||
typedef off64_t off_t;
|
||||
#define BITS64
|
||||
#elif __arm__
|
||||
typedef unsigned int size_t;
|
||||
typedef int ssize_t;
|
||||
typedef int32_t intptr_t;
|
||||
typedef uint32_t uintptr_t;
|
||||
typedef off_t off_t;
|
||||
#define BITS32
|
||||
#elif __aarch64__
|
||||
typedef uint64_t size_t;
|
||||
typedef int64_t ssize_t;
|
||||
typedef int64_t intptr_t;
|
||||
typedef uint64_t uintptr_t;
|
||||
typedef off64_t off_t;
|
||||
#define BITS64
|
||||
#elif defined(__riscv) && (__riscv_xlen == 64)
|
||||
typedef uint64_t size_t;
|
||||
typedef int64_t ssize_t;
|
||||
typedef int64_t intptr_t;
|
||||
typedef uint64_t uintptr_t;
|
||||
typedef off64_t off_t;
|
||||
#define BITS64
|
||||
#endif
|
||||
|
||||
#define __user
|
||||
|
||||
#define bool _Bool
|
||||
#define true (1)
|
||||
#define false (0)
|
||||
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
#define NULL ((void*)0)
|
||||
|
||||
#define MINORBITS 20
|
||||
#define MINORMASK ((1U << MINORBITS) - 1)
|
||||
|
||||
#define MAJOR(dev) ((unsigned int)((dev) >> MINORBITS))
|
||||
#define MINOR(dev) ((unsigned int)((dev)&MINORMASK))
|
||||
#define MKDEV(ma, mi) (((ma) << MINORBITS) | (mi))
|
||||
|
||||
#endif // _KERNEL_LIBKERN_TYPES_H
|
||||
77
kernel/include/libkern/umem.h
Normal file
77
kernel/include/libkern/umem.h
Normal file
@@ -0,0 +1,77 @@
|
||||
#ifndef _KERNEL_LIBKERN_UMEM_H
|
||||
#define _KERNEL_LIBKERN_UMEM_H
|
||||
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
#define USER_STR_MAXLEN (128)
|
||||
#define USER_PTRARRAY_MAXLEN (128)
|
||||
#define USER_STRARRAY_MAXLEN (128)
|
||||
|
||||
bool umem_validate_str(const char __user* us, size_t maxlen);
|
||||
bool umem_validate_ptrarray(const void __user** uptrarr, size_t maxlen);
|
||||
static ALWAYS_INLINE bool umem_validate_strarray(const char __user** s, size_t maxlen) { return umem_validate_ptrarray((const void __user**)s, maxlen); }
|
||||
void* umem_bring_to_kernel(const void __user* data, size_t size);
|
||||
char* umem_bring_to_kernel_str(const char __user* data, size_t maxlen);
|
||||
char* umem_bring_to_kernel_str_with_len(const char __user* data, size_t size);
|
||||
char** umem_bring_to_kernel_strarray(const char __user** udata, size_t maxlen);
|
||||
void umem_copy_to_user(void __user* dest, const void* src, size_t length);
|
||||
void umem_copy_from_user(void* dest, const void __user* src, size_t length);
|
||||
|
||||
static ALWAYS_INLINE void umem_get_user_1(uint8_t* ptr, uint8_t* uptr) { *ptr = *uptr; }
|
||||
static ALWAYS_INLINE void umem_get_user_2(uint16_t* ptr, uint16_t* uptr) { *ptr = *uptr; }
|
||||
static ALWAYS_INLINE void umem_get_user_4(uint32_t* ptr, uint32_t* uptr) { *ptr = *uptr; }
|
||||
static ALWAYS_INLINE void umem_get_user_8(uint64_t* ptr, uint64_t* uptr) { *ptr = *uptr; }
|
||||
|
||||
static ALWAYS_INLINE void umem_put_user_1(uint8_t* val, uint8_t* uptr) { *uptr = *val; }
|
||||
static ALWAYS_INLINE void umem_put_user_2(uint16_t* val, uint16_t* uptr) { *uptr = *val; }
|
||||
static ALWAYS_INLINE void umem_put_user_4(uint32_t* val, uint32_t* uptr) { *uptr = *val; }
|
||||
static ALWAYS_INLINE void umem_put_user_8(uint64_t* val, uint64_t* uptr) { *uptr = *val; }
|
||||
|
||||
#define __umem_put_user_impl_size(size, x, ptr) umem_put_user_##size(x, ptr)
|
||||
#define umem_put_user(x, ptr) \
|
||||
({ \
|
||||
__typeof__(*(ptr)) __user_val; \
|
||||
__user_val = x; \
|
||||
switch (sizeof(*(ptr))) { \
|
||||
case 1: \
|
||||
__umem_put_user_impl_size(1, (uint8_t*)&__user_val, (uint8_t*)ptr); \
|
||||
break; \
|
||||
case 2: \
|
||||
__umem_put_user_impl_size(2, (uint16_t*)&__user_val, (uint16_t*)ptr); \
|
||||
break; \
|
||||
case 4: \
|
||||
__umem_put_user_impl_size(4, (uint32_t*)&__user_val, (uint32_t*)ptr); \
|
||||
break; \
|
||||
case 8: \
|
||||
__umem_put_user_impl_size(8, (uint64_t*)&__user_val, (uint64_t*)ptr); \
|
||||
break; \
|
||||
default: \
|
||||
umem_copy_to_user(ptr, &__user_val, sizeof(*(ptr))); \
|
||||
break; \
|
||||
} \
|
||||
})
|
||||
|
||||
#define __umem_get_user_impl_size(size, x, ptr) umem_get_user_##size(x, ptr)
|
||||
#define umem_get_user(ptr, uptr) \
|
||||
({ \
|
||||
switch (sizeof(*(ptr))) { \
|
||||
case 1: \
|
||||
__umem_get_user_impl_size(1, (uint8_t*)ptr, (uint8_t*)uptr); \
|
||||
break; \
|
||||
case 2: \
|
||||
__umem_get_user_impl_size(2, (uint16_t*)ptr, (uint16_t*)uptr); \
|
||||
break; \
|
||||
case 4: \
|
||||
__umem_get_user_impl_size(4, (uint32_t*)ptr, (uint32_t*)uptr); \
|
||||
break; \
|
||||
case 8: \
|
||||
__umem_get_user_impl_size(8, (uint64_t*)ptr, (uint64_t*)uptr); \
|
||||
break; \
|
||||
default: \
|
||||
umem_copy_from_user(ptr, uptr, sizeof(*(ptr))); \
|
||||
break; \
|
||||
} \
|
||||
})
|
||||
|
||||
#endif // _KERNEL_LIBKERN_UMEM_H
|
||||
23
kernel/include/libkern/version.h
Normal file
23
kernel/include/libkern/version.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef _KERNEL_LIBKERN_VERSION_H
|
||||
#define _KERNEL_LIBKERN_VERSION_H
|
||||
|
||||
#define OSTYPE "xOS"
|
||||
#define OSRELEASE "1.0.0-dev"
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 0
|
||||
#define VERSION_REVISION 0
|
||||
#define VERSION_VARIANT "0"
|
||||
|
||||
#ifdef __i386__
|
||||
#define MACHINE "x86"
|
||||
#elif __x86_64__
|
||||
#define MACHINE "x86-64"
|
||||
#elif __arm__
|
||||
#define MACHINE "arm"
|
||||
#elif __aarch64__
|
||||
#define MACHINE "arm64"
|
||||
#elif defined(__riscv) && (__riscv_xlen == 64)
|
||||
#define MACHINE "riscv64"
|
||||
#endif
|
||||
|
||||
#endif // _KERNEL_LIBKERN_VERSION_H
|
||||
Reference in New Issue
Block a user