summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Process.cpp24
-rw-r--r--Kernel/Process.h2
-rw-r--r--Kernel/Syscall.cpp4
-rw-r--r--Kernel/Syscall.h2
4 files changed, 32 insertions, 0 deletions
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index 363487ebd5..c7b009aeb7 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -2461,3 +2461,27 @@ int Process::sys$create_thread(int(*entry)(void*), void* argument)
thread->set_state(Thread::State::Runnable);
return 0;
}
+
+int Process::sys$gettid()
+{
+ return current->tid();
+}
+
+int Process::sys$donate(int tid)
+{
+ if (tid < 0)
+ return -EINVAL;
+ InterruptDisabler disabler;
+ Thread* beneficiary = nullptr;
+ for_each_thread([&] (Thread& thread) {
+ if (thread.tid() == tid) {
+ beneficiary = &thread;
+ return IterationDecision::Abort;
+ }
+ return IterationDecision::Continue;
+ });
+ if (!beneficiary)
+ return -ENOTHREAD;
+ Scheduler::donate_to(beneficiary, "sys$donate");
+ return 0;
+}
diff --git a/Kernel/Process.h b/Kernel/Process.h
index 66d0770c41..cc15c1c251 100644
--- a/Kernel/Process.h
+++ b/Kernel/Process.h
@@ -97,6 +97,8 @@ public:
void die();
void finalize();
+ int sys$gettid();
+ int sys$donate(int tid);
pid_t sys$setsid();
pid_t sys$getsid(pid_t);
int sys$setpgid(pid_t pid, pid_t pgid);
diff --git a/Kernel/Syscall.cpp b/Kernel/Syscall.cpp
index fcc5845787..abce43a6c2 100644
--- a/Kernel/Syscall.cpp
+++ b/Kernel/Syscall.cpp
@@ -57,6 +57,10 @@ static dword handle(RegisterDump& regs, dword function, dword arg1, dword arg2,
case Syscall::SC_yield:
Scheduler::yield();
break;
+ case Syscall::SC_donate:
+ return current->process().sys$donate((int)arg1);
+ case Syscall::SC_gettid:
+ return current->process().sys$gettid();
case Syscall::SC_putch:
Console::the().put_char(arg1 & 0xff);
break;
diff --git a/Kernel/Syscall.h b/Kernel/Syscall.h
index 8124cbc694..6bb0e3ed05 100644
--- a/Kernel/Syscall.h
+++ b/Kernel/Syscall.h
@@ -93,6 +93,8 @@
__ENUMERATE_SYSCALL(getsockopt) \
__ENUMERATE_SYSCALL(setsockopt) \
__ENUMERATE_SYSCALL(create_thread) \
+ __ENUMERATE_SYSCALL(gettid) \
+ __ENUMERATE_SYSCALL(donate) \
namespace Syscall {