syscalls: umask

This commit is contained in:
Matheus
2023-07-06 21:17:54 -03:00
parent e29d75580a
commit 300e77e36d
9 changed files with 41 additions and 12 deletions
+3 -1
View File
@@ -32,6 +32,7 @@ extern syscall_linkat
extern syscall_readlinkat extern syscall_readlinkat
extern syscall_fchmod extern syscall_fchmod
extern syscall_fchmodat extern syscall_fchmodat
extern syscall_umask
syscalltab: syscalltab:
dq syscall_print dq syscall_print
dq syscall_mmap dq syscall_mmap
@@ -66,7 +67,8 @@ dq syscall_linkat
dq syscall_readlinkat dq syscall_readlinkat
dq syscall_fchmod dq syscall_fchmod
dq syscall_fchmodat dq syscall_fchmodat
syscallcount equ 33 dq syscall_umask
syscallcount equ 34
section .text section .text
global arch_syscall_entry global arch_syscall_entry
; on entry: ; on entry:
+5 -3
View File
@@ -4,7 +4,7 @@
#ifdef SYSCALL_LOGGING #ifdef SYSCALL_LOGGING
#define SYSCALL_COUNT 33 #define SYSCALL_COUNT 34
#define LOGSTR(x) arch_e9_puts(x) #define LOGSTR(x) arch_e9_puts(x)
static char *name[] = { static char *name[] = {
@@ -40,7 +40,8 @@ static char *name[] = {
"linkat", "linkat",
"readlinkat", "readlinkat",
"fchmod", "fchmod",
"fchmodat" "fchmodat",
"umask"
}; };
static char *args[] = { static char *args[] = {
@@ -76,7 +77,8 @@ static char *args[] = {
"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 "dirfd %d path %s buffer %p buffer length %lu", // readlinkat
"fd %d mode %o", // fchmod "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 #endif
+2
View File
@@ -67,6 +67,8 @@ typedef struct proc_t {
#include <arch/cpu.h> #include <arch/cpu.h>
#define UMASK(mode) ((mode) & ~_cpu()->thread->proc->umask)
extern proc_t *sched_initproc; extern proc_t *sched_initproc;
void sched_init(); void sched_init();
+1 -1
View File
@@ -11,7 +11,7 @@ static int dochmod(vnode_t *node, mode_t mode) {
if (e) if (e)
return e; return e;
attr.mode = mode; attr.mode = UMASK(mode);
return VOP_SETATTR(node, &attr, cred); return VOP_SETATTR(node, &attr, cred);
} }
+2 -1
View File
@@ -40,7 +40,8 @@ syscallret_t syscall_linkat(context_t *, int olddirfd, const char *uoldpath, int
vattr_t attr = { vattr_t attr = {
.gid = _cpu()->thread->proc->cred.gid, .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); ret.errno = vfs_link(olddirnode, oldpath, newdirnode, newpath, type == 0 ? V_TYPE_REGULAR : V_TYPE_LINK, &attr);
+1 -1
View File
@@ -26,7 +26,7 @@ syscallret_t syscall_mkdirat(context_t *, int dirfd, const char *upath, mode_t m
goto cleanup; goto cleanup;
vattr_t attr = { vattr_t attr = {
.mode = mode, .mode = UMASK(mode),
.gid = _cpu()->thread->proc->cred.gid, .gid = _cpu()->thread->proc->cred.gid,
.uid = _cpu()->thread->proc->cred.uid .uid = _cpu()->thread->proc->cred.uid
}; };
+1 -1
View File
@@ -35,7 +35,7 @@ syscallret_t syscall_openat(context_t *context, int dirfd, const char *path, int
if (ret.errno == ENOENT && (flags & O_CREAT)) { if (ret.errno == ENOENT && (flags & O_CREAT)) {
vattr_t attr = { vattr_t attr = {
.mode = mode, .mode = UMASK(mode),
.gid = _cpu()->thread->proc->cred.gid, .gid = _cpu()->thread->proc->cred.gid,
.uid = _cpu()->thread->proc->cred.uid .uid = _cpu()->thread->proc->cred.uid
}; };
+14
View File
@@ -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;
}
+12 -4
View File
@@ -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..569f811 index 0000000..74cb539
--- /dev/null --- /dev/null
+++ mlibc-workdir/sysdeps/astral/generic/generic.cpp +++ mlibc-workdir/sysdeps/astral/generic/generic.cpp
@@ -0,0 +1,343 @@ @@ -0,0 +1,350 @@
+#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..569f811
+ return 0; + 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) { + int sys_fchmod(int fd, mode_t mode) {
+ long ret; + long ret;
+ return syscall(SYSCALL_FCHMOD, &ret, fd, mode); + return syscall(SYSCALL_FCHMOD, &ret, fd, mode);
@@ -499,10 +506,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..d058baa index 0000000..7f39915
--- /dev/null --- /dev/null
+++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h +++ mlibc-workdir/sysdeps/astral/include/astral/syscall.h
@@ -0,0 +1,56 @@ @@ -0,0 +1,57 @@
+#ifndef _SYSCALL_H_INCLUDE +#ifndef _SYSCALL_H_INCLUDE
+#define _SYSCALL_H_INCLUDE +#define _SYSCALL_H_INCLUDE
+ +
@@ -539,6 +546,7 @@ index 0000000..d058baa
+#define SYSCALL_READLINKAT 30 +#define SYSCALL_READLINKAT 30
+#define SYSCALL_FCHMOD 31 +#define SYSCALL_FCHMOD 31
+#define SYSCALL_FCHMODAT 32 +#define SYSCALL_FCHMODAT 32
+#define SYSCALL_UMASK 33
+ +
+#include <stddef.h> +#include <stddef.h>
+#include <stdint.h> +#include <stdint.h>