From d1ac6fb03e3110e35023f60f643f0c4d02c3d8b6 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sat, 24 Oct 2009 22:58:28 +0200 Subject: More work on syscalls : userland applications can run other apps. --- Source/Library/Userland/Binding/Process.class.h | 22 ++++++++++++++++++++++ Source/Library/Userland/Start.cpp | 12 ++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'Source/Library/Userland') diff --git a/Source/Library/Userland/Binding/Process.class.h b/Source/Library/Userland/Binding/Process.class.h index 9687ea9..a3fc569 100644 --- a/Source/Library/Userland/Binding/Process.class.h +++ b/Source/Library/Userland/Binding/Process.class.h @@ -2,6 +2,7 @@ #define DEF_PROCESS_CLASS_H #include +#include #include #include @@ -12,6 +13,9 @@ class Process : public RessourceCaller { u32int id = RessourceCaller::sCall(PRIF_OBJTYPE, PRIF_SGETCPR); return Process(id); } + static Process run(const String& app) { + return Process(sCall(PRIF_OBJTYPE, PRIF_SRUN, (u32int)&app)); + } Process(u32int id) : RessourceCaller(id, PRIF_OBJTYPE) {} void exit() { @@ -35,6 +39,24 @@ class Process : public RessourceCaller { String argv(u32int idx) { return String::unserialize(doCall(PRIF_ARGV, idx)); } + void start() { + doCall(PRIF_START); + } + s32int wait() { + return sCall(PRIF_OBJTYPE, PRIF_SWAIT, resId()); + } + void autoDelete(bool ad = true) { + doCall(PRIF_AUTODELETE, (ad ? 1 : 0)); + } + void pushArg(const String& arg) { + doCall(PRIF_PUSHARG, (u32int)&arg); + } + void setInVT(VirtualTerminal vt) { + doCall(PRIF_SETINVT, vt.resId()); + } + void setOutVT(VirtualTerminal vt) { + doCall(PRIF_SETOUTVT, vt.resId()); + } }; #endif diff --git a/Source/Library/Userland/Start.cpp b/Source/Library/Userland/Start.cpp index be4f81e..930c4dd 100644 --- a/Source/Library/Userland/Start.cpp +++ b/Source/Library/Userland/Start.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -15,14 +16,21 @@ VirtualTerminal invt(0), outvt(0); int main(const Vector& args); +void doExit(u32int v) { + asm volatile("int $66" : : "a"(v)); +} + extern "C" void start() { //Call static constructors + u32int i = 0; for(u32int * call = &start_ctors; call < &end_ctors; call++) { ((void (*)(void))*call)(); } - heap.create(0x40000000, 0x00100000, 0x00004000); //Initially create a 1M heap with 16ko index + heap.create(0x40000000, 0x00040000, 0x00004000); //Initially create a 256ko heap with 16ko index invt = VirtualTerminal::getIn(); outvt = VirtualTerminal::getOut(); + if (!invt.valid()) doExit(1); + if (!outvt.valid()) doExit(2); u32int argc = Process::get().argc(); Vector args(argc); @@ -35,7 +43,7 @@ extern "C" void start() { ((void (*)(void))*call)(); } - asm volatile("int $66" : : "a"(r)); + doExit(r); } namespace Mem { -- cgit v1.2.3