From b2d23f83ab04ee1e7ca5d16ec32416939077bc4c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 6 Nov 2018 13:40:23 +0100 Subject: [PATCH] Add umask(). --- Kernel/Process.cpp | 7 +++++++ Kernel/Process.h | 2 ++ Kernel/Syscall.cpp | 2 ++ Kernel/Syscall.h | 1 + LibC/Makefile | 1 + LibC/sys/stat.h | 10 ++++++++++ 6 files changed, 23 insertions(+) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index e207870781..7ecddc2ae6 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1320,6 +1320,13 @@ pid_t Process::sys$getppid() return m_ppid; } +mode_t Process::sys$umask(mode_t mask) +{ + auto old_mask = m_umask; + m_umask = mask; + return old_mask; +} + pid_t Process::sys$waitpid(pid_t waitee, int* wstatus, int options) { if (wstatus) diff --git a/Kernel/Process.h b/Kernel/Process.h index 7558b8bfaf..64deb9a44a 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -104,6 +104,7 @@ public: gid_t sys$getegid(); pid_t sys$getpid(); pid_t sys$getppid(); + mode_t sys$umask(mode_t); int sys$open(const char* path, int options); int sys$close(int fd); ssize_t sys$read(int fd, void* outbuf, size_t nread); @@ -235,6 +236,7 @@ private: LinearAddress m_return_from_signal_trampoline; pid_t m_ppid { 0 }; + mode_t m_umask { 022 }; static void notify_waiters(pid_t waitee, int exit_status, int signal); diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index 83ffab9631..aa6d84cd1a 100644 --- a/Kernel/Syscall.cpp +++ b/Kernel/Syscall.cpp @@ -150,6 +150,8 @@ static DWORD handle(RegisterDump& regs, DWORD function, DWORD arg1, DWORD arg2, return current->sys$dup2((int)arg1, (int)arg2); case Syscall::SC_sigaction: return current->sys$sigaction((int)arg1, (const Unix::sigaction*)arg2, (Unix::sigaction*)arg3); + case Syscall::SC_umask: + return current->sys$umask((mode_t)arg1); default: kprintf("<%u> int0x80: Unknown function %x requested {%x, %x, %x}\n", current->pid(), function, arg1, arg2, arg3); break; diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index 04cae54102..53b3ed848b 100644 --- a/Kernel/Syscall.h +++ b/Kernel/Syscall.h @@ -51,6 +51,7 @@ __ENUMERATE_SYSCALL(dup2) \ __ENUMERATE_SYSCALL(sigaction) \ __ENUMERATE_SYSCALL(getppid) \ + __ENUMERATE_SYSCALL(umask) \ #define DO_SYSCALL_A0(function) Syscall::invoke((dword)(function)) diff --git a/LibC/Makefile b/LibC/Makefile index a0036d427b..03f367cf58 100644 --- a/LibC/Makefile +++ b/LibC/Makefile @@ -23,6 +23,7 @@ LIBC_OBJS = \ times.o \ termcap.o \ setjmp.o \ + stat.o \ entry.o OBJS = $(AK_OBJS) $(LIBC_OBJS) diff --git a/LibC/sys/stat.h b/LibC/sys/stat.h index e69de29bb2..902e63268d 100644 --- a/LibC/sys/stat.h +++ b/LibC/sys/stat.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +__BEGIN_DECLS + +mode_t umask(mode_t); + +__END_DECLS