summaryrefslogtreecommitdiff
path: root/Source/Kernel
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Kernel')
-rw-r--r--Source/Kernel/SyscallManager/Res.ns.cpp4
-rw-r--r--Source/Kernel/TaskManager/Process.class.cpp23
-rw-r--r--Source/Kernel/TaskManager/Process.class.h9
-rw-r--r--Source/Kernel/TaskManager/Thread.class.cpp25
-rw-r--r--Source/Kernel/TaskManager/Thread.class.h6
5 files changed, 58 insertions, 9 deletions
diff --git a/Source/Kernel/SyscallManager/Res.ns.cpp b/Source/Kernel/SyscallManager/Res.ns.cpp
index aceadf7..274f6f1 100644
--- a/Source/Kernel/SyscallManager/Res.ns.cpp
+++ b/Source/Kernel/SyscallManager/Res.ns.cpp
@@ -1,6 +1,8 @@
#include "Res.ns.h"
#include <VirtualTerminal.iface.h>
+#include <Process.iface.h>
+#include <Thread.iface.h>
#include <TaskManager/Task.ns.h>
namespace Res {
@@ -42,6 +44,8 @@ void unregisterRes(u32int id) {
u32int call(u32int ressource, u8int wat, u32int a, u32int b, u32int c, u32int d, u32int e) {
if (ressource == 0xFFFFFE) { //TODO : return ressource id for some stuff for current process
if (a == VT_IFACE_OBJTYPE) return Task::currProcess()->getVirtualTerminal()->resId();
+ if (a == PR_IFACE_OBJTYPE) return Task::currProcess()->resId();
+ if (a == TH_IFACE_OBJTYPE) return Task::currThread()->resId();
return 0;
} else {
if (ressource > size or ressources[ressource] == 0) {
diff --git a/Source/Kernel/TaskManager/Process.class.cpp b/Source/Kernel/TaskManager/Process.class.cpp
index bad4e52..39428b4 100644
--- a/Source/Kernel/TaskManager/Process.class.cpp
+++ b/Source/Kernel/TaskManager/Process.class.cpp
@@ -3,12 +3,13 @@
#include <MemoryManager/PhysMem.ns.h>
#include <VFS/File.class.h>
#include <Linker/Binary.proto.h>
+#include <Process.iface.h>
namespace Mem {
extern Heap kheap;
}
-Process::Process() { //Private constructor, does nothing
+Process::Process() : Ressource(PR_IFACE_OBJTYPE) { //Private constructor, does nothing
}
Process* Process::createKernel(String cmdline, VirtualTerminal *vt) {
@@ -53,7 +54,9 @@ Process* Process::run(String filename, FSNode* cwd, u32int uid) {
}
}
-Process::Process(String cmdline, u32int uid) {
+Process::Process(String cmdline, u32int uid) : Ressource(PR_IFACE_OBJTYPE) {
+ addCall0(PR_IFACE_EXIT, (call0)&Process::exitSC);
+ addCall1(PR_IFACE_ALLOCPAGE, (call1)&Process::allocPageSC);
m_pid = Task::nextPid();
m_cmdline = cmdline;
m_retval = 0;
@@ -99,7 +102,7 @@ void Process::registerThread(Thread* t) {
void Process::threadFinishes(Thread* thread, u32int retval) {
// If it is the main thread of the process, or if it pagefaulted
- if (thread == m_threads[0] or retval == E_PAGEFAULT) {
+ if (thread == m_threads[0] or retval == E_PAGEFAULT or retval == E_EXIT) {
exit();
} else {
//Simply unregister thread
@@ -133,3 +136,17 @@ VirtualTerminal* Process::getVirtualTerminal() {
void Process::setVirtualTerminal(VirtualTerminal* vt) {
m_vt = vt;
}
+
+u32int Process::exitSC() {
+ if (Task::currProcess() != this) return 1;
+ Task::currentThreadExits(E_EXIT);
+ return 0;
+}
+
+u32int Process::allocPageSC(u32int pos) {
+ if (Task::currProcess() != this) return 1;
+ if ((pos & 0x00000FFF) != 0) pos = (pos & 0xFFFFF000) + 0x1000;
+ if (pos >= 0xC0000000) return 1;
+ m_pagedir->allocFrame(pos, true, true);
+ return 0;
+}
diff --git a/Source/Kernel/TaskManager/Process.class.h b/Source/Kernel/TaskManager/Process.class.h
index fdd1377..1b614b7 100644
--- a/Source/Kernel/TaskManager/Process.class.h
+++ b/Source/Kernel/TaskManager/Process.class.h
@@ -9,13 +9,15 @@
#include <VTManager/VirtualTerminal.proto.h>
#include <VFS/File.class.h>
+#include <SyscallManager/Ressource.class.h>
+
#define P_ZOMBIE 0
#define P_RUNNING 1
#define P_STARTING 2
#define P_FINISHED 3
#define E_PAGEFAULT 0x0FFFFF00
-#define E_ABORTED 0x0FFFFF01
+#define E_EXIT 0x0FFFFF01
#define E_UNHANDLED_EXCEPTION 0x0FFFFF02
#define STACKSIZE 4096 //Could change
@@ -26,7 +28,7 @@
class Thread;
class File;
-class Process {
+class Process : public Ressource {
friend class Thread;
private:
@@ -67,6 +69,9 @@ class Process {
void setVirtualTerminal(VirtualTerminal* vt);
u32int getState() { return m_state; }
+ //System calls
+ u32int exitSC();
+ u32int allocPageSC(u32int);
};
#endif
diff --git a/Source/Kernel/TaskManager/Thread.class.cpp b/Source/Kernel/TaskManager/Thread.class.cpp
index 9a2df3f..2237457 100644
--- a/Source/Kernel/TaskManager/Thread.class.cpp
+++ b/Source/Kernel/TaskManager/Thread.class.cpp
@@ -4,6 +4,8 @@
#include <DeviceManager/Time.ns.h>
#include <MemoryManager/GDT.ns.h>
+#include <Thread.iface.h>
+
void runThread(Thread* thread, void* data, thread_entry_t entry_point) {
if (thread->m_isKernel) {
asm volatile("sti");
@@ -49,10 +51,10 @@ void runThread(Thread* thread, void* data, thread_entry_t entry_point) {
}
}
-Thread::Thread() { //Private constructor, does nothing
+Thread::Thread() : Ressource(TH_IFACE_OBJTYPE) { //Private constructor, does nothing
}
-Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) {
+Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) : Ressource(TH_IFACE_OBJTYPE) {
if (iskernel) {
setup(Task::getKernelProcess(), entry_point, data, true);
} else {
@@ -60,7 +62,7 @@ Thread::Thread(thread_entry_t entry_point, void* data, bool iskernel) {
}
}
-Thread::Thread(Process* process, thread_entry_t entry_point, void* data) {
+Thread::Thread(Process* process, thread_entry_t entry_point, void* data) : Ressource(TH_IFACE_OBJTYPE) {
setup(process, entry_point, data, false);
}
@@ -75,6 +77,9 @@ Thread::~Thread() {
}
void Thread::setup(Process* process, thread_entry_t entry_point, void* data, bool isKernel) {
+ addCall1(TH_IFACE_SLEEP, (call1)&Thread::sleepSC);
+ addCall1(TH_IFACE_FINISH, (call1)&Thread::finishSC);
+
m_isKernel = isKernel;
m_process = process;
m_kernelStack.addr = Mem::kalloc(STACKSIZE);
@@ -199,3 +204,17 @@ bool Thread::runnable() {
}
return false;
}
+
+u32int Thread::sleepSC(u32int msecs) {
+ if (this != Task::currThread()) return 1;
+ sleep(msecs);
+ return 0;
+}
+
+u32int Thread::finishSC(u32int errcode) {
+ if (this != Task::currThread()) return 1;
+ Task::currentThreadExits(errcode);
+ return 0;
+}
+
+
diff --git a/Source/Kernel/TaskManager/Thread.class.h b/Source/Kernel/TaskManager/Thread.class.h
index aeb1f93..8a7d45e 100644
--- a/Source/Kernel/TaskManager/Thread.class.h
+++ b/Source/Kernel/TaskManager/Thread.class.h
@@ -11,7 +11,7 @@
typedef u32int(*thread_entry_t)(void*);
-class Thread {
+class Thread : public Ressource {
friend class Process; //This might be useful
friend void runThread(Thread*, void*, thread_entry_t);
@@ -59,6 +59,10 @@ class Thread {
}
return false;
}
+
+ //Syscalls
+ u32int sleepSC(u32int msecs);
+ u32int finishSC(u32int errcode);
};
#endif