Kernel: Add sys$set_coredump_metadata() syscall

This can be used by applications to store information (key/value pairs)
likely useful for debugging, which will then be embedded in the coredump.
This commit is contained in:
Linus Groh 2020-12-30 15:19:57 +01:00 committed by Andreas Kling
parent 7413a7c509
commit 91332515a6
Notes: sideshowbarker 2024-07-19 00:22:17 +09:00
3 changed files with 34 additions and 1 deletions

View File

@ -196,7 +196,8 @@ namespace Kernel {
S(adjtime) \
S(allocate_tls) \
S(prctl) \
S(mremap)
S(mremap) \
S(set_coredump_metadata)
namespace Syscall {
@ -442,6 +443,11 @@ struct SC_ptrace_peek_params {
u32* out_data;
};
struct SC_set_coredump_metadata_params {
StringArgument key;
StringArgument value;
};
void initialize();
int sync();

View File

@ -363,6 +363,7 @@ public:
int sys$disown(ProcessID);
void* sys$allocate_tls(size_t);
int sys$prctl(int option, FlatPtr arg1, FlatPtr arg2);
int sys$set_coredump_metadata(Userspace<const Syscall::SC_set_coredump_metadata_params*>);
template<bool sockname, typename Params>
int get_sock_or_peer_name(const Params&);
@ -500,6 +501,8 @@ public:
void unblock_waiters(Thread::WaitBlocker::UnblockFlags, u8 signal = 0);
Thread::WaitBlockCondition& wait_block_condition() { return m_wait_block_condition; }
const HashMap<String, String>& coredump_metadata() const { return m_coredump_metadata; }
private:
friend class MemoryManager;
friend class Scheduler;
@ -644,6 +647,8 @@ private:
bool m_wait_for_tracer_at_next_execve { false };
Thread::WaitBlockCondition m_wait_block_condition;
HashMap<String, String> m_coredump_metadata;
};
extern InlineLinkedList<Process>* g_processes;

View File

@ -24,6 +24,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <AK/Types.h>
#include <Kernel/Process.h>
#include <Kernel/SharedBuffer.h>
@ -64,4 +65,25 @@ int Process::sys$set_process_name(Userspace<const char*> user_name, size_t user_
return 0;
}
int Process::sys$set_coredump_metadata(Userspace<const Syscall::SC_set_coredump_metadata_params*> user_params)
{
Syscall::SC_set_coredump_metadata_params params;
if (!copy_from_user(&params, user_params))
return -EFAULT;
if (params.key.length == 0 || params.key.length > 16 * KiB)
return -EINVAL;
if (params.value.length > 16 * KiB)
return -EINVAL;
auto copied_key = copy_string_from_user(params.key.characters, params.key.length);
if (copied_key.is_null())
return -EFAULT;
auto copied_value = copy_string_from_user(params.value.characters, params.value.length);
if (copied_value.is_null())
return -EFAULT;
if (!m_coredump_metadata.contains(copied_key) && m_coredump_metadata.size() >= 16)
return -EFAULT;
m_coredump_metadata.set(move(copied_key), move(copied_value));
return 0;
}
}