user: implement mlibc as the libc, finally.

It's finally done..

Signed-off-by: kaguya <vpshinomiya@protonmail.com>
This commit is contained in:
kaguya
2026-05-02 03:31:49 -04:00
parent 2fa39ad85a
commit 9a9b91c940
2387 changed files with 152741 additions and 315 deletions
+25
View File
@@ -0,0 +1,25 @@
#ifndef _SYS_AUXV_H
#define _SYS_AUXV_H
#include <elf.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
/* mlibc extension: Like getauxval but handles errors in a sane way. */
/* Success: Return 0. */
/* Failure: Return -1 and set errno. */
int peekauxval(unsigned long __type, unsigned long *__value);
unsigned long getauxval(unsigned long __type);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
+16
View File
@@ -0,0 +1,16 @@
#ifndef _SYS_CACHECTL_H
#define _SYS_CACHECTL_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __riscv
int __riscv_flush_icache(void *, void *, unsigned long);
#endif
#ifdef __cplusplus
}
#endif
#endif
+8
View File
@@ -0,0 +1,8 @@
#ifndef _SYS_DIR_H
#define _SYS_DIR_H
#include <dirent.h>
#define direct dirent
#endif
View File
+1
View File
@@ -0,0 +1 @@
#include <errno.h>
+1
View File
@@ -0,0 +1 @@
#include <fcntl.h>
+26
View File
@@ -0,0 +1,26 @@
#ifndef _SYS_FILE_H
#define _SYS_FILE_H
#define LOCK_SH 1
#define LOCK_EX 2
#define LOCK_NB 4
#define LOCK_UN 8
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
int flock(int __fd, int __op);
int flock64(int __fd, int __op);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_FILE_H */
+108
View File
@@ -0,0 +1,108 @@
#ifndef _SYS_IO_H
#define _SYS_IO_H
#include <bits/inline-definition.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
int ioperm(unsigned long int __from, unsigned long int __num, int __turn_on);
__attribute__((deprecated)) int iopl(int __level);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __x86_64__
__MLIBC_INLINE_DEFINITION unsigned char inb(unsigned short int __port) {
unsigned char __value;
__asm__ __volatile__ ("inb %w1,%0":"=a" (__value):"Nd" (__port));
return __value;
}
__MLIBC_INLINE_DEFINITION unsigned char inb_p(unsigned short int __port) {
unsigned char __value;
__asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (__value):"Nd" (__port));
return __value;
}
__MLIBC_INLINE_DEFINITION unsigned short int inw(unsigned short int __port) {
unsigned short __value;
__asm__ __volatile__ ("inw %w1,%0":"=a" (__value):"Nd" (__port));
return __value;
}
__MLIBC_INLINE_DEFINITION unsigned short int inw_p(unsigned short int __port) {
unsigned short int __value;
__asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (__value):"Nd" (__port));
return __value;
}
__MLIBC_INLINE_DEFINITION unsigned int inl(unsigned short int __port) {
unsigned int __value;
__asm__ __volatile__ ("inl %w1,%0":"=a" (__value):"Nd" (__port));
return __value;
}
__MLIBC_INLINE_DEFINITION unsigned int inl_p(unsigned short int __port) {
unsigned int __value;
__asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (__value):"Nd" (__port));
return __value;
}
__MLIBC_INLINE_DEFINITION void outb(unsigned char value, unsigned short int __port) {
__asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (__port));
}
__MLIBC_INLINE_DEFINITION void outb_p(unsigned char __value, unsigned short int __port) {
__asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value), "Nd" (__port));
}
__MLIBC_INLINE_DEFINITION void outw(unsigned short int __value, unsigned short int __port) {
__asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
}
__MLIBC_INLINE_DEFINITION void outw_p(unsigned short int __value, unsigned short int __port) {
__asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value), "Nd" (__port));
}
__MLIBC_INLINE_DEFINITION void outl(unsigned int __value, unsigned short int __port) {
__asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
}
__MLIBC_INLINE_DEFINITION void outl_p(unsigned int __value, unsigned short int __port) {
__asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value), "Nd" (__port));
}
__MLIBC_INLINE_DEFINITION void insb(unsigned short int __port, void *__addr, unsigned long int __count) {
__asm__ __volatile__ ("cld ; rep ; insb":"=D" (__addr), "=c" (__count) :"d" (__port), "0" (__addr), "1" (__count));
}
__MLIBC_INLINE_DEFINITION void insw(unsigned short int __port, void *__addr, unsigned long int __count) {
__asm__ __volatile__ ("cld ; rep ; insw":"=D" (__addr), "=c" (__count) :"d" (__port), "0" (__addr), "1" (__count));
}
__MLIBC_INLINE_DEFINITION void insl(unsigned short int __port, void *__addr, unsigned long int __count) {
__asm__ __volatile__ ("cld ; rep ; insl":"=D" (__addr), "=c" (__count) :"d" (__port), "0" (__addr), "1" (__count));
}
__MLIBC_INLINE_DEFINITION void outsb(unsigned short int __port, const void *__addr, unsigned long int __count) {
__asm__ __volatile__ ("cld ; rep ; outsb":"=S" (__addr), "=c" (__count) :"d" (__port), "0" (__addr), "1" (__count));
}
__MLIBC_INLINE_DEFINITION void outsw(unsigned short int __port, const void *__addr, unsigned long int __count) {
__asm__ __volatile__ ("cld ; rep ; outsw":"=S" (__addr), "=c" (__count) :"d" (__port), "0" (__addr), "1" (__count));
}
__MLIBC_INLINE_DEFINITION void outsl(unsigned short int __port, const void *__addr, unsigned long int __count) {
__asm__ __volatile__ ("cld ; rep ; outsl":"=S" (__addr), "=c" (__count) :"d" (__port), "0" (__addr), "1" (__count));
}
#endif
#ifdef __cplusplus
}
#endif
#endif /* _SYS_IO_H */
+48
View File
@@ -0,0 +1,48 @@
#ifndef _SYS_IOCTL_H
#define _SYS_IOCTL_H
#include <mlibc-config.h>
#include <abi-bits/ioctls.h>
/* On Linux, sys/ioctl.h includes the termios ioctls. */
#if __MLIBC_LINUX_OPTION
# include <asm/ioctls.h>
# include <bits/winsize.h>
# include <sys/ttydefaults.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
int ioctl(int __fd, unsigned long __request, ...);
#endif /* !__MLIBC_ABI_ONLY */
#define TIOCMGET 0x5415
#define TIOCMBIS 0x5416
#define TIOCMBIC 0x5417
#define FIONREAD 0x541B
#define FIONBIO 0x5421
#define FIONCLEX 0x5450
#define FIOCLEX 0x5451
#define SIOCGIFNAME 0x8910
#define SIOCGIFCONF 0x8912
#define SIOCGIFFLAGS 0x8913
#define SIOCSIFFLAGS 0x8914
#define SIOCGIFMTU 0x8921
#define SIOCSIFMTU 0x8922
#define SIOCGIFINDEX 0x8933
#define SIOCPROTOPRIVATE 0x89E0
#define SIOCDEVPRIVATE 0x89F0
#ifdef __cplusplus
}
#endif
#endif /* _SYS_IOCTL_H */
+20
View File
@@ -0,0 +1,20 @@
#ifndef _SYS_IPC_H
#define _SYS_IPC_H
#include <abi-bits/ipc.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
key_t ftok(const char *__path, int __proj_id);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif
+17
View File
@@ -0,0 +1,17 @@
#ifndef _SYS_KD_H
#define _SYS_KD_H
/* Make sure the <linux/types.h> header is not loaded. */
#ifndef _LINUX_TYPES_H
# define _LINUX_TYPES_H 1
# define __undef_LINUX_TYPES_H
#endif
#include <linux/kd.h>
#ifdef __undef_LINUX_TYPES_H
# undef _LINUX_TYPES_H
# undef __undef_LINUX_TYPES_H
#endif
#endif /* _SYS_KD_H */
+46
View File
@@ -0,0 +1,46 @@
#ifndef _SYS_MMAN_H
#define _SYS_MMAN_H
#include <mlibc-config.h>
#include <abi-bits/mode_t.h>
#include <abi-bits/vm-flags.h>
#include <bits/off_t.h>
#include <bits/size_t.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
void *mmap(void *__addr, size_t __size, int __prot, int __flags, int __fd, off_t __offset);
void *mmap64(void *__addr, size_t __size, int __prot, int __flags, int __fd, off64_t __offset);
int mprotect(void *__addr, size_t __size, int __prot);
int munmap(void *__addr, size_t __size);
int mlock(const void *__addr, size_t __size);
int mlockall(int __flags);
int munlock(const void *__addr, size_t __size);
int munlockall(void);
int posix_madvise(void *__addr, size_t __size, int __advise);
int msync(void *__addr, size_t __size, int __flags);
int shm_open(const char *__name, int __oflag, mode_t __mode);
int shm_unlink(const char *__name);
#if __MLIBC_LINUX_OPTION
void *mremap(void *__old_address, size_t __old_size, size_t __new_size, int __flags, ...);
int remap_file_pages(void *__addr, size_t __size, int __prot, size_t __pgoff, int __flags);
int memfd_create(const char *__name, unsigned int __flags);
int madvise(void *__addr, size_t __size, int __advise);
int mincore(void *__addr, size_t __size, unsigned char *__vec);
#endif /* __MLIBC_LINUX_OPTION */
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_MMAN_H */
+27
View File
@@ -0,0 +1,27 @@
#ifndef _SYS_MSG_H
#define _SYS_MSG_H
#include <abi-bits/msg.h>
#include <bits/size_t.h>
#include <bits/ssize_t.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
int msgget(key_t __key, int __msgflg);
int msgctl(int __msqid, int __cmd, struct msqid_ds *__buf);
ssize_t msgrcv(int __msqid, void *__msgp, size_t __size, long __msgtyp, int __msgflg);
int msgsnd(int __msqid, const void *__msgp, size_t __size, int __msgflg);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_MSG_H */
+102
View File
@@ -0,0 +1,102 @@
#ifndef _SYS_MTIO_H
#define _SYS_MTIO_H
#include <mlibc-config.h>
#include <sys/ioctl.h>
#ifdef __cplusplus
extern "C" {
#endif
struct mtop {
short int mt_op;
int mt_count;
};
struct mtget {
long int mt_type;
long int mt_resid;
long int mt_dsreg;
long int mt_gstat;
long int mt_erreg;
int mt_fileno;
int mt_blkno;
};
struct mtpos {
long int mt_blkno;
};
struct mtconfiginfo {
long int mt_type;
long int ifc_type;
unsigned short int irqnr;
unsigned short int dmanr;
unsigned short int port;
unsigned long int debug;
unsigned have_dens:1;
unsigned have_bsf:1;
unsigned have_fsr:1;
unsigned have_bsr:1;
unsigned have_eod:1;
unsigned have_seek:1;
unsigned have_tell:1;
unsigned have_ras1:1;
unsigned have_ras2:1;
unsigned have_ras3:1;
unsigned have_qfa:1;
unsigned pad1:5;
char reserved[10];
};
#define MTRESET 0
#define MTFSF 1
#define MTBSF 2
#define MTFSR 3
#define MTBSR 4
#define MTWEOF 5
#define MTREW 6
#define MTOFFL 7
#define MTNOP 8
#define MTRETEN 9
#define MTBSFM 10
#define MTFSFM 11
#define MTEOM 12
#define MTERASE 13
#define MTRAS1 14
#define MTRAS2 15
#define MTRAS3 16
#define MTSETBLK 20
#define MTSETDENSITY 21
#define MTSEEK 22
#define MTTELL 23
#define MTSETDRVBUFFER 24
#define MTFSS 25
#define MTBSS 26
#define MTWSM 27
#define MTLOCK 28
#define MTUNLOCK 29
#define MTLOAD 30
#define MTUNLOAD 31
#define MTCOMPRESSION 32
#define MTSETPART 33
#define MTMKPART 34
#define GMT_WR_PROT(x) ((x) & 0x04000000)
#if __MLIBC_LINUX_OPTION
#define MTIOCTOP _IOR('m', 1, struct mtop)
#define MTIOCGET _IOR('m', 2, struct mtget)
#define MTIOCPOS _IOR('m', 3, struct mtpos)
#define MTIOCGETCONFIG _IOR('m', 4, struct mtconfiginfo)
#define MTIOCSETCONFIG _IOR('m', 5, struct mtconfiginfo)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _SYS_MTIO_H */
+35
View File
@@ -0,0 +1,35 @@
#ifndef _SYS_PARAM_H
#define _SYS_PARAM_H
#include <endian.h>
#include <limits.h>
#define NBBY CHAR_BIT
#define NGROUPS NGROUPS_MAX
/* Report the same value as Linux here. */
#define MAXNAMLEN 255
#define MAXPATHLEN 4096
#define MAXSYMLINKS 20
#define MAXHOSTNAMELEN HOST_NAME_MAX
#ifdef __cplusplus
extern "C" {
#endif
#undef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#undef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define howmany(x, y) (((x) + ((y) - 1)) / (y))
#define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
#ifdef __cplusplus
}
#endif
#endif /* _SYS_PARAM_H */
+58
View File
@@ -0,0 +1,58 @@
#ifndef _SYS_PERSONALITY_H
#define _SYS_PERSONALITY_H
#ifdef __cplusplus
extern "C" {
#endif
enum {
UNAME26 = 0x0020000,
ADDR_NO_RANDOMIZE = 0x0040000,
FDPIC_FUNCPTRS = 0x0080000,
MMAP_PAGE_ZERO = 0x0100000,
ADDR_COMPAT_LAYOUT = 0x0200000,
READ_IMPLIES_EXEC = 0x0400000,
ADDR_LIMIT_32BIT = 0x0800000,
SHORT_INODE = 0x1000000,
WHOLE_SECONDS = 0x2000000,
STICKY_TIMEOUTS = 0x4000000,
ADDR_LIMIT_3GB = 0x8000000
};
enum {
PER_LINUX = 0x0000,
PER_LINUX_32BIT = 0x0000 | ADDR_LIMIT_32BIT,
PER_LINUX_FDPIC = 0x0000 | FDPIC_FUNCPTRS,
PER_SVR4 = 0x0001 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
PER_SVR3 = 0x0002 | STICKY_TIMEOUTS | SHORT_INODE,
PER_SCOSVR3 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS | SHORT_INODE,
PER_OSR5 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS,
PER_WYSEV386 = 0x0004 | STICKY_TIMEOUTS | SHORT_INODE,
PER_ISCR4 = 0x0005 | STICKY_TIMEOUTS,
PER_BSD = 0x0006,
PER_SUNOS = 0x0006 | STICKY_TIMEOUTS,
PER_XENIX = 0x0007 | STICKY_TIMEOUTS | SHORT_INODE,
PER_LINUX32 = 0x0008,
PER_LINUX32_3GB = 0x0008 | ADDR_LIMIT_3GB,
PER_IRIX32 = 0x0009 | STICKY_TIMEOUTS,
PER_IRIXN32 = 0x000a | STICKY_TIMEOUTS,
PER_IRIX64 = 0x000b | STICKY_TIMEOUTS,
PER_RISCOS = 0x000c,
PER_SOLARIS = 0x000d | STICKY_TIMEOUTS,
PER_UW7 = 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
PER_OSF4 = 0x000f,
PER_HPUX = 0x0010,
PER_MASK = 0x00ff
};
#ifndef __MLIBC_ABI_ONLY
int personality(unsigned long __persona);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_PERSONALITY_H */
+38
View File
@@ -0,0 +1,38 @@
#ifndef _SYS_POLL_H
#define _SYS_POLL_H
#include <bits/types.h>
#include <bits/sigset_t.h>
#include <bits/ansi/timespec.h>
#include <abi-bits/poll.h>
#include <abi-bits/signal.h>
#include <mlibc-config.h>
typedef __mlibc_size nfds_t;
#ifdef __cplusplus
extern "C" {
#endif
struct pollfd {
int fd;
short events;
short revents;
};
#ifndef __MLIBC_ABI_ONLY
int poll(struct pollfd *__fds, nfds_t __nfds, int __timeout);
#if __MLIBC_LINUX_OPTION
int ppoll(struct pollfd *__fds, nfds_t __nfds,
const struct timespec *__timeout_ts, const sigset_t *__sigmask);
#endif /* __MLIBC_LINUX_OPTION */
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_POLL_H */
+75
View File
@@ -0,0 +1,75 @@
#ifndef _SYS_PROCFS_H
#define _SYS_PROCFS_H
#include <sys/user.h>
#include <sys/time.h>
#include <abi-bits/pid_t.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned long elf_greg_t;
#define ELF_NGREG (sizeof (struct user_regs_struct) / sizeof (elf_greg_t))
typedef elf_greg_t elf_gregset_t[ELF_NGREG];
typedef struct user_fpregs_struct elf_fpregset_t;
typedef elf_gregset_t prgregset_t;
typedef struct user_fpregs_struct prfpregset_t;
#define ELF_PRARGSZ 80
struct elf_siginfo {
int si_signo;
int si_code;
int si_errno;
};
struct elf_prstatus {
struct elf_siginfo pr_info;
short int pr_cursig;
unsigned long int pr_sigpend;
unsigned long int pr_sighold;
pid_t pr_pid;
pid_t pr_ppid;
pid_t pr_pgrp;
pid_t pr_sid;
struct timeval pr_utime;
struct timeval pr_stime;
struct timeval pr_cutime;
struct timeval pr_cstime;
elf_gregset_t pr_reg;
int pr_fpvalid;
};
struct elf_prpsinfo {
char pr_state;
char pr_sname;
char pr_zomb;
char pr_nice;
unsigned long pr_flag;
#if __INTPTR_WIDTH__ == 32
unsigned short int pr_uid;
unsigned short int pr_gid;
#else
unsigned int pr_uid;
unsigned int pr_gid;
#endif
int pr_pid;
int pr_ppid;
int pr_pgrp;
int pr_sid;
char pr_fname[16];
char pr_psargs[ELF_PRARGSZ];
};
typedef pid_t lwpid_t;
typedef void *psaddr_t;
typedef struct elf_prstatus prstatus_t;
#ifdef __cplusplus
}
#endif
#endif
+574
View File
@@ -0,0 +1,574 @@
/*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*/
#ifndef _SYS_QUEUE_H_
#define _SYS_QUEUE_H_
/*
* This file defines five types of data structures: singly-linked lists,
* lists, simple queues, tail queues, and circular queues.
*
* A singly-linked list is headed by a single forward pointer. The
* elements are singly linked for minimum space and pointer manipulation
* overhead at the expense of O(n) removal for arbitrary elements. New
* elements can be added to the list after an existing element or at the
* head of the list. Elements being removed from the head of the list
* should use the explicit macro for this purpose for optimum
* efficiency. A singly-linked list may only be traversed in the forward
* direction. Singly-linked lists are ideal for applications with large
* datasets and few or no removals or for implementing a LIFO queue.
*
* A list is headed by a single forward pointer (or an array of forward
* pointers for a hash table header). The elements are doubly linked
* so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before
* or after an existing element or at the head of the list. A list
* may only be traversed in the forward direction.
*
* A simple queue is headed by a pair of pointers, one the head of the
* list and the other to the tail of the list. The elements are singly
* linked to save space, so elements can only be removed from the
* head of the list. New elements can be added to the list after
* an existing element, at the head of the list, or at the end of the
* list. A simple queue may only be traversed in the forward direction.
*
* A tail queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or
* after an existing element, at the head of the list, or at the end of
* the list. A tail queue may be traversed in either direction.
*
* A circle queue is headed by a pair of pointers, one to the head of the
* list and the other to the tail of the list. The elements are doubly
* linked so that an arbitrary element can be removed without a need to
* traverse the list. New elements can be added to the list before or after
* an existing element, at the head of the list, or at the end of the list.
* A circle queue may be traversed in either direction, but has a more
* complex end of list detection.
*
* For details on the use of these macros, see the queue(3) manual page.
*/
/*
* List definitions.
*/
#define LIST_HEAD(name, type) \
struct name { \
struct type *lh_first; /* first element */ \
}
#define LIST_HEAD_INITIALIZER(head) \
{ NULL }
#define LIST_ENTRY(type) \
struct { \
struct type *le_next; /* next element */ \
struct type **le_prev; /* address of previous next element */ \
}
/*
* List functions.
*/
#define LIST_INIT(head) do { \
(head)->lh_first = NULL; \
} while (0)
#define LIST_INSERT_AFTER(listelm, elm, field) do { \
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
(listelm)->field.le_next->field.le_prev = \
&(elm)->field.le_next; \
(listelm)->field.le_next = (elm); \
(elm)->field.le_prev = &(listelm)->field.le_next; \
} while (0)
#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.le_prev = (listelm)->field.le_prev; \
(elm)->field.le_next = (listelm); \
*(listelm)->field.le_prev = (elm); \
(listelm)->field.le_prev = &(elm)->field.le_next; \
} while (0)
#define LIST_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.le_next = (head)->lh_first) != NULL) \
(head)->lh_first->field.le_prev = &(elm)->field.le_next;\
(head)->lh_first = (elm); \
(elm)->field.le_prev = &(head)->lh_first; \
} while (0)
#define LIST_REMOVE(elm, field) do { \
if ((elm)->field.le_next != NULL) \
(elm)->field.le_next->field.le_prev = \
(elm)->field.le_prev; \
*(elm)->field.le_prev = (elm)->field.le_next; \
} while (0)
#define LIST_FOREACH(var, head, field) \
for ((var) = ((head)->lh_first); \
(var); \
(var) = ((var)->field.le_next))
/*
* List access methods.
*/
#define LIST_EMPTY(head) ((head)->lh_first == NULL)
#define LIST_FIRST(head) ((head)->lh_first)
#define LIST_NEXT(elm, field) ((elm)->field.le_next)
/*
* Singly-linked List definitions.
*/
#define SLIST_HEAD(name, type) \
struct name { \
struct type *slh_first; /* first element */ \
}
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#define SLIST_ENTRY(type) \
struct { \
struct type *sle_next; /* next element */ \
}
/*
* Singly-linked List functions.
*/
#define SLIST_INIT(head) do { \
(head)->slh_first = NULL; \
} while (0)
#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
(elm)->field.sle_next = (slistelm)->field.sle_next; \
(slistelm)->field.sle_next = (elm); \
} while (0)
#define SLIST_INSERT_HEAD(head, elm, field) do { \
(elm)->field.sle_next = (head)->slh_first; \
(head)->slh_first = (elm); \
} while (0)
#define SLIST_REMOVE_HEAD(head, field) do { \
(head)->slh_first = (head)->slh_first->field.sle_next; \
} while (0)
#define SLIST_REMOVE(head, elm, type, field) do { \
if ((head)->slh_first == (elm)) { \
SLIST_REMOVE_HEAD((head), field); \
} \
else { \
struct type *curelm = (head)->slh_first; \
while(curelm->field.sle_next != (elm)) \
curelm = curelm->field.sle_next; \
curelm->field.sle_next = \
curelm->field.sle_next->field.sle_next; \
} \
} while (0)
#define SLIST_FOREACH(var, head, field) \
for((var) = (head)->slh_first; (var); (var) = (var)->field.sle_next)
/*
* Singly-linked List access methods.
*/
#define SLIST_EMPTY(head) ((head)->slh_first == NULL)
#define SLIST_FIRST(head) ((head)->slh_first)
#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
/*
* Singly-linked Tail queue declarations.
*/
#define STAILQ_HEAD(name, type) \
struct name { \
struct type *stqh_first; /* first element */ \
struct type **stqh_last; /* addr of last next element */ \
}
#define STAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).stqh_first }
#define STAILQ_ENTRY(type) \
struct { \
struct type *stqe_next; /* next element */ \
}
/*
* Singly-linked Tail queue functions.
*/
#define STAILQ_INIT(head) do { \
(head)->stqh_first = NULL; \
(head)->stqh_last = &(head)->stqh_first; \
} while (0)
#define STAILQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.stqe_next = (head)->stqh_first) == NULL) \
(head)->stqh_last = &(elm)->field.stqe_next; \
(head)->stqh_first = (elm); \
} while (0)
#define STAILQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.stqe_next = NULL; \
*(head)->stqh_last = (elm); \
(head)->stqh_last = &(elm)->field.stqe_next; \
} while (0)
#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.stqe_next = (listelm)->field.stqe_next) == NULL)\
(head)->stqh_last = &(elm)->field.stqe_next; \
(listelm)->field.stqe_next = (elm); \
} while (0)
#define STAILQ_REMOVE_HEAD(head, field) do { \
if (((head)->stqh_first = (head)->stqh_first->field.stqe_next) == NULL) \
(head)->stqh_last = &(head)->stqh_first; \
} while (0)
#define STAILQ_REMOVE(head, elm, type, field) do { \
if ((head)->stqh_first == (elm)) { \
STAILQ_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->stqh_first; \
while (curelm->field.stqe_next != (elm)) \
curelm = curelm->field.stqe_next; \
if ((curelm->field.stqe_next = \
curelm->field.stqe_next->field.stqe_next) == NULL) \
(head)->stqh_last = &(curelm)->field.stqe_next; \
} \
} while (0)
#define STAILQ_FOREACH(var, head, field) \
for ((var) = ((head)->stqh_first); \
(var); \
(var) = ((var)->field.stqe_next))
#define STAILQ_CONCAT(head1, head2) do { \
if (!STAILQ_EMPTY((head2))) { \
*(head1)->stqh_last = (head2)->stqh_first; \
(head1)->stqh_last = (head2)->stqh_last; \
STAILQ_INIT((head2)); \
} \
} while (0)
/*
* Singly-linked Tail queue access methods.
*/
#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL)
#define STAILQ_FIRST(head) ((head)->stqh_first)
#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next)
/*
* Simple queue definitions.
*/
#define SIMPLEQ_HEAD(name, type) \
struct name { \
struct type *sqh_first; /* first element */ \
struct type **sqh_last; /* addr of last next element */ \
}
#define SIMPLEQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).sqh_first }
#define SIMPLEQ_ENTRY(type) \
struct { \
struct type *sqe_next; /* next element */ \
}
/*
* Simple queue functions.
*/
#define SIMPLEQ_INIT(head) do { \
(head)->sqh_first = NULL; \
(head)->sqh_last = &(head)->sqh_first; \
} while (0)
#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
(head)->sqh_last = &(elm)->field.sqe_next; \
(head)->sqh_first = (elm); \
} while (0)
#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.sqe_next = NULL; \
*(head)->sqh_last = (elm); \
(head)->sqh_last = &(elm)->field.sqe_next; \
} while (0)
#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
(head)->sqh_last = &(elm)->field.sqe_next; \
(listelm)->field.sqe_next = (elm); \
} while (0)
#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
(head)->sqh_last = &(head)->sqh_first; \
} while (0)
#define SIMPLEQ_REMOVE(head, elm, type, field) do { \
if ((head)->sqh_first == (elm)) { \
SIMPLEQ_REMOVE_HEAD((head), field); \
} else { \
struct type *curelm = (head)->sqh_first; \
while (curelm->field.sqe_next != (elm)) \
curelm = curelm->field.sqe_next; \
if ((curelm->field.sqe_next = \
curelm->field.sqe_next->field.sqe_next) == NULL) \
(head)->sqh_last = &(curelm)->field.sqe_next; \
} \
} while (0)
#define SIMPLEQ_FOREACH(var, head, field) \
for ((var) = ((head)->sqh_first); \
(var); \
(var) = ((var)->field.sqe_next))
/*
* Simple queue access methods.
*/
#define SIMPLEQ_EMPTY(head) ((head)->sqh_first == NULL)
#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
/*
* Tail queue definitions.
*/
#define _TAILQ_HEAD(name, type, qual) \
struct name { \
qual type *tqh_first; /* first element */ \
qual type *qual *tqh_last; /* addr of last next element */ \
}
#define TAILQ_HEAD(name, type) _TAILQ_HEAD(name, struct type,)
#define TAILQ_HEAD_INITIALIZER(head) \
{ NULL, &(head).tqh_first }
#define _TAILQ_ENTRY(type, qual) \
struct { \
qual type *tqe_next; /* next element */ \
qual type *qual *tqe_prev; /* address of previous next element */\
}
#define TAILQ_ENTRY(type) _TAILQ_ENTRY(struct type,)
/*
* Tail queue functions.
*/
#define TAILQ_INIT(head) do { \
(head)->tqh_first = NULL; \
(head)->tqh_last = &(head)->tqh_first; \
} while (0)
#define TAILQ_INSERT_HEAD(head, elm, field) do { \
if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
(head)->tqh_first->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(head)->tqh_first = (elm); \
(elm)->field.tqe_prev = &(head)->tqh_first; \
} while (0)
#define TAILQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.tqe_next = NULL; \
(elm)->field.tqe_prev = (head)->tqh_last; \
*(head)->tqh_last = (elm); \
(head)->tqh_last = &(elm)->field.tqe_next; \
} while (0)
#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
(elm)->field.tqe_next->field.tqe_prev = \
&(elm)->field.tqe_next; \
else \
(head)->tqh_last = &(elm)->field.tqe_next; \
(listelm)->field.tqe_next = (elm); \
(elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
} while (0)
#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
(elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
(elm)->field.tqe_next = (listelm); \
*(listelm)->field.tqe_prev = (elm); \
(listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
} while (0)
#define TAILQ_REMOVE(head, elm, field) do { \
if (((elm)->field.tqe_next) != NULL) \
(elm)->field.tqe_next->field.tqe_prev = \
(elm)->field.tqe_prev; \
else \
(head)->tqh_last = (elm)->field.tqe_prev; \
*(elm)->field.tqe_prev = (elm)->field.tqe_next; \
} while (0)
#define TAILQ_FOREACH(var, head, field) \
for ((var) = ((head)->tqh_first); \
(var); \
(var) = ((var)->field.tqe_next))
#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
for ((var) = (*(((struct headname *)((head)->tqh_last))->tqh_last)); \
(var); \
(var) = (*(((struct headname *)((var)->field.tqe_prev))->tqh_last)))
#define TAILQ_CONCAT(head1, head2, field) do { \
if (!TAILQ_EMPTY(head2)) { \
*(head1)->tqh_last = (head2)->tqh_first; \
(head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
(head1)->tqh_last = (head2)->tqh_last; \
TAILQ_INIT((head2)); \
} \
} while (0)
/*
* Tail queue access methods.
*/
#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL)
#define TAILQ_FIRST(head) ((head)->tqh_first)
#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
#define TAILQ_LAST(head, headname) \
(*(((struct headname *)((head)->tqh_last))->tqh_last))
#define TAILQ_PREV(elm, headname, field) \
(*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
/*
* Circular queue definitions.
*/
#define CIRCLEQ_HEAD(name, type) \
struct name { \
struct type *cqh_first; /* first element */ \
struct type *cqh_last; /* last element */ \
}
#define CIRCLEQ_HEAD_INITIALIZER(head) \
{ (void *)&head, (void *)&head }
#define CIRCLEQ_ENTRY(type) \
struct { \
struct type *cqe_next; /* next element */ \
struct type *cqe_prev; /* previous element */ \
}
/*
* Circular queue functions.
*/
#define CIRCLEQ_INIT(head) do { \
(head)->cqh_first = (void *)(head); \
(head)->cqh_last = (void *)(head); \
} while (0)
#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm)->field.cqe_next; \
(elm)->field.cqe_prev = (listelm); \
if ((listelm)->field.cqe_next == (void *)(head)) \
(head)->cqh_last = (elm); \
else \
(listelm)->field.cqe_next->field.cqe_prev = (elm); \
(listelm)->field.cqe_next = (elm); \
} while (0)
#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
(elm)->field.cqe_next = (listelm); \
(elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
if ((listelm)->field.cqe_prev == (void *)(head)) \
(head)->cqh_first = (elm); \
else \
(listelm)->field.cqe_prev->field.cqe_next = (elm); \
(listelm)->field.cqe_prev = (elm); \
} while (0)
#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
(elm)->field.cqe_next = (head)->cqh_first; \
(elm)->field.cqe_prev = (void *)(head); \
if ((head)->cqh_last == (void *)(head)) \
(head)->cqh_last = (elm); \
else \
(head)->cqh_first->field.cqe_prev = (elm); \
(head)->cqh_first = (elm); \
} while (0)
#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
(elm)->field.cqe_next = (void *)(head); \
(elm)->field.cqe_prev = (head)->cqh_last; \
if ((head)->cqh_first == (void *)(head)) \
(head)->cqh_first = (elm); \
else \
(head)->cqh_last->field.cqe_next = (elm); \
(head)->cqh_last = (elm); \
} while (0)
#define CIRCLEQ_REMOVE(head, elm, field) do { \
if ((elm)->field.cqe_next == (void *)(head)) \
(head)->cqh_last = (elm)->field.cqe_prev; \
else \
(elm)->field.cqe_next->field.cqe_prev = \
(elm)->field.cqe_prev; \
if ((elm)->field.cqe_prev == (void *)(head)) \
(head)->cqh_first = (elm)->field.cqe_next; \
else \
(elm)->field.cqe_prev->field.cqe_next = \
(elm)->field.cqe_next; \
} while (0)
#define CIRCLEQ_FOREACH(var, head, field) \
for ((var) = ((head)->cqh_first); \
(var) != (const void *)(head); \
(var) = ((var)->field.cqe_next))
#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
for ((var) = ((head)->cqh_last); \
(var) != (const void *)(head); \
(var) = ((var)->field.cqe_prev))
/*
* Circular queue access methods.
*/
#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head))
#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
#define CIRCLEQ_LAST(head) ((head)->cqh_last)
#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
#define CIRCLEQ_LOOP_NEXT(head, elm, field) \
(((elm)->field.cqe_next == (void *)(head)) \
? ((head)->cqh_first) \
: (elm->field.cqe_next))
#define CIRCLEQ_LOOP_PREV(head, elm, field) \
(((elm)->field.cqe_prev == (void *)(head)) \
? ((head)->cqh_last) \
: (elm->field.cqe_prev))
#endif /* _SYS_QUEUE_H_ */
+36
View File
@@ -0,0 +1,36 @@
#ifndef _SYS_REG_H
#define _SYS_REG_H
#ifdef __x86_64__
#define R15 0
#define R14 1
#define R13 2
#define R12 3
#define RBP 4
#define RBX 5
#define R11 6
#define R10 7
#define R9 8
#define R8 9
#define RAX 10
#define RCX 11
#define RDX 12
#define RSI 13
#define RDI 14
#define ORIG_RAX 15
#define RIP 16
#define CS 17
#define EFLAGS 18
#define RSP 19
#define SS 20
#define FS_BASE 21
#define GS_BASE 22
#define DS 23
#define ES 24
#define FS 25
#define GS 26
#elif !(defined(__i386__) || defined(__riscv) || defined(__aarch64__) || defined(__m68k__) || defined(__loongarch64))
#error "Missing architecture specific code."
#endif
#endif
+53
View File
@@ -0,0 +1,53 @@
#ifndef _SYS_RESOURCE_H
#define _SYS_RESOURCE_H
#include <abi-bits/pid_t.h>
#include <abi-bits/resource.h>
#include <abi-bits/rlim_t.h>
#include <abi-bits/suseconds_t.h>
#include <bits/ansi/time_t.h>
#include <bits/posix/id_t.h>
#include <bits/posix/timeval.h>
#define PRIO_PROCESS 1
#define PRIO_PGRP 2
#define PRIO_USER 3
#define PRIO_MIN (-20)
#define PRIO_MAX 20
#define RLIM_INFINITY ((rlim_t)-1)
#define RLIM_SAVED_MAX ((rlim_t)-1)
#define RLIM_SAVED_CUR ((rlim_t)-1)
#define RLIM_NLIMITS RLIMIT_NLIMITS
#ifdef __cplusplus
extern "C" {
#endif
struct rlimit {
rlim_t rlim_cur;
rlim_t rlim_max;
};
#ifndef __MLIBC_ABI_ONLY
int getpriority(int __which, id_t __who);
int setpriority(int __which, id_t __who, int __prio);
int getrusage(int __who, struct rusage *__usage);
int getrlimit(int __resource, struct rlimit *__rlim);
int getrlimit64(int __resource, struct rlimit *__rlim);
int setrlimit(int __resource, const struct rlimit *__rlim);
int setrlimit64(int __resource, const struct rlimit *__rlim);
int prlimit(pid_t __pid, int __resource, const struct rlimit *__new_limits, struct rlimit *__old_limits);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_RESOURCE_H */
+49
View File
@@ -0,0 +1,49 @@
#ifndef _SYS_SELECT_H
#define _SYS_SELECT_H
#include <abi-bits/signal.h>
#include <bits/ansi/time_t.h>
#include <bits/ansi/timespec.h>
#include <abi-bits/suseconds_t.h>
#include <bits/posix/timeval.h>
#include <bits/posix/fd_set.h>
#define FD_SETSIZE 1024
#ifdef __cplusplus
extern "C" {
#endif
typedef long int __fd_mask;
#define __NFDBITS (8 * (int) sizeof (__fd_mask))
typedef __fd_mask fd_mask;
#define NFDBITS __NFDBITS
#ifndef __MLIBC_ABI_ONLY
void __FD_CLR(int __fd, fd_set *__set);
int __FD_ISSET(int __fd, fd_set *__set);
void __FD_SET(int __fd, fd_set *__set);
void __FD_ZERO(fd_set *__set);
#define FD_CLR(fd, set) __FD_CLR(fd, set)
#define FD_ISSET(fd, set) __FD_ISSET(fd, set)
#define FD_SET(fd, set) __FD_SET(fd, set)
#define FD_ZERO(set) __FD_ZERO(set)
int select(int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds,
fd_set *__restrict __exceptfds, struct timeval *__restrict __timeout);
int pselect(int __nfds, fd_set *__restrict __readfds, fd_set *__restrict __writefds,
fd_set *__exceptfds, const struct timespec *__timeout, const sigset_t *__sigmask);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_SELECT_H */
+46
View File
@@ -0,0 +1,46 @@
#ifndef _SYS_SEM_H
#define _SYS_SEM_H
#include <bits/ansi/time_t.h>
#include <sys/ipc.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#define GETPID 11
#define GETVAL 12
#define GETALL 13
#define SETVAL 16
#define SETALL 17
#define SEM_UNDO 0x1000
struct sembuf {
unsigned short int sem_num;
short int sem_op;
short int sem_flg;
};
struct semid_ds {
struct ipc_perm sem_perm;
time_t sem_otime;
time_t sem_ctime;
unsigned long sem_nsems;
};
#ifndef __MLIBC_ABI_ONLY
int semget(key_t __key, int __nsems, int __semflg);
int semop(int __semid, struct sembuf *__sops, size_t __nsops);
int semctl(int __semid, int __semnum, int __op, ...);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_SEM_H */
+28
View File
@@ -0,0 +1,28 @@
#ifndef _SYS_SHM_H
#define _SYS_SHM_H
#ifdef __cplusplus
extern "C" {
#endif
#include <abi-bits/pid_t.h>
#include <abi-bits/shm.h>
#include <bits/size_t.h>
#include <time.h>
#include <sys/ipc.h>
#ifndef __MLIBC_ABI_ONLY
void *shmat(int __shmid, const void *__shmaddr, int __shmflg);
int shmctl(int __shmid, int __cmd, struct shmid_ds *__buf);
int shmdt(const void *__shmaddr);
int shmget(key_t __key, size_t __size, int __shmflg);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_SHM_H */
+1
View File
@@ -0,0 +1 @@
#include <signal.h>
+107
View File
@@ -0,0 +1,107 @@
#ifndef _SOCKET_H
#define _SOCKET_H
#include <abi-bits/gid_t.h>
#include <abi-bits/pid_t.h>
#include <bits/size_t.h>
#include <abi-bits/socklen_t.h>
#include <bits/ssize_t.h>
#include <abi-bits/uid_t.h>
#include <bits/posix/iovec.h>
#include <abi-bits/socket.h>
#include <bits/ansi/time_t.h>
#include <bits/ansi/timespec.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
struct sockaddr {
sa_family_t sa_family;
char sa_data[14];
};
/* Control message format: */
/* The offsets marked with ^ are aligned to alignof(size_t). */
/* */
/* |---HEADER---|---DATA---|---PADDING---|---HEADER---|... */
/* ^ ^ ^ */
/* |---------CMSG_LEN------| */
/* |---------------CMSG_SPACE------------| */
/* Auxiliary macro. While there is basically no reason for applications */
/* to use this, it is exported by glibc. */
#define CMSG_ALIGN(s) (((s) + __alignof__(size_t) - 1) & \
~(__alignof__(size_t) - 1))
/* Basic macros to return content and padding size of a control message. */
#define CMSG_LEN(s) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (s))
#define CMSG_SPACE(s) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(s))
/* Provides access to the data of a control message. */
#define CMSG_DATA(c) ((char *)(c) + CMSG_ALIGN(sizeof(struct cmsghdr)))
#define __MLIBC_CMSG_NEXT(c) ((char *)(c) + CMSG_ALIGN((c)->cmsg_len))
#define __MLIBC_MHDR_LIMIT(m) ((char *)(m)->msg_control + (m)->msg_controllen)
/* For parsing control messages only. */
/* Returns a pointer to the first header or nullptr if there is none. */
#define CMSG_FIRSTHDR(m) ((size_t)(m)->msg_controllen <= sizeof(struct cmsghdr) \
? (struct cmsghdr *)0 : (struct cmsghdr *) (m)->msg_control)
/* For parsing control messages only. */
/* Returns a pointer to the next header or nullptr if there is none. */
#define CMSG_NXTHDR(m, c) \
((c)->cmsg_len < sizeof(struct cmsghdr) || \
(ptrdiff_t)(sizeof(struct cmsghdr) + CMSG_ALIGN((c)->cmsg_len)) \
>= __MLIBC_MHDR_LIMIT(m) - (char *)(c) \
? (struct cmsghdr *)0 : (struct cmsghdr *)__MLIBC_CMSG_NEXT(c))
struct linger{
int l_onoff;
int l_linger;
};
struct ucred {
pid_t pid;
uid_t uid;
gid_t gid;
};
#ifndef __MLIBC_ABI_ONLY
int accept(int __sockfd, struct sockaddr *__restrict __addr, socklen_t *__restrict __addrlen);
int accept4(int __sockfd, struct sockaddr *__restrict __addr, socklen_t *__restrict __addrlen, int __flags);
int bind(int __sockfd, const struct sockaddr *__addr, socklen_t __addrlen);
int connect(int __sockfd, const struct sockaddr *__addr, socklen_t __addrlen);
int getpeername(int __sockfd, struct sockaddr *__restrict __addr, socklen_t *__restrict __addrlen);
int getsockname(int __sockfd, struct sockaddr *__restrict __addr, socklen_t *__restrict __addrlen);
int getsockopt(int __sockfd, int __level, int __optname, void *__restrict __optval, socklen_t *__restrict __optlen);
int listen(int __sockfd, int __backlog);
ssize_t recv(int __sockfd, void *__buf, size_t __size, int __flags);
ssize_t recvfrom(int __sockfd, void *__restrict __buf, size_t __size, int __flags,
struct sockaddr *__restrict __src_addr, socklen_t *__restrict __addrlen);
ssize_t recvmsg(int __sockfd, struct msghdr *__msg, int __flags);
ssize_t send(int __sockfd, const void *__buf, size_t __size, int __flags);
ssize_t sendmsg(int __sockfd, const struct msghdr *__msg, int __flags);
ssize_t sendto(int __sockfd, const void *__buf, size_t __size, int __flags,
const struct sockaddr *__dest_addr, socklen_t __addrlen);
int recvmmsg(int __sockfd, struct mmsghdr *__msgvec, unsigned int __vlen, int __flags, struct timespec *__timeout);
int sendmmsg(int __sockfd, struct mmsghdr *__msgvec, unsigned int __vlen, int __flags);
int setsockopt(int __sockfd, int __level, int __option_name, const void *__optval, socklen_t __optlen);
int shutdown(int __sockfd, int __how);
int sockatmark(int __sockfd);
int socket(int __domain, int __type, int __protocol);
int socketpair(int __domain, int __type, int __protocol, int __sv[2]);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _UNISTD_H */
+44
View File
@@ -0,0 +1,44 @@
#ifndef _SYS_STAT_H
#define _SYS_STAT_H
#include <bits/posix/stat.h>
#include <mlibc-config.h>
#if __MLIBC_LINUX_OPTION
#include <bits/linux/linux_stat.h>
#endif /* !__MLIBC_LINUX_OPTION */
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
int chmod(const char *__pathname, mode_t __mode);
int fchmod(int __fd, mode_t __mode);
int fchmodat(int __fd, const char *__pathname, mode_t __mode, int __flags);
int fstat(int __fd, struct stat *__result);
int fstat64(int __fd, struct stat64 *__result);
int fstatat(int __fd, const char *__restrict __pathname, struct stat *__restrict __buf, int __flags);
int futimens(int __fd, const struct timespec __times[2]);
int lstat(const char *__restrict __pathname, struct stat *__restrict __buf);
int lstat64(const char *__restrict __pathname, struct stat64 *__restrict __buf);
int mkdir(const char *__pathname, mode_t __mode);
int mkdirat(int __dirfd, const char *__pathname, mode_t __mode);
int mkfifo(const char *__pathname, mode_t __mode);
int mkfifoat(int __dirfd, const char *__pathname, mode_t __mode);
int mknod(const char *__pathname, mode_t __mode, dev_t __dev);
int mknodat(int __dirfd, const char *__pathname, mode_t __mode, dev_t __dev);
int stat(const char *__restrict __pathname, struct stat *__restrict __buf);
mode_t umask(mode_t __mode);
int utimensat(int __dirfd, const char *__pathname, const struct timespec __times[2], int __flags);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_STAT_H */
+24
View File
@@ -0,0 +1,24 @@
#ifndef _SYS_STATVFS_H
#define _SYS_STATVFS_H
#ifdef __cplusplus
extern "C" {
#endif
#include <abi-bits/statvfs.h>
#ifndef __MLIBC_ABI_ONLY
int statvfs(const char *__restrict __pathname, struct statvfs *__restrict __buf);
int statvfs64(const char *__restrict __pathname, struct statvfs64 *__restrict __buf);
int fstatvfs(int __fd, struct statvfs *__buf);
int fstatvfs64(int __fd, struct statvfs64 *__buf);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_STATVFS_H */
+1
View File
@@ -0,0 +1 @@
#include <syslog.h>
+6
View File
@@ -0,0 +1,6 @@
#ifndef _SYS_TERMIOS_H
#define _SYS_TERMIOS_H
#include <termios.h>
#endif /* _SYS_TERMIOS_H */
+62
View File
@@ -0,0 +1,62 @@
#ifndef _SYS_TIME_H
#define _SYS_TIME_H
#include <abi-bits/time.h>
#include <abi-bits/signal.h>
#include <abi-bits/clockid_t.h>
#include <bits/ansi/time_t.h>
#include <abi-bits/suseconds_t.h>
#include <bits/posix/timer_t.h>
#include <bits/posix/timeval.h>
#include <sys/select.h>
#ifdef __cplusplus
extern "C" {
#endif
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
#ifndef __MLIBC_ABI_ONLY
/* TODO: this function is [OB]. disable it by default and add a macro to enable it */
int gettimeofday(struct timeval *__restrict __result, void *__restrict __unused);
int settimeofday(const struct timeval *__result, const struct timezone *__zone);
void timeradd(const struct timeval *__a, const struct timeval *__b, struct timeval *__res);
void timersub(const struct timeval *__a, const struct timeval *__b, struct timeval *__res);
void timerclear(struct timeval *__tvp);
int timerisset(struct timeval *__tvp);
#endif /* !__MLIBC_ABI_ONLY */
/* timercmp taken from musl */
#define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \
(s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec)
#ifndef __MLIBC_ABI_ONLY
int getitimer(int __which, struct itimerval *__curr_value);
int setitimer(int __which, const struct itimerval *__new_value,
struct itimerval *__old_value);
#endif /* !__MLIBC_ABI_ONLY */
/* The following 2 macros are taken from musl */
#define TIMEVAL_TO_TIMESPEC(tv, ts) ( \
(ts)->tv_sec = (tv)->tv_sec, \
(ts)->tv_nsec = (tv)->tv_usec * 1000, \
(void)0 )
#define TIMESPEC_TO_TIMEVAL(tv, ts) ( \
(tv)->tv_sec = (ts)->tv_sec, \
(tv)->tv_usec = (ts)->tv_nsec / 1000, \
(void)0 )
#ifdef __cplusplus
}
#endif
#endif /* _SYS_TIME_H */
+14
View File
@@ -0,0 +1,14 @@
#ifndef _SYS_TIMEB_H
#define _SYS_TIMEB_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* _SYS_TIMEB_H */
+28
View File
@@ -0,0 +1,28 @@
#ifndef _SYS_TIMES_H
#define _SYS_TIMES_H
/* TODO: Only define the clock_t type. */
#include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
struct tms {
clock_t tms_utime;
clock_t tms_stime;
clock_t tms_cutime;
clock_t tms_cstime;
};
#ifndef __MLIBC_ABI_ONLY
clock_t times(struct tms *__tms);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_TIMES_H */
+80
View File
@@ -0,0 +1,80 @@
#ifndef _SYS_TIMEX_H
#define _SYS_TIMEX_H
#ifdef __cplusplus
extern "C" {
#endif
#include <abi-bits/clockid_t.h>
#include <bits/posix/timeval.h>
struct timex {
int modes;
long offset;
long freq;
long maxerror;
long esterror;
int status;
long constant;
long precision;
long tolerance;
struct timeval time;
long tick;
long ppsfreq;
long jitter;
int shift;
long stabil;
long jitcnt;
long calcnt;
long errcnt;
long stbcnt;
int tai;
int __padding[11];
};
#define ADJ_OFFSET 0x0001
#define ADJ_FREQUENCY 0x0002
#define ADJ_MAXERROR 0x0004
#define ADJ_ESTERROR 0x0008
#define ADJ_STATUS 0x0010
#define ADJ_TIMECONST 0x0020
#define ADJ_TAI 0x0080
#define ADJ_SETOFFSET 0x0100
#define ADJ_MICRO 0x1000
#define ADJ_NANO 0x2000
#define ADJ_TICK 0x4000
#define ADJ_OFFSET_SINGLESHOT 0x8001
#define ADJ_OFFSET_SS_READ 0xa001
#define STA_PLL 0x0001
#define STA_PPSFREQ 0x0002
#define STA_PPSTIME 0x0004
#define STA_FLL 0x0008
#define STA_INS 0x0010
#define STA_DEL 0x0020
#define STA_UNSYNC 0x0040
#define STA_FREQHOLD 0x0080
#define STA_PPSSIGNAL 0x0100
#define STA_PPSJITTER 0x0200
#define STA_PPSWANDER 0x0400
#define STA_PPSERROR 0x0800
#define STA_CLOCKERR 0x1000
#define STA_NANO 0x2000
#define STA_MODE 0x4000
#define STA_CLK 0x8000
#define TIME_ERROR 5
#ifndef __MLIBC_ABI_ONLY
int adjtimex(struct timex *__buf);
int clock_adjtime(clockid_t __clockid, struct timex *__buf);
int ntp_adjtime(struct timex *__buf);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_TIMEX_H */
+39
View File
@@ -0,0 +1,39 @@
#ifndef _SYS_TTYDEFAULTS_H
#define _SYS_TTYDEFAULTS_H
/* Values taken from musl */
#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS)
#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
#define TTYDEF_CFLAG (CREAD | CS7 | PARENB | HUPCL)
#define TTYDEF_SPEED (B9600)
#define CTRL(x) ((x) & 037)
#define CEOF CTRL('d')
#define CEOL '\0'
#define CEOL2 '\0'
#define CSTATUS '\0'
#define CERASE 0177
#define CINTR CTRL('c')
#define CKILL CTRL('u')
#define CMIN 1
#define CQUIT 034
#define CSUSP CTRL('z')
#define CTIME 0
#define CDSUSP CTRL('y')
#define CSTART CTRL('q')
#define CSTOP CTRL('s')
#define CLNEXT CTRL('v')
#define CDISCARD CTRL('o')
#define CWERASE CTRL('w')
#define CREPRINT CTRL('r')
#define CEOT CEOF
#define CBRK CEOL
#define CRPRNT CREPRINT
#define CFLUSH CDISCARD
#endif /* _SYS_TTYDEFAULTS_H */
+53
View File
@@ -0,0 +1,53 @@
#ifndef _SYS_TYPES_H
#define _SYS_TYPES_H
#include <bits/size_t.h>
#include <bits/ssize_t.h>
#include <bits/off_t.h>
#include <bits/posix/id_t.h>
#include <abi-bits/uid_t.h>
#include <abi-bits/gid_t.h>
#include <abi-bits/pid_t.h>
#include <abi-bits/mode_t.h>
#include <abi-bits/dev_t.h>
#include <abi-bits/ino_t.h>
#include <abi-bits/blksize_t.h>
#include <abi-bits/blkcnt_t.h>
#include <abi-bits/nlink_t.h>
#include <bits/ansi/time_t.h>
#include <abi-bits/suseconds_t.h>
#include <abi-bits/fsblkcnt_t.h>
#include <abi-bits/fsfilcnt_t.h>
#include <bits/posix/fd_set.h>
#include <stdint.h>
#include <sys/select.h>
typedef unsigned int u_int;
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned long int u_long;
typedef char *caddr_t;
typedef off64_t loff_t;
typedef unsigned long int ulong;
typedef unsigned short int ushort;
typedef unsigned int uint;
typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
typedef uint64_t u_int64_t;
/* BSD extensions */
typedef int64_t quad_t;
typedef uint64_t u_quad_t;
#endif /* _SYS_TYPES_H */
+14
View File
@@ -0,0 +1,14 @@
#ifndef _SYS_UCONTEXT_H
#define _SYS_UCONTEXT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif /* _SYS_UCONTEXT_H */
+37
View File
@@ -0,0 +1,37 @@
#ifndef _SYS_UIO_H
#define _SYS_UIO_H
#include <abi-bits/pid_t.h>
#include <bits/posix/iovec.h>
#include <bits/ssize_t.h>
#include <bits/off_t.h>
#include <bits/size_t.h>
#include <limits.h>
#include <mlibc-config.h>
#ifdef __cplusplus
extern "C" {
#endif
#define UIO_MAXIOV IOV_MAX
#ifndef __MLIBC_ABI_ONLY
ssize_t readv(int __fd, const struct iovec *__iov, int __iovcnt);
ssize_t writev(int __fd, const struct iovec *__iov, int __iovcnt);
/* Non standard extensions, also found on modern BSD's */
ssize_t preadv(int __fd, const struct iovec *__iov, int __iovcnt, off_t __offset);
ssize_t pwritev(int __fd, const struct iovec *__iov, int __iovcnt, off_t __offset);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#if __MLIBC_LINUX_OPTION
#include <bits/linux/linux_uio.h>
#endif /* __MLIBC_LINUX_OPTION */
#endif /* _SYS_UIO_H */
+24
View File
@@ -0,0 +1,24 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H
#ifdef __cplusplus
extern "C" {
#endif
#include <abi-bits/socket.h>
struct sockaddr_un {
sa_family_t sun_family;
char sun_path[108];
};
/* Evaluate to actual length of the `sockaddr_un' structure. */
#define SUN_LEN(ptr) ((size_t) offsetof(struct sockaddr_un, sun_path) + strlen((ptr)->sun_path))
#ifdef __cplusplus
}
#endif
#endif /* _SYS_UN_H */
+51
View File
@@ -0,0 +1,51 @@
#ifndef _SYS_USER_H
#define _SYS_USER_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/* TODO: This assumes x86-64. */
struct user_fpregs_struct {
uint16_t cwd, swd, ftw, fop;
uint64_t rip, rdp;
uint32_t mxcsr, mxcr_mask;
uint32_t st_space[32], xmm_space[64], padding[24];
};
struct user_regs_struct {
unsigned long r15, r14, r13, r12, rbp, rbx, r11, r10, r9, r8;
unsigned long rax, rcx, rdx, rsi, rdi, orig_rax, rip;
unsigned long cs, eflags, rsp, ss, fs_base, gs_base, ds, es, fs, gs;
};
struct user {
struct user_regs_struct regs;
int u_fpvalid;
struct user_fpregs_struct i387;
unsigned long u_tsize;
unsigned long u_dsize;
unsigned long u_ssize;
unsigned long start_code;
unsigned long start_stack;
long signal;
int reserved;
struct user_regs_struct *u_ar0;
struct user_fpregs_struct *u_fpstate;
unsigned long magic;
char u_comm[32];
unsigned long u_debugreg[8];
};
#ifdef __cplusplus
}
#endif
#define PAGE_SHIFT 12
#define PAGE_SIZE (1UL << PAGE_SHIFT)
#define PAGE_MASK (~(PAGE_SIZE - 1))
#endif
+22
View File
@@ -0,0 +1,22 @@
#ifndef _SYS_UTSNAME_H
#define _SYS_UTSNAME_H
#include <abi-bits/utsname.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef __MLIBC_ABI_ONLY
int uname(struct utsname *__name);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_UTSNAME_H */
+40
View File
@@ -0,0 +1,40 @@
#ifndef _SYS_WAIT_H
#define _SYS_WAIT_H
#include <bits/posix/id_t.h>
#include <abi-bits/pid_t.h>
/* for siginfo_t */
#include <abi-bits/signal.h>
#include <abi-bits/wait.h>
#ifdef __cplusplus
extern "C" {
#endif
/* According to POSIX, <sys/wait.h> does not make rusage available. */
struct rusage;
/* TODO: move to own file and include in sys/types.h */
typedef enum {
P_ALL, P_PID, P_PGID, P_PIDFD
} idtype_t;
#ifndef __MLIBC_ABI_ONLY
pid_t wait(int *__status);
int waitid(idtype_t __idtype, id_t __id, siginfo_t *__siginfo, int __flags);
pid_t waitpid(pid_t __pid, int *__status, int __flags);
/* GNU extensions. */
pid_t wait3(int *__status, int __options, struct rusage *__ru);
pid_t wait4(pid_t __pid, int *__status, int __options, struct rusage *__ru);
#endif /* !__MLIBC_ABI_ONLY */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_WAIT_H */