2020-01-18 03:38:21 -05:00
|
|
|
/*
|
2021-08-14 10:03:38 -04:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 03:38:21 -05:00
|
|
|
*
|
2021-04-22 04:24:48 -04:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 03:38:21 -05:00
|
|
|
*/
|
|
|
|
|
2018-10-14 16:57:41 -04:00
|
|
|
#pragma once
|
|
|
|
|
2020-08-08 11:32:34 -04:00
|
|
|
#include <AK/DistinctNumeric.h>
|
2019-04-06 08:29:29 -04:00
|
|
|
#include <AK/Types.h>
|
2021-08-14 09:36:26 -04:00
|
|
|
#include <Kernel/API/POSIX/fcntl.h>
|
2021-08-14 11:12:54 -04:00
|
|
|
#include <Kernel/API/POSIX/futex.h>
|
2021-08-14 10:53:38 -04:00
|
|
|
#include <Kernel/API/POSIX/netinet/in.h>
|
2021-08-14 11:05:53 -04:00
|
|
|
#include <Kernel/API/POSIX/signal.h>
|
2021-08-14 10:03:38 -04:00
|
|
|
#include <Kernel/API/POSIX/sys/mman.h>
|
2021-08-14 10:34:29 -04:00
|
|
|
#include <Kernel/API/POSIX/sys/socket.h>
|
2021-08-14 09:42:24 -04:00
|
|
|
#include <Kernel/API/POSIX/sys/stat.h>
|
2021-08-14 10:34:29 -04:00
|
|
|
#include <Kernel/API/POSIX/sys/un.h>
|
2021-08-14 10:14:32 -04:00
|
|
|
#include <Kernel/API/POSIX/termios.h>
|
2021-08-14 09:42:24 -04:00
|
|
|
#include <Kernel/API/POSIX/time.h>
|
2020-05-28 10:52:02 -04:00
|
|
|
|
|
|
|
// Kernel internal options.
|
|
|
|
#define O_NOFOLLOW_NOERROR (1 << 29)
|
|
|
|
#define O_UNLINK_INTERNAL (1 << 30)
|
|
|
|
|
|
|
|
#define MS_NODEV (1 << 0)
|
|
|
|
#define MS_NOEXEC (1 << 1)
|
|
|
|
#define MS_NOSUID (1 << 2)
|
|
|
|
#define MS_BIND (1 << 3)
|
2020-05-28 10:56:25 -04:00
|
|
|
#define MS_RDONLY (1 << 4)
|
2020-05-28 14:12:13 -04:00
|
|
|
#define MS_REMOUNT (1 << 5)
|
2020-05-28 10:52:02 -04:00
|
|
|
|
2020-07-14 16:41:59 -04:00
|
|
|
enum {
|
2021-06-03 19:45:04 -04:00
|
|
|
_SC_MONOTONIC_CLOCK,
|
2020-07-14 16:41:59 -04:00
|
|
|
_SC_NPROCESSORS_CONF,
|
|
|
|
_SC_NPROCESSORS_ONLN,
|
2021-01-18 03:51:21 -05:00
|
|
|
_SC_OPEN_MAX,
|
|
|
|
_SC_TTY_NAME_MAX,
|
2021-01-29 13:28:19 -05:00
|
|
|
_SC_PAGESIZE,
|
2021-02-11 21:11:50 -05:00
|
|
|
_SC_GETPW_R_SIZE_MAX,
|
2021-03-16 14:05:23 -04:00
|
|
|
_SC_CLK_TCK,
|
2020-07-14 16:41:59 -04:00
|
|
|
};
|
|
|
|
|
2021-04-25 17:42:36 -04:00
|
|
|
enum {
|
2021-05-14 02:10:43 -04:00
|
|
|
PERF_EVENT_SAMPLE = 1,
|
|
|
|
PERF_EVENT_MALLOC = 2,
|
|
|
|
PERF_EVENT_FREE = 4,
|
|
|
|
PERF_EVENT_MMAP = 8,
|
|
|
|
PERF_EVENT_MUNMAP = 16,
|
|
|
|
PERF_EVENT_PROCESS_CREATE = 32,
|
|
|
|
PERF_EVENT_PROCESS_EXEC = 64,
|
|
|
|
PERF_EVENT_PROCESS_EXIT = 128,
|
|
|
|
PERF_EVENT_THREAD_CREATE = 256,
|
|
|
|
PERF_EVENT_THREAD_EXIT = 512,
|
|
|
|
PERF_EVENT_CONTEXT_SWITCH = 1024,
|
2021-05-13 07:09:00 -04:00
|
|
|
PERF_EVENT_KMALLOC = 2048,
|
|
|
|
PERF_EVENT_KFREE = 4096,
|
2021-05-18 05:26:11 -04:00
|
|
|
PERF_EVENT_PAGE_FAULT = 8192,
|
2021-08-10 15:02:59 -04:00
|
|
|
PERF_EVENT_SYSCALL = 16384,
|
2021-08-11 14:04:03 -04:00
|
|
|
PERF_EVENT_SIGNPOST = 32768,
|
2021-04-25 17:42:36 -04:00
|
|
|
};
|
2020-02-02 14:26:27 -05:00
|
|
|
|
2018-11-16 18:11:08 -05:00
|
|
|
#define WNOHANG 1
|
2019-07-14 05:35:49 -04:00
|
|
|
#define WUNTRACED 2
|
|
|
|
#define WSTOPPED WUNTRACED
|
|
|
|
#define WEXITED 4
|
|
|
|
#define WCONTINUED 8
|
2020-11-29 18:05:27 -05:00
|
|
|
#define WNOWAIT 0x1000000
|
2018-11-16 18:11:08 -05:00
|
|
|
|
2019-02-26 09:57:59 -05:00
|
|
|
#define R_OK 4
|
|
|
|
#define W_OK 2
|
|
|
|
#define X_OK 1
|
|
|
|
#define F_OK 0
|
|
|
|
|
2018-10-14 16:57:41 -04:00
|
|
|
#define SEEK_SET 0
|
|
|
|
#define SEEK_CUR 1
|
|
|
|
#define SEEK_END 2
|
|
|
|
|
2019-12-09 13:12:38 -05:00
|
|
|
#define MADV_SET_VOLATILE 0x100
|
|
|
|
#define MADV_SET_NONVOLATILE 0x200
|
|
|
|
|
2018-11-11 09:36:40 -05:00
|
|
|
#define F_DUPFD 0
|
|
|
|
#define F_GETFD 1
|
|
|
|
#define F_SETFD 2
|
|
|
|
#define F_GETFL 3
|
|
|
|
#define F_SETFL 4
|
2020-05-19 13:34:45 -04:00
|
|
|
#define F_ISTTY 5
|
2021-07-19 01:29:56 -04:00
|
|
|
#define F_GETLK 6
|
|
|
|
#define F_SETLK 7
|
|
|
|
#define F_SETLKW 8
|
2018-11-11 09:36:40 -05:00
|
|
|
|
2018-11-12 19:36:31 -05:00
|
|
|
#define FD_CLOEXEC 1
|
|
|
|
|
2020-08-08 11:32:34 -04:00
|
|
|
// Avoid interference with AK/Types.h and LibC/sys/types.h by defining *separate* names:
|
|
|
|
TYPEDEF_DISTINCT_ORDERED_ID(pid_t, ProcessID);
|
|
|
|
TYPEDEF_DISTINCT_ORDERED_ID(pid_t, ThreadID);
|
|
|
|
TYPEDEF_DISTINCT_ORDERED_ID(pid_t, SessionID);
|
|
|
|
TYPEDEF_DISTINCT_ORDERED_ID(pid_t, ProcessGroupID);
|
2018-12-02 19:12:26 -05:00
|
|
|
|
|
|
|
struct tms {
|
|
|
|
clock_t tms_utime;
|
|
|
|
clock_t tms_stime;
|
|
|
|
clock_t tms_cutime;
|
|
|
|
clock_t tms_cstime;
|
|
|
|
};
|
2018-10-17 04:55:43 -04:00
|
|
|
|
2021-03-13 16:02:54 -05:00
|
|
|
typedef i64 off_t;
|
2020-01-27 04:56:04 -05:00
|
|
|
typedef i64 time_t;
|
2018-10-17 04:55:43 -04:00
|
|
|
|
2019-07-03 15:17:35 -04:00
|
|
|
typedef u32 blksize_t;
|
|
|
|
typedef u32 blkcnt_t;
|
2018-10-14 16:57:41 -04:00
|
|
|
|
2019-05-28 05:53:16 -04:00
|
|
|
#define POLLIN (1u << 0)
|
2020-11-29 18:05:27 -05:00
|
|
|
#define POLLPRI (1u << 1)
|
|
|
|
#define POLLOUT (1u << 2)
|
|
|
|
#define POLLERR (1u << 3)
|
|
|
|
#define POLLHUP (1u << 4)
|
|
|
|
#define POLLNVAL (1u << 5)
|
|
|
|
#define POLLRDHUP (1u << 13)
|
2019-01-23 01:27:41 -05:00
|
|
|
|
|
|
|
struct pollfd {
|
2019-05-28 05:53:16 -04:00
|
|
|
int fd;
|
2019-01-23 01:27:41 -05:00
|
|
|
short events;
|
|
|
|
short revents;
|
|
|
|
};
|
2019-02-14 08:17:38 -05:00
|
|
|
|
2019-07-03 15:17:35 -04:00
|
|
|
typedef u32 __u32;
|
|
|
|
typedef u16 __u16;
|
|
|
|
typedef u8 __u8;
|
2019-04-06 08:29:29 -04:00
|
|
|
typedef int __s32;
|
|
|
|
typedef short __s16;
|
|
|
|
|
2019-07-03 15:17:35 -04:00
|
|
|
typedef u32 useconds_t;
|
|
|
|
typedef i32 suseconds_t;
|
2019-04-06 08:29:29 -04:00
|
|
|
|
|
|
|
struct timeval {
|
|
|
|
time_t tv_sec;
|
|
|
|
suseconds_t tv_usec;
|
|
|
|
};
|
|
|
|
|
2020-02-05 11:41:52 -05:00
|
|
|
typedef enum {
|
|
|
|
P_ALL = 1,
|
|
|
|
P_PID,
|
|
|
|
P_PGID
|
|
|
|
} idtype_t;
|
|
|
|
|
2019-04-06 08:29:29 -04:00
|
|
|
#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];
|
|
|
|
};
|
|
|
|
|
2019-05-09 21:19:25 -04:00
|
|
|
struct iovec {
|
|
|
|
void* iov_base;
|
|
|
|
size_t iov_len;
|
|
|
|
};
|
2019-05-29 17:20:51 -04:00
|
|
|
|
|
|
|
struct sched_param {
|
|
|
|
int sched_priority;
|
|
|
|
};
|
2019-09-23 13:06:03 -04:00
|
|
|
|
|
|
|
struct ifreq {
|
|
|
|
#define IFNAMSIZ 16
|
|
|
|
char ifr_name[IFNAMSIZ];
|
|
|
|
union {
|
|
|
|
struct sockaddr ifru_addr;
|
|
|
|
struct sockaddr ifru_dstaddr;
|
|
|
|
struct sockaddr ifru_broadaddr;
|
2020-03-11 16:30:41 -04:00
|
|
|
struct sockaddr ifru_netmask;
|
2019-10-02 12:20:11 -04:00
|
|
|
struct sockaddr ifru_hwaddr;
|
2019-09-23 13:06:03 -04:00
|
|
|
short ifru_flags;
|
|
|
|
int ifru_metric;
|
|
|
|
int64_t ifru_vnetid;
|
|
|
|
uint64_t ifru_media;
|
|
|
|
void* ifru_data;
|
|
|
|
unsigned int ifru_index;
|
|
|
|
} ifr_ifru;
|
2020-12-30 16:44:54 -05:00
|
|
|
|
2019-09-23 13:06:03 -04:00
|
|
|
#define ifr_addr ifr_ifru.ifru_addr // address
|
|
|
|
#define ifr_dstaddr ifr_ifru.ifru_dstaddr // other end of p-to-p link
|
|
|
|
#define ifr_broadaddr ifr_ifru.ifru_broadaddr // broadcast address
|
2020-03-11 16:30:41 -04:00
|
|
|
#define ifr_netmask ifr_ifru.ifru_netmask // network mask
|
2019-09-23 13:06:03 -04:00
|
|
|
#define ifr_flags ifr_ifru.ifru_flags // flags
|
|
|
|
#define ifr_metric ifr_ifru.ifru_metric // metric
|
|
|
|
#define ifr_mtu ifr_ifru.ifru_metric // mtu (overload)
|
|
|
|
#define ifr_hardmtu ifr_ifru.ifru_metric // hardmtu (overload)
|
|
|
|
#define ifr_media ifr_ifru.ifru_media // media options
|
|
|
|
#define ifr_rdomainid ifr_ifru.ifru_metric // VRF instance (overload)
|
|
|
|
#define ifr_vnetid ifr_ifru.ifru_vnetid // Virtual Net Id
|
|
|
|
#define ifr_ttl ifr_ifru.ifru_metric // tunnel TTL (overload)
|
|
|
|
#define ifr_data ifr_ifru.ifru_data // for use by interface
|
|
|
|
#define ifr_index ifr_ifru.ifru_index // interface index
|
|
|
|
#define ifr_llprio ifr_ifru.ifru_metric // link layer priority
|
2019-10-02 12:20:11 -04:00
|
|
|
#define ifr_hwaddr ifr_ifru.ifru_hwaddr // MAC address
|
2019-09-23 13:06:03 -04:00
|
|
|
};
|
2019-11-10 07:47:02 -05:00
|
|
|
|
2020-03-14 15:00:49 -04:00
|
|
|
struct rtentry {
|
|
|
|
struct sockaddr rt_gateway; /* the gateway address */
|
|
|
|
struct sockaddr rt_genmask; /* the target network mask */
|
|
|
|
unsigned short int rt_flags;
|
|
|
|
char* rt_dev;
|
|
|
|
/* FIXME: complete the struct */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define RTF_UP 0x1 /* do not delete the route */
|
|
|
|
#define RTF_GATEWAY 0x2 /* the route is a gateway and not an end host */
|
|
|
|
|
2019-11-10 07:47:02 -05:00
|
|
|
#define AT_FDCWD -100
|
2021-05-14 14:34:31 -04:00
|
|
|
#define AT_SYMLINK_NOFOLLOW 0x100
|
2019-11-10 07:47:02 -05:00
|
|
|
|
2021-07-24 20:04:11 -04:00
|
|
|
struct arpreq {
|
|
|
|
struct sockaddr arp_pa; /* protocol address */
|
|
|
|
struct sockaddr arp_ha; /* hardware address */
|
|
|
|
struct sockaddr arp_netmask; /* netmask of protocol address */
|
|
|
|
int arp_flags; /* flags */
|
|
|
|
char arp_dev[16];
|
|
|
|
};
|
|
|
|
|
2019-12-29 07:16:53 -05:00
|
|
|
#define PURGE_ALL_VOLATILE 0x1
|
|
|
|
#define PURGE_ALL_CLEAN_INODE 0x2
|
2020-03-28 04:47:16 -04:00
|
|
|
|
|
|
|
#define PT_TRACE_ME 1
|
|
|
|
#define PT_ATTACH 2
|
|
|
|
#define PT_CONTINUE 3
|
|
|
|
#define PT_SYSCALL 4
|
|
|
|
#define PT_GETREGS 5
|
|
|
|
#define PT_DETACH 6
|
2020-04-04 04:26:56 -04:00
|
|
|
#define PT_PEEK 7
|
2020-04-05 15:58:44 -04:00
|
|
|
#define PT_POKE 8
|
2020-04-07 11:23:37 -04:00
|
|
|
#define PT_SETREGS 9
|
2021-04-15 12:34:51 -04:00
|
|
|
#define PT_POKEDEBUG 10
|
|
|
|
#define PT_PEEKDEBUG 11
|
2020-08-28 09:15:51 -04:00
|
|
|
|
|
|
|
// Used in struct dirent
|
|
|
|
enum {
|
|
|
|
DT_UNKNOWN = 0,
|
|
|
|
#define DT_UNKNOWN DT_UNKNOWN
|
|
|
|
DT_FIFO = 1,
|
|
|
|
#define DT_FIFO DT_FIFO
|
|
|
|
DT_CHR = 2,
|
|
|
|
#define DT_CHR DT_CHR
|
|
|
|
DT_DIR = 4,
|
|
|
|
#define DT_DIR DT_DIR
|
|
|
|
DT_BLK = 6,
|
|
|
|
#define DT_BLK DT_BLK
|
|
|
|
DT_REG = 8,
|
|
|
|
#define DT_REG DT_REG
|
|
|
|
DT_LNK = 10,
|
|
|
|
#define DT_LNK DT_LNK
|
|
|
|
DT_SOCK = 12,
|
|
|
|
#define DT_SOCK DT_SOCK
|
|
|
|
DT_WHT = 14
|
|
|
|
#define DT_WHT DT_WHT
|
|
|
|
};
|
2021-05-19 05:31:43 -04:00
|
|
|
|
|
|
|
typedef uint64_t fsblkcnt_t;
|
|
|
|
typedef uint64_t fsfilcnt_t;
|
|
|
|
|
|
|
|
#define ST_RDONLY 0x1
|
|
|
|
#define ST_NOSUID 0x2
|
|
|
|
|
|
|
|
struct statvfs {
|
|
|
|
unsigned long f_bsize;
|
|
|
|
unsigned long f_frsize;
|
|
|
|
fsblkcnt_t f_blocks;
|
|
|
|
fsblkcnt_t f_bfree;
|
|
|
|
fsblkcnt_t f_bavail;
|
|
|
|
|
|
|
|
fsfilcnt_t f_files;
|
|
|
|
fsfilcnt_t f_ffree;
|
|
|
|
fsfilcnt_t f_favail;
|
|
|
|
|
|
|
|
unsigned long f_fsid;
|
|
|
|
unsigned long f_flag;
|
|
|
|
unsigned long f_namemax;
|
|
|
|
};
|