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 
29 struct Message;
30 class MemoryContext;
31 class MemoryChannel;
32 struct ProcessEvent;
33 class ProcessManager;
34 class Scheduler;
35 
44 class Process
45 {
46  friend class ProcessManager;
47  friend class Scheduler;
48 
49  public:
50 
54  enum Result
55  {
61  };
62 
66  enum State
67  {
72  };
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 
202  Result wait(ProcessID id);
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 */
Scheduler
Responsible for deciding which Process may execute on the local Core.
Definition: Scheduler.h:36
Process::m_waitId
ProcessID m_waitId
Waits for exit of this Process.
Definition: Process.h:256
Process::m_memoryContext
MemoryContext * m_memoryContext
MMU memory context.
Definition: Process.h:271
Process::reset
virtual void reset(const Address entry)=0
Restart execution at the given entry point.
ProcessManager
Represents a process which may run on the host.
Definition: ProcessManager.h:44
Process::MemoryMapError
@ MemoryMapError
Definition: Process.h:58
MemoryContext
Virtual memory abstract interface.
Definition: MemoryContext.h:42
Macros.h
Types.h
Process::getState
State getState() const
Retrieves the current state.
Definition: Process.cpp:80
Process
Represents a process which may run on the host.
Definition: Process.h:44
Process::WakeupPending
@ WakeupPending
Definition: Process.h:60
Process::raiseEvent
Result raiseEvent(const struct ProcessEvent *event)
Raise kernel event.
Definition: Process.cpp:161
Process::Ready
@ Ready
Definition: Process.h:68
Process::getID
ProcessID getID() const
Retrieve our ID number.
Definition: Process.cpp:60
Process::~Process
virtual ~Process()
Destructor function.
Definition: Process.cpp:41
Process::isPrivileged
bool isPrivileged() const
Get privilege.
Definition: Process.cpp:100
Process::m_map
MemoryMap m_map
Virtual memory layout.
Definition: Process.h:268
Process::getParent
ProcessID getParent() const
Retrieve our parent ID.
Definition: Process.cpp:65
ProcessID
u32 ProcessID
Process Identification Number.
Definition: Types.h:140
Process::m_waitResult
uint m_waitResult
Wait exit result of the other Process.
Definition: Process.h:259
Address
unsigned long Address
A memory address.
Definition: Types.h:131
Process::m_sleepTimer
Timer::Info m_sleepTimer
Sleep timer value.
Definition: Process.h:281
Process::Success
@ Success
Definition: Process.h:56
Process::Process
Process(ProcessID id, Address entry, bool privileged, const MemoryMap &map)
Constructor function.
Definition: Process.cpp:26
Timer::Info
Timer information structure.
Definition: Timer.h:42
Process::wakeup
Result wakeup()
Prevent process from sleeping.
Definition: Process.cpp:224
uint
unsigned int uint
Unsigned integer number.
Definition: Types.h:44
Process::m_state
State m_state
Current process status.
Definition: Process.h:253
Process::getShares
ProcessShares & getShares()
Get process shares.
Definition: Process.cpp:85
Process::stop
Result stop()
Stop execution of this process.
Definition: Process.cpp:137
Process::getMemoryContext
MemoryContext * getMemoryContext()
Get MMU memory context.
Definition: Process.cpp:95
Process::Result
Result
Result codes.
Definition: Process.h:54
Process::resume
Result resume()
Resume execution when this process is stopped.
Definition: Process.cpp:149
Timer.h
Process::OutOfMemory
@ OutOfMemory
Definition: Process.h:59
ProcessEvent
Represents a process which may run on the host.
Definition: ProcessEvent.h:40
Process::execute
virtual void execute(Process *previous)=0
Allow the Process to run on the CPU.
Process::m_wakeups
Size m_wakeups
Number of wakeups received.
Definition: Process.h:274
Process::m_shares
ProcessShares m_shares
Contains virtual memory shares between this process and others.
Definition: Process.h:284
Process::InvalidArgument
@ InvalidArgument
Definition: Process.h:57
MemoryMap
Describes virtual memory map layout.
Definition: MemoryMap.h:38
Process::Stopped
@ Stopped
Definition: Process.h:71
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
Process::m_entry
Address m_entry
Entry point of the program.
Definition: Process.h:265
MemoryMap.h
MemoryChannel
Unidirectional point-to-point channel using shared memory.
Definition: MemoryChannel.h:43
Process::m_id
const ProcessID m_id
Process Identifier.
Definition: Process.h:247
Process::setParent
void setParent(ProcessID id)
Set parent process ID.
Definition: Process.cpp:105
Process::Waiting
@ Waiting
Definition: Process.h:70
Process::Sleeping
@ Sleeping
Definition: Process.h:69
Process::join
virtual Result join(const uint result)
Complete waiting for another Process.
Definition: Process.cpp:124
Process::initialize
virtual Result initialize()
Initialize the Process.
Definition: Process.cpp:172
Process::State
State
Represents the execution state of the Process.
Definition: Process.h:66
entry
u32 entry[]
Definition: IntelACPI.h:64
Process::sleep
Result sleep(const Timer::Info *timer, bool ignoreWakeups)
Stops the process for executing until woken up.
Definition: Process.cpp:244
Process::getWaitResult
uint getWaitResult() const
Get wait result.
Definition: Process.cpp:75
Process::operator==
bool operator==(Process *proc)
Compare two processes.
Definition: Process.cpp:265
Process::getSleepTimer
const Timer::Info & getSleepTimer() const
Get sleep timer.
Definition: Process.cpp:90
Process::m_kernelChannel
MemoryChannel * m_kernelChannel
Channel for sending kernel events to the Process.
Definition: Process.h:287
Process::wait
Result wait(ProcessID id)
Let Process wait for other Process to terminate.
Definition: Process.cpp:110
List.h
Process::getWait
ProcessID getWait() const
Get Wait ID.
Definition: Process.cpp:70
Process::m_privileged
bool m_privileged
Privilege level.
Definition: Process.h:262
ProcessShares
Manages memory shares for a Process.
Definition: ProcessShares.h:39
Process::m_parent
ProcessID m_parent
Parent process.
Definition: Process.h:250
ProcessShares.h