mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
syscalls: readlinkat
This commit is contained in:
@@ -29,6 +29,7 @@ extern syscall_ioctl
|
|||||||
extern syscall_mkdirat
|
extern syscall_mkdirat
|
||||||
extern syscall_clockget
|
extern syscall_clockget
|
||||||
extern syscall_linkat
|
extern syscall_linkat
|
||||||
|
extern syscall_readlinkat
|
||||||
syscalltab:
|
syscalltab:
|
||||||
dq syscall_print
|
dq syscall_print
|
||||||
dq syscall_mmap
|
dq syscall_mmap
|
||||||
@@ -60,7 +61,8 @@ dq syscall_ioctl
|
|||||||
dq syscall_mkdirat
|
dq syscall_mkdirat
|
||||||
dq syscall_clockget
|
dq syscall_clockget
|
||||||
dq syscall_linkat
|
dq syscall_linkat
|
||||||
syscallcount equ 30
|
dq syscall_readlinkat
|
||||||
|
syscallcount equ 31
|
||||||
section .text
|
section .text
|
||||||
global arch_syscall_entry
|
global arch_syscall_entry
|
||||||
; on entry:
|
; on entry:
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ static char *name[] = {
|
|||||||
"ioctl",
|
"ioctl",
|
||||||
"mkdirat",
|
"mkdirat",
|
||||||
"clockget",
|
"clockget",
|
||||||
"linkat"
|
"linkat",
|
||||||
|
"readlinkat"
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *args[] = {
|
static char *args[] = {
|
||||||
@@ -70,7 +71,8 @@ static char *args[] = {
|
|||||||
"fd %d request %lu argument %d", // ioctl
|
"fd %d request %lu argument %d", // ioctl
|
||||||
"dirfd %d path %s mode %o", // mkdirat
|
"dirfd %d path %s mode %o", // mkdirat
|
||||||
"clockid %d timespec %p", // clockget
|
"clockid %d timespec %p", // clockget
|
||||||
"olddirfd %d oldpath %s newdirfd %d oldpath %s flags %d type %d" // linkat
|
"olddirfd %d oldpath %s newdirfd %d oldpath %s flags %d type %d", // linkat
|
||||||
|
"dirfd %d path %s buffer %p buffer length %lu" // readlinkat
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
#include <kernel/syscalls.h>
|
||||||
|
#include <kernel/vfs.h>
|
||||||
|
#include <kernel/file.h>
|
||||||
|
#include <kernel/alloc.h>
|
||||||
|
#include <arch/cpu.h>
|
||||||
|
|
||||||
|
syscallret_t syscall_readlinkat(context_t *, int dirfd, const char *upath, char *ubuffer, size_t ubuffersize) {
|
||||||
|
syscallret_t ret = {
|
||||||
|
.ret = -1
|
||||||
|
};
|
||||||
|
|
||||||
|
char *path = alloc(strlen(upath + 1));
|
||||||
|
|
||||||
|
if (path == NULL) {
|
||||||
|
ret.errno = ENOMEM;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(path, upath);
|
||||||
|
|
||||||
|
file_t *file = NULL;
|
||||||
|
vnode_t *dirnode = NULL;
|
||||||
|
ret.errno = dirfd_enter(path, dirfd, &file, &dirnode);
|
||||||
|
if (ret.errno)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
vnode_t *node = NULL;
|
||||||
|
ret.errno = vfs_lookup(&node, dirnode, path, NULL, VFS_LOOKUP_NOLINK);
|
||||||
|
if (ret.errno)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
char *buffer = NULL;
|
||||||
|
|
||||||
|
ret.errno = VOP_READLINK(node, &buffer, &_cpu()->thread->proc->cred);
|
||||||
|
if (ret.errno)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
size_t bufferlen = strlen(buffer);
|
||||||
|
size_t copylen = bufferlen > ubuffersize ? ubuffersize : bufferlen;
|
||||||
|
|
||||||
|
memcpy(ubuffer, buffer, copylen);
|
||||||
|
|
||||||
|
ret.ret = copylen;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
|
||||||
|
if (buffer)
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
if (node)
|
||||||
|
VOP_RELEASE(node);
|
||||||
|
|
||||||
|
if (dirnode)
|
||||||
|
dirfd_leave(dirnode, file);
|
||||||
|
|
||||||
|
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
|
diff --git mlibc-workdir/sysdeps/astral/generic/generic.cpp mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..0b9a48b
|
index 0000000..90bfad3
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||||
@@ -0,0 +1,322 @@
|
@@ -0,0 +1,329 @@
|
||||||
+#include <bits/ensure.h>
|
+#include <bits/ensure.h>
|
||||||
+#include <mlibc/debug.hpp>
|
+#include <mlibc/debug.hpp>
|
||||||
+#include <mlibc/all-sysdeps.hpp>
|
+#include <mlibc/all-sysdeps.hpp>
|
||||||
@@ -211,6 +211,13 @@ index 0000000..0b9a48b
|
|||||||
+ return 0;
|
+ return 0;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ int sys_readlink(const char *path, void *buffer, size_t max_size, ssize_t *length) {
|
||||||
|
+ long ret;
|
||||||
|
+ long error = syscall(SYSCALL_READLINKAT, &ret, AT_FDCWD, (uint64_t)path, (uint64_t)buffer, max_size);
|
||||||
|
+ *length = ret;
|
||||||
|
+ return error;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
+ static int dolink(int oldfd, const char *oldpath, int newfd, const char *newpath, int flags, int type) {
|
+ static int dolink(int oldfd, const char *oldpath, int newfd, const char *newpath, int flags, int type) {
|
||||||
+ long ret;
|
+ long ret;
|
||||||
+ return syscall(SYSCALL_LINKAT, &ret, oldfd, (uint64_t)oldpath, newfd, (uint64_t)newpath, flags, type);
|
+ return syscall(SYSCALL_LINKAT, &ret, oldfd, (uint64_t)oldpath, newfd, (uint64_t)newpath, flags, type);
|
||||||
@@ -478,10 +485,10 @@ index 0000000..990eca0
|
|||||||
+#endif
|
+#endif
|
||||||
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
diff --git mlibc-workdir/sysdeps/astral/include/astral/syscall.h mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..ee926b6
|
index 0000000..fa60d43
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||||
@@ -0,0 +1,53 @@
|
@@ -0,0 +1,54 @@
|
||||||
+#ifndef _SYSCALL_H_INCLUDE
|
+#ifndef _SYSCALL_H_INCLUDE
|
||||||
+#define _SYSCALL_H_INCLUDE
|
+#define _SYSCALL_H_INCLUDE
|
||||||
+
|
+
|
||||||
@@ -515,6 +522,7 @@ index 0000000..ee926b6
|
|||||||
+#define SYSCALL_MKDIRAT 27
|
+#define SYSCALL_MKDIRAT 27
|
||||||
+#define SYSCALL_CLOCKGET 28
|
+#define SYSCALL_CLOCKGET 28
|
||||||
+#define SYSCALL_LINKAT 29
|
+#define SYSCALL_LINKAT 29
|
||||||
|
+#define SYSCALL_READLINKAT 30
|
||||||
+
|
+
|
||||||
+#include <stddef.h>
|
+#include <stddef.h>
|
||||||
+#include <stdint.h>
|
+#include <stdint.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user