2011-08-05 08:25:00 -04:00
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
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;
|
2011-08-27 10:46:00 -04:00
|
|
|
struct ProcessSegment;
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2011-09-21 14:52:29 -04:00
|
|
|
const size_t DEFAULT_STACK_SIZE = 64*1024;
|
2011-12-16 09:33:12 -05:00
|
|
|
const int SEG_NONE = 0;
|
|
|
|
const int SEG_TEXT = 1;
|
|
|
|
const int SEG_DATA = 2;
|
|
|
|
const int SEG_STACK = 3;
|
|
|
|
const int SEG_OTHER = 4;
|
2011-09-21 14:52:29 -04:00
|
|
|
|
2011-08-27 10:46:00 -04:00
|
|
|
struct ProcessSegment
|
2011-08-05 08:25:00 -04:00
|
|
|
{
|
|
|
|
public:
|
2011-08-27 10:46:00 -04:00
|
|
|
ProcessSegment() : prev(NULL), next(NULL) { }
|
2011-08-05 08:25:00 -04:00
|
|
|
|
|
|
|
public:
|
2011-08-27 10:46:00 -04:00
|
|
|
ProcessSegment* prev;
|
|
|
|
ProcessSegment* next;
|
|
|
|
addr_t position;
|
|
|
|
size_t size;
|
2011-12-16 07:24:49 -05:00
|
|
|
int type;
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2011-08-27 10:46:00 -04:00
|
|
|
public:
|
2011-09-21 14:52:29 -04:00
|
|
|
bool Intersects(ProcessSegment* segments);
|
|
|
|
ProcessSegment* Fork();
|
2011-08-27 10:46:00 -04:00
|
|
|
|
|
|
|
};
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2011-08-27 10:46:00 -04:00
|
|
|
class Process
|
|
|
|
{
|
2011-08-05 08:25:00 -04:00
|
|
|
public:
|
2011-09-21 14:52:29 -04:00
|
|
|
Process();
|
2011-08-27 10:46:00 -04:00
|
|
|
~Process();
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2011-10-26 18:05:20 -04:00
|
|
|
public:
|
|
|
|
static void Init();
|
|
|
|
|
2011-08-05 08:25:00 -04:00
|
|
|
private:
|
2011-09-21 14:52:29 -04:00
|
|
|
static pid_t AllocatePID();
|
|
|
|
|
|
|
|
public:
|
|
|
|
addr_t addrspace;
|
2011-11-06 16:00:29 -05:00
|
|
|
int exitstatus;
|
2011-11-21 06:19:57 -05:00
|
|
|
char* workingdir;
|
2011-09-21 14:52:29 -04:00
|
|
|
pid_t pid;
|
2011-11-22 11:26:47 -05:00
|
|
|
int* errno;
|
2011-09-21 14:52:29 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
Process* parent;
|
|
|
|
Process* prevsibling;
|
|
|
|
Process* nextsibling;
|
|
|
|
Process* firstchild;
|
2011-11-06 16:00:29 -05:00
|
|
|
Process* zombiechild;
|
2011-09-21 14:52:29 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
Thread* firstthread;
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2011-08-27 10:46:00 -04:00
|
|
|
public:
|
|
|
|
DescriptorTable descriptors;
|
|
|
|
ProcessSegment* segments;
|
|
|
|
|
2011-08-27 17:03:39 -04:00
|
|
|
public:
|
|
|
|
bool sigint;
|
|
|
|
|
2011-08-27 10:46:00 -04:00
|
|
|
public:
|
2011-11-22 07:53:36 -05:00
|
|
|
int Execute(const char* programname, const byte* program, size_t programsize, int argc, const char* const* argv, CPU::InterruptRegisters* regs);
|
2011-09-21 14:52:29 -04:00
|
|
|
void ResetAddressSpace();
|
2011-11-22 07:53:36 -05:00
|
|
|
void Exit(int status);
|
2011-08-27 10:46:00 -04:00
|
|
|
|
|
|
|
public:
|
2011-09-21 14:52:29 -04:00
|
|
|
bool IsSane() { return addrspace != 0; }
|
2011-08-27 10:46:00 -04:00
|
|
|
|
|
|
|
public:
|
2011-09-21 14:52:29 -04:00
|
|
|
Process* Fork();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Thread* ForkThreads(Process* processclone);
|
2011-11-28 19:21:59 -05:00
|
|
|
void ExecuteCPU(int argc, char** argv, addr_t stackpos, addr_t entry, CPU::InterruptRegisters* regs);
|
2011-09-21 14:52:29 -04:00
|
|
|
|
|
|
|
public:
|
|
|
|
void ResetForExecute();
|
|
|
|
|
|
|
|
public:
|
|
|
|
inline size_t DefaultStackSize() { return DEFAULT_STACK_SIZE; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
addr_t mmapfrom;
|
|
|
|
|
|
|
|
public:
|
|
|
|
addr_t AllocVirtualAddr(size_t size);
|
2011-08-05 08:25:00 -04:00
|
|
|
|
2011-11-06 16:00:29 -05:00
|
|
|
public:
|
|
|
|
void OnChildProcessExit(Process* process);
|
|
|
|
|
2011-11-02 10:41:35 -04:00
|
|
|
public:
|
|
|
|
static Process* Get(pid_t pid);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool Put(Process* process);
|
|
|
|
static void Remove(Process* process);
|
|
|
|
|
2011-08-05 08:25:00 -04:00
|
|
|
};
|
2011-08-27 10:46:00 -04:00
|
|
|
|
|
|
|
Process* CurrentProcess();
|
2011-08-05 08:25:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|