From 6ad3efe0671cb428a10b6825daa8f03f56ff9cc2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 15 Aug 2019 20:55:10 +0200 Subject: [PATCH] Kernel+LibC: Add get_process_name() syscall It does exactly what it sounds like: int get_process_name(char* buffer, int buffer_size); --- Kernel/Process.cpp | 16 ++++++++++++++++ Kernel/Process.h | 1 + Kernel/Syscall.cpp | 2 ++ Kernel/Syscall.h | 3 ++- Libraries/LibC/unistd.cpp | 7 +++++++ Libraries/LibC/unistd.h | 1 + 6 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index cffb076425..980958d6e1 100644 --- a/Kernel/Process.cpp +++ b/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; +} + diff --git a/Kernel/Process.h b/Kernel/Process.h index 8e1c38a85b..2b239d68dd 100644 --- a/Kernel/Process.h +++ b/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); diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp index 8d43d8a56c..417f6b1c36 100644 --- a/Kernel/Syscall.cpp +++ b/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; diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h index cec9a23749..4355250a0c 100644 --- a/Kernel/Syscall.h +++ b/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 { diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index 59207b097d..e0f0971e9f 100644 --- a/Libraries/LibC/unistd.cpp +++ b/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); +} + } diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index 00cedd489e..f8f1dce672 100644 --- a/Libraries/LibC/unistd.h +++ b/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();