summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/Applications/SampleApps/cxxdemo.cpp6
-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
-rw-r--r--Source/Library/Interface/Process.iface.h8
-rw-r--r--Source/Library/Interface/Thread.iface.h8
-rw-r--r--Source/Library/Userland/Binding/Process.class.h19
-rw-r--r--Source/Library/Userland/Binding/Thread.class.h19
-rw-r--r--Source/Library/Userland/Binding/VirtualTerminal.class.h (renamed from Source/Library/Userland/VirtualTerminal.class.h)0
11 files changed, 116 insertions, 11 deletions
diff --git a/Source/Applications/SampleApps/cxxdemo.cpp b/Source/Applications/SampleApps/cxxdemo.cpp
index af16599..8da475a 100644
--- a/Source/Applications/SampleApps/cxxdemo.cpp
+++ b/Source/Applications/SampleApps/cxxdemo.cpp
@@ -1,11 +1,13 @@
#include <Syscall/Syscall.wtf.h>
#include <WChar.class.h>
-#include <VirtualTerminal.class.h>
+#include <Binding/VirtualTerminal.class.h>
+#include <Binding/Thread.class.h>
int main() {
VirtualTerminal x = VirtualTerminal::get();
+ Thread t = Thread::get();
for (char c = ' '; c <= 'z'; c++) {
- sleep((u32int)c / 4);
+ t.sleep((u32int)c / 4);
x.put(c);
}
x.put("\n");
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
diff --git a/Source/Library/Interface/Process.iface.h b/Source/Library/Interface/Process.iface.h
new file mode 100644
index 0000000..d639725
--- /dev/null
+++ b/Source/Library/Interface/Process.iface.h
@@ -0,0 +1,8 @@
+#ifndef DEF_PROCESS_IFACE_H
+#define DEF_PROCESS_IFACE_H
+
+#define PR_IFACE_OBJTYPE 0x20
+#define PR_IFACE_EXIT 0x01
+#define PR_IFACE_ALLOCPAGE 0x02
+
+#endif
diff --git a/Source/Library/Interface/Thread.iface.h b/Source/Library/Interface/Thread.iface.h
new file mode 100644
index 0000000..2a64924
--- /dev/null
+++ b/Source/Library/Interface/Thread.iface.h
@@ -0,0 +1,8 @@
+#ifndef DEF_THREAD_IFACE_H
+#define DEF_THREAD_IFACE_H
+
+#define TH_IFACE_OBJTYPE 0x21
+#define TH_IFACE_SLEEP 0x01
+#define TH_IFACE_FINISH 0x02
+
+#endif
diff --git a/Source/Library/Userland/Binding/Process.class.h b/Source/Library/Userland/Binding/Process.class.h
new file mode 100644
index 0000000..c484e19
--- /dev/null
+++ b/Source/Library/Userland/Binding/Process.class.h
@@ -0,0 +1,19 @@
+#include <Syscall/RessourceCaller.class.h>
+
+#include <Process.iface.h>
+
+class Process : public RessourceCaller {
+ public:
+ static Process get() {
+ u32int id = RessourceCaller::getObjId(PR_IFACE_OBJTYPE);
+ return Process(id);
+ }
+ Process(u32int id) : RessourceCaller(id, PR_IFACE_OBJTYPE) {}
+
+ void exit() {
+ doCall(PR_IFACE_EXIT);
+ }
+ void allocPage(u32int pos) {
+ doCall(PR_IFACE_ALLOCPAGE, pos);
+ }
+};
diff --git a/Source/Library/Userland/Binding/Thread.class.h b/Source/Library/Userland/Binding/Thread.class.h
new file mode 100644
index 0000000..beef9c5
--- /dev/null
+++ b/Source/Library/Userland/Binding/Thread.class.h
@@ -0,0 +1,19 @@
+#include <Syscall/RessourceCaller.class.h>
+
+#include <Thread.iface.h>
+
+class Thread : public RessourceCaller {
+ public:
+ static Thread get() {
+ u32int id = RessourceCaller::getObjId(TH_IFACE_OBJTYPE);
+ return Thread(id);
+ }
+ Thread(u32int id) : RessourceCaller(id, TH_IFACE_OBJTYPE) {}
+
+ void sleep(u32int msecs) {
+ doCall(TH_IFACE_SLEEP, msecs);
+ }
+ void finish(u32int errcode) {
+ doCall(TH_IFACE_FINISH, errcode);
+ }
+};
diff --git a/Source/Library/Userland/VirtualTerminal.class.h b/Source/Library/Userland/Binding/VirtualTerminal.class.h
index a7bb4c2..a7bb4c2 100644
--- a/Source/Library/Userland/VirtualTerminal.class.h
+++ b/Source/Library/Userland/Binding/VirtualTerminal.class.h