mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Merge gitorious.org:sortix/sortix
This commit is contained in:
commit
329c8cc468
2 changed files with 51 additions and 0 deletions
|
@ -25,6 +25,7 @@
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include <libmaxsi/memory.h>
|
#include <libmaxsi/memory.h>
|
||||||
#include <libmaxsi/string.h>
|
#include <libmaxsi/string.h>
|
||||||
|
#include <libmaxsi/sortedlist.h>
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
#include "memorymanagement.h"
|
#include "memorymanagement.h"
|
||||||
|
@ -94,10 +95,13 @@ namespace Sortix
|
||||||
firstthread = NULL;
|
firstthread = NULL;
|
||||||
mmapfrom = 0x80000000UL;
|
mmapfrom = 0x80000000UL;
|
||||||
pid = AllocatePID();
|
pid = AllocatePID();
|
||||||
|
Put(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Process::~Process()
|
Process::~Process()
|
||||||
{
|
{
|
||||||
|
Remove(this);
|
||||||
|
|
||||||
ResetAddressSpace();
|
ResetAddressSpace();
|
||||||
|
|
||||||
// Avoid memory leaks.
|
// Avoid memory leaks.
|
||||||
|
@ -304,6 +308,43 @@ namespace Sortix
|
||||||
return nextpidtoallocate++;
|
return nextpidtoallocate++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ProcessCompare(Process* a, Process* b)
|
||||||
|
{
|
||||||
|
if ( a->pid < b->pid ) { return -1; }
|
||||||
|
if ( a->pid > b->pid ) { return 1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ProcessPIDCompare(Process* a, pid_t pid)
|
||||||
|
{
|
||||||
|
if ( a->pid < pid ) { return -1; }
|
||||||
|
if ( a->pid > pid ) { return 1; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SortedList<Process*>* pidlist;
|
||||||
|
|
||||||
|
Process* Process::Get(pid_t pid)
|
||||||
|
{
|
||||||
|
size_t index = pidlist->Search(ProcessPIDCompare, pid);
|
||||||
|
if ( index == SIZE_MAX ) { return NULL; }
|
||||||
|
|
||||||
|
return pidlist->Get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Process::Put(Process* process)
|
||||||
|
{
|
||||||
|
return pidlist->Add(process);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Process::Remove(Process* process)
|
||||||
|
{
|
||||||
|
size_t index = pidlist->Search(process);
|
||||||
|
ASSERT(index != SIZE_MAX);
|
||||||
|
|
||||||
|
pidlist->Remove(index);
|
||||||
|
}
|
||||||
|
|
||||||
void Process::Init()
|
void Process::Init()
|
||||||
{
|
{
|
||||||
Syscall::Register(SYSCALL_EXEC, (void*) SysExecute);
|
Syscall::Register(SYSCALL_EXEC, (void*) SysExecute);
|
||||||
|
@ -312,6 +353,9 @@ namespace Sortix
|
||||||
Syscall::Register(SYSCALL_GETPPID, (void*) SysGetParentPID);
|
Syscall::Register(SYSCALL_GETPPID, (void*) SysGetParentPID);
|
||||||
|
|
||||||
nextpidtoallocate = 0;
|
nextpidtoallocate = 0;
|
||||||
|
|
||||||
|
pidlist = new SortedList<Process*>(ProcessCompare);
|
||||||
|
if ( !pidlist ) { Panic("could not allocate pidlist\n"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
addr_t Process::AllocVirtualAddr(size_t size)
|
addr_t Process::AllocVirtualAddr(size_t size)
|
||||||
|
|
|
@ -111,6 +111,13 @@ namespace Sortix
|
||||||
public:
|
public:
|
||||||
addr_t AllocVirtualAddr(size_t size);
|
addr_t AllocVirtualAddr(size_t size);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Process* Get(pid_t pid);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static bool Put(Process* process);
|
||||||
|
static void Remove(Process* process);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Process* CurrentProcess();
|
Process* CurrentProcess();
|
||||||
|
|
Loading…
Add table
Reference in a new issue