2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <errno.h>
|
|
|
|
#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);
|
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);
|
2019-07-29 08:26:01 +03:00
|
|
|
int set_process_icon(int icon_id);
|
2018-10-31 21:49:22 +03:00
|
|
|
inline int getpagesize() { return 4096; }
|
2018-11-02 22:41:58 +03:00
|
|
|
pid_t fork();
|
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();
|
2018-11-07 03:38:51 +03:00
|
|
|
int getgroups(int size, gid_t list[]);
|
|
|
|
int setgroups(size_t, const gid_t*);
|
2019-02-22 01:35:07 +03:00
|
|
|
int setuid(uid_t);
|
|
|
|
int setgid(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);
|
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);
|
2018-11-11 02:20:53 +03:00
|
|
|
int fstat(int fd, struct stat* statbuf);
|
2018-10-31 04:09:11 +03:00
|
|
|
int lstat(const char* path, struct stat* statbuf);
|
2018-10-31 12:14:56 +03:00
|
|
|
int stat(const char* path, struct stat* statbuf);
|
2018-10-25 14:53:49 +03:00
|
|
|
int sleep(unsigned 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);
|
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
|
|
|
|
|
|
|
#define HOST_NAME_MAX 64
|
2018-10-24 14:19:36 +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-01-11 18:45:38 +03:00
|
|
|
|
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
|
|
|
|
2018-10-31 04:09:11 +03:00
|
|
|
__END_DECLS
|