working on it

This commit is contained in:
Dawid Sobczak 2025-04-05 10:55:40 +01:00
parent 56a6e78765
commit 35a88970c2
1094 changed files with 51093 additions and 51 deletions

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include <stdlib.h>
void _exit(int status)
{
_Exit(status);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int access(const char *filename, int amode)
{
return syscall2(__NR_access, (long)filename, amode);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
unsigned alarm(unsigned seconds)
{
return syscall1(__NR_alarm, seconds);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int chdir(const char *path)
{
return syscall1(__NR_chdir, (long)path);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int chown(const char *path, uid_t uid, gid_t gid)
{
return syscall3(__NR_chown, (long)path, uid, gid);
}

View file

@ -0,0 +1,11 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
int close(int fd)
{
int ret = __syscall_close(fd);
CANCELPT_BEGIN;
CANCELPT_END;
return ret;
}

View file

@ -0,0 +1,23 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
char *ctermid(char *s)
{
static char *s2;
int fd;
if (!s) {
if (!s2) s2 = malloc(L_ctermid);
s = s2;
}
fd = open("/dev/tty", O_WRONLY | O_NOCTTY);
if (fd < 0)
return strcpy(s, "");
if (ttyname_r(fd, s, L_ctermid))
strcpy(s, "");
close(fd);
return s;
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int dup(int fd)
{
return syscall1(__NR_dup, fd);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int dup2(int old, int new)
{
return __syscall_dup2(old, new);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int faccessat(int fd, const char *filename, int amode, int flag)
{
return syscall4(__NR_faccessat, fd, (long)filename, amode, flag);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int fchdir(int fd)
{
return syscall1(__NR_fchdir, fd);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int fchown(int fd, uid_t uid, gid_t gid)
{
return syscall3(__NR_fchown, fd, uid, gid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int fchownat(int fd, const char *path, uid_t uid, gid_t gid, int flag)
{
return syscall5(__NR_fchownat, fd, (long)path, uid, gid, flag);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int fdatasync(int fd)
{
return 0;
}

View file

@ -0,0 +1,8 @@
#include <unistd.h>
#include "syscall.h"
int fsync(int fd)
{
//return syscall1(__NR_fsync, fd);
return 0;
}

View file

@ -0,0 +1,10 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
int ftruncate(int fd, off_t length)
{
return syscall3(__NR_ftruncate, fd, SYSCALL_LL(length));
}
LFS64(ftruncate);

View file

@ -0,0 +1,8 @@
#include <unistd.h>
#include <errno.h>
#include "syscall.h"
char *getcwd(char *buf, size_t size)
{
return syscall2(__NR_getcwd, (long)buf, size) < 0 ? NULL : buf;
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
gid_t getegid(void)
{
return syscall0(__NR_getegid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
uid_t geteuid(void)
{
return syscall0(__NR_geteuid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
gid_t getgid(void)
{
return syscall0(__NR_getgid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int getgroups(int count, gid_t list[])
{
return syscall2(__NR_getgroups, count, (long)list);
}

View file

@ -0,0 +1,14 @@
#include <unistd.h>
#include <sys/utsname.h>
#include <string.h>
int gethostname(char *name, size_t len)
{
size_t i;
struct utsname uts;
if (uname(&uts)) return -1;
if (len > sizeof uts.nodename) len = sizeof uts.nodename;
for (i=0; i<len && (name[i] = uts.nodename[i]); i++);
if (i==len) name[i-1] = 0;
return 0;
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include <stdlib.h>
char *getlogin(void)
{
return getenv("LOGNAME");
}

View file

@ -0,0 +1,13 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
int getlogin_r(char *name, size_t size)
{
char *logname = getlogin();
if (!logname) return ENXIO; /* or...? */
if (strlen(name) >= size) return ERANGE;
strcpy(name, logname);
return 0;
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
pid_t getpgid(pid_t pid)
{
return syscall1(__NR_getpgid, pid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
pid_t getpgrp(void)
{
return syscall0(__NR_getpgrp);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
pid_t getpid(void)
{
return syscall0(__NR_getpid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
pid_t getppid(void)
{
return syscall0(__NR_getppid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
pid_t getsid(pid_t pid)
{
return syscall1(__NR_getsid, pid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
uid_t getuid(void)
{
return syscall0(__NR_getuid);
}

View file

@ -0,0 +1,8 @@
#include <unistd.h>
#include <termios.h>
int isatty(int fd)
{
struct termios t;
return tcgetattr(fd, &t) == 0;
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int lchown(const char *path, uid_t uid, gid_t gid)
{
return syscall3(__NR_lchown, (long)path, uid, gid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int link(const char *existing, const char *new)
{
return syscall2(__NR_link, (long)existing, (long)new);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int linkat(int fd1, const char *existing, int fd2, const char *new, int flag)
{
return syscall5(__NR_linkat, fd1, (long)existing, fd2, (long)new, flag);
}

View file

@ -0,0 +1,15 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
off_t lseek(int fd, off_t offset, int whence)
{
#ifdef __NR__llseek
off_t result;
return syscall5(__NR__llseek, fd, offset>>32, offset, (long)&result, whence) ? -1 : result;
#else
return syscall3(__NR_lseek, fd, offset, whence);
#endif
}
LFS64(lseek);

View file

@ -0,0 +1,12 @@
#include <unistd.h>
#include <sys/resource.h>
#include "syscall.h"
int nice(int inc)
{
#ifdef __NR_nice
return syscall1(__NR_nice, inc);
#else
return setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS, 0)+inc);
#endif
}

View file

@ -0,0 +1,12 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
int pause(void)
{
int r;
CANCELPT_BEGIN;
r = syscall0(__NR_pause);
CANCELPT_END;
return r;
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int pipe(int fd[2])
{
return syscall1(__NR_pipe, (long)fd);
}

View file

@ -0,0 +1,14 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
{
ssize_t r;
CANCELPT_BEGIN;
r = syscall5(__NR_pread, fd, (long)buf, size, SYSCALL_LL(ofs));
CANCELPT_END;
return r;
}
LFS64(pread);

View file

@ -0,0 +1,14 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
{
ssize_t r;
CANCELPT_BEGIN;
r = syscall5(__NR_pwrite, fd, (long)buf, size, SYSCALL_LL(ofs));
CANCELPT_END;
return r;
}
LFS64(pwrite);

View file

@ -0,0 +1,12 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
ssize_t read(int fd, void *buf, size_t count)
{
ssize_t r;
CANCELPT_BEGIN;
r = __syscall_read(fd, buf, count);
CANCELPT_END;
return r;
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int readlink(const char *path, char *buf, size_t bufsize)
{
return syscall3(__NR_readlink, (long)path, (long)buf, bufsize);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int readlinkat(int fd, const char *path, char *buf, size_t bufsize)
{
return syscall4(__NR_readlinkat, fd, (long)path, (long)buf, bufsize);
}

View file

@ -0,0 +1,12 @@
#include <sys/uio.h>
#include "syscall.h"
#include "libc.h"
ssize_t readv(int fd, const struct iovec *iov, int count)
{
ssize_t r;
CANCELPT_BEGIN;
r = syscall3(__NR_readv, fd, (long)iov, count);
CANCELPT_END;
return r;
}

View file

@ -0,0 +1,7 @@
#include <stdio.h>
#include "syscall.h"
int renameat(int oldfd, const char *old, int newfd, const char *new)
{
return syscall4(__NR_renameat, oldfd, (long)old, newfd, (long)new);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int rmdir(const char *path)
{
return syscall1(__NR_rmdir, (long)path);
}

View file

@ -0,0 +1,6 @@
#include <unistd.h>
int setegid(gid_t egid)
{
return setregid(-1, egid);
}

View file

@ -0,0 +1,6 @@
#include <unistd.h>
int seteuid(uid_t euid)
{
return setreuid(-1, euid);
}

View file

@ -0,0 +1,9 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
int setgid(gid_t gid)
{
if (libc.rsyscall) return libc.rsyscall(__NR_setgid, gid, 0, 0, 0, 0, 0);
return syscall1(__NR_setgid, gid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
pid_t setpgid(pid_t pid, pid_t pgid)
{
return syscall2(__NR_setpgid, pid, pgid);
}

View file

@ -0,0 +1,6 @@
#include <unistd.h>
pid_t setpgrp(void)
{
return setpgid(0, 0);
}

View file

@ -0,0 +1,9 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
int setregid(gid_t rgid, gid_t egid)
{
if (libc.rsyscall) return libc.rsyscall(__NR_setregid, rgid, egid, 0, 0, 0, 0);
return syscall2(__NR_setregid, rgid, egid);
}

View file

@ -0,0 +1,9 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
int setreuid(uid_t ruid, uid_t euid)
{
if (libc.rsyscall) return libc.rsyscall(__NR_setreuid, ruid, euid, 0, 0, 0, 0);
return syscall2(__NR_setreuid, ruid, euid);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
pid_t setsid(void)
{
return syscall0(__NR_setsid);
}

View file

@ -0,0 +1,9 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
int setuid(uid_t uid)
{
if (libc.rsyscall) return libc.rsyscall(__NR_setuid, uid, 0, 0, 0, 0, 0);
return syscall1(__NR_setuid, uid);
}

View file

@ -0,0 +1,10 @@
#include <unistd.h>
#include <time.h>
unsigned sleep(unsigned seconds)
{
struct timespec tv = { .tv_sec = seconds, .tv_nsec = 0 };
if (nanosleep(&tv, &tv))
return tv.tv_sec;
return 0;
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int symlink(const char *existing, const char *new)
{
return syscall2(__NR_symlink, (long)existing, (long)new);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int symlinkat(const char *existing, int fd, const char *new)
{
return syscall3(__NR_symlinkat, (long)existing, fd, (long)new);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
void sync(void)
{
syscall0(__NR_sync);
}

View file

@ -0,0 +1,11 @@
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
pid_t tcgetpgrp(int fd)
{
int pgrp;
if (ioctl(fd, TIOCGPGRP, &pgrp) < 0)
return -1;
return pgrp;
}

View file

@ -0,0 +1,9 @@
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
int tcsetpgrp(int fd, pid_t pgrp)
{
int pgrp_int = pgrp;
return ioctl(fd, TIOCSPGRP, &pgrp_int);
}

View file

@ -0,0 +1,10 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
int truncate(const char *path, off_t length)
{
return syscall3(__NR_truncate, (long)path, SYSCALL_LL(length));
}
LFS64(truncate);

View file

@ -0,0 +1,14 @@
#include <unistd.h>
#include <errno.h>
#include <limits.h>
char *ttyname(int fd)
{
static char buf[TTY_NAME_MAX];
int result;
if ((result = ttyname_r(fd, buf, sizeof buf))) {
errno = result;
return NULL;
}
return buf;
}

View file

@ -0,0 +1,19 @@
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
int ttyname_r(int fd, char *name, size_t size)
{
char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2];
ssize_t l;
if (!isatty(fd)) return ENOTTY;
snprintf(procname, sizeof procname, "/proc/self/fd/%d", fd);
l = readlink(procname, name, size);
if (l < 0) return errno;
else if (l == size) return ERANGE;
else return 0;
}

View file

@ -0,0 +1,8 @@
#include <unistd.h>
#include "syscall.h"
/* FIXME: ?? */
useconds_t ualarm(useconds_t useconds, useconds_t interval)
{
return -1;
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int unlink(const char *path)
{
return __syscall_unlink(path);
}

View file

@ -0,0 +1,7 @@
#include <unistd.h>
#include "syscall.h"
int unlinkat(int fd, const char *path, int flag)
{
return syscall3(__NR_unlinkat, fd, (long)path, flag);
}

View file

@ -0,0 +1,11 @@
#include <unistd.h>
#include <time.h>
int usleep(useconds_t useconds)
{
struct timespec tv = {
.tv_sec = useconds/1000000,
.tv_nsec = (useconds%1000000)*1000
};
return nanosleep(&tv, &tv);
}

View file

@ -0,0 +1,12 @@
#include <unistd.h>
#include "syscall.h"
#include "libc.h"
ssize_t write(int fd, const void *buf, size_t count)
{
int r;
CANCELPT_BEGIN;
r = __syscall_write(fd, buf, count);
CANCELPT_END;
return r;
}

View file

@ -0,0 +1,12 @@
#include <sys/uio.h>
#include "syscall.h"
#include "libc.h"
ssize_t writev(int fd, const struct iovec *iov, int count)
{
ssize_t r;
CANCELPT_BEGIN;
r = syscall3(__NR_writev, fd, (long)iov, count);
CANCELPT_END;
return r;
}