1 | ;
|
---|
2 | ; PROCESS.INC -- Manage processes
|
---|
3 | ;
|
---|
4 | ; Copyright (c) 1991-1996 by Eberhard Mattes
|
---|
5 | ;
|
---|
6 | ; This file is part of emx.
|
---|
7 | ;
|
---|
8 | ; emx is free software; you can redistribute it and/or modify it
|
---|
9 | ; under the terms of the GNU General Public License as published by
|
---|
10 | ; the Free Software Foundation; either version 2, or (at your option)
|
---|
11 | ; any later version.
|
---|
12 | ;
|
---|
13 | ; emx is distributed in the hope that it will be useful,
|
---|
14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | ; GNU General Public License for more details.
|
---|
17 | ;
|
---|
18 | ; You should have received a copy of the GNU General Public License
|
---|
19 | ; along with emx; see the file COPYING. If not, write to
|
---|
20 | ; the Free Software Foundation, 59 Temple Place - Suite 330,
|
---|
21 | ; Boston, MA 02111-1307, USA.
|
---|
22 | ;
|
---|
23 | ; See emx.asm for a special exception.
|
---|
24 | ;
|
---|
25 |
|
---|
26 | ;
|
---|
27 | ; Requires: SIGNAL.INC (for SIGNALS)
|
---|
28 | ;
|
---|
29 |
|
---|
30 | ;
|
---|
31 | ; Capacity
|
---|
32 | ;
|
---|
33 | MAX_FILES = 40 ; Max number of open files per process
|
---|
34 | MAX_PROCESSES = 6 ; Max number of processes
|
---|
35 | MAX_TIMERS = 2 * MAX_PROCESSES ; Max number of timers
|
---|
36 |
|
---|
37 | ;
|
---|
38 | ; Special process pointers
|
---|
39 | ;
|
---|
40 | NO_PROCESS = 0 ; Used for PROCESS_PTR, PROCESS_SIG,
|
---|
41 | ; FIND_PROCESS, etc.
|
---|
42 | NO_WPROCESS = 1 ; Used for WAIT_PROCESS
|
---|
43 |
|
---|
44 | ;
|
---|
45 | ; P_FLAGS bits
|
---|
46 | ;
|
---|
47 | PF_DEBUG = 0001H ; Process is being debugged
|
---|
48 | PF_WAIT_WAIT = 0002H ; Process waits for being waited for
|
---|
49 | PF_387_USED = 0004H ; 387 used, don't FNINIT
|
---|
50 | PF_PRELOADING = 0008H ; Preloading in progress (for swapper)
|
---|
51 | PF_TERMIO_TIME = 0010H ; VTIME expired
|
---|
52 | PF_SLEEP_FLAG = 0020H ; sleep interval expired
|
---|
53 | PF_PSEUDO_ASYNC = 0040H ; wait() can be done for pseudo async
|
---|
54 | PF_REDIR_STDERR = 0200H ; Redirect stderr to stdout
|
---|
55 | PF_QUOTE = 0400H ; Quote arguments for children
|
---|
56 | PF_COMMIT = 0800H ; Commit memory
|
---|
57 | PF_DONT_ZERO = 1000H ; Don't zero unitialized data
|
---|
58 | PF_PRELOAD = 4000H ; Disable preloading (-L)
|
---|
59 | PF_NO_CORE = 8000H ; Disable core dumps (-c)
|
---|
60 | PF_FPUEMU_INIT = 10000H ; FPU emu initialized for this process
|
---|
61 |
|
---|
62 | ;
|
---|
63 | ; P_UFLAGS bits
|
---|
64 | ;
|
---|
65 | UF_SIG_MODEL = 00003H ; Mask for signal() semantics
|
---|
66 | UF_SIG_EMX = 00000H ; signal() semantics: emx (SIG_ACK)
|
---|
67 | UF_SIG_SYSV = 00001H ; signal() semantics: System V
|
---|
68 | UF_SIG_BSD = 00002H ; signal() semantics: BSD
|
---|
69 |
|
---|
70 | ;
|
---|
71 | ; P_STATUS values
|
---|
72 | ;
|
---|
73 | PS_NONE = 0 ; empty slot
|
---|
74 | PS_DEFUNCT = 1 ; terminated, zombie (til wait)
|
---|
75 | PS_INIT = 2 ; initialized but not started
|
---|
76 | PS_RUN = 3 ; running
|
---|
77 | PS_STOP = 4 ; stopped (debugging)
|
---|
78 | PS_WAIT_SPAWN = 5 ; executes synchronous spawn
|
---|
79 | PS_WAIT_CHILD = 6 ; executes wait()
|
---|
80 | PS_WAIT_PTRACE = 7 ; executes ptrace()
|
---|
81 | PS_FPUEMU_CLIENT = 8 ; application being serviced by FPU emu
|
---|
82 | PS_FPUEMU_NEXT = 9 ; FPU emulator waiting for notification
|
---|
83 |
|
---|
84 | ;
|
---|
85 | ; Bits in the P_HW_ACCESS byte
|
---|
86 | ;
|
---|
87 | HW_ACCESS_MEM = 01H ; Memory read access allowed
|
---|
88 | HW_ACCESS_IO = 02H ; Port access allowed
|
---|
89 | HW_ACCESS_WRITE = 04H ; Memory write access allowed
|
---|
90 | HW_ACCESS_CODE = 08H ; Data segment and stack executable
|
---|
91 |
|
---|
92 | ;
|
---|
93 | ; Bits in the P_HFLAGS array, cf. <sys/fcntl.h>
|
---|
94 | ;
|
---|
95 | HF_APPEND = 0008H ; O_APPEND
|
---|
96 | HF_NDELAY = 0004H ; O_NONBLOCK and O_NDELAY
|
---|
97 | HF_NOINHERIT = 1000H ; O_NOINHERIT and FD_CLOEXEC
|
---|
98 |
|
---|
99 | ;
|
---|
100 | ; Process table entry
|
---|
101 | ;
|
---|
102 | ; Note: P_PID must come first to simplify initialization
|
---|
103 | ;
|
---|
104 | PROCESS STRUC
|
---|
105 | P_PID DD ? ; Process ID (NO_PID: slot not used)
|
---|
106 | P_LINEAR DD ? ; Linear address
|
---|
107 | P_DSEG_SIZE DD ? ; Size of data segment
|
---|
108 | P_LIN_SIZE DD ? ; Allocated linear addresses
|
---|
109 | P_BRK DD ? ; Current break value
|
---|
110 | P_INIT_BRK DD ? ; Initial break value
|
---|
111 | P_STACK_ADDR DD ? ; Top of stack
|
---|
112 | P_STACK_SIZE DD ? ; Stack size
|
---|
113 | P_TEXT_OFF DD ? ; Start of code area
|
---|
114 | P_TEXT_SIZE DD ? ; Size of code area
|
---|
115 | P_DATA_OFF DD ? ; Start of data area
|
---|
116 | P_DATA_SIZE DD ? ; Size of data area
|
---|
117 | P_BSS_OFF DD ? ; Start of bss area
|
---|
118 | P_BSS_SIZE DD ? ; Size of bss area
|
---|
119 | P_ENTRY_POINT DD ? ; Entry point
|
---|
120 | P_NUMBER DD ? ; Process number for __fpuemu()
|
---|
121 | P_SYMBOLS DD ? ; Number of symbols
|
---|
122 | P_STATUS DW ? ; Process status (PS_*)
|
---|
123 | P_EXEC_HANDLE DW ? ; Handle of executable file
|
---|
124 | P_LDT DW ? ; Selector of local descriptor table
|
---|
125 | P_LDT_PTR DW ? ; Pointer to LDT
|
---|
126 | P_UMASK DW ? ; umask
|
---|
127 | P_UMASK1 DW ? ; umask (old semantics)
|
---|
128 | P_LAST_BYTES DW ? ; Number of bytes in last page
|
---|
129 | P_PIDX DB ? ; Process index for paging
|
---|
130 | P_RC DB ? ; Return code (P_STATUS = PS_DEFUNCT)
|
---|
131 | P_SIG_NO DB ? ; Signal number (P_STATUS = PS_STOP)
|
---|
132 | P_HW_ACCESS DB ? ; -a option bits
|
---|
133 | P_DRIVE DB ? ; -r option
|
---|
134 | P_INTERFACE DB ? ; Interface version, from layout table
|
---|
135 | P_PAD DB 0 DUP (?) ; Padding
|
---|
136 | P_COMMIT_SIZE DD ? ; Additional pages
|
---|
137 | P_SPAWN_RC DD ? ; Return code of child process (note 1)
|
---|
138 | P_PAGE_FAULTS DD ? ; Number of page faults
|
---|
139 | P_PPID DD ? ; Parent process id
|
---|
140 | P_STR_OFF DD ? ; Offset of strings in symbol segment
|
---|
141 | P_EXEC_OFFSET DD ? ; Offset of first page in exec file
|
---|
142 | P_LAST_PAGE DD ? ; Last page of exec file (0=ignore)
|
---|
143 | P_SYM_PAGE DD ? ; Page number for symbols
|
---|
144 | P_RELOC_SIZE DD ? ; Size of relocation information
|
---|
145 | P_FLAGS DD ? ; Flags (PF_*)
|
---|
146 | P_TRUNC DD ? ; Bits set by -t option
|
---|
147 | P_SIG_HANDLERS DD SIGNALS DUP (?) ; Signal handlers
|
---|
148 | P_SA_MASK DD SIGNALS DUP (?) ; sa_mask of struct sigaction
|
---|
149 | P_SA_FLAGS DD SIGNALS DUP (?) ; sa_flags of struct sigaction
|
---|
150 | P_SIG_PENDING DD ? ; Pending signals (bitwise)
|
---|
151 | P_SIG_BLOCKED DD ? ; Blocked signals (bitwise)
|
---|
152 | P_UFLAGS DD ? ; These flags can be changed by process
|
---|
153 | P_VESAINFO_PTR DD ? ; Pointer to VESA info data area
|
---|
154 | P_PRF_BUFF DD ? ; profil(): Pointer to counters
|
---|
155 | P_PRF_BUFSIZ DD ? ; profil(): Size of buffer
|
---|
156 | P_PRF_OFFSET DD ? ; profil(): First address
|
---|
157 | P_PRF_SCALE DD ? ; profil(): Scaling factor
|
---|
158 | P_HANDLES DW MAX_FILES DUP (?) ; DOS file handles
|
---|
159 | P_HFLAGS DW MAX_FILES DUP (?) ; Handle flags (note 2)
|
---|
160 | ;
|
---|
161 | ; Cf. PMINT.INC!!! (sequence, padding!)
|
---|
162 | ;
|
---|
163 | P_GS DW ?
|
---|
164 | P_FS DW ?
|
---|
165 | P_ES DW ?
|
---|
166 | P_DS DW ?
|
---|
167 | P_EDI DD ?
|
---|
168 | P_ESI DD ?
|
---|
169 | P_EBP DD ?
|
---|
170 | P_ESP_1 DD ?
|
---|
171 | P_EBX DD ?
|
---|
172 | P_EDX DD ?
|
---|
173 | P_ECX DD ?
|
---|
174 | P_EAX DD ?
|
---|
175 | P_ERRCD DD ?
|
---|
176 | P_EIP DD ?
|
---|
177 | P_CS DW ?, 0
|
---|
178 | P_EFLAGS DD ?
|
---|
179 | P_ESP DD ?
|
---|
180 | P_SS DW ?, 0
|
---|
181 | ;
|
---|
182 | ; Floating point status
|
---|
183 | ;
|
---|
184 | IF FLOATING_POINT
|
---|
185 | P_CW DW ?, 0 ; Control-word register
|
---|
186 | P_SW DW ?, 0 ; Status-word register
|
---|
187 | P_TW DW ?, 0 ; Tag-word register
|
---|
188 | P_FIP DD ? ; Last instruction (EIP)
|
---|
189 | P_FCS DW ? ; Last instruction (CS)
|
---|
190 | P_FOP DW ? ; Last instruction (opcode)
|
---|
191 | P_FOO DD ? ; Memory operand offset
|
---|
192 | P_FOS DW ?, 0 ; Memory operand segment
|
---|
193 | P_FST DT 8 DUP (?) ; Stack
|
---|
194 | ENDIF
|
---|
195 | PROCESS ENDS
|
---|
196 | ;
|
---|
197 | ; Note 1: The P_SPAWN_RC field contains the process ID of the child,
|
---|
198 | ; if a child has been spawned for debugging (NP_DEBUG)
|
---|
199 | ; or if an asynchronous child process has ended.
|
---|
200 | ;
|
---|
201 | ; Note 2: P_HFLAGS is 16 bits wide to simplify things -- everytime we
|
---|
202 | ; access P_HFLAGS, we also access P_HANDLES, therefore we already
|
---|
203 | ; have computed the offset (2 * handle)
|
---|
204 | ;
|
---|
205 |
|
---|
206 | ;
|
---|
207 | ; Cf. <sys/process.h>
|
---|
208 | ;
|
---|
209 | NP_SPAWN_SYNC = 0 ; P_WAIT
|
---|
210 | NP_SPAWN_ASYNC = 1 ; P_NOWAIT
|
---|
211 | NP_EXEC = 2 ; P_OVERLAY
|
---|
212 | NP_DEBUG = 3 ; P_DEBUG
|
---|
213 |
|
---|
214 | NP2_QUOTE = 0001H ; P_QUOTE >> 16
|
---|
215 |
|
---|
216 | ;
|
---|
217 | ; Cf. struct _new_proc in <sys/emx.h>
|
---|
218 | ;
|
---|
219 | ; Note: Fields sorted by size to avoid problems with alignment (gcc!)
|
---|
220 | ;
|
---|
221 | NEW_PROC STRUC
|
---|
222 | NP_ARG_OFF DD ? ; Pointer to arguments (offset)
|
---|
223 | NP_ENV_OFF DD ? ; Pointer to environment (offset)
|
---|
224 | NP_FNAME_OFF DD ? ; Pointer to file name (offset)
|
---|
225 | NP_ARG_SEL DW ? ; Pointer to arguments (selector)
|
---|
226 | NP_ENV_SEL DW ? ; Pointer to environment (selector)
|
---|
227 | NP_FNAME_SEL DW ? ; Pointer to file name (selector)
|
---|
228 | NP_ARG_COUNT DW ? ; Number of arguments
|
---|
229 | NP_ARG_SIZE DW ? ; Size of arguments
|
---|
230 | NP_ENV_COUNT DW ? ; Number of environment strings
|
---|
231 | NP_ENV_SIZE DW ? ; Size of environment
|
---|
232 | NP_MODE1 DW ? ; Lower 16 bits of mode (see above)
|
---|
233 | NP_MODE2 DW ? ; Upper 16 bits of mode (note 2)
|
---|
234 | ; The fields below are in addition to the structure passed to function 7F06H
|
---|
235 | NP_PARENT DW ? ; Pointer to parent process (note 3)
|
---|
236 | NP_FPROC DW ? ; Pointer to files process (note 4)
|
---|
237 | NEW_PROC ENDS
|
---|
238 |
|
---|
239 | NP_USER_SIZE = NEW_PROC.NP_MODE2 ; Size of structure passed to
|
---|
240 | ; function 7F06H
|
---|
241 | ;
|
---|
242 | ; Note 2: The NP_MODE2 field of the NEW_PROC structure is ignored unless
|
---|
243 | ; Bit 15 of NP_MODE1 is set.
|
---|
244 | ;
|
---|
245 | ; Note 3: The NP_PARENT field of the NEW_PROC structure points to the
|
---|
246 | ; process table entry of the process starting the new process.
|
---|
247 | ; If the new process is exec'ed (not spawned), this is *not*
|
---|
248 | ; the parent process.
|
---|
249 | ;
|
---|
250 | ; Note 4: The NP_FPROC field of the NEW_PROC structure points to the
|
---|
251 | ; process table entry of the process from which the file handles
|
---|
252 | ; and signal settings are to be inherited.
|
---|
253 | ;
|
---|
254 |
|
---|
255 | ;
|
---|
256 | ; Timers
|
---|
257 | ;
|
---|
258 | TT_NONE = 0
|
---|
259 | TT_EXPIRED = 1
|
---|
260 | TT_ALARM = 2
|
---|
261 | TT_SLEEP = 3
|
---|
262 | TT_TERMIO_TIME = 4
|
---|
263 |
|
---|
264 | TT_RUNNING = TT_ALARM ; T_TYPE >= TT_RUNNING -> running
|
---|
265 |
|
---|
266 | TIMER STRUC
|
---|
267 | T_TYPE DW ? ; Type of timer
|
---|
268 | T_PROCESS DW ? ; Pointer to process table entry
|
---|
269 | T_TICKS DD ? ; Remaining timer ticks
|
---|
270 | TIMER ENDS
|
---|
271 |
|
---|
272 | ;
|
---|
273 | ; Status of floating point unit emulator. Some of the status information
|
---|
274 | ; should be kept in P_STATUS of the PTE for the client process instead.
|
---|
275 | ;
|
---|
276 | FES_OFF = 0 ; FPU emu not loaded
|
---|
277 | FES_NONE = 1 ; Failed to load the FPU emu
|
---|
278 | FES_LOADING = 2 ; Loading the FPU emu
|
---|
279 | FES_INIT1 = 3 ; Initialization, sending FPUN_NEWPROC
|
---|
280 | FES_ON = 4 ; Normal state of the FPU emu
|
---|
281 | FES_NEWPROC = 5 ; New process started
|
---|
282 | FES_ENDPROC = 6 ; Process ended
|
---|
283 |
|
---|
284 | SV_DATA SEGMENT
|
---|
285 | EXTERNDEF CLOCK_LO:DWORD
|
---|
286 | EXTERNDEF CLOCK_HI:DWORD
|
---|
287 | SV_DATA ENDS
|
---|
288 |
|
---|
289 | IFNDEF __PROCESS
|
---|
290 |
|
---|
291 | SV_DATA SEGMENT
|
---|
292 |
|
---|
293 | EXTRN PROCESS_TABLE:DWORD
|
---|
294 | EXTRN PROC0:PROCESS
|
---|
295 | EXTRN PROCESS_PTR:WORD
|
---|
296 | EXTRN PROCESS_SIG:WORD
|
---|
297 | EXTRN PROCESS_FP:WORD
|
---|
298 | EXTRN PROCESS_FPUEMU:WORD
|
---|
299 | EXTRN PROCESS_FPUCLIENT:WORD
|
---|
300 | EXTRN VIDEO_LIN:DWORD
|
---|
301 | EXTRN TIMER_TABLE:DWORD
|
---|
302 | EXTRN TIMER_MIN:DWORD
|
---|
303 | EXTRN TIMER_TICKS:DWORD
|
---|
304 | EXTRN FPUEMU_STATE:BYTE
|
---|
305 | EXTRN NP1:NEW_PROC
|
---|
306 | EXTRN EMX_DIR:BYTE
|
---|
307 |
|
---|
308 | SV_DATA ENDS
|
---|
309 |
|
---|
310 |
|
---|
311 | SV_CODE SEGMENT
|
---|
312 |
|
---|
313 | EXTRN NEW_PROCESS:NEAR
|
---|
314 | EXTRN FIND_PROCESS:NEAR
|
---|
315 | EXTRN REMOVE_PROCESS:NEAR
|
---|
316 | EXTRN ZOMBIE_PROCESS:NEAR
|
---|
317 | EXTRN KILL_PROCESS:NEAR
|
---|
318 | EXTRN SAVE_PROCESS:NEAR
|
---|
319 | EXTRN REST_PROCESS:NEAR
|
---|
320 | EXTRN WAIT_PROCESS:NEAR
|
---|
321 | EXTRN SET_TIMER:NEAR
|
---|
322 | EXTRN SLEEP:NEAR
|
---|
323 | EXTRN SET_COMMIT:NEAR
|
---|
324 | EXTRN CREATE_PID:NEAR
|
---|
325 | EXTRN FIND_EXEC:NEAR
|
---|
326 | EXTRN FPUEMU_LOAD:NEAR
|
---|
327 | EXTRN FPUEMU_CALL:NEAR
|
---|
328 | EXTRN FPUEMU_ENDPROC:NEAR
|
---|
329 | EXTRN FPUEMU_NEWPROC:NEAR
|
---|
330 |
|
---|
331 | SV_CODE ENDS
|
---|
332 |
|
---|
333 |
|
---|
334 | INIT_CODE SEGMENT
|
---|
335 |
|
---|
336 | EXTRN PROCESS_INIT:NEAR
|
---|
337 |
|
---|
338 | INIT_CODE ENDS
|
---|
339 |
|
---|
340 | ENDIF
|
---|