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/processor/state_forward.h"
26 #include "pedigree/kernel/utilities/String.h"
27 
28 class File;
29 class Process;
30 class Thread;
31 template <class T>
32 class Vector;
33 
43 {
44  friend class Process;
45 
46  public:
49  {
50  Posix = 0,
51  Native = 1,
52  None = 255
53  };
54 
57  {
58  Interrupted = 0,
59  Terminated = 1,
60  Unknown = 255
61  };
62 
68  {
69  InvalidOpcode = 0,
70  PageFault = 1,
71  GeneralProtectionFault = 2,
72  DivideByZero = 3,
73  FpuError = 4,
74  SpecialFpuError = 5,
75  TerminalInput = 6, // Read from terminal, but not foreground.
76  TerminalOutput = 7, // Output to terminal, but not foreground.
77  Continue = 8,
78  Stop = 9,
79  Interrupt = 10,
80  Quit = 11,
81  Child = 12, // Child pause/continue/quit.
82  Pipe = 13, // Pipe broken.
83  Other = 255
84  };
85 
87  Subsystem() : m_Type(None), m_pProcess(0)
88  {
89  }
90 
92  Subsystem(const Subsystem &s) : m_Type(s.m_Type), m_pProcess(0)
93  {
94  }
95 
97  Subsystem(SubsystemType type) : m_Type(type), m_pProcess(0)
98  {
99  }
100 
102  virtual ~Subsystem();
103 
113  virtual void acquire();
114 
116  virtual void release();
117 
119  virtual void exit(int code) = 0;
120 
125  virtual bool kill(KillReason killReason, Thread *pThread = 0) = 0;
126 
128  virtual void threadException(Thread *pThread, ExceptionType eType);
129 
132  {
133  return m_Type;
134  }
135 
137  virtual void setProcess(Process *p)
138  {
139  if ((!m_pProcess) | (m_pProcess == p))
140  m_pProcess = p;
141  else
142  WARNING(
143  "An attempt was made to change the Process of a Subsystem!");
144  }
145 
147  virtual bool
148  invoke(const char *name, Vector<String> &argv, Vector<String> &env) = 0;
149 
151  virtual bool invoke(
152  const char *name, Vector<String> &argv, Vector<String> &env,
153  SyscallState &state) = 0;
154 
156  virtual bool invoke(
157  File *originalFile, const String &originalName, Vector<String> &argv,
158  Vector<String> &env) = 0;
159 
161  virtual bool invoke(
162  File *originalFile, const String &originalName, Vector<String> &argv,
163  Vector<String> &env, SyscallState &state) = 0;
164 
166  virtual File *findFile(const String &path, File *workingDir) = 0;
167 
168  protected:
170  virtual void threadRemoved(Thread *pThread)
171  {
172  }
173 
174  SubsystemType m_Type;
175 
176  Process *m_pProcess;
177 
178  private:
179  const Subsystem &operator=(const Subsystem &);
180 };
181 
182 #endif
Subsystem()
Definition: Subsystem.h:87
A vector / dynamic array.
Definition: String.h:49
#define WARNING(text)
Definition: Log.h:78
Subsystem(SubsystemType type)
Definition: Subsystem.h:97
Definition: Thread.h:54
SubsystemType getType()
Definition: Subsystem.h:131
void kill() NORETURN
Definition: Process.cc:239
Definition: File.h:66
Subsystem(const Subsystem &s)
Definition: Subsystem.h:92
virtual void setProcess(Process *p)
Definition: Subsystem.h:137
virtual void threadRemoved(Thread *pThread)
Definition: Subsystem.h:170
Definition: Pipe.h:35