ソースを参照

Kernel+LibC: Add get_process_name() syscall

It does exactly what it sounds like:

    int get_process_name(char* buffer, int buffer_size);
Andreas Kling 5 年 前
コミット
6ad3efe067
6 ファイル変更29 行追加1 行削除
  1. 16 0
      Kernel/Process.cpp
  2. 1 0
      Kernel/Process.h
  3. 2 0
      Kernel/Syscall.cpp
  4. 2 1
      Kernel/Syscall.h
  5. 7 0
      Libraries/LibC/unistd.cpp
  6. 1 0
      Libraries/LibC/unistd.h

+ 16 - 0
Kernel/Process.cpp

@@ -2859,3 +2859,19 @@ int Process::sys$set_process_icon(int icon_id)
     m_icon_id = icon_id;
     return 0;
 }
+
+int Process::sys$get_process_name(char* buffer, int buffer_size)
+{
+    if (buffer_size <= 0)
+        return -EINVAL;
+
+    if (!validate_write(buffer, buffer_size))
+        return -EFAULT;
+
+    if (m_name.length() >= buffer_size)
+        return -ENAMETOOLONG;
+
+    strncpy(buffer, m_name.characters(), buffer_size);
+    return 0;
+}
+

+ 1 - 0
Kernel/Process.h

@@ -108,6 +108,7 @@ public:
     void die();
     void finalize();
 
+    int sys$get_process_name(char* buffer, int buffer_size);
     int sys$watch_file(const char* path, int path_length);
     int sys$dbgputch(u8);
     int sys$dbgputstr(const u8*, int length);

+ 2 - 0
Kernel/Syscall.cpp

@@ -307,6 +307,8 @@ static u32 handle(RegisterDump& regs, u32 function, u32 arg1, u32 arg2, u32 arg3
         return current->process().sys$set_process_icon((int)arg1);
     case Syscall::SC_mprotect:
         return current->process().sys$mprotect((void*)arg1, (size_t)arg2, (int)arg3);
+    case Syscall::SC_get_process_name:
+        return current->process().sys$get_process_name((char*)arg1, (int)arg2);
     default:
         kprintf("<%u> int0x82: Unknown function %u requested {%x, %x, %x}\n", current->process().pid(), function, arg1, arg2, arg3);
         return -ENOSYS;

+ 2 - 1
Kernel/Syscall.h

@@ -123,7 +123,8 @@ struct timeval;
     __ENUMERATE_SYSCALL(watch_file)             \
     __ENUMERATE_SYSCALL(share_buffer_globally)  \
     __ENUMERATE_SYSCALL(set_process_icon)       \
-    __ENUMERATE_SYSCALL(mprotect)
+    __ENUMERATE_SYSCALL(mprotect)               \
+    __ENUMERATE_SYSCALL(get_process_name)
 
 namespace Syscall {
 

+ 7 - 0
Libraries/LibC/unistd.cpp

@@ -561,4 +561,11 @@ void dump_backtrace()
 {
     syscall(SC_dump_backtrace);
 }
+
+int get_process_name(char* buffer, int buffer_size)
+{
+    int rc = syscall(SC_get_process_name, buffer, buffer_size);
+    __RETURN_WITH_ERRNO(rc, rc, -1);
+}
+
 }

+ 1 - 0
Libraries/LibC/unistd.h

@@ -14,6 +14,7 @@ __BEGIN_DECLS
 
 extern char** environ;
 
+int get_process_name(char* buffer, int buffer_size);
 void dump_backtrace();
 int fsync(int fd);
 void sysbeep();