From f5fcc84903fdb7aa6d82fdf9c92794b8bc85f839 Mon Sep 17 00:00:00 2001 From: Ponali Date: Thu, 30 Oct 2025 17:48:16 +0100 Subject: [PATCH] fixed the "user" kernel module getting the wrong IDs when creating tasks when the user kernel module creates a task, it used to count the amount of processes in the system, which can lead to some processes having the same IDs as another, which causes havoc. this has been fixed by using the ID counter in the tsched kernel module. --- halyde/kernel/modules/tsched.lua | 17 ++++++++++++----- halyde/kernel/modules/user.lua | 21 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/halyde/kernel/modules/tsched.lua b/halyde/kernel/modules/tsched.lua index c152d7b..c1f811a 100644 --- a/halyde/kernel/modules/tsched.lua +++ b/halyde/kernel/modules/tsched.lua @@ -16,7 +16,7 @@ function module.init() local gpu = component.gpu local log = require("log") - local idCounter = 1 + tsched.idCounter = 1 function _G._PUBLIC.tsched.runAsTask(path, ...) checkArg(1, path, "string") @@ -68,20 +68,27 @@ function module.init() checkArg(1, func, "function") checkArg(2, name, "string") local task = coroutine.create(func) - local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = idCounter} + local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = tsched.idCounter } if type(tsched.currentTask) == "table" and type(tsched.currentTask.id) == "number" then taskInfo.parent = tsched.currentTask.id taskInfo.user = tsched.currentTask.user end table.insert(tsched.tasks, taskInfo) - idCounter = idCounter + 1 + tsched.idCounter = tsched.idCounter + 1 if taskInfo.parent then log.kernel.info( - ("[tsched] Created task %s (PID %d) by parent PID %d as UID %d"):format(name, idCounter - 1, taskInfo.parent, taskInfo.user) + ("[tsched] Created task %s (PID %d) by parent PID %d as UID %d"):format( + name, + tsched.idCounter - 1, + taskInfo.parent, + taskInfo.user + ) ) else taskInfo.user = 1 -- It's probably being run from kernel level - log.kernel.info(string.format("[tsched] Created task %s (PID %d) as UID 1 (no parent found)", name, idCounter - 1)) + log.kernel.info( + string.format("[tsched] Created task %s (PID %d) as UID 1 (no parent found)", name, tsched.idCounter - 1) + ) end return task, taskInfo end diff --git a/halyde/kernel/modules/user.lua b/halyde/kernel/modules/user.lua index ba59d4d..23f2bb3 100644 --- a/halyde/kernel/modules/user.lua +++ b/halyde/kernel/modules/user.lua @@ -38,17 +38,32 @@ function module.init() end local task = coroutine.create(func) - local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = #_PUBLIC.tsched.getTasks() + 1, ["user"] = userId} + local taskInfo = { ["task"] = task, ["name"] = name, ["id"] = tsched.idCounter, ["user"] = userId } if type(tsched.currentTask) == "table" and type(tsched.currentTask.id) == "number" then taskInfo.parent = tsched.currentTask.id + else + log.kernel.info("debug: tsched.currentTask is " .. require("serialize").table(tsched.currentTask)) end table.insert(tsched.tasks, taskInfo) if taskInfo.parent then log.kernel.info( - ("[tsched (user)] Created task %s (PID %d) by parent PID %d as UID %d"):format(name, #_PUBLIC.tsched.getTasks(), taskInfo.parent, taskInfo.user) + ("[tsched (user)] Created task %s (PID %d) by parent PID %d as UID %d"):format( + name, + #_PUBLIC.tsched.getTasks(), + taskInfo.parent, + taskInfo.user + ) + ) + log.kernel.info( + string.format( + "[tsched (user)] Created task %s (PID %d) as UID %d (no parent found)", + name, + #_PUBLIC.tsched.getTasks(), + taskInfo.user + ) ) - log.kernel.info(string.format("[tsched (user)] Created task %s (PID %d) as UID %d (no parent found)", name, #_PUBLIC.tsched.getTasks(), taskInfo.user)) end + tsched.idCounter = tsched.idCounter + 1 return task, taskInfo end end