The Pedigree Project 0.1
Subsystem.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef SUBSYSTEM_H
21#define SUBSYSTEM_H
22
23#include "pedigree/kernel/Log.h"
24#include "pedigree/kernel/compiler.h"
25#include "pedigree/kernel/process/FilesystemContext.h"
26#include "pedigree/kernel/processor/state_forward.h"
27#include "pedigree/kernel/utilities/String.h"
28
29class File;
30class Process;
31class Thread;
32class Event;
33class UserReturnFrame;
34template <class T>
35class Vector;
36
45class EXPORTED_PUBLIC Subsystem {
46 friend class Process;
47
48 public:
49 virtual bool filesystemConstrained() const {
50 return false;
51 }
52 virtual uint64_t filesystemAccess(const FilesystemPathRef*, size_t) const {
53 return ~uint64_t(0);
54 }
55 virtual bool filesystemReparent(const FilesystemPathRef*, size_t, const FilesystemPathRef*,
56 size_t) const {
57 return true;
58 }
59 enum class UserReturnResult { Continue, Terminal };
60 enum class UserReturnEventResult { Deliver, Consumed, Terminal };
61 virtual UserReturnResult userReturnCheckpoint(Thread&, UserReturnFrame&) {
62 return UserReturnResult::Continue;
63 }
64 virtual UserReturnEventResult userReturnEvent(Thread&, Event&, UserReturnFrame&) {
65 return UserReturnEventResult::Deliver;
66 }
67
69 enum SubsystemType { Posix = 0, Native = 1, None = 255 };
70
72 enum KillReason { Interrupted = 0, Terminated = 1, Unknown = 255 };
73
75 enum class ExitCause { Normal, Signal };
76
82 InvalidOpcode = 0,
83 PageFault = 1,
84 GeneralProtectionFault = 2,
85 DivideByZero = 3,
86 FpuError = 4,
87 SpecialFpuError = 5,
88 TerminalInput = 6, // Read from terminal, but not foreground.
89 TerminalOutput = 7, // Output to terminal, but not foreground.
90 Continue = 8,
91 Stop = 9,
92 Interrupt = 10,
93 Quit = 11,
94 Child = 12, // Child pause/continue/quit.
95 Pipe = 13, // Pipe broken.
96 FileMappingFault = 14,
97 Other = 255
98 };
99
101 Subsystem() : m_Type(None), m_pProcess(0) {}
102
104 Subsystem(const Subsystem& s) : m_Type(s.m_Type), m_pProcess(0) {}
105
107 Subsystem(SubsystemType type) : m_Type(type), m_pProcess(0) {}
108
110 virtual ~Subsystem();
111
121 virtual void acquire();
122
124 virtual void release();
125
127 virtual void exit(int code, ExitCause cause = ExitCause::Normal) = 0;
128
133 virtual bool kill(KillReason killReason, Thread* pThread = 0) = 0;
134
141 virtual void threadException(Thread* pThread, ExceptionType eType,
142 InterruptState* pState = nullptr, uintptr_t faultAddress = 0,
143 uintptr_t errorCode = 0);
144
146 virtual bool resolveUserPageFault(Thread&, InterruptState&, uintptr_t, uintptr_t) {
147 return false;
148 }
149
152 return m_Type;
153 }
154
156 virtual void setProcess(Process* p) {
157 if ((!m_pProcess) | (m_pProcess == p))
158 m_pProcess = p;
159 else
160 WARNING("An attempt was made to change the Process of a Subsystem!");
161 }
162
164 virtual bool invoke(const char* name, Vector<String>& argv, Vector<String>& env) = 0;
165
167 virtual bool invoke(const char* name, Vector<String>& argv, Vector<String>& env,
168 SyscallState& state) = 0;
169
171 virtual bool invoke(File* originalFile, const String& originalName, Vector<String>& argv,
172 Vector<String>& env) = 0;
173
175 virtual bool invoke(File* originalFile, const String& originalName, Vector<String>& argv,
176 Vector<String>& env, SyscallState& state) = 0;
177
178 protected:
180 virtual void prepareThreadsForExec(Thread* owner) {}
181
184
186 virtual void threadExiting(Thread* pThread) {}
187
189 virtual void threadRemoved(Thread* pThread) {}
190
191 SubsystemType m_Type;
192
193 Process* m_pProcess;
194
195 private:
196 const Subsystem& operator=(const Subsystem&);
197};
198
199#endif
Definition Event.h:49
Definition File.h:75
Definition Pipe.h:36
virtual void preserveProcessSignalsForThreadExit(Thread *thread)
Definition Subsystem.h:183
virtual bool invoke(const char *name, Vector< String > &argv, Vector< String > &env)=0
virtual bool resolveUserPageFault(Thread &, InterruptState &, uintptr_t, uintptr_t)
Definition Subsystem.h:146
virtual bool kill(KillReason killReason, Thread *pThread=0)=0
virtual void threadExiting(Thread *pThread)
Definition Subsystem.h:186
virtual void setProcess(Process *p)
Definition Subsystem.h:156
SubsystemType getType()
Definition Subsystem.h:151
virtual void prepareThreadsForExec(Thread *owner)
Definition Subsystem.h:180
Subsystem(SubsystemType type)
Definition Subsystem.h:107
virtual bool invoke(File *originalFile, const String &originalName, Vector< String > &argv, Vector< String > &env)=0
virtual void threadRemoved(Thread *pThread)
Definition Subsystem.h:189
virtual bool invoke(const char *name, Vector< String > &argv, Vector< String > &env, SyscallState &state)=0
Subsystem(const Subsystem &s)
Definition Subsystem.h:104
virtual bool invoke(File *originalFile, const String &originalName, Vector< String > &argv, Vector< String > &env, SyscallState &state)=0
virtual void exit(int code, ExitCause cause=ExitCause::Normal)=0
virtual ~Subsystem()
A vector / dynamic array.
Definition Vector.h:33