-
Notifications
You must be signed in to change notification settings - Fork 0
/
disastrOS_pcb.h
90 lines (68 loc) · 1.98 KB
/
disastrOS_pcb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
#include <ucontext.h> // this is the cpu status
#include "disastrOS_constants.h"
#include "linked_list.h"
#include "disastrOS_timer.h"
typedef enum ProcessStatus {Invalid=-1,
Created=0x0,
Running=0x1,
Ready=0x2,
Waiting=0x3, // io or semaphore wait
Suspended=0x4, // ctrl-z
Zombie=0x5}
ProcessStatus;
typedef struct PCB{
ListItem list; // MUST BE THE FIRST!!!
int pid;
int return_value; // ret value for the parent
ProcessStatus status;
int signals;
int signals_mask;
struct PCB* parent;
ListHead children;
ucontext_t cpu_state;
// timers
struct TimerItem *timer;
// descriptors (for all resources)
int last_fd;
ListHead descriptors;
//we are really rude :) the stack is INSIDE the pcb
//forgive me for the bestiality
char stack[STACK_SIZE];
// more stuff to come
//the one below is a hack for the syscalls
//in a real system one needs to use the cpu to pass
//arguments to a syscall
// we use long int so we can store pointers on 64 bit machines
int syscall_num;
long int syscall_args[DSOS_MAX_SYSCALLS_ARGS];
int syscall_retvalue;
} PCB;
// initializes the memory allocation
// for the PCB structures
// called internally
void PCB_init();
// allocates and initializes a new pcb block
PCB* PCB_alloc();
// frees a pcb block
int PCB_free(PCB* pcb);
// prints a PCB
void PCB_print(PCB* pcb);
// returns a pcb whose pid is pid in the list
PCB* PCB_byPID(ListHead* head, int pid);
// prints a list of PCB
void PCBList_print(ListHead* head);
// this is a list of *pointers* to pcb used in many cases
typedef struct PCBPtr{
ListItem list;
PCB* pcb;
} PCBPtr;
// allocates a list item whose data field
// is a pointer to a PCB
PCBPtr* PCBPtr_alloc(PCB* pcb);
// frees a PCB item
int PCBPtr_free(PCBPtr* pcb);
// returns a pcb whose pid is pid in the list of pointers
PCBPtr* PCBPtr_byPID(ListHead* head, int pid);
// prints a list of pcb ptrs
void PCBPtrList_print(ListHead* head);