2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-10-04 12:02:42 +03:00
|
|
|
/* standard symbolic constants and types
|
|
|
|
*
|
|
|
|
* values from POSIX standard unix specification
|
|
|
|
*
|
|
|
|
* https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html
|
|
|
|
*/
|
|
|
|
|
2018-10-22 14:57:25 +03:00
|
|
|
#pragma once
|
|
|
|
|
2021-01-19 01:05:11 +03:00
|
|
|
#include <fd_set.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <limits.h>
|
2018-10-31 04:09:11 +03:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#include <sys/types.h>
|
2018-10-22 14:57:25 +03:00
|
|
|
|
2018-10-31 04:09:11 +03:00
|
|
|
__BEGIN_DECLS
|
2018-10-22 14:57:25 +03:00
|
|
|
|
2019-02-23 19:24:50 +03:00
|
|
|
#define HZ 1000
|
2019-02-26 14:57:02 +03:00
|
|
|
#define STDIN_FILENO 0
|
|
|
|
#define STDOUT_FILENO 1
|
|
|
|
#define STDERR_FILENO 2
|
2019-02-23 19:24:50 +03:00
|
|
|
|
2019-10-04 12:02:42 +03:00
|
|
|
/* lseek whence values */
|
2019-11-16 11:35:48 +03:00
|
|
|
#ifndef _STDIO_H /* also defined in stdio.h */
|
|
|
|
# define SEEK_SET 0 /* from beginning of file. */
|
|
|
|
# define SEEK_CUR 1 /* from current position in file. */
|
|
|
|
# define SEEK_END 2 /* from the end of the file. */
|
2019-10-04 12:02:42 +03:00
|
|
|
#endif
|
|
|
|
|
2018-10-31 19:50:43 +03:00
|
|
|
extern char** environ;
|
|
|
|
|
2019-08-15 21:55:10 +03:00
|
|
|
int get_process_name(char* buffer, int buffer_size);
|
2020-07-27 19:42:10 +03:00
|
|
|
int set_process_name(const char* name, size_t name_length);
|
2019-07-21 10:59:17 +03:00
|
|
|
void dump_backtrace();
|
2019-05-19 20:54:20 +03:00
|
|
|
int fsync(int fd);
|
2019-05-17 15:32:53 +03:00
|
|
|
void sysbeep();
|
2019-03-25 15:03:49 +03:00
|
|
|
int gettid();
|
|
|
|
int donate(int tid);
|
2020-07-28 00:39:31 +03:00
|
|
|
int getpagesize();
|
2018-11-02 22:41:58 +03:00
|
|
|
pid_t fork();
|
2021-03-28 02:01:51 +03:00
|
|
|
pid_t vfork();
|
2019-03-14 17:18:15 +03:00
|
|
|
int execv(const char* path, char* const argv[]);
|
2019-01-23 19:03:14 +03:00
|
|
|
int execve(const char* filename, char* const argv[], char* const envp[]);
|
2019-04-26 04:16:26 +03:00
|
|
|
int execvpe(const char* filename, char* const argv[], char* const envp[]);
|
2019-01-23 19:03:14 +03:00
|
|
|
int execvp(const char* filename, char* const argv[]);
|
2019-02-03 06:32:31 +03:00
|
|
|
int execl(const char* filename, const char* arg, ...);
|
2019-11-16 11:35:48 +03:00
|
|
|
int execlp(const char* filename, const char* arg, ...);
|
2020-01-11 01:14:04 +03:00
|
|
|
int chroot(const char* path);
|
2020-01-12 21:03:42 +03:00
|
|
|
int chroot_with_mount_flags(const char* path, int mount_flags);
|
2018-12-20 02:39:29 +03:00
|
|
|
void sync();
|
2020-05-26 13:15:14 +03:00
|
|
|
__attribute__((noreturn)) void _exit(int status);
|
2018-11-02 14:56:51 +03:00
|
|
|
pid_t getsid(pid_t);
|
|
|
|
pid_t setsid();
|
|
|
|
int setpgid(pid_t pid, pid_t pgid);
|
|
|
|
pid_t getpgid(pid_t);
|
|
|
|
pid_t getpgrp();
|
2018-11-05 17:04:19 +03:00
|
|
|
uid_t geteuid();
|
|
|
|
gid_t getegid();
|
2018-10-22 14:57:25 +03:00
|
|
|
uid_t getuid();
|
|
|
|
gid_t getgid();
|
|
|
|
pid_t getpid();
|
2019-02-26 16:05:28 +03:00
|
|
|
pid_t getppid();
|
2020-07-01 02:34:20 +03:00
|
|
|
int getresuid(uid_t*, uid_t*, uid_t*);
|
|
|
|
int getresgid(gid_t*, gid_t*, gid_t*);
|
2018-11-07 03:38:51 +03:00
|
|
|
int getgroups(int size, gid_t list[]);
|
|
|
|
int setgroups(size_t, const gid_t*);
|
2020-06-17 15:58:00 +03:00
|
|
|
int seteuid(uid_t);
|
|
|
|
int setegid(gid_t);
|
2019-02-22 01:35:07 +03:00
|
|
|
int setuid(uid_t);
|
|
|
|
int setgid(gid_t);
|
2021-04-09 14:13:15 +03:00
|
|
|
int setreuid(uid_t, uid_t);
|
2020-06-17 15:58:00 +03:00
|
|
|
int setresuid(uid_t, uid_t, uid_t);
|
|
|
|
int setresgid(gid_t, gid_t, gid_t);
|
2018-11-02 15:14:25 +03:00
|
|
|
pid_t tcgetpgrp(int fd);
|
|
|
|
int tcsetpgrp(int fd, pid_t pgid);
|
2018-10-23 11:12:50 +03:00
|
|
|
ssize_t read(int fd, void* buf, size_t count);
|
2020-02-20 08:59:23 +03:00
|
|
|
ssize_t pread(int fd, void* buf, size_t count, off_t);
|
2018-10-30 17:33:37 +03:00
|
|
|
ssize_t write(int fd, const void* buf, size_t count);
|
2021-04-21 12:11:04 +03:00
|
|
|
ssize_t pwrite(int fd, const void* buf, size_t count, off_t);
|
2018-10-23 11:12:50 +03:00
|
|
|
int close(int fd);
|
2018-10-26 15:24:11 +03:00
|
|
|
int chdir(const char* path);
|
2019-09-12 02:18:25 +03:00
|
|
|
int fchdir(int fd);
|
2018-10-24 15:28:22 +03:00
|
|
|
char* getcwd(char* buffer, size_t size);
|
2018-11-06 17:59:57 +03:00
|
|
|
char* getwd(char* buffer);
|
2021-04-11 20:00:36 +03:00
|
|
|
unsigned int sleep(unsigned int seconds);
|
2019-02-03 18:11:28 +03:00
|
|
|
int usleep(useconds_t);
|
2018-10-26 10:54:29 +03:00
|
|
|
int gethostname(char*, size_t);
|
2020-04-26 08:59:47 +03:00
|
|
|
int sethostname(const char*, ssize_t);
|
2018-10-28 16:11:51 +03:00
|
|
|
ssize_t readlink(const char* path, char* buffer, size_t);
|
2018-10-31 00:03:02 +03:00
|
|
|
char* ttyname(int fd);
|
|
|
|
int ttyname_r(int fd, char* buffer, size_t);
|
2018-10-31 19:50:43 +03:00
|
|
|
off_t lseek(int fd, off_t, int whence);
|
2018-11-05 18:40:48 +03:00
|
|
|
int link(const char* oldpath, const char* newpath);
|
|
|
|
int unlink(const char* pathname);
|
2019-03-02 03:50:34 +03:00
|
|
|
int symlink(const char* target, const char* linkpath);
|
2019-01-28 06:16:01 +03:00
|
|
|
int rmdir(const char* pathname);
|
2018-11-05 21:01:22 +03:00
|
|
|
int dup(int old_fd);
|
|
|
|
int dup2(int old_fd, int new_fd);
|
2018-11-11 02:20:53 +03:00
|
|
|
int pipe(int pipefd[2]);
|
2019-08-05 15:29:05 +03:00
|
|
|
int pipe2(int pipefd[2], int flags);
|
2018-11-11 02:20:53 +03:00
|
|
|
unsigned int alarm(unsigned int seconds);
|
|
|
|
int access(const char* pathname, int mode);
|
2018-11-11 12:11:09 +03:00
|
|
|
int isatty(int fd);
|
2018-11-17 02:11:08 +03:00
|
|
|
int mknod(const char* pathname, mode_t, dev_t);
|
2018-11-17 17:56:09 +03:00
|
|
|
long fpathconf(int fd, int name);
|
2019-05-28 12:53:16 +03:00
|
|
|
long pathconf(const char* path, int name);
|
2019-02-26 14:57:02 +03:00
|
|
|
char* getlogin();
|
2019-02-27 14:32:53 +03:00
|
|
|
int chown(const char* pathname, uid_t, gid_t);
|
2019-06-01 21:31:36 +03:00
|
|
|
int fchown(int fd, uid_t, gid_t);
|
2019-03-24 02:53:39 +03:00
|
|
|
int ftruncate(int fd, off_t length);
|
2020-06-15 18:28:42 +03:00
|
|
|
int truncate(const char* path, off_t length);
|
2019-07-19 14:08:26 +03:00
|
|
|
int halt();
|
2019-07-19 10:58:12 +03:00
|
|
|
int reboot();
|
2020-04-06 11:55:08 +03:00
|
|
|
int mount(int source_fd, const char* target, const char* fs_type, int flags);
|
2019-08-11 16:56:39 +03:00
|
|
|
int umount(const char* mountpoint);
|
2020-01-11 22:45:51 +03:00
|
|
|
int pledge(const char* promises, const char* execpromises);
|
Kernel: Add a basic implementation of unveil()
This syscall is a complement to pledge() and adds the same sort of
incremental relinquishing of capabilities for filesystem access.
The first call to unveil() will "drop a veil" on the process, and from
now on, only unveiled parts of the filesystem are visible to it.
Each call to unveil() specifies a path to either a directory or a file
along with permissions for that path. The permissions are a combination
of the following:
- r: Read access (like the "rpath" promise)
- w: Write access (like the "wpath" promise)
- x: Execute access
- c: Create/remove access (like the "cpath" promise)
Attempts to open a path that has not been unveiled with fail with
ENOENT. If the unveiled path lacks sufficient permissions, it will fail
with EACCES.
Like pledge(), subsequent calls to unveil() with the same path can only
remove permissions, not add them.
Once you call unveil(nullptr, nullptr), the veil is locked, and it's no
longer possible to unveil any more paths for the process, ever.
This concept comes from OpenBSD, and their implementation does various
things differently, I'm sure. This is just a first implementation for
SerenityOS, and we'll keep improving on it as we go. :^)
2020-01-21 00:12:04 +03:00
|
|
|
int unveil(const char* path, const char* permissions);
|
2020-02-20 08:58:48 +03:00
|
|
|
char* getpass(const char* prompt);
|
2018-11-17 17:56:09 +03:00
|
|
|
|
2019-06-07 18:13:23 +03:00
|
|
|
enum {
|
2018-11-17 17:56:09 +03:00
|
|
|
_PC_NAME_MAX,
|
2019-09-02 08:36:22 +03:00
|
|
|
_PC_PATH_MAX,
|
2019-12-01 13:34:34 +03:00
|
|
|
_PC_PIPE_BUF,
|
|
|
|
_PC_VDISABLE
|
2018-11-17 17:56:09 +03:00
|
|
|
};
|
2018-10-26 10:54:29 +03:00
|
|
|
|
2019-02-08 04:38:21 +03:00
|
|
|
#define R_OK 4
|
|
|
|
#define W_OK 2
|
|
|
|
#define X_OK 1
|
|
|
|
#define F_OK 0
|
2018-10-24 14:19:36 +03:00
|
|
|
|
2020-05-28 17:52:02 +03:00
|
|
|
#define MS_NODEV (1 << 0)
|
|
|
|
#define MS_NOEXEC (1 << 1)
|
|
|
|
#define MS_NOSUID (1 << 2)
|
|
|
|
#define MS_BIND (1 << 3)
|
2020-05-28 17:56:25 +03:00
|
|
|
#define MS_RDONLY (1 << 4)
|
2020-05-28 21:12:13 +03:00
|
|
|
#define MS_REMOUNT (1 << 5)
|
2020-01-11 18:45:38 +03:00
|
|
|
|
2020-06-17 15:58:00 +03:00
|
|
|
#define _POSIX_SAVED_IDS
|
|
|
|
|
2019-05-30 00:20:51 +03:00
|
|
|
/*
|
|
|
|
* We aren't fully compliant (don't support policies, and don't have a wide
|
|
|
|
* range of values), but we do have process priorities.
|
|
|
|
*/
|
|
|
|
#define _POSIX_PRIORITY_SCHEDULING
|
2019-12-01 13:34:34 +03:00
|
|
|
#define _POSIX_VDISABLE '\0'
|
2019-05-30 00:20:51 +03:00
|
|
|
|
2020-07-14 23:41:59 +03:00
|
|
|
enum {
|
|
|
|
_SC_NPROCESSORS_CONF,
|
|
|
|
_SC_NPROCESSORS_ONLN,
|
2020-09-09 10:35:02 +03:00
|
|
|
_SC_OPEN_MAX,
|
2021-01-18 11:51:21 +03:00
|
|
|
_SC_TTY_NAME_MAX,
|
|
|
|
_SC_PAGESIZE,
|
2021-02-12 05:11:50 +03:00
|
|
|
_SC_GETPW_R_SIZE_MAX,
|
2021-03-16 21:05:23 +03:00
|
|
|
_SC_CLK_TCK,
|
2020-07-14 23:41:59 +03:00
|
|
|
};
|
2020-08-01 09:18:47 +03:00
|
|
|
|
|
|
|
#define _SC_NPROCESSORS_CONF _SC_NPROCESSORS_CONF
|
|
|
|
#define _SC_NPROCESSORS_ONLN _SC_NPROCESSORS_ONLN
|
2020-09-09 10:35:02 +03:00
|
|
|
#define _SC_OPEN_MAX _SC_OPEN_MAX
|
2021-01-18 11:51:21 +03:00
|
|
|
#define _SC_PAGESIZE _SC_PAGESIZE
|
|
|
|
#define _SC_TTY_NAME_MAX _SC_TTY_NAME_MAX
|
2021-02-12 05:11:50 +03:00
|
|
|
#define _SC_GETPW_R_SIZE_MAX _SC_GETPW_R_SIZE_MAX
|
2021-04-12 02:36:38 +03:00
|
|
|
#define _SC_CLK_TCK _SC_CLK_TCK
|
2020-08-01 09:18:47 +03:00
|
|
|
|
2020-07-14 23:41:59 +03:00
|
|
|
long sysconf(int name);
|
|
|
|
|
2020-09-05 20:47:40 +03:00
|
|
|
// If opterr is set (the default), print error messages to stderr.
|
|
|
|
extern int opterr;
|
|
|
|
// On errors, optopt is set to the erroneous *character*.
|
|
|
|
extern int optopt;
|
|
|
|
// Index of the next argument to process upon a getopt*() call.
|
|
|
|
extern int optind;
|
|
|
|
// If set, reset the internal state kept by getopt*(). You may also want to set
|
|
|
|
// optind to 1 in that case. Alternatively, setting optind to 0 is treated like
|
|
|
|
// doing both of the above.
|
|
|
|
extern int optreset;
|
|
|
|
// After parsing an option that accept an argument, set to point to the argument
|
|
|
|
// value.
|
|
|
|
extern char* optarg;
|
|
|
|
|
2021-04-11 07:47:47 +03:00
|
|
|
int getopt(int argc, char* const* argv, const char* short_options);
|
2020-09-05 20:47:40 +03:00
|
|
|
|
2018-10-31 04:09:11 +03:00
|
|
|
__END_DECLS
|