123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #include <libc/unistd.h>
- #include <libsystem/syscall.h>
- #include <libc/errno.h>
- #include <libc/stdio.h>
- #include <libc/stddef.h>
- int close(int fd)
- {
- return syscall_invoke(SYS_CLOSE, fd, 0, 0, 0, 0, 0, 0, 0);
- }
- ssize_t read(int fd, void *buf, size_t count)
- {
- return (ssize_t)syscall_invoke(SYS_READ, fd, (uint64_t)buf, count, 0, 0, 0, 0, 0);
- }
- ssize_t write(int fd, void const *buf, size_t count)
- {
- return (ssize_t)syscall_invoke(SYS_WRITE, fd, (uint64_t)buf, count, 0, 0, 0, 0, 0);
- }
- off_t lseek(int fd, off_t offset, int whence)
- {
- return (off_t)syscall_invoke(SYS_LSEEK, fd, offset, whence, 0, 0, 0, 0, 0);
- }
- pid_t fork(void)
- {
- return (pid_t)syscall_invoke(SYS_FORK, 0, 0, 0, 0, 0, 0, 0, 0);
- }
- pid_t vfork(void)
- {
- return (pid_t)syscall_invoke(SYS_VFORK, 0, 0, 0, 0, 0, 0, 0, 0);
- }
- uint64_t brk(uint64_t end_brk)
- {
- uint64_t x = (uint64_t)syscall_invoke(SYS_BRK, (uint64_t)end_brk, 0, 0, 0, 0, 0, 0, 0);
-
- return x;
- }
- void *sbrk(int64_t increment)
- {
- void *retval = (void *)syscall_invoke(SYS_SBRK, (uint64_t)increment, 0, 0, 0, 0, 0, 0, 0);
- if (retval == (void *)-ENOMEM)
- return (void *)(-1);
- else
- {
- errno = 0;
- return (void *)retval;
- }
- }
- int64_t chdir(char *dest_path)
- {
- if (dest_path == NULL)
- {
- errno = -EFAULT;
- return -1;
- }
- else
- {
- return syscall_invoke(SYS_CHDIR, (uint64_t)dest_path, 0, 0, 0, 0, 0, 0, 0);
- }
- }
- int execv(const char *path, char *const argv[])
- {
- if (path == NULL)
- {
- errno = -ENOENT;
- return -1;
- }
- int retval = syscall_invoke(SYS_EXECVE, (uint64_t)path, (uint64_t)argv, 0, 0, 0, 0, 0, 0);
- if(retval != 0)
- return -1;
- else return 0;
- }
|