The Pedigree Project  0.1
PosixProcess.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 POSIX_PROCESS_H
21 #define POSIX_PROCESS_H
22 
23 #include "PosixSubsystem.h"
24 #include "pedigree/kernel/Log.h"
25 #include "pedigree/kernel/compiler.h"
26 #include "pedigree/kernel/machine/TimerHandler.h"
27 #include "pedigree/kernel/process/Process.h"
28 #include "pedigree/kernel/processor/types.h"
29 
30 class PosixProcess;
31 
33 {
34  public:
35  PosixSession() : Leader(0)
36  {
37  }
38 
39  ~PosixSession()
40  {
41  }
42 
45 };
46 
48 {
49  public:
50  ProcessGroup() : processGroupId(0), Leader(0), Members()
51  {
52  Members.clear();
53  }
54 
55  virtual ~ProcessGroup();
56 
59 
62 
68 
69  private:
70  ProcessGroup(const ProcessGroup &);
71  ProcessGroup &operator=(ProcessGroup &);
72 };
73 
75 {
76  public:
77  enum Mode
78  {
80  Hardware = 0,
84  Profile
85  };
86 
89  IntervalTimer(PosixProcess *pProcess, Mode mode = Hardware);
90  virtual ~IntervalTimer();
91 
94  void setInterval(
95  Time::Timestamp interval, Time::Timestamp *prevInterval = nullptr);
96 
98  void
99  setTimerValue(Time::Timestamp value, Time::Timestamp *prevValue = nullptr);
100 
102  void setIntervalAndValue(
103  Time::Timestamp interval, Time::Timestamp value,
104  Time::Timestamp *prevInterval = nullptr,
105  Time::Timestamp *prevValue = nullptr);
106 
107  void getIntervalAndValue(Time::Timestamp &interval, Time::Timestamp &value);
108 
110  void adjustValue(int64_t adjustment);
111 
112  Time::Timestamp getInterval() const;
113  Time::Timestamp getValue() const;
114 
115  private:
116  virtual void timer(uint64_t delta, InterruptState &state);
117 
118  void signal();
119 
120  PosixProcess *m_Process;
121  Mode m_Mode;
122  Time::Timestamp m_Value;
123  Time::Timestamp m_Interval;
124  Spinlock m_Lock;
125  bool m_Armed;
126 };
127 
129 {
130  public:
133  {
137  Leader = 0,
138 
141 
143  NoGroup
144  };
145 
148  {
149  void *head;
150  size_t head_len;
151  };
152 
153  PosixProcess();
154 
156  PosixProcess(Process *pParent, bool bCopyOnWrite = true);
157  virtual ~PosixProcess();
158 
159  void setProcessGroup(ProcessGroup *newGroup, bool bRemoveFromGroup = true);
160  ProcessGroup *getProcessGroup() const;
161 
162  void setGroupMembership(Membership type);
163  Membership getGroupMembership() const;
164 
165  PosixSession *getSession() const;
166  void setSession(PosixSession *p);
167 
168  virtual ProcessType getType();
169 
170  void setMask(uint32_t mask);
171  uint32_t getMask() const;
172 
173  const RobustListData &getRobustList() const;
174  void setRobustList(const RobustListData &data);
175 
176  IntervalTimer &getRealIntervalTimer();
177  IntervalTimer &getVirtualIntervalTimer();
178  IntervalTimer &getProfileIntervalTimer();
179 
180  virtual int64_t getUserId() const;
181  virtual int64_t getGroupId() const;
182  virtual int64_t getEffectiveUserId() const;
183  virtual int64_t getEffectiveGroupId() const;
184  virtual void getSupplementalGroupIds(Vector<int64_t> &vec) const;
185 
186  void setUserId(int64_t id);
187  void setGroupId(int64_t id);
188  void setEffectiveUserId(int64_t id);
189  void setEffectiveGroupId(int64_t id);
190  void setSupplementalGroupIds(const Vector<int64_t> &vec);
191 
192  int64_t getSavedUserId() const;
193  int64_t getSavedGroupId() const;
194  void setSavedUserId(int64_t id);
195  void setSavedGroupId(int64_t id);
196 
197  private:
198  // Register with other systems e.g. procfs
199  void registerProcess();
200  void unregisterProcess();
201 
202  virtual void
203  reportTimesUpdated(Time::Timestamp user, Time::Timestamp system);
204  virtual void processTerminated();
205 
206  PosixProcess(const PosixProcess &);
207  PosixProcess &operator=(const PosixProcess &);
208 
209  PosixSession *m_pSession;
210  ProcessGroup *m_pProcessGroup;
211  Membership m_GroupMembership;
212  uint32_t m_Mask;
213  RobustListData m_RobustListData;
214 
215  IntervalTimer m_RealIntervalTimer;
216  IntervalTimer m_VirtualIntervalTimer;
217  IntervalTimer m_ProfileIntervalTimer;
218 
219  int64_t m_Uid;
220  int64_t m_Gid;
221  int64_t m_Euid;
222  int64_t m_Egid;
223  int64_t m_Suid;
224  int64_t m_Sgid;
225  Vector<int64_t> m_SupplementalIds;
226 };
227 
228 #endif
ProcessType
Definition: Process.h:61
PosixProcess * Leader
Definition: PosixProcess.h:44
int processGroupId
Definition: PosixProcess.h:58
CPU time in user mode only.
Definition: PosixProcess.h:82
List< PosixProcess * > Members
Definition: PosixProcess.h:67
PosixProcess * Leader
Definition: PosixProcess.h:61