From 0c617366e528680e51b4134e12a67120850fba79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Fri, 18 Feb 2022 11:11:09 +0100 Subject: [PATCH] lx_emul: get pid from task Issue #4455. --- repos/dde_linux/src/include/lx_emul/task.h | 2 ++ repos/dde_linux/src/lib/lx_emul/task.cc | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/repos/dde_linux/src/include/lx_emul/task.h b/repos/dde_linux/src/include/lx_emul/task.h index d348527390..8aec4517c8 100644 --- a/repos/dde_linux/src/include/lx_emul/task.h +++ b/repos/dde_linux/src/include/lx_emul/task.h @@ -26,6 +26,8 @@ struct task_struct * lx_emul_task_get_current(void); struct task_struct * lx_emul_task_get(int pid); +int lx_emul_task_pid(struct task_struct *task); + void lx_emul_task_create(struct task_struct * task, const char * name, int pid, diff --git a/repos/dde_linux/src/lib/lx_emul/task.cc b/repos/dde_linux/src/lib/lx_emul/task.cc index 1e958e78b0..800f3ae54d 100644 --- a/repos/dde_linux/src/lib/lx_emul/task.cc +++ b/repos/dde_linux/src/lib/lx_emul/task.cc @@ -70,6 +70,19 @@ extern "C" struct task_struct * lx_emul_task_get(int pid) } +extern "C" int lx_emul_task_pid(struct task_struct * t) +{ + int ret = -1; + + Lx_kit::env().scheduler.for_each_task([&] (Lx_kit::Task & task) { + if (t == task.lx_task()) + ret = task.pid(); + }); + + return ret; +} + + extern "C" void lx_emul_task_name(struct task_struct * t, const char * name) { Lx_kit::env().scheduler.task((void*)t).name(name);