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.
This commit is contained in:
Linus Groh 2021-01-15 20:21:03 +01:00 committed by Andreas Kling
parent 7668e968af
commit 1ccc2e6482
Notes: sideshowbarker 2024-07-18 23:47:31 +09:00
4 changed files with 14 additions and 0 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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&);

View File

@ -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;