core+system: Make the getPriority() and setPriority() syscalls accept a PID

This commit is contained in:
Gabriel 2025-02-24 19:18:24 +01:00
parent c5876768c5
commit 0b32214f0e
2 changed files with 12 additions and 9 deletions
core/src/sys
system/lib

@ -24,15 +24,15 @@ pub fn yield(regs: *platform.Registers, _: *sys.Arguments, _: *isize) anyerror!v
pub fn setPriority(_: *platform.Registers, args: *sys.Arguments, _: *isize) anyerror!void {
const core = cpu.thisCore();
if (!sys.checkToken(core, system.kernel.Token.ThreadPriority)) return error.NotAuthorized;
const target = thread.lookupThreadById(args.arg0) orelse return error.NoSuchThread;
core.current_thread.user_priority = @truncate(args.arg0);
target.user_priority = @truncate(args.arg1);
}
pub fn getPriority(_: *platform.Registers, _: *sys.Arguments, retval: *isize) anyerror!void {
const core = cpu.thisCore();
retval.* = core.current_thread.user_priority;
pub fn getPriority(_: *platform.Registers, args: *sys.Arguments, retval: *isize) anyerror!void {
const target = thread.lookupThreadById(args.arg0) orelse return error.NoSuchThread;
retval.* = target.user_priority;
}
pub fn sleep(regs: *platform.Registers, args: *sys.Arguments, _: *isize) anyerror!void {

@ -36,12 +36,15 @@ pub fn yield() void {
_ = syscall(.Yield, 0, 0, 0);
}
pub fn setPriority(priority: u8) void {
_ = syscall(.SetPriority, priority, 0, 0);
pub fn setPriority(pid: u64, priority: u8) !void {
const retval = syscall(.SetPriority, pid, priority, 0);
if (retval < 0) return error.NoSuchThread;
}
pub fn getPriority() u8 {
return @truncate(@as(u64, @bitCast(syscall(.GetPriority, 0, 0, 0))));
pub fn getPriority(pid: u64) !u8 {
const retval = syscall(.GetPriority, pid, 0, 0);
if (retval < 0) return error.NoSuchThread;
return @truncate(@as(u64, @bitCast(retval)));
}
pub fn sleep(ms: u64) void {