1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/sortix/process.h
2011-11-02 17:51:01 +01:00

127 lines
2.3 KiB
C++

/******************************************************************************
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
This file is part of Sortix.
Sortix is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
Sortix is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along
with Sortix. If not, see <http://www.gnu.org/licenses/>.
process.h
Describes a process belonging to a subsystem.
******************************************************************************/
#ifndef SORTIX_PROCESS_H
#define SORTIX_PROCESS_H
#include "descriptors.h"
namespace Sortix
{
class Thread;
class Process;
struct ProcessSegment;
const size_t DEFAULT_STACK_SIZE = 64*1024;
struct ProcessSegment
{
public:
ProcessSegment() : prev(NULL), next(NULL) { }
public:
ProcessSegment* prev;
ProcessSegment* next;
addr_t position;
size_t size;
public:
bool Intersects(ProcessSegment* segments);
ProcessSegment* Fork();
};
class Process
{
public:
Process();
~Process();
public:
static void Init();
static int Execute(const char* programname, CPU::InterruptRegisters* regs);
private:
static pid_t AllocatePID();
public:
addr_t addrspace;
public:
pid_t pid;
public:
Process* parent;
Process* prevsibling;
Process* nextsibling;
Process* firstchild;
public:
Thread* firstthread;
public:
DescriptorTable descriptors;
ProcessSegment* segments;
public:
bool sigint;
public:
void ResetAddressSpace();
public:
bool IsSane() { return addrspace != 0; }
public:
Process* Fork();
private:
Thread* ForkThreads(Process* processclone);
public:
void ResetForExecute();
public:
inline size_t DefaultStackSize() { return DEFAULT_STACK_SIZE; }
private:
addr_t mmapfrom;
public:
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();
}
#endif