mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
syscalls: mkdirat and gethostname + uname stubs in mlibc
This commit is contained in:
@@ -26,6 +26,7 @@ extern syscall_isatty
|
||||
extern syscall_faccessat
|
||||
extern syscall_unlinkat
|
||||
extern syscall_ioctl
|
||||
extern syscall_mkdirat
|
||||
syscalltab:
|
||||
dq syscall_print
|
||||
dq syscall_mmap
|
||||
@@ -54,7 +55,8 @@ dq syscall_isatty
|
||||
dq syscall_faccessat
|
||||
dq syscall_unlinkat
|
||||
dq syscall_ioctl
|
||||
syscallcount equ 27
|
||||
dq syscall_mkdirat
|
||||
syscallcount equ 28
|
||||
section .text
|
||||
global arch_syscall_entry
|
||||
; on entry:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#ifdef SYSCALL_LOGGING
|
||||
|
||||
#define SYSCALL_COUNT 25
|
||||
#define SYSCALL_COUNT 28
|
||||
#define LOGSTR(x) arch_e9_puts(x)
|
||||
|
||||
static char *name[] = {
|
||||
@@ -33,7 +33,9 @@ static char *name[] = {
|
||||
"pipe2",
|
||||
"isatty",
|
||||
"faccessat",
|
||||
"unlinkat"
|
||||
"unlinkat",
|
||||
"ioctl",
|
||||
"mkdirat"
|
||||
};
|
||||
|
||||
static char *args[] = {
|
||||
@@ -62,7 +64,9 @@ static char *args[] = {
|
||||
"flags %d", // pipe2
|
||||
"fd %d", // isatty
|
||||
"dirfd %d pathname %s mode %d flags %d", // faccessat
|
||||
"dirfd %d pathname %d flags %d" // unlinkat
|
||||
"dirfd %d pathname %d flags %d", // unlinkat
|
||||
"fd %d request %lu argument %d", // ioctl
|
||||
"dirfd %d path %s mode %o" // mkdirat
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -238,6 +238,7 @@ static void ctor(scache_t *cache, void *obj) {
|
||||
node->attr.inode = ++currentinode;
|
||||
EVENT_INIT(&node->writeevent);
|
||||
EVENT_INIT(&node->readevent);
|
||||
node->vnode.type = V_TYPE_FIFO;
|
||||
}
|
||||
|
||||
void pipefs_init() {
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <kernel/file.h>
|
||||
#include <kernel/vfs.h>
|
||||
#include <kernel/alloc.h>
|
||||
#include <kernel/abi.h>
|
||||
#include <arch/cpu.h>
|
||||
|
||||
syscallret_t syscall_mkdirat(context_t *, int dirfd, const char *upath, mode_t mode) {
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
char *path = alloc(strlen(upath) + 1);
|
||||
if (path == NULL) {
|
||||
ret.errno = ENOMEM;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// TODO safe strcopy
|
||||
strcpy(path, upath);
|
||||
|
||||
vnode_t *dirnode = NULL;
|
||||
file_t *file = NULL;
|
||||
if (*path == '/') {
|
||||
dirnode = sched_getroot();
|
||||
} else if (dirfd == AT_FDCWD) {
|
||||
dirnode = sched_getcwd();
|
||||
} else {
|
||||
file = fd_get(dirfd);
|
||||
if (file == NULL) {
|
||||
ret.errno = EBADF;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
dirnode = file->vnode;
|
||||
|
||||
if (dirnode->type != V_TYPE_DIR) {
|
||||
ret.errno = ENOTDIR;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
vattr_t attr = {
|
||||
.mode = mode,
|
||||
.gid = _cpu()->thread->proc->cred.gid,
|
||||
.uid = _cpu()->thread->proc->cred.uid
|
||||
};
|
||||
|
||||
ret.errno = vfs_create(dirnode, path, &attr, V_TYPE_DIR, NULL);
|
||||
ret.ret = ret.errno ? -1 : 0;
|
||||
|
||||
cleanup:
|
||||
|
||||
if (file)
|
||||
fd_release(file);
|
||||
else
|
||||
VOP_RELEASE(dirnode);
|
||||
|
||||
free(path);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -133,10 +133,10 @@ index 0000000..e5b087a
|
||||
+
|
||||
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||
new file mode 100644
|
||||
index 0000000..8c06e96
|
||||
index 0000000..28f6942
|
||||
--- /dev/null
|
||||
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||
@@ -0,0 +1,267 @@
|
||||
@@ -0,0 +1,295 @@
|
||||
+#include <bits/ensure.h>
|
||||
+#include <mlibc/debug.hpp>
|
||||
+#include <mlibc/all-sysdeps.hpp>
|
||||
@@ -192,6 +192,34 @@ index 0000000..8c06e96
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ #define ASTRALHOSTNAME "astral"
|
||||
+
|
||||
+ int sys_gethostname(char *buffer, size_t bufsize) {
|
||||
+ // TODO unstub
|
||||
+ memcpy(buffer, ASTRALHOSTNAME, strlen(ASTRALHOSTNAME));
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ int sys_uname(struct utsname *buf) {
|
||||
+ // TODO unstub
|
||||
+ memcpy(buf->sysname, "Astral", 7);
|
||||
+ memcpy(buf->nodename, ASTRALHOSTNAME, strlen(ASTRALHOSTNAME)+1);
|
||||
+ memcpy(buf->version, "rw-0.0.1", 9);
|
||||
+ memcpy(buf->release, "Astral", 13);
|
||||
+ memcpy(buf->machine, "x86_64", 7);
|
||||
+ memcpy(buf->domainname, ASTRALHOSTNAME, strlen(ASTRALHOSTNAME)+1);
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ int sys_mkdirat(int dirfd, const char *path, mode_t mode) {
|
||||
+ long ret;
|
||||
+ return syscall(SYSCALL_MKDIRAT, &ret, dirfd, (uint64_t)path, mode);
|
||||
+ }
|
||||
+
|
||||
+ int sys_mkdir(const char *path, mode_t mode) {
|
||||
+ return sys_mkdirat(AT_FDCWD, path, mode);
|
||||
+ }
|
||||
+
|
||||
+ int sys_ioctl(int fd, unsigned long request, void *arg, int *result) {
|
||||
+ long ret;
|
||||
+ long err = syscall(SYSCALL_IOCTL, &ret, fd, request, (uint64_t)arg);
|
||||
@@ -423,10 +451,10 @@ index 0000000..990eca0
|
||||
+#endif
|
||||
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||
new file mode 100644
|
||||
index 0000000..294c8ab
|
||||
index 0000000..a569d38
|
||||
--- /dev/null
|
||||
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||
@@ -0,0 +1,50 @@
|
||||
@@ -0,0 +1,51 @@
|
||||
+#ifndef _SYSCALL_H_INCLUDE
|
||||
+#define _SYSCALL_H_INCLUDE
|
||||
+
|
||||
@@ -457,6 +485,7 @@ index 0000000..294c8ab
|
||||
+#define SYSCALL_FACCESSAT 24
|
||||
+#define SYSCALL_UNLINKAT 25
|
||||
+#define SYSCALL_IOCTL 26
|
||||
+#define SYSCALL_MKDIRAT 27
|
||||
+
|
||||
+#include <stddef.h>
|
||||
+#include <stdint.h>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
diff -ruN neofetch-clean/neofetch neofetch/neofetch
|
||||
--- neofetch-clean/neofetch 2022-10-11 23:41:56.059897155 -0300
|
||||
+++ neofetch/neofetch 2022-10-11 23:46:14.506561675 -0300
|
||||
@@ -929,6 +929,7 @@
|
||||
AIX) os=AIX ;;
|
||||
IRIX*) os=IRIX ;;
|
||||
FreeMiNT) os=FreeMiNT ;;
|
||||
+ Astral) os=Astral ;;
|
||||
|
||||
Linux|GNU*)
|
||||
os=Linux
|
||||
@@ -954,6 +955,7 @@
|
||||
[[ $distro ]] && return
|
||||
|
||||
case $os in
|
||||
+ Astral) distro=Astral;;
|
||||
Linux|BSD|MINIX)
|
||||
if [[ -f /bedrock/etc/bedrock-release && $PATH == */bedrock/cross/* ]]; then
|
||||
case $distro_shorthand in
|
||||
@@ -5288,6 +5290,24 @@
|
||||
#
|
||||
# $ascii_distro is the same as $distro.
|
||||
case $(trim "$ascii_distro") in
|
||||
+ "Astral"*)
|
||||
+ set_colors 4 7
|
||||
+ read -rd '' ascii_data <<'EOF'
|
||||
+
|
||||
+${c2} .::.
|
||||
+ .:' .:
|
||||
+ * ${c1}MMM8&&${c2}.::' .:'
|
||||
+ ${c1}MMMM${c2}.::'${c1}&&${c2} .:'
|
||||
+ ${c1}MM${c2}..:'${c1}88&&&&&&
|
||||
+ ${c1}M${c2}.:'${c1}MM88&&&&&&
|
||||
+ ${c2}.:'${c1}MMMM88&&&&&& ${c2}*
|
||||
+ ${c2}.:' ${c1}MMMMM88&&&&
|
||||
+${c2}.:' * .:'${c1}MMM8&&&'
|
||||
+${c2}:' .:'
|
||||
+${c2}'::' *
|
||||
+
|
||||
+EOF
|
||||
+ ;;
|
||||
"AIX"*)
|
||||
set_colors 2 7
|
||||
read -rd '' ascii_data <<'EOF'
|
||||
Reference in New Issue
Block a user