mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 12:48:22 +00:00
syscalls: umask
This commit is contained in:
@@ -32,6 +32,7 @@ extern syscall_linkat
|
||||
extern syscall_readlinkat
|
||||
extern syscall_fchmod
|
||||
extern syscall_fchmodat
|
||||
extern syscall_umask
|
||||
syscalltab:
|
||||
dq syscall_print
|
||||
dq syscall_mmap
|
||||
@@ -66,7 +67,8 @@ dq syscall_linkat
|
||||
dq syscall_readlinkat
|
||||
dq syscall_fchmod
|
||||
dq syscall_fchmodat
|
||||
syscallcount equ 33
|
||||
dq syscall_umask
|
||||
syscallcount equ 34
|
||||
section .text
|
||||
global arch_syscall_entry
|
||||
; on entry:
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
#ifdef SYSCALL_LOGGING
|
||||
|
||||
#define SYSCALL_COUNT 33
|
||||
#define SYSCALL_COUNT 34
|
||||
#define LOGSTR(x) arch_e9_puts(x)
|
||||
|
||||
static char *name[] = {
|
||||
@@ -40,7 +40,8 @@ static char *name[] = {
|
||||
"linkat",
|
||||
"readlinkat",
|
||||
"fchmod",
|
||||
"fchmodat"
|
||||
"fchmodat",
|
||||
"umask"
|
||||
};
|
||||
|
||||
static char *args[] = {
|
||||
@@ -76,7 +77,8 @@ static char *args[] = {
|
||||
"olddirfd %d oldpath %s newdirfd %d oldpath %s flags %d type %d", // linkat
|
||||
"dirfd %d path %s buffer %p buffer length %lu", // readlinkat
|
||||
"fd %d mode %o", // fchmod
|
||||
"dirfd %d path %s mode %o flags %d" // fchmodat
|
||||
"dirfd %d path %s mode %o flags %d", // fchmodat
|
||||
"mode %o" // umask
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -67,6 +67,8 @@ typedef struct proc_t {
|
||||
|
||||
#include <arch/cpu.h>
|
||||
|
||||
#define UMASK(mode) ((mode) & ~_cpu()->thread->proc->umask)
|
||||
|
||||
extern proc_t *sched_initproc;
|
||||
|
||||
void sched_init();
|
||||
|
||||
@@ -11,7 +11,7 @@ static int dochmod(vnode_t *node, mode_t mode) {
|
||||
if (e)
|
||||
return e;
|
||||
|
||||
attr.mode = mode;
|
||||
attr.mode = UMASK(mode);
|
||||
|
||||
return VOP_SETATTR(node, &attr, cred);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,8 @@ syscallret_t syscall_linkat(context_t *, int olddirfd, const char *uoldpath, int
|
||||
|
||||
vattr_t attr = {
|
||||
.gid = _cpu()->thread->proc->cred.gid,
|
||||
.uid = _cpu()->thread->proc->cred.uid
|
||||
.uid = _cpu()->thread->proc->cred.uid,
|
||||
.mode = UMASK(0777)
|
||||
};
|
||||
|
||||
ret.errno = vfs_link(olddirnode, oldpath, newdirnode, newpath, type == 0 ? V_TYPE_REGULAR : V_TYPE_LINK, &attr);
|
||||
|
||||
@@ -26,7 +26,7 @@ syscallret_t syscall_mkdirat(context_t *, int dirfd, const char *upath, mode_t m
|
||||
goto cleanup;
|
||||
|
||||
vattr_t attr = {
|
||||
.mode = mode,
|
||||
.mode = UMASK(mode),
|
||||
.gid = _cpu()->thread->proc->cred.gid,
|
||||
.uid = _cpu()->thread->proc->cred.uid
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int
|
||||
|
||||
if (ret.errno == ENOENT && (flags & O_CREAT)) {
|
||||
vattr_t attr = {
|
||||
.mode = mode,
|
||||
.mode = UMASK(mode),
|
||||
.gid = _cpu()->thread->proc->cred.gid,
|
||||
.uid = _cpu()->thread->proc->cred.uid
|
||||
};
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <arch/cpu.h>
|
||||
|
||||
syscallret_t syscall_umask(context_t *, mode_t mode) {
|
||||
syscallret_t ret = {
|
||||
.errno = 0
|
||||
};
|
||||
|
||||
mode &= 0777;
|
||||
|
||||
ret.ret = __atomic_exchange_n(&_cpu()->thread->proc->umask, mode, __ATOMIC_SEQ_CST);
|
||||
|
||||
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..569f811
|
||||
index 0000000..74cb539
|
||||
--- /dev/null
|
||||
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
|
||||
@@ -0,0 +1,343 @@
|
||||
@@ -0,0 +1,350 @@
|
||||
+#include <bits/ensure.h>
|
||||
+#include <mlibc/debug.hpp>
|
||||
+#include <mlibc/all-sysdeps.hpp>
|
||||
@@ -211,6 +211,13 @@ index 0000000..569f811
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ int sys_umask(mode_t mode, mode_t *old) {
|
||||
+ long ret;
|
||||
+ long error = syscall(SYSCALL_UMASK, &ret, mode);
|
||||
+ *old = ret;
|
||||
+ return error;
|
||||
+ }
|
||||
+
|
||||
+ int sys_fchmod(int fd, mode_t mode) {
|
||||
+ long ret;
|
||||
+ return syscall(SYSCALL_FCHMOD, &ret, fd, mode);
|
||||
@@ -499,10 +506,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..d058baa
|
||||
index 0000000..7f39915
|
||||
--- /dev/null
|
||||
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
|
||||
@@ -0,0 +1,56 @@
|
||||
@@ -0,0 +1,57 @@
|
||||
+#ifndef _SYSCALL_H_INCLUDE
|
||||
+#define _SYSCALL_H_INCLUDE
|
||||
+
|
||||
@@ -539,6 +546,7 @@ index 0000000..d058baa
|
||||
+#define SYSCALL_READLINKAT 30
|
||||
+#define SYSCALL_FCHMOD 31
|
||||
+#define SYSCALL_FCHMODAT 32
|
||||
+#define SYSCALL_UMASK 33
|
||||
+
|
||||
+#include <stddef.h>
|
||||
+#include <stdint.h>
|
||||
|
||||
Reference in New Issue
Block a user