127 lines
3.2 KiB
C
127 lines
3.2 KiB
C
/* process.h - This file is a part of NutsOS
|
|
*
|
|
* NutsOS
|
|
* Copyright (C) 2013 Free Software Foundation, Inc.
|
|
*
|
|
* NutsOS 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.
|
|
*
|
|
* NutsOS 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 NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* Valentin Verdier <valentin.verdier03@gmail.com>
|
|
*/
|
|
|
|
#pragma once
|
|
#ifndef PROCESS_H
|
|
#define PROCESS_H
|
|
|
|
#include "types.h"
|
|
#include "memory.h"
|
|
#include "utils.h"
|
|
#include "ipc.h"
|
|
|
|
|
|
#define USER_SPACE_BASE_ADDR (KERNEL_SPACE_SIZE)
|
|
#define USER_STACK_ADDR 0xFFBFF000
|
|
#define USER_SPACE_END_ADDR 0xFFBFE000
|
|
|
|
#define PROCESS_STATUS_RUNNING 0
|
|
#define PROCESS_STATUS_WAIT_MUTEX 1
|
|
#define PROCESS_STATUS_SLEEP 2
|
|
#define PROCESS_STATUS_ZOMBIE 3
|
|
|
|
struct ProcessModel
|
|
{
|
|
struct ProcessModel* next; /* 0 */
|
|
struct ProcessModel* prev; /* 4 */
|
|
|
|
bits32 reg_EAX; /* 8 */
|
|
bits32 reg_EBX; /* 12 */
|
|
bits32 reg_ECX; /* 16 */
|
|
bits32 reg_EDX; /* 20 */
|
|
bits32 reg_ESI; /* 24 */
|
|
bits32 reg_EDI; /* 28 */
|
|
bits32 reg_EBP; /* 32 */
|
|
bits32 reg_ESP; /* 36 */
|
|
bits32 reg_EIP; /* 40 */
|
|
bits32 reg_EFLAGS; /* 44 */
|
|
bits16 reg_CS; /* 48 */
|
|
bits16 reg_DS; /* 50 */
|
|
bits16 reg_ES; /* 52 */
|
|
bits16 reg_FS; /* 54 */
|
|
bits16 reg_GS; /* 56 */
|
|
bits16 reg_SS; /* 58 */
|
|
bits32 reg_CR3; /* 60 */
|
|
|
|
bits32 kernelStackPtr;
|
|
T_PageDirectory pageDir;
|
|
T_LinkedList processRegionsList;
|
|
|
|
unsigned int pid;
|
|
struct ProcessModel* parent;
|
|
T_LinkedList processChildrenList;
|
|
unsigned int signal;
|
|
void* signalAction[32];
|
|
|
|
bits8 status; /* 0:actif 1:wait mutex 2:sleep 3:zombie */
|
|
unsigned int* ipcWaitMutex;
|
|
unsigned int ipcInSection;
|
|
};
|
|
typedef struct ProcessModel T_Process;
|
|
|
|
#ifdef PROCESS_PRIVATE
|
|
#define PROCESS_REGION_RO 0
|
|
#define PROCESS_REGION_RW 1
|
|
#define PROCESS_REGION_HEAP 3
|
|
|
|
struct ProcessRegion
|
|
{
|
|
struct ProcessRegion* next;
|
|
struct ProcessRegion* prev;
|
|
T_Page startPage;
|
|
T_Page endPage;
|
|
unsigned char type;
|
|
};
|
|
|
|
struct ProcessChild
|
|
{
|
|
struct ProcessChild* next;
|
|
struct ProcessChild* prev;
|
|
T_Process* process;
|
|
};
|
|
|
|
unsigned int PidCounter;
|
|
#endif
|
|
|
|
T_LinkedList Processes;
|
|
T_Process* CurrentProcess;
|
|
T_Process Process_0;
|
|
|
|
void InitProcessManager();
|
|
unsigned int CreateProcess(void*);
|
|
|
|
/* Fonctions éxécutées par le processus lui meme */
|
|
void DestroyProcess();
|
|
unsigned int ProcessCreateRegion_RO(T_Page, T_Page*, unsigned int, T_LinkedList*);
|
|
unsigned int ProcessCreateRegion_RW(T_Page, unsigned int, T_LinkedList*);
|
|
void ProcessRemoveRegion(T_Page, unsigned int, T_LinkedList*);
|
|
/* ############################################# */
|
|
|
|
/* Fonctions d'ordonnancement */
|
|
void _LoadContext(T_Process*);
|
|
bits32* _SaveContex();
|
|
T_Process* SchedulingAlgorithm();
|
|
void Schedule();
|
|
void ScheduleAtClock();
|
|
/* ############################################# */
|
|
|
|
#endif
|