⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 process.c

📁 一个操作系统的源代码
💻 C
字号:
/** process.c                                   **                                                               ** Original Author: Guido de Jong ** Date: 11.13.99      **  ** Description: ** Process routines **                                        ** Revision History:  ** First version      ** ** 0.0.1 11.04.99 Guido de Jong - (no comments) ** 0.0.2 11.13.99 Kasper Verdich Lund - (no comments) ** 0.0.3 12.13.99 Guido de Jong - merged with process_queue ** ** This program 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  ** 2 of the License, or (at your option) any later version.      **                                                               ** This program is distributed in the hope that it will be       ** useful, but WITHOUT ANY WARRANTY; without even the implied    ** warranty or 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 this program; if not, write to the         ** Free Software Foundation, Inc., 59 Temple Place, Suite 330,   ** Boston, MA 02111-1307 USA                                     **                                                               *********************************************************Apostle OS**/#include <process.h>#include <activation.h>#include <address_space.h>#include <halt.h>#include <mem.h>#include <paging.h>#include <string.h>#include <types.h>#ifdef DEBUG#include <debug/conio.h>#endifProcess *NewProcess(void){  Process *p = malloc(sizeof(Process));  p->addressSpace = pmalloc();  memset(p->addressSpace, 0, PAGE_SIZE);  /* map kernel space into newly created address space */   memcpy(p->addressSpace, systemSpace, 512);  p->allocated = p->deallocated = 0xffffffff;  p->pendingUpcallType = None;  p->pendingActivation = NULL;  p->upcallOffset = 0x20000000;  p->upcallCount = 0;  p->singleActivation = NewActivation();  p->singleActivation->eip = 0x20000000;  p->singleActivation->eflags = 0x202; /* interrupts enabled */  p->singleThreaded = TRUE;  p->usedActivations = NULL;  p->next = NULL;  return p;}void DeleteProcess(Process *p){  Activation *usedAct;  /* process must be removed from any queues */#ifdef DEBUG  if (p->next)    {      DebugPrintF("Trying to delete a queued process.\n");      halt();    }#endif  while ((usedAct = RemoveActivation(&p->usedActivations,                                      p->upcallCount + UPCALL_SAVES + 1)))    free(usedAct);  free(p->pendingActivation);  free(p->singleActivation);  flush(p->addressSpace, NULL, 0x100000, FALSE, TRUE);  pfree(p->addressSpace);  free(p);}extern void __Upcall(dword edi, dword esi, dword ebp,		     dword ebx, dword edx, dword ecx, dword eax,		     dword eip, dword cs, dword eflags, dword esp, dword ss);void Upcall(Process *p, dword CPU, UpcallType ut, Activation *a){  UpcallType pendUT;  Activation *pendAct, *usedAct;  dword alloc, dealloc;;  p->upcallCount++;  while ((usedAct = RemoveActivation(&p->usedActivations, p->upcallCount)))    free(usedAct);  if (p->pendingActivation)    InsertActivation(&p->usedActivations, p->pendingActivation);  if (a)    InsertActivation(&p->usedActivations, a);    /* save attributes */  pendUT = p->pendingUpcallType;  pendAct = p->pendingActivation;  alloc = p->allocated;  dealloc = p->deallocated;  /* reset attributes */  p->pendingUpcallType = None;  p->pendingActivation = NULL;  p->allocated = p->deallocated = 0xffffffff;  /* do the actual upcall */  __Upcall(alloc, dealloc, CPU, (dword) a, (dword) pendAct, pendUT, ut,  	   p->upcallOffset, 0x1b, 0x202, 0x0, 0x23);}#ifdef DEBUGvoid PrintProcess(Process *p){  DebugPrintF("%08x",p->addressSpace);  /* print process information */}#endifvoid InsertProcess(ProcessQueue *q, Process *p, bool atHead){  if (*q == NULL)    *q = p;  else    p->next = (*q)->next;  (*q)->next = p;  if (!atHead)    *q = p;}Process* RemoveProcess(ProcessQueue *q){  Process *p = NULL;  if (*q)    {      p = (*q)->next;      if (*q == p)        *q = NULL;      else        (*q)->next = p->next;      p->next = NULL;    }  return p;}#ifdef DEBUGvoid PrintProcessQueue(ProcessQueue q){  Process *p = q;  DebugPrintF("ProcessQueue: ");  do    {      p = p->next;      PrintProcess(p);      if (p != q)        DebugPrintF("->");          }  while (p != q);  DebugPrintF("\n");}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -