user: implement mlibc as the libc, finally.
It's finally done.. Signed-off-by: kaguya <vpshinomiya@protonmail.com>
This commit is contained in:
+18
@@ -0,0 +1,18 @@
|
||||
#include <bits/ensure.h>
|
||||
#include <mlibc/elf/startup.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/auxv.h>
|
||||
|
||||
extern "C" void __dlapi_enter(uintptr_t *);
|
||||
|
||||
extern char **environ;
|
||||
|
||||
extern "C" void __mlibc_entry(uintptr_t *entry_stack,
|
||||
int (*main_fn)(int argc, char *argv[],
|
||||
char *env[])) {
|
||||
__dlapi_enter(entry_stack);
|
||||
auto result =
|
||||
main_fn(mlibc::entry_stack.argc, mlibc::entry_stack.argv, environ);
|
||||
exit(result);
|
||||
}
|
||||
+478
@@ -0,0 +1,478 @@
|
||||
#include "syscall.h"
|
||||
#include <asm/ioctls.h>
|
||||
#include <bits/ensure.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <mlibc/all-sysdeps.hpp>
|
||||
#include <mlibc/debug.hpp>
|
||||
#include <nyaux/syscalls.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/types.h>
|
||||
#define STUB_ONLY \
|
||||
{ \
|
||||
__ensure(!"STUB_ONLY function was called"); \
|
||||
__builtin_unreachable(); \
|
||||
}
|
||||
|
||||
namespace mlibc {
|
||||
|
||||
void sys_libc_log(const char *message) {
|
||||
__syscall2(SYSCALL_DEBUG, (uint64_t)message, strlen(message));
|
||||
}
|
||||
void sys_exit(int status) {
|
||||
__syscall1(SYSCALL_EXIT, status);
|
||||
__builtin_unreachable();
|
||||
};
|
||||
void sys_libc_panic() {
|
||||
sys_libc_log("\nMLIBC PANIC\n");
|
||||
sys_exit(1);
|
||||
}
|
||||
int sys_vm_map(void *hint, size_t size, int prot, int flags, int fd, off_t offset, void **window) {
|
||||
struct __syscall_ret ret = __syscall6(
|
||||
SYSCALL_MMAP,
|
||||
(uint64_t)hint,
|
||||
(uint64_t)size,
|
||||
(uint64_t)prot,
|
||||
(uint64_t)flags,
|
||||
(uint64_t)fd,
|
||||
(uint64_t)offset
|
||||
);
|
||||
*window = (void *)ret.ret;
|
||||
return ret.err;
|
||||
};
|
||||
int sys_anon_allocate(size_t size, void **pointer) {
|
||||
return sys_vm_map(NULL, size, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0, pointer);
|
||||
};
|
||||
int sys_vm_protect(void *pointer, size_t size, int prot) { return 0; }
|
||||
int sys_anon_free(void *pointer, size_t size) {
|
||||
__syscall2(SYSCALL_FREE, (uint64_t)pointer, size);
|
||||
return 0;
|
||||
};
|
||||
int sys_close(int fd) {
|
||||
__syscall_ret ret = __syscall1(SYSCALL_CLOSE, fd);
|
||||
|
||||
if (ret.err != 0)
|
||||
return ret.err;
|
||||
|
||||
return 0;
|
||||
};
|
||||
int sys_futex_wait(int *pointer, int expected, const struct timespec *time) STUB_ONLY;
|
||||
int sys_futex_wake(int *pointer) {
|
||||
// sys_libc_log("sys futex wake is a stub");
|
||||
return 0;
|
||||
};
|
||||
int sys_openat(int dirfd, const char *path, int flags, mode_t mode, int *fd) {
|
||||
__syscall_ret ret = __syscall4(SYSCALL_OPENAT, dirfd, (uint64_t)path, flags, mode);
|
||||
|
||||
if (ret.err != 0)
|
||||
return ret.err;
|
||||
|
||||
*fd = (int)ret.ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uid_t sys_geteuid() {
|
||||
mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog;
|
||||
return 0;
|
||||
}
|
||||
int sys_gethostname(char *buffer, size_t bufsize) {
|
||||
if (bufsize >= 6) {
|
||||
memcpy(buffer, "nyaux", 6);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int sys_uname(struct utsname *buf) {
|
||||
|
||||
memcpy(buf->sysname, "Nyaux", sizeof("Nyaux"));
|
||||
memcpy(buf->release, "1.0", sizeof("1.0"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
gid_t sys_getgid() {
|
||||
mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_setgid(gid_t gid) {
|
||||
(void)gid;
|
||||
mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t sys_getpgid(pid_t pid, pid_t *pgid) {
|
||||
(void)pid;
|
||||
mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog;
|
||||
*pgid = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
gid_t sys_getegid() {
|
||||
mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_setpgid(pid_t pid, pid_t pgid) {
|
||||
(void)pid;
|
||||
(void)pgid;
|
||||
mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_ttyname(int fd, char *buf, size_t size) {
|
||||
(void)fd;
|
||||
(void)buf;
|
||||
(void)size;
|
||||
mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog;
|
||||
return ENOSYS;
|
||||
}
|
||||
uid_t sys_getuid() {
|
||||
mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!\n" << frg::endlog;
|
||||
return 0;
|
||||
}
|
||||
int sys_open(const char *path, int flags, mode_t mode, int *fd) {
|
||||
return sys_openat(AT_FDCWD, path, flags, mode, fd);
|
||||
}
|
||||
int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read) {
|
||||
__syscall_ret ret = __syscall3(SYSCALL_READ, fd, (uint64_t)buf, count);
|
||||
|
||||
if (ret.err != 0) {
|
||||
return ret.err;
|
||||
}
|
||||
|
||||
*bytes_read = (ssize_t)ret.ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_seek(int fd, off_t offset, int whence, off_t *new_offset) {
|
||||
__syscall_ret ret = __syscall3(SYSCALL_SEEK, fd, offset, whence);
|
||||
|
||||
if (ret.err != 0) {
|
||||
return ret.err;
|
||||
}
|
||||
|
||||
*new_offset = (off_t)ret.ret;
|
||||
return 0;
|
||||
}
|
||||
int sys_tcb_set(void *pointer) {
|
||||
__syscall_ret ret = __syscall1(SYSCALL_SETFSBASE, (uint64_t)pointer);
|
||||
if (ret.err != 0) {
|
||||
return ret.err;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
int sys_isatty(int fd) {
|
||||
__syscall_ret ret = __syscall1(SYSCALL_ISATTY, fd);
|
||||
if (ret.err != 0) {
|
||||
return ret.err;
|
||||
}
|
||||
|
||||
return ret.ret;
|
||||
}
|
||||
int sys_vm_unmap(void *pointer, size_t size) STUB_ONLY;
|
||||
int sys_clock_get(int clock, time_t *secs, long *nanos) {
|
||||
__syscall_ret ret = __syscall3(SYSCALL_CLOCKGET, clock, (uint64_t)secs, (uint64_t)nanos);
|
||||
if (ret.err != 0)
|
||||
return ret.err;
|
||||
return 0;
|
||||
}
|
||||
#ifndef MLIBC_BUILDING_RTLD
|
||||
int sys_getcwd(char *buffer, size_t size) {
|
||||
__syscall_ret ret = __syscall2(SYSCALL_GETCWD, (uint64_t)buffer, size);
|
||||
|
||||
if (ret.err != 0)
|
||||
return ret.err;
|
||||
|
||||
return 0;
|
||||
}
|
||||
int sys_write(int fd, const void *buf, size_t count, ssize_t *bytes_written) {
|
||||
__syscall_ret ret = __syscall3(SYSCALL_WRITE, fd, (uint64_t)buf, count);
|
||||
|
||||
if (ret.err != 0) {
|
||||
return ret.err;
|
||||
}
|
||||
|
||||
*bytes_written = (ssize_t)ret.ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
pid_t sys_getpid() {
|
||||
__syscall_ret ret = __syscall0(16);
|
||||
return ret.ret;
|
||||
}
|
||||
#endif
|
||||
pid_t sys_getppid() {
|
||||
mlibc::infoLogger() << "mlibc: " << __func__ << " is a stub!" << frg::endlog;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#ifndef MLIBC_BUILDING_RTLD
|
||||
int sys_fork(pid_t *child) {
|
||||
__syscall_ret ret = __syscall0(SYSCALL_FORK);
|
||||
|
||||
if (ret.err != 0) {
|
||||
return ret.err;
|
||||
}
|
||||
|
||||
*child = (pid_t)ret.ret;
|
||||
return 0;
|
||||
}
|
||||
int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {
|
||||
__syscall_ret ret = __syscall3(SYSCALL_IOCTL, fd, request, (uint64_t)arg);
|
||||
|
||||
if (ret.err != 0)
|
||||
return ret.err;
|
||||
*result = (int)ret.ret;
|
||||
return 0;
|
||||
}
|
||||
int sys_poll(struct pollfd *fds, nfds_t count, int timeout, int *num_events) {
|
||||
__syscall_ret ret = __syscall3(SYSCALL_POLL, (uint64_t)fds, count, timeout);
|
||||
if (ret.err != 0)
|
||||
return ret.err;
|
||||
|
||||
*num_events = (int)ret.ret;
|
||||
return 0;
|
||||
}
|
||||
int sys_fcntl(int fd, int request, va_list args, int *result) {
|
||||
// __syscall_ret ret = __syscall(12, fd, request, va_arg(args, uint64_t));
|
||||
|
||||
// if (ret.errno != 0)
|
||||
// return ret.errno;
|
||||
|
||||
// *result = (ssize_t)ret.ret;
|
||||
// return 0;
|
||||
mlibc::infoLogger() << "mlibc: fd " << fd << " request " << request << frg::endlog;
|
||||
return ENOSYS;
|
||||
}
|
||||
int sys_ppoll(
|
||||
struct pollfd *fds,
|
||||
int nfds,
|
||||
const struct timespec *timeout,
|
||||
const sigset_t *sigmask,
|
||||
int *num_events
|
||||
) {
|
||||
sigset_t origmask;
|
||||
int timeoutr;
|
||||
int ret;
|
||||
|
||||
timeoutr = (timeout == NULL) ? -1 : (timeout->tv_sec * 1000 + timeout->tv_nsec / 1000000);
|
||||
pthread_sigmask(SIG_SETMASK, sigmask, &origmask);
|
||||
ret = sys_poll(fds, nfds, timeoutr, num_events);
|
||||
pthread_sigmask(SIG_SETMASK, &origmask, NULL);
|
||||
return ret;
|
||||
}
|
||||
int sys_pselect(
|
||||
int nfds,
|
||||
fd_set *read_set,
|
||||
fd_set *write_set,
|
||||
fd_set *except_set,
|
||||
const struct timespec *timeout,
|
||||
const sigset_t *sigmask,
|
||||
int *num_events
|
||||
) {
|
||||
// this is a stub to please bash
|
||||
struct pollfd *fds = (struct pollfd *)calloc(nfds, sizeof(struct pollfd));
|
||||
if (fds == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nfds; i++) {
|
||||
struct pollfd *fd = &fds[i];
|
||||
|
||||
if (read_set && FD_ISSET(i, read_set))
|
||||
fd->events |= POLLIN; // TODO: Additional events.
|
||||
if (write_set && FD_ISSET(i, write_set))
|
||||
fd->events |= POLLOUT; // TODO: Additional events.
|
||||
if (except_set && FD_ISSET(i, except_set))
|
||||
fd->events |= POLLPRI;
|
||||
|
||||
if (!fd->events) {
|
||||
fd->fd = -1;
|
||||
continue;
|
||||
}
|
||||
|
||||
fd->fd = i;
|
||||
}
|
||||
|
||||
int e = sys_ppoll(fds, nfds, timeout, sigmask, num_events);
|
||||
|
||||
if (e != 0) {
|
||||
free(fds);
|
||||
return e;
|
||||
}
|
||||
|
||||
fd_set res_read_set;
|
||||
fd_set res_write_set;
|
||||
fd_set res_except_set;
|
||||
FD_ZERO(&res_read_set);
|
||||
FD_ZERO(&res_write_set);
|
||||
FD_ZERO(&res_except_set);
|
||||
|
||||
for (int i = 0; i < nfds; i++) {
|
||||
struct pollfd *fd = &fds[i];
|
||||
|
||||
if (read_set && FD_ISSET(i, read_set) && fd->revents & (POLLIN | POLLERR | POLLHUP)) {
|
||||
FD_SET(i, &res_read_set);
|
||||
}
|
||||
|
||||
if (write_set && FD_ISSET(i, write_set) && fd->revents & (POLLOUT | POLLERR | POLLHUP)) {
|
||||
FD_SET(i, &res_write_set);
|
||||
}
|
||||
|
||||
if (except_set && FD_ISSET(i, except_set) && fd->revents & POLLPRI) {
|
||||
FD_SET(i, &res_except_set);
|
||||
}
|
||||
}
|
||||
|
||||
free(fds);
|
||||
|
||||
if (read_set)
|
||||
*read_set = res_read_set;
|
||||
if (write_set)
|
||||
*write_set = res_write_set;
|
||||
if (except_set)
|
||||
*except_set = res_except_set;
|
||||
|
||||
return 0;
|
||||
}
|
||||
int sys_tcsetattr(int fd, int optional_action, const struct termios *attr) {
|
||||
int ret;
|
||||
|
||||
switch (optional_action) {
|
||||
case TCSANOW:
|
||||
optional_action = TCSETS;
|
||||
break;
|
||||
case TCSADRAIN:
|
||||
optional_action = TCSETS;
|
||||
break;
|
||||
case TCSAFLUSH:
|
||||
optional_action = TCSETS;
|
||||
break;
|
||||
default:
|
||||
__ensure(!"Unsupported tcsetattr");
|
||||
}
|
||||
|
||||
if (int r = sys_ioctl(fd, optional_action, (void *)attr, &ret) != 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru, pid_t *ret_pid) {
|
||||
if (ru) {
|
||||
mlibc::infoLogger() << "mlibc: struct rusage in sys_waitpid is unsupported" << frg::endlog;
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
again:
|
||||
__syscall_ret ret = __syscall3(SYSCALL_WAITPID, pid, (uint64_t)status, flags);
|
||||
|
||||
if (ret.err != 0) {
|
||||
if (ret.err == EINTR) {
|
||||
goto again;
|
||||
}
|
||||
|
||||
return ret.err;
|
||||
}
|
||||
|
||||
*ret_pid = (pid_t)ret.ret;
|
||||
return 0;
|
||||
}
|
||||
int sys_execve(const char *path, char *const argv[], char *const envp[]) {
|
||||
__syscall_ret ret = __syscall3(SYSCALL_EXECVE, (uint64_t)path, (uint64_t)argv, (uint64_t)envp);
|
||||
if (ret.ret != 0) {
|
||||
return ret.err;
|
||||
} else {
|
||||
mlibc::infoLogger() << "mlibc: kernel failed execve syscall" << frg::endlog;
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
int sys_faccessat(int dirfd, const char *pathname, int mode, int flags) {
|
||||
__syscall_ret ret = __syscall4(SYSCALL_FACCESSAT, dirfd, (uint64_t)pathname, mode, flags);
|
||||
|
||||
if (ret.err != 0) {
|
||||
return ret.err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_access(const char *path, int mode) { return sys_faccessat(AT_FDCWD, path, mode, 0); }
|
||||
#endif
|
||||
int sys_sigprocmask(int how, const sigset_t *__restrict set, sigset_t *__restrict retrieve) {
|
||||
return ENOSYS;
|
||||
}
|
||||
int sys_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) {
|
||||
return ENOSYS;
|
||||
}
|
||||
int sys_tcgetattr(int fd, struct termios *attr) {
|
||||
int ret;
|
||||
|
||||
if (int r = sys_ioctl(fd, TCGETS, attr, &ret) != 0) {
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
int sys_dup(int fd, int flags, int *newfd) {
|
||||
(void)flags;
|
||||
__syscall_ret ret = __syscall2(SYSCALL_DUP, fd, flags);
|
||||
|
||||
if (ret.err != 0)
|
||||
return ret.err;
|
||||
|
||||
*newfd = (ssize_t)ret.ret;
|
||||
return 0;
|
||||
}
|
||||
int sys_dup2(int fd, int flags, int newfd) {
|
||||
__syscall_ret ret = __syscall3(SYSCALL_DUP2, fd, newfd, flags);
|
||||
|
||||
if (ret.err != 0)
|
||||
return ret.err;
|
||||
|
||||
return 0;
|
||||
}
|
||||
int sys_stat(fsfd_target fsfdt, int fd, const char *path, int flags, struct stat *statbuf) {
|
||||
__syscall_ret ret;
|
||||
switch (fsfdt) {
|
||||
case fsfd_target::fd: {
|
||||
ret = __syscall2(SYSCALL_FSTAT, fd, (uint64_t)statbuf);
|
||||
if (ret.err != 0) {
|
||||
return ret.err;
|
||||
}
|
||||
return ret.ret;
|
||||
break;
|
||||
}
|
||||
case fsfd_target::path: {
|
||||
int fd = 0;
|
||||
int bad = sys_openat(AT_FDCWD, path, flags, O_RDONLY, &fd);
|
||||
if (bad != 0) {
|
||||
return bad;
|
||||
}
|
||||
ret = __syscall2(SYSCALL_FSTAT, fd, (uint64_t)statbuf);
|
||||
bad = sys_close(fd);
|
||||
// ret = __syscall(11, AT_FDCWD, path, statbuf, flags);
|
||||
return ret.ret;
|
||||
break;
|
||||
}
|
||||
case fsfd_target::fd_path: {
|
||||
mlibc::infoLogger() << "mlibc: statfd_path is a stub" << frg::endlog;
|
||||
// ret = __syscall(11, fd, path, statbuf, flags);
|
||||
return ENOSYS;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
__ensure(!"stat: Invalid fsfdt");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
}
|
||||
if (ret.err != 0)
|
||||
return ret.err;
|
||||
return ret.ret;
|
||||
}
|
||||
|
||||
} // namespace mlibc
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
struct __syscall_ret {
|
||||
uint64_t ret;
|
||||
uint64_t err;
|
||||
};
|
||||
|
||||
static __syscall_ret __syscall6(int number, uint64_t arg1, uint64_t arg2,
|
||||
uint64_t arg3, uint64_t arg4, uint64_t arg5,
|
||||
uint64_t arg6) {
|
||||
struct __syscall_ret ret;
|
||||
register uint64_t arg_r8 asm("r8") = arg4;
|
||||
register uint64_t arg_r9 asm("r9") = arg5;
|
||||
register uint64_t arg_r10 asm("r10") = arg6;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret.ret), "=d"(ret.err)
|
||||
: "a"(number), "D"(arg1), "S"(arg2), "d"(arg3), "r"(arg_r8),
|
||||
"r"(arg_r9), "r"(arg_r10)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
static __syscall_ret __syscall5(int number, uint64_t arg1, uint64_t arg2,
|
||||
uint64_t arg3, uint64_t arg4, uint64_t arg5) {
|
||||
struct __syscall_ret ret;
|
||||
register uint64_t arg_r8 asm("r8") = arg4;
|
||||
register uint64_t arg_r9 asm("r9") = arg5;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret.ret), "=d"(ret.err)
|
||||
: "a"(number), "D"(arg1), "S"(arg2), "d"(arg3), "r"(arg_r8),
|
||||
"r"(arg_r9)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
static __syscall_ret __syscall4(int number, uint64_t arg1, uint64_t arg2,
|
||||
uint64_t arg3, uint64_t arg4) {
|
||||
struct __syscall_ret ret;
|
||||
register uint64_t arg_r8 asm("r8") = arg4;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret.ret), "=d"(ret.err)
|
||||
: "a"(number), "D"(arg1), "S"(arg2), "d"(arg3), "r"(arg_r8)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
static __syscall_ret __syscall3(int number, uint64_t arg1, uint64_t arg2,
|
||||
uint64_t arg3) {
|
||||
struct __syscall_ret ret;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret.ret), "=d"(ret.err)
|
||||
: "a"(number), "D"(arg1), "S"(arg2), "d"(arg3)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
static __syscall_ret __syscall2(int number, uint64_t arg1, uint64_t arg2) {
|
||||
struct __syscall_ret ret;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret.ret), "=d"(ret.err)
|
||||
: "a"(number), "D"(arg1), "S"(arg2)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
static __syscall_ret __syscall1(int number, uint64_t arg1) {
|
||||
struct __syscall_ret ret;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret.ret), "=d"(ret.err)
|
||||
: "a"(number), "D"(arg1)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
static __syscall_ret __syscall0(int number) {
|
||||
struct __syscall_ret ret;
|
||||
asm volatile("syscall"
|
||||
: "=a"(ret.ret), "=d"(ret.err)
|
||||
: "a"(number)
|
||||
: "rcx", "r11", "memory");
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/access.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/auxv.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/blkcnt_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/blksize_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/clockid_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/dev_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/epoll.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/errno.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/fcntl.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/fsblkcnt_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/fsfilcnt_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/gid_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/in.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/ino_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/inotify.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/ioctls.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/ipc.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/limits.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/mode_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/mqueue.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/msg.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/nlink_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/packet.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/pid_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/poll.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/ptrace.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/random.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/reboot.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/resource.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/rlim_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/seek-whence.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/shm.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/sigevent.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/signal.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/sigval.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/socket.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/socklen_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/stat.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/statfs.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/statvfs.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/statx.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/suseconds_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/termios.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/time.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/uid_t.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/utmp-defines.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/utmpx.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/utsname.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/vm-flags.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/vt.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/wait.h
|
||||
@@ -0,0 +1 @@
|
||||
../../../../abis/linux/xattr.h
|
||||
@@ -0,0 +1,27 @@
|
||||
#ifndef _NYAUX_SYSCALL_H
|
||||
#define _NYAUX_SYSCALL_H
|
||||
|
||||
#define SYSCALL_EXIT 0
|
||||
#define SYSCALL_DEBUG 1
|
||||
#define SYSCALL_SETFSBASE 2
|
||||
#define SYSCALL_MMAP 3
|
||||
#define SYSCALL_OPENAT 4
|
||||
#define SYSCALL_READ 5
|
||||
#define SYSCALL_SEEK 6
|
||||
#define SYSCALL_CLOSE 7
|
||||
#define SYSCALL_ISATTY 8
|
||||
#define SYSCALL_WRITE 9
|
||||
#define SYSCALL_IOCTL 10
|
||||
#define SYSCALL_DUP 11
|
||||
#define SYSCALL_FSTAT 12
|
||||
#define SYSCALL_GETCWD 13
|
||||
#define SYSCALL_FORK 14
|
||||
#define SYSCALL_WAITPID 15
|
||||
#define SYSCALL_GETPID 16
|
||||
#define SYSCALL_FREE 17
|
||||
#define SYSCALL_EXECVE 18
|
||||
#define SYSCALL_FACCESSAT 19
|
||||
#define SYSCALL_DUP2 20
|
||||
#define SYSCALL_POLL 21
|
||||
#define SYSCALL_CLOCKGET 22
|
||||
#endif
|
||||
Executable
+105
@@ -0,0 +1,105 @@
|
||||
sysdep_supported_options = {
|
||||
'posix': true,
|
||||
'linux': true,
|
||||
'glibc': true,
|
||||
'bsd': true,
|
||||
}
|
||||
|
||||
rtld_sources += files(
|
||||
'generic/generic.cpp'
|
||||
)
|
||||
|
||||
libc_sources += files(
|
||||
'generic/entry.cpp',
|
||||
'generic/generic.cpp'
|
||||
)
|
||||
|
||||
if not no_headers
|
||||
install_headers(
|
||||
'include/abi-bits/auxv.h',
|
||||
'include/abi-bits/seek-whence.h',
|
||||
'include/abi-bits/vm-flags.h',
|
||||
'include/abi-bits/errno.h',
|
||||
'include/abi-bits/fcntl.h',
|
||||
'include/abi-bits/in.h',
|
||||
'include/abi-bits/reboot.h',
|
||||
'include/abi-bits/resource.h',
|
||||
'include/abi-bits/stat.h',
|
||||
'include/abi-bits/signal.h',
|
||||
'include/abi-bits/socket.h',
|
||||
'include/abi-bits/termios.h',
|
||||
'include/abi-bits/time.h',
|
||||
'include/abi-bits/blkcnt_t.h',
|
||||
'include/abi-bits/blksize_t.h',
|
||||
'include/abi-bits/dev_t.h',
|
||||
'include/abi-bits/gid_t.h',
|
||||
'include/abi-bits/ino_t.h',
|
||||
'include/abi-bits/mode_t.h',
|
||||
'include/abi-bits/nlink_t.h',
|
||||
'include/abi-bits/pid_t.h',
|
||||
'include/abi-bits/uid_t.h',
|
||||
'include/abi-bits/access.h',
|
||||
'include/abi-bits/wait.h',
|
||||
'include/abi-bits/limits.h',
|
||||
'include/abi-bits/utsname.h',
|
||||
'include/abi-bits/poll.h',
|
||||
'include/abi-bits/packet.h',
|
||||
'include/abi-bits/clockid_t.h',
|
||||
'include/abi-bits/ipc.h',
|
||||
'include/abi-bits/shm.h',
|
||||
'include/abi-bits/mqueue.h',
|
||||
'include/abi-bits/suseconds_t.h',
|
||||
'include/abi-bits/fsfilcnt_t.h',
|
||||
'include/abi-bits/fsblkcnt_t.h',
|
||||
'include/abi-bits/socklen_t.h',
|
||||
'include/abi-bits/statvfs.h',
|
||||
'include/abi-bits/ioctls.h',
|
||||
'include/abi-bits/msg.h',
|
||||
'include/abi-bits/rlim_t.h',
|
||||
'include/abi-bits/sigval.h',
|
||||
'include/abi-bits/sigevent.h',
|
||||
'include/abi-bits/xattr.h',
|
||||
'include/abi-bits/random.h',
|
||||
'include/abi-bits/vt.h',
|
||||
'include/abi-bits/ptrace.h',
|
||||
'include/abi-bits/epoll.h',
|
||||
'include/abi-bits/inotify.h',
|
||||
'include/abi-bits/statfs.h',
|
||||
'include/abi-bits/statx.h',
|
||||
'include/abi-bits/time.h',
|
||||
'include/abi-bits/utmpx.h',
|
||||
'include/abi-bits/utmp-defines.h',
|
||||
subdir: 'abi-bits',
|
||||
follow_symlinks: true
|
||||
)
|
||||
endif
|
||||
|
||||
if not headers_only
|
||||
crt = custom_target('crt0',
|
||||
build_by_default: true,
|
||||
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
|
||||
input: host_machine.cpu_family() / 'crt-src/crt0.S',
|
||||
output: 'crt0.o',
|
||||
install: true,
|
||||
install_dir: get_option('libdir')
|
||||
)
|
||||
|
||||
custom_target('crti',
|
||||
build_by_default: true,
|
||||
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
|
||||
input: host_machine.cpu_family() / 'crt-src/crti.S',
|
||||
output: 'crti.o',
|
||||
install: true,
|
||||
install_dir: get_option('libdir')
|
||||
)
|
||||
|
||||
custom_target('crtn',
|
||||
build_by_default: true,
|
||||
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
|
||||
input: host_machine.cpu_family() / 'crt-src/crtn.S',
|
||||
output: 'crtn.o',
|
||||
install: true,
|
||||
install_dir: get_option('libdir')
|
||||
)
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
.section .text
|
||||
.global _start
|
||||
_start:
|
||||
mov %rsp, %rdi
|
||||
lea main(%rip), %rsi
|
||||
call __mlibc_entry
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
.section .init
|
||||
.global _init
|
||||
_init:
|
||||
push %rax
|
||||
|
||||
.section .fini
|
||||
.global _fini
|
||||
_fini:
|
||||
push %rax
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
.section .init
|
||||
pop %rax
|
||||
ret
|
||||
|
||||
.section .fini
|
||||
pop %rax
|
||||
ret
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
Reference in New Issue
Block a user