Skip to content

Commit

Permalink
Merge pull request #1050 from Andy-Python-Programmer/master
Browse files Browse the repository at this point in the history
sysdeps(aero): update
  • Loading branch information
mintsuki authored Apr 4, 2024
2 parents 0c28bd8 + 7c71f31 commit 266ec42
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 15 deletions.
10 changes: 10 additions & 0 deletions sysdeps/aero/crt-x86_64/crti.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.section .init
.global _init
_init:
push %rax

.section .fini
.global _fini
_fini:
push %rax
.section .note.GNU-stack,"",%progbits
8 changes: 8 additions & 0 deletions sysdeps/aero/crt-x86_64/crtn.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.section .init
pop %rax
ret

.section .fini
pop %rax
ret
.section .note.GNU-stack,"",%progbits
14 changes: 11 additions & 3 deletions sysdeps/aero/generic/aero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,18 @@ int sys_clone(void *tcb, pid_t *tid_out, void *stack) {
return 0;
}

void sys_thread_exit() UNIMPLEMENTED("sys_thread_exit")
int sys_thread_setname(void *tcb, const char *name) {
mlibc::infoLogger() << "The name of this thread is " << name << frg::endlog;
return 0;
}

void sys_thread_exit() {
syscall(SYS_EXIT);
__builtin_trap();
}

int sys_waitpid(pid_t pid, int *status, int flags, struct rusage *ru,
pid_t *ret_pid) {
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"
Expand Down
21 changes: 21 additions & 0 deletions sysdeps/aero/generic/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ int sys_read(int fd, void *buf, size_t count, ssize_t *bytes_read) {
return 0;
}

int sys_fsync(int) {
mlibc::infoLogger() << "\e[35mmlibc: fsync is a stub\e[39m" << frg::endlog;
return 0;
}

int sys_fdatasync(int) {
mlibc::infoLogger() << "\e[35mmlibc: fdatasync() is a no-op\e[39m" << frg::endlog;
return 0;
}

// clang-format off
int sys_pwrite(int fd, const void *buffer, size_t count, off_t off,
ssize_t *written) UNIMPLEMENTED("sys_pwrite")
Expand Down Expand Up @@ -195,6 +205,17 @@ int sys_unlinkat(int fd, const char *path, int flags) {
return 0;
}

int sys_symlink(const char *target_path, const char *link_path) {
return sys_symlinkat(target_path, AT_FDCWD, link_path);
}

int sys_symlinkat(const char *target_path, int dirfd, const char *link_path) {
auto ret = syscall(SYS_SYMLINK_AT, dirfd, target_path, strlen(target_path), link_path, strlen(link_path));
if (int e = sc_error(ret); e)
return e;
return 0;
}

struct aero_dir_entry {
size_t inode;
size_t offset;
Expand Down
19 changes: 7 additions & 12 deletions sysdeps/aero/generic/signals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,20 @@ int sys_sigaction(int how, const struct sigaction *__restrict action,
#endif

auto sigreturn = (sc_word_t)__mlibc_signal_restore;

auto res = syscall(SYS_SIGACTION, how, (sc_word_t)action, sigreturn,
auto ret = syscall(SYS_SIGACTION, how, (sc_word_t)action, sigreturn,
(sc_word_t)old_action);

if (res < 0) {
return -res;
}

if(int e = sc_error(ret); e)
return e;
return 0;
}

int sys_sigprocmask(int how, const sigset_t *__restrict set,
sigset_t *__restrict retrieve) {
auto result = syscall(SYS_SIGPROCMASK, how, set, retrieve);

if (result < 0) {
return -result;
}

return 0;
auto ret = syscall(SYS_SIGPROCMASK, how, set, retrieve);
if(int e = sc_error(ret); e)
return e;
return 0;
}
} // namespace mlibc
16 changes: 16 additions & 0 deletions sysdeps/aero/generic/sockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,22 @@ int sys_setsockopt(int fd, int layer, int number, const void *buffer,
}
}

int sys_peername(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, socklen_t *actual_length) {
auto ret = syscall(SYS_GETPEERNAME, fd, addr_ptr, &max_addr_length);
if(int e = sc_error(ret); e)
return e;
*actual_length = max_addr_length;
return 0;
}

int sys_sockname(int fd, struct sockaddr *addr_ptr, socklen_t max_addr_length, socklen_t *actual_length) {
auto ret = syscall(SYS_GETSOCKNAME, fd, addr_ptr, &max_addr_length);
if(int e = sc_error(ret); e)
return e;
*actual_length = max_addr_length;
return 0;
}

int sys_shutdown(int sockfd, int how) {
auto ret = syscall(SYS_SOCK_SHUTDOWN, sockfd, how);
if(int e = sc_error(ret); e)
Expand Down
6 changes: 6 additions & 0 deletions sysdeps/aero/include/aero/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
#define SYS_SETSID 73
#define SYS_GETPGID 74
#define SYS_SOCK_SHUTDOWN 75
#define SYS_GETPEERNAME 76
#define SYS_GETSOCKNAME 77
#define SYS_DEBUG 78
#define SYS_SETSOCKOPT 79
#define SYS_GETSOCKOPT 80
#define SYS_SYMLINK_AT 81

// Invalid syscall used to trigger a log error in the kernel (as a hint)
// so, that we can implement the syscall in the kernel.
Expand Down
18 changes: 18 additions & 0 deletions sysdeps/aero/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ if not headers_only
install: true,
install_dir: get_option('libdir')
)

custom_target('crti',
build_by_default: true,
command: c_compiler.cmd_array() + ['-c', '-o', '@OUTPUT@', '@INPUT@'],
input: 'crt-x86_64/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: 'crt-x86_64/crtn.S',
output: 'crtn.o',
install: true,
install_dir: get_option('libdir')
)
endif

if host_machine.cpu_family() == 'x86_64'
Expand Down

0 comments on commit 266ec42

Please sign in to comment.