diff options
author | Linus Groh <mail@linusgroh.de> | 2021-01-15 20:21:03 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-15 23:26:47 +0100 |
commit | 1ccc2e6482aa9567039c8bc8b9df35f9275c4947 (patch) | |
tree | d596d3aa4c23d41ce3eeaa7cec3f8d701e5e5c23 | |
parent | 7668e968afff92d90f08c5467e93e89366d39750 (diff) | |
download | serenity-1ccc2e6482aa9567039c8bc8b9df35f9275c4947.zip |
Kernel: Store process arguments and environment in coredumps
Currently they're only pushed onto the stack but not easily accessible
from the Process class, so this adds a Vector<String> for both.
-rw-r--r-- | Kernel/CoreDump.cpp | 4 | ||||
-rw-r--r-- | Kernel/Process.cpp | 2 | ||||
-rw-r--r-- | Kernel/Process.h | 6 | ||||
-rw-r--r-- | Kernel/Syscalls/execve.cpp | 2 |
4 files changed, 14 insertions, 0 deletions
diff --git a/Kernel/CoreDump.cpp b/Kernel/CoreDump.cpp index feaf75a1f3..7b81f61793 100644 --- a/Kernel/CoreDump.cpp +++ b/Kernel/CoreDump.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2019-2020, Jesse Buhagiar <jooster669@gmail.com> * Copyright (c) 2020, Itamar S. <itamar8910@gmail.com> + * Copyright (c) 2020-2021, Linus Groh <mail@linusgroh.de> * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,6 +27,7 @@ */ #include <AK/ByteBuffer.h> +#include <AK/JsonArray.h> #include <AK/JsonObject.h> #include <Kernel/CoreDump.h> #include <Kernel/FileSystem/Custody.h> @@ -225,6 +227,8 @@ ByteBuffer CoreDump::create_notes_process_data() const process_obj.set("pid", m_process->pid().value()); process_obj.set("termination_signal", m_process->termination_signal()); process_obj.set("executable_path", m_process->executable() ? m_process->executable()->absolute_path() : String::empty()); + process_obj.set("arguments", JsonArray(m_process->arguments())); + process_obj.set("environment", JsonArray(m_process->environment())); auto json_data = process_obj.to_string(); process_data.append(json_data.characters(), json_data.length() + 1); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index edc448fb02..05b83cb753 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -641,6 +641,8 @@ void Process::finalize() m_cwd = nullptr; m_root_directory = nullptr; m_root_directory_relative_to_global_root = nullptr; + m_arguments.clear(); + m_environment.clear(); m_dead = true; diff --git a/Kernel/Process.h b/Kernel/Process.h index fbc669bd2d..f6772bae62 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -400,6 +400,9 @@ public: Custody* executable() { return m_executable.ptr(); } const Custody* executable() const { return m_executable.ptr(); } + const Vector<String>& arguments() const { return m_arguments; }; + const Vector<String>& environment() const { return m_environment; }; + int number_of_open_file_descriptors() const; int max_open_file_descriptors() const { @@ -614,6 +617,9 @@ private: RefPtr<Custody> m_root_directory; RefPtr<Custody> m_root_directory_relative_to_global_root; + Vector<String> m_arguments; + Vector<String> m_environment; + RefPtr<TTY> m_tty; Region* find_region_from_range(const Range&); diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index 4d302fb19c..0f806a6fc9 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -507,6 +507,8 @@ int Process::do_exec(NonnullRefPtr<FileDescription> main_program_description, Ve #endif m_executable = main_program_description->custody(); + m_arguments = arguments; + m_environment = environment; m_promises = m_execpromises; |