Przeglądaj źródła

feat(gblibc): add umask()

greatbridf 2 lat temu
rodzic
commit
769feae046

+ 2 - 0
gblibc/include/sys/stat.h

@@ -28,6 +28,8 @@ struct stat {
 int stat(const char* pathname, struct stat* statbuf);
 int fstat(int fd, struct stat* statbuf);
 
+mode_t umask(mode_t mask);
+
 #ifdef __cplusplus
 }
 #endif

+ 1 - 0
gblibc/private-include/syscall.h

@@ -23,6 +23,7 @@
 #define SYS_getdents (78)
 #define SYS_getcwd (79)
 #define SYS_chdir (80)
+#define SYS_umask (95)
 #define SYS_gettimeofday (96)
 #define SYS_setpgid (109)
 #define SYS_getppid (110)

+ 5 - 0
gblibc/src/stat.c

@@ -22,3 +22,8 @@ int fstat(int fd, struct stat* statbuf)
     }
     return ret;
 }
+
+mode_t umask(mode_t mask)
+{
+    return syscall1(SYS_umask, mask);
+}

+ 2 - 0
include/kernel/process.hpp

@@ -358,6 +358,8 @@ public:
     void* start_brk;
     void* brk;
 
+    mode_t umask;
+
 public:
     // if waitlist is not empty or mutex in cv_wait
     // is locked, its behavior is undefined

+ 4 - 0
src/kernel/process.cpp

@@ -101,6 +101,7 @@ process::process(process&& val)
     , sid(val.sid)
     , start_brk(val.start_brk)
     , brk(val.brk)
+    , umask(val.umask)
 {
     if (current_process == &val)
         current_process = this;
@@ -118,6 +119,8 @@ process::process(const process& parent)
     this->start_brk = parent.start_brk;
     this->brk = parent.brk;
 
+    this->umask = parent.umask;
+
     for (auto& area : parent.mms) {
         if (area.is_kernel_space() || area.attr.in.system)
             continue;
@@ -142,6 +145,7 @@ process::process(pid_t _ppid,
     , sid { 0 }
     , start_brk(nullptr)
     , brk(nullptr)
+    , umask(0022)
 {
 }
 

+ 12 - 0
src/kernel/syscall.cpp

@@ -15,6 +15,7 @@
 #include <stdint.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/types.h>
 #include <types/allocator.hpp>
 #include <types/elf.hpp>
 #include <types/lock.hpp>
@@ -531,6 +532,16 @@ int _syscall_gettimeofday(interrupt_stack* data)
     return 0;
 }
 
+int _syscall_umask(interrupt_stack* data)
+{
+    mode_t mask = data->s_regs.edi;
+
+    mode_t old = current_process->umask;
+    current_process->umask = mask;
+
+    return old;
+}
+
 extern "C" void syscall_entry(interrupt_stack* data)
 {
     int syscall_no = data->s_regs.eax;
@@ -569,6 +580,7 @@ void init_syscall(void)
     syscall_handlers[78] = _syscall_getdents;
     syscall_handlers[79] = _syscall_getcwd;
     syscall_handlers[80] = _syscall_chdir;
+    syscall_handlers[95] = _syscall_umask;
     syscall_handlers[96] = _syscall_gettimeofday;
     syscall_handlers[109] = _syscall_setpgid;
     syscall_handlers[110] = _syscall_getppid;