2019-06-07 09:49:03 +00:00
|
|
|
#include <AK/AKString.h>
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <Kernel/Syscall.h>
|
2018-11-05 15:40:48 +00:00
|
|
|
#include <assert.h>
|
2019-06-07 09:49:03 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2018-11-07 00:38:51 +00:00
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
2019-06-07 09:49:03 +00:00
|
|
|
#include <stdarg.h>
|
2018-11-07 00:38:51 +00:00
|
|
|
#include <stdio.h>
|
2019-02-08 01:38:21 +00:00
|
|
|
#include <stdlib.h>
|
2019-06-07 09:49:03 +00:00
|
|
|
#include <string.h>
|
2018-11-16 12:11:21 +00:00
|
|
|
#include <sys/ioctl.h>
|
2019-01-21 23:58:13 +00:00
|
|
|
#include <sys/types.h>
|
2019-06-07 09:49:03 +00:00
|
|
|
#include <unistd.h>
|
2018-10-22 11:57:25 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
2019-04-22 16:44:45 +00:00
|
|
|
int systrace(pid_t pid)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_systrace, pid);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-02-27 11:32:53 +00:00
|
|
|
int chown(const char* pathname, uid_t uid, gid_t gid)
|
2019-02-23 16:24:50 +00:00
|
|
|
{
|
2019-02-27 11:32:53 +00:00
|
|
|
int rc = syscall(SC_chown, pathname, uid, gid);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2019-02-23 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2019-06-01 18:31:36 +00:00
|
|
|
int fchown(int fd, uid_t uid, gid_t gid)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_fchown, fd, uid, gid);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-11-02 19:41:58 +00:00
|
|
|
pid_t fork()
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_fork);
|
2018-11-03 00:49:40 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-03-14 14:18:15 +00:00
|
|
|
int execv(const char* path, char* const argv[])
|
|
|
|
{
|
2019-03-27 00:39:13 +00:00
|
|
|
return execve(path, argv, environ);
|
2019-03-14 14:18:15 +00:00
|
|
|
}
|
|
|
|
|
2019-01-23 16:03:14 +00:00
|
|
|
int execve(const char* filename, char* const argv[], char* const envp[])
|
2018-11-03 00:49:40 +00:00
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_execve, filename, argv, envp);
|
2018-11-03 00:49:40 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-11-02 19:41:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 01:16:26 +00:00
|
|
|
int execvpe(const char* filename, char* const argv[], char* const envp[])
|
2019-01-23 05:35:34 +00:00
|
|
|
{
|
2019-06-22 12:07:34 +00:00
|
|
|
int rc = execve(filename, argv, envp);
|
2019-03-27 00:39:13 +00:00
|
|
|
if (rc < 0 && errno != ENOENT) {
|
2019-04-26 01:16:26 +00:00
|
|
|
fprintf(stderr, "execvpe() failed on first with %s\n", strerror(errno));
|
2019-03-27 00:39:13 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
String path = getenv("PATH");
|
|
|
|
if (path.is_empty())
|
|
|
|
path = "/bin:/usr/bin";
|
|
|
|
auto parts = path.split(':');
|
|
|
|
for (auto& part : parts) {
|
|
|
|
auto candidate = String::format("%s/%s", part.characters(), filename);
|
2019-06-22 12:07:34 +00:00
|
|
|
int rc = execve(candidate.characters(), argv, envp);
|
2019-03-27 00:39:13 +00:00
|
|
|
if (rc < 0 && errno != ENOENT) {
|
2019-04-26 01:16:26 +00:00
|
|
|
printf("execvpe() failed on attempt (%s) with %s\n", candidate.characters(), strerror(errno));
|
2019-03-27 00:39:13 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
errno = ENOENT;
|
|
|
|
return -1;
|
2019-01-23 05:35:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 01:16:26 +00:00
|
|
|
int execvp(const char* filename, char* const argv[])
|
|
|
|
{
|
|
|
|
return execvpe(filename, argv, environ);
|
|
|
|
}
|
|
|
|
|
2019-02-03 03:32:31 +00:00
|
|
|
int execl(const char* filename, const char* arg0, ...)
|
|
|
|
{
|
2019-04-20 12:02:19 +00:00
|
|
|
Vector<const char*, 16> args;
|
2019-02-03 03:32:31 +00:00
|
|
|
args.append(arg0);
|
|
|
|
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, arg0);
|
|
|
|
for (;;) {
|
|
|
|
const char* arg = va_arg(ap, const char*);
|
|
|
|
if (!arg)
|
|
|
|
break;
|
|
|
|
args.append(arg);
|
|
|
|
}
|
|
|
|
va_end(ap);
|
2019-02-07 23:12:12 +00:00
|
|
|
args.append(nullptr);
|
2019-04-23 11:00:53 +00:00
|
|
|
return execve(filename, const_cast<char* const*>(args.data()), environ);
|
2019-02-03 03:32:31 +00:00
|
|
|
}
|
|
|
|
|
2018-10-22 11:57:25 +00:00
|
|
|
uid_t getuid()
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
return syscall(SC_getuid);
|
2018-10-22 11:57:25 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 08:00:37 +00:00
|
|
|
gid_t getgid()
|
2018-10-22 11:57:25 +00:00
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
return syscall(SC_getgid);
|
2018-10-22 11:57:25 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 14:04:19 +00:00
|
|
|
uid_t geteuid()
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
return syscall(SC_geteuid);
|
2018-11-05 14:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gid_t getegid()
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
return syscall(SC_getegid);
|
2018-11-05 14:04:19 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 08:00:37 +00:00
|
|
|
pid_t getpid()
|
2018-10-22 11:57:25 +00:00
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
return syscall(SC_getpid);
|
2018-10-22 11:57:25 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 12:33:06 +00:00
|
|
|
pid_t getppid()
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
return syscall(SC_getppid);
|
2018-11-06 12:33:06 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 11:56:51 +00:00
|
|
|
pid_t setsid()
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_setsid);
|
2018-11-03 00:49:40 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-11-02 11:56:51 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 12:14:25 +00:00
|
|
|
pid_t tcgetpgrp(int fd)
|
2018-11-02 11:56:51 +00:00
|
|
|
{
|
2018-11-16 12:11:21 +00:00
|
|
|
return ioctl(fd, TIOCGPGRP);
|
2018-11-02 12:14:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int tcsetpgrp(int fd, pid_t pgid)
|
|
|
|
{
|
2018-11-16 12:11:21 +00:00
|
|
|
return ioctl(fd, TIOCSPGRP, pgid);
|
2018-11-02 11:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int setpgid(pid_t pid, pid_t pgid)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_setpgid, pid, pgid);
|
2018-11-03 00:49:40 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-11-02 11:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pid_t getpgid(pid_t pid)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_getpgid, pid);
|
2018-11-03 00:49:40 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-11-02 11:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pid_t getpgrp()
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_getpgrp);
|
2018-11-03 00:49:40 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-11-02 11:56:51 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 00:39:13 +00:00
|
|
|
int creat(const char* path, mode_t mode)
|
|
|
|
{
|
2019-03-27 15:42:30 +00:00
|
|
|
return open(path, O_CREAT | O_WRONLY | O_TRUNC, mode);
|
2019-03-27 00:39:13 +00:00
|
|
|
}
|
|
|
|
|
2019-07-08 18:01:49 +00:00
|
|
|
int creat_with_path_length(const char* path, size_t path_length, mode_t mode)
|
|
|
|
{
|
|
|
|
return open_with_path_length(path, path_length, O_CREAT | O_WRONLY | O_TRUNC, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
int open_with_path_length(const char* path, size_t path_length, int options, mode_t mode)
|
|
|
|
{
|
|
|
|
if (path_length > INT32_MAX) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
Syscall::SC_open_params params { path, (int)path_length, options, mode };
|
|
|
|
int rc = syscall(SC_open, ¶ms);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-11-05 15:40:48 +00:00
|
|
|
int open(const char* path, int options, ...)
|
2018-10-23 08:12:50 +00:00
|
|
|
{
|
2018-11-05 15:40:48 +00:00
|
|
|
va_list ap;
|
|
|
|
va_start(ap, options);
|
2019-07-08 18:01:49 +00:00
|
|
|
auto mode = (mode_t)va_arg(ap, unsigned);
|
2018-11-05 15:40:48 +00:00
|
|
|
va_end(ap);
|
2019-07-08 18:01:49 +00:00
|
|
|
return open_with_path_length(path, strlen(path), options, mode);
|
2018-10-23 08:12:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t read(int fd, void* buf, size_t count)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_read, fd, buf, count);
|
2018-10-25 10:06:00 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-23 08:12:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-30 14:33:37 +00:00
|
|
|
ssize_t write(int fd, const void* buf, size_t count)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_write, fd, buf, count);
|
2018-10-30 14:33:37 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-30 21:03:02 +00:00
|
|
|
int ttyname_r(int fd, char* buffer, size_t size)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_ttyname_r, fd, buffer, size);
|
2018-10-30 21:03:02 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char ttyname_buf[32];
|
|
|
|
char* ttyname(int fd)
|
|
|
|
{
|
|
|
|
if (ttyname_r(fd, ttyname_buf, sizeof(ttyname_buf)) < 0)
|
|
|
|
return nullptr;
|
|
|
|
return ttyname_buf;
|
|
|
|
}
|
|
|
|
|
2018-10-23 08:12:50 +00:00
|
|
|
int close(int fd)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_close, fd);
|
2018-10-25 10:06:00 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-23 08:12:50 +00:00
|
|
|
}
|
|
|
|
|
2018-10-26 23:24:22 +00:00
|
|
|
pid_t waitpid(pid_t waitee, int* wstatus, int options)
|
2018-10-23 22:20:34 +00:00
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_waitpid, waitee, wstatus, options);
|
2018-10-25 10:06:00 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-23 22:20:34 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 09:14:56 +00:00
|
|
|
int lstat(const char* path, struct stat* statbuf)
|
2018-10-24 11:19:36 +00:00
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_lstat, path, statbuf);
|
2018-10-25 10:06:00 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-24 11:19:36 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 09:14:56 +00:00
|
|
|
int stat(const char* path, struct stat* statbuf)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_stat, path, statbuf);
|
2018-10-31 09:14:56 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-06-07 09:49:03 +00:00
|
|
|
int fstat(int fd, struct stat* statbuf)
|
2018-11-10 23:20:53 +00:00
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_fstat, fd, statbuf);
|
2018-11-10 23:20:53 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-26 12:24:11 +00:00
|
|
|
int chdir(const char* path)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_chdir, path);
|
2018-10-26 12:24:11 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-24 12:28:22 +00:00
|
|
|
char* getcwd(char* buffer, size_t size)
|
|
|
|
{
|
2019-02-08 01:38:21 +00:00
|
|
|
if (!buffer) {
|
|
|
|
size = size ? size : PATH_MAX;
|
|
|
|
buffer = (char*)malloc(size);
|
|
|
|
}
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_getcwd, buffer, size);
|
2018-10-25 10:06:00 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, buffer, nullptr);
|
2018-10-24 12:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 14:59:57 +00:00
|
|
|
char* getwd(char* buf)
|
|
|
|
{
|
2018-11-11 14:36:40 +00:00
|
|
|
auto* p = getcwd(buf, PATH_MAX);
|
|
|
|
return p;
|
2018-11-06 14:59:57 +00:00
|
|
|
}
|
|
|
|
|
2018-10-25 11:53:49 +00:00
|
|
|
int sleep(unsigned seconds)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
return syscall(SC_sleep, seconds);
|
2018-10-25 11:53:49 +00:00
|
|
|
}
|
|
|
|
|
2019-02-03 15:11:28 +00:00
|
|
|
int usleep(useconds_t usec)
|
|
|
|
{
|
|
|
|
return syscall(SC_usleep, usec);
|
|
|
|
}
|
|
|
|
|
2018-10-26 07:54:29 +00:00
|
|
|
int gethostname(char* buffer, size_t size)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_gethostname, buffer, size);
|
2018-10-26 07:54:29 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-28 13:11:51 +00:00
|
|
|
ssize_t readlink(const char* path, char* buffer, size_t size)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_readlink, path, buffer, size);
|
2018-10-28 13:11:51 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-10-31 16:50:43 +00:00
|
|
|
off_t lseek(int fd, off_t offset, int whence)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_lseek, fd, offset, whence);
|
2018-10-31 16:50:43 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-02-21 12:26:40 +00:00
|
|
|
int link(const char* old_path, const char* new_path)
|
2018-11-05 15:40:48 +00:00
|
|
|
{
|
2019-02-21 12:26:40 +00:00
|
|
|
int rc = syscall(SC_link, old_path, new_path);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-11-05 15:40:48 +00:00
|
|
|
}
|
|
|
|
|
2019-01-22 06:03:44 +00:00
|
|
|
int unlink(const char* pathname)
|
2018-11-05 15:40:48 +00:00
|
|
|
{
|
2019-01-22 06:03:44 +00:00
|
|
|
int rc = syscall(SC_unlink, pathname);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-11-05 15:40:48 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 00:50:34 +00:00
|
|
|
int symlink(const char* target, const char* linkpath)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_symlink, target, linkpath);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-01-28 03:16:01 +00:00
|
|
|
int rmdir(const char* pathname)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_rmdir, pathname);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-11-05 17:16:00 +00:00
|
|
|
int isatty(int fd)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_isatty, fd);
|
2018-11-05 17:16:00 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, 1, 0);
|
|
|
|
}
|
|
|
|
|
2018-11-05 18:01:22 +00:00
|
|
|
int getdtablesize()
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_getdtablesize);
|
2018-11-11 09:11:09 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-11-05 18:01:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int dup(int old_fd)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_dup, old_fd);
|
2018-11-05 18:01:22 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-10-22 11:57:25 +00:00
|
|
|
}
|
|
|
|
|
2018-11-05 18:01:22 +00:00
|
|
|
int dup2(int old_fd, int new_fd)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_dup2, old_fd, new_fd);
|
2018-11-05 18:01:22 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-11-07 00:38:51 +00:00
|
|
|
int setgroups(size_t size, const gid_t* list)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_getgroups, size, list);
|
2018-11-07 00:38:51 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int getgroups(int size, gid_t list[])
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_getgroups, size, list);
|
2018-11-07 00:38:51 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2018-11-10 23:20:53 +00:00
|
|
|
int pipe(int pipefd[2])
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_pipe, pipefd);
|
2018-11-10 23:20:53 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int alarm(unsigned int seconds)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
return syscall(SC_alarm, seconds);
|
2018-11-10 23:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int setuid(uid_t uid)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_setuid, uid);
|
2018-11-10 23:20:53 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int setgid(uid_t gid)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_setgid, gid);
|
2018-11-10 23:20:53 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int access(const char* pathname, int mode)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
int rc = syscall(SC_access, pathname, mode);
|
2018-11-10 23:20:53 +00:00
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-05-03 20:59:58 +00:00
|
|
|
int mknod(const char* pathname, mode_t mode, dev_t dev)
|
2018-11-16 23:11:08 +00:00
|
|
|
{
|
2019-05-03 20:59:58 +00:00
|
|
|
int rc = syscall(SC_mknod, pathname, mode, dev);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2018-11-16 23:11:08 +00:00
|
|
|
}
|
|
|
|
|
2018-11-17 14:56:09 +00:00
|
|
|
long fpathconf(int fd, int name)
|
|
|
|
{
|
2019-06-07 09:49:03 +00:00
|
|
|
(void)fd;
|
|
|
|
(void)name;
|
2019-04-23 19:52:02 +00:00
|
|
|
ASSERT_NOT_REACHED();
|
2018-11-17 14:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
long pathconf(const char* path, int name)
|
|
|
|
{
|
2019-06-07 09:49:03 +00:00
|
|
|
(void)path;
|
|
|
|
(void)name;
|
2019-04-23 19:52:02 +00:00
|
|
|
ASSERT_NOT_REACHED();
|
2018-11-17 14:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _exit(int status)
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
syscall(SC_exit, status);
|
2019-04-23 19:52:02 +00:00
|
|
|
ASSERT_NOT_REACHED();
|
2018-11-17 14:56:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 23:39:29 +00:00
|
|
|
void sync()
|
|
|
|
{
|
2018-12-21 02:02:06 +00:00
|
|
|
syscall(SC_sync);
|
2018-12-19 23:39:29 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 01:09:29 +00:00
|
|
|
int read_tsc(unsigned* lsw, unsigned* msw)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_read_tsc, lsw, msw);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-03-08 11:22:55 +00:00
|
|
|
int create_shared_buffer(pid_t peer_pid, int size, void** buffer)
|
2019-02-16 11:13:43 +00:00
|
|
|
{
|
|
|
|
int rc = syscall(SC_create_shared_buffer, peer_pid, size, buffer);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* get_shared_buffer(int shared_buffer_id)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_get_shared_buffer, shared_buffer_id);
|
2019-02-16 23:13:47 +00:00
|
|
|
if (rc < 0 && -rc < EMAXERRNO) {
|
|
|
|
errno = -rc;
|
|
|
|
return (void*)-1;
|
|
|
|
}
|
|
|
|
return (void*)rc;
|
2019-02-16 11:13:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int release_shared_buffer(int shared_buffer_id)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_release_shared_buffer, shared_buffer_id);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-03-08 11:22:55 +00:00
|
|
|
int get_shared_buffer_size(int shared_buffer_id)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_get_shared_buffer_size, shared_buffer_id);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int seal_shared_buffer(int shared_buffer_id)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_seal_shared_buffer, shared_buffer_id);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-02-26 11:57:02 +00:00
|
|
|
char* getlogin()
|
|
|
|
{
|
2019-03-10 02:15:36 +00:00
|
|
|
static char __getlogin_buffer[256];
|
|
|
|
if (auto* passwd = getpwuid(getuid())) {
|
|
|
|
strncpy(__getlogin_buffer, passwd->pw_name, sizeof(__getlogin_buffer));
|
|
|
|
return __getlogin_buffer;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2019-02-26 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
2019-06-07 09:49:03 +00:00
|
|
|
int create_thread(int (*entry)(void*), void* argument)
|
2019-03-23 21:59:08 +00:00
|
|
|
{
|
|
|
|
int rc = syscall(SC_create_thread, entry, argument);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-04-29 13:18:21 +00:00
|
|
|
void exit_thread(int code)
|
2019-04-29 13:17:20 +00:00
|
|
|
{
|
2019-04-29 13:18:21 +00:00
|
|
|
syscall(SC_exit_thread, code);
|
|
|
|
ASSERT_NOT_REACHED();
|
2019-04-29 13:17:20 +00:00
|
|
|
}
|
|
|
|
|
2019-03-23 23:53:39 +00:00
|
|
|
int ftruncate(int fd, off_t length)
|
|
|
|
{
|
2019-04-08 23:10:00 +00:00
|
|
|
int rc = syscall(SC_ftruncate, fd, length);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
2019-03-23 23:53:39 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 12:03:49 +00:00
|
|
|
int gettid()
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_gettid);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int donate(int tid)
|
|
|
|
{
|
|
|
|
int rc = syscall(SC_donate, tid);
|
|
|
|
__RETURN_WITH_ERRNO(rc, rc, -1);
|
|
|
|
}
|
|
|
|
|
2019-05-17 12:32:53 +00:00
|
|
|
void sysbeep()
|
2019-05-15 19:40:41 +00:00
|
|
|
{
|
|
|
|
syscall(SC_beep);
|
|
|
|
}
|
|
|
|
|
2019-05-19 17:54:20 +00:00
|
|
|
int fsync(int fd)
|
|
|
|
{
|
|
|
|
UNUSED_PARAM(fd);
|
|
|
|
dbgprintf("FIXME: Implement fsync()\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2018-11-05 18:01:22 +00:00
|
|
|
}
|