FreeNOS
Process.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2015 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __KERNEL_PROCESS_H
19#define __KERNEL_PROCESS_H
20
21#include <Types.h>
22#include <Macros.h>
23#include <List.h>
24#include <MemoryMap.h>
25#include <Timer.h>
26#include "ProcessShares.h"
27
29struct Message;
30class MemoryContext;
31class MemoryChannel;
32struct ProcessEvent;
33class ProcessManager;
34class Scheduler;
35
45{
46 friend class ProcessManager;
47 friend class Scheduler;
48
49 public:
50
62
73
74 public:
75
84 Process(ProcessID id, Address entry, bool privileged, const MemoryMap &map);
85
89 virtual ~Process();
90
96 ProcessID getID() const;
97
103 ProcessID getParent() const;
104
108 ProcessID getWait() const;
109
113 uint getWaitResult() const;
114
121
127 State getState() const;
128
135
141 bool isPrivileged() const;
142
150 bool operator == (Process *proc);
151
152 protected:
153
162 virtual Result initialize();
163
169 virtual void reset(const Address entry) = 0;
170
176 virtual void execute(Process *previous) = 0;
177
183 Result wakeup();
184
193 Result sleep(const Timer::Info *timer, bool ignoreWakeups);
194
203
209 virtual Result join(const uint result);
210
216 Result stop();
217
223 Result resume();
224
230 Result raiseEvent(const struct ProcessEvent *event);
231
237 const Timer::Info & getSleepTimer() const;
238
242 void setParent(ProcessID id);
243
244 protected:
245
248
251
254
257
260
263
266
269
272
275
282
285
288};
289
294#endif /* __KERNEL_PROCESS_H */
u32 entry[]
Definition IntelACPI.h:1
Unidirectional point-to-point channel using shared memory.
Virtual memory abstract interface.
Describes virtual memory map layout.
Definition MemoryMap.h:39
Represents a process which may run on the host.
Manages memory shares for a Process.
Represents a process which may run on the host.
Definition Process.h:45
virtual void reset(const Address entry)=0
Restart execution at the given entry point.
const Timer::Info & getSleepTimer() const
Get sleep timer.
Definition Process.cpp:90
MemoryContext * m_memoryContext
MMU memory context.
Definition Process.h:271
Result wait(ProcessID id)
Let Process wait for other Process to terminate.
Definition Process.cpp:110
State
Represents the execution state of the Process.
Definition Process.h:67
@ Stopped
Definition Process.h:71
@ Ready
Definition Process.h:68
@ Sleeping
Definition Process.h:69
@ Waiting
Definition Process.h:70
Size m_wakeups
Number of wakeups received.
Definition Process.h:274
const ProcessID m_id
Process Identifier.
Definition Process.h:247
virtual Result join(const uint result)
Complete waiting for another Process.
Definition Process.cpp:124
uint getWaitResult() const
Get wait result.
Definition Process.cpp:75
Result stop()
Stop execution of this process.
Definition Process.cpp:137
MemoryChannel * m_kernelChannel
Channel for sending kernel events to the Process.
Definition Process.h:287
State m_state
Current process status.
Definition Process.h:253
ProcessID getWait() const
Get Wait ID.
Definition Process.cpp:70
Result resume()
Resume execution when this process is stopped.
Definition Process.cpp:149
Result
Result codes.
Definition Process.h:55
@ Success
Definition Process.h:56
@ InvalidArgument
Definition Process.h:57
@ OutOfMemory
Definition Process.h:59
@ MemoryMapError
Definition Process.h:58
@ WakeupPending
Definition Process.h:60
Result sleep(const Timer::Info *timer, bool ignoreWakeups)
Stops the process for executing until woken up.
Definition Process.cpp:244
State getState() const
Retrieves the current state.
Definition Process.cpp:80
virtual Result initialize()
Initialize the Process.
Definition Process.cpp:172
ProcessShares m_shares
Contains virtual memory shares between this process and others.
Definition Process.h:284
ProcessID getID() const
Retrieve our ID number.
Definition Process.cpp:60
void setParent(ProcessID id)
Set parent process ID.
Definition Process.cpp:105
virtual void execute(Process *previous)=0
Allow the Process to run on the CPU.
MemoryMap m_map
Virtual memory layout.
Definition Process.h:268
ProcessID getParent() const
Retrieve our parent ID.
Definition Process.cpp:65
MemoryContext * getMemoryContext()
Get MMU memory context.
Definition Process.cpp:95
virtual ~Process()
Destructor function.
Definition Process.cpp:41
bool m_privileged
Privilege level.
Definition Process.h:262
ProcessShares & getShares()
Get process shares.
Definition Process.cpp:85
ProcessID m_waitId
Waits for exit of this Process.
Definition Process.h:256
Result wakeup()
Prevent process from sleeping.
Definition Process.cpp:224
Result raiseEvent(const struct ProcessEvent *event)
Raise kernel event.
Definition Process.cpp:161
bool operator==(Process *proc)
Compare two processes.
Definition Process.cpp:265
uint m_waitResult
Wait exit result of the other Process.
Definition Process.h:259
bool isPrivileged() const
Get privilege.
Definition Process.cpp:100
Address m_entry
Entry point of the program.
Definition Process.h:265
ProcessID m_parent
Parent process.
Definition Process.h:250
Timer::Info m_sleepTimer
Sleep timer value.
Definition Process.h:281
Responsible for deciding which Process may execute on the local Core.
Definition Scheduler.h:37
u32 ProcessID
Process Identification Number.
Definition Types.h:140
unsigned long Address
A memory address.
Definition Types.h:131
unsigned int uint
Unsigned integer number.
Definition Types.h:44
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Represents a process which may run on the host.
Timer information structure.
Definition Timer.h:43