3 ****************************************************************************
4 * Copyright IBM Corporation 1988, 1989 - All Rights Reserved *
6 * Permission to use, copy, modify, and distribute this software and its *
7 * documentation for any purpose and without fee is hereby granted, *
8 * provided that the above copyright notice appear in all copies and *
9 * that both that copyright notice and this permission notice appear in *
10 * supporting documentation, and that the name of IBM not be used in *
11 * advertising or publicity pertaining to distribution of the software *
12 * without specific, written prior permission. *
14 * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL *
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL IBM *
16 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY *
17 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER *
18 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING *
19 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
20 ****************************************************************************
23 /*******************************************************************\
25 * Information Technology Center *
26 * Carnegie-Mellon University *
29 \*******************************************************************/
33 #ifndef __LWP_INCLUDE_
34 #define __LWP_INCLUDE_ 1
39 #ifdef HAVE_SYS_TYPES_H
40 #include <sys/types.h>
42 #ifdef HAVE_SYS_SELECT_H
43 #include <sys/select.h>
48 #ifdef HAVE_POSIX_SIGNALS
49 #define AFS_POSIX_SIGNALS 1
53 #define LWP_EBADPID -1
54 #define LWP_EBLOCKED -2
56 #define LWP_EMAXPROC -4
57 #define LWP_ENOBLOCK -5
59 #define LWP_ENOPROCESS -7
60 #define LWP_ENOWAIT -8
61 #define LWP_EBADCOUNT -9
62 #define LWP_EBADEVENT -10
63 #define LWP_EBADPRI -11
64 #define LWP_NO_STACK -12
65 /* These two are for the signal mechanism. */
66 #define LWP_EBADSIG -13 /* bad signal number */
67 #define LWP_ESYSTEM -14 /* system call failed */
68 /* These are for the rock mechanism */
69 #define LWP_ENOROCKS -15 /* all rocks are in use */
70 #define LWP_EBADROCK -16 /* the specified rock does not exist */
73 /* Maximum priority permissible (minimum is always 0) */
74 #define LWP_MAX_PRIORITY 4 /* changed from 1 by Satya, 22 Nov. 85 */
76 /* Usual priority used by user LWPs */
77 #define LWP_NORMAL_PRIORITY (LWP_MAX_PRIORITY-2)
79 /* Initial size of eventlist in a PCB; grows dynamically */
82 typedef struct lwp_pcb
*PROCESS
;
84 struct lwp_context
{ /* saved context for dispatcher */
85 char *topstack
; /* ptr to top of process stack */
89 #define nregs (7+1+62+2)
91 #define nregs (7+1+32+2+32+2) /* g1-g7, y reg, f0-f31, fsr, fq, c0-c31, csr, cq. */
96 long globals
[8]; /* g1-g7 and y registers. */
99 #if defined(powerpc) || defined(ppc) || defined(powerc) || defined(__POWERPC__)
100 char *linkRegister
; /* the contents of the link register */
101 long conditionRegister
; /* the contents of the condition register */
102 #endif /* defined(powerpc) || defined(ppc) || defined(powerc) || defined(__POWERPC__) */
106 {/* to hide things associated with this LWP under */
107 int tag
; /* unique identifier for this rock */
108 char *value
; /* pointer to some arbitrary data structure */
111 #define MAXROCKS 4 /* max no. of rocks per LWP */
113 struct lwp_pcb
{ /* process control block */
114 char name
[32]; /* ASCII name */
115 int rc
; /* most recent return code */
116 char status
; /* status flags */
117 char blockflag
; /* if (blockflag), process blocked */
118 char eventlistsize
; /* size of eventlist array */
119 char padding
; /* force 32-bit alignment */
120 char **eventlist
; /* ptr to array of eventids */
121 int eventcnt
; /* no. of events currently in eventlist array*/
122 int wakevent
; /* index of eventid causing wakeup */
123 int waitcnt
; /* min number of events awaited */
124 int priority
; /* dispatching priority */
125 struct lwp_pcb
*misc
; /* for LWP internal use only */
126 char *stack
; /* ptr to process stack */
127 int stacksize
; /* size of stack */
128 long stackcheck
; /* first word of stack for overflow checking */
129 void (*ep
)(); /* initial entry point */
130 char *parm
; /* initial parm for process */
132 context
; /* saved context for next dispatch */
133 int rused
; /* no of rocks presently in use */
134 struct rock rlist
[MAXROCKS
]; /* set of rocks to hide things under */
135 struct lwp_pcb
*next
, *prev
; /* ptrs to next and previous pcb */
136 int level
; /* nesting level of critical sections */
137 struct IoRequest
*iomgrRequest
; /* request we're waiting for */
138 int index
; /* LWP index: should be small index; actually is
139 incremented on each lwp_create_process */
142 extern int lwp_nextindex
; /* Next lwp index to assign */
146 #define LWP_INVALIDTHREADID (-1)
147 #define LWP_ActiveProcess (lwp_cpptr+0)
148 #define LWP_Index() (LWP_ActiveProcess->index)
149 #define LWP_HighestIndex() (lwp_nextindex - 1)
150 #define LWP_SignalProcess(event) LWP_INTERNALSIGNAL(event, 1)
151 #define LWP_NoYieldSignal(event) LWP_INTERNALSIGNAL(event, 0)
155 PROCESS lwp_cpptr
; /* pointer to current process pcb */
157 struct lwp_ctl
{ /* LWP control structure */
158 int processcnt
; /* number of lightweight processes */
159 char *outersp
; /* outermost stack pointer */
160 struct lwp_pcb
*outerpid
; /* process carved by Initialize */
161 struct lwp_pcb
*first
, last
; /* ptrs to first and last pcbs */
163 double dsptchstack
[100]; /* stack for dispatcher use only */
164 /* force 8 byte alignment */
166 char dsptchstack
[800]; /* stack for dispatcher use only */
173 int lwp_debug
; /* ON = show LWP debugging trace */
175 #if defined(AFS_SUN5_ENV) || defined(AFS_LINUX_ENV)
176 #define AFS_POSIX_SIGNALS
180 * Under some unices any stack size smaller than 16K seems prone to
181 * overflow problems. Set it to a somewhat larger value.
184 #define AFS_LWP_MINSTACKSIZE (100 * 1024)
186 /* Action to take on stack overflow. */
187 #define LWP_SOQUIET 1 /* do nothing */
188 #define LWP_SOABORT 2 /* abort the program */
189 #define LWP_SOMESSAGE 3 /* print a message and be quiet */
190 extern int lwp_overflowAction
;
192 /* Tells if stack size counting is enabled. */
193 extern int lwp_stackUseEnabled
;
194 extern int lwp_MaxStackSeen
;
198 int LWP_QSignal(PROCESS
);
199 int LWP_DispatchProcess(void);
200 int LWP_InitializeProcessSupport(int, PROCESS
*);
201 int LWP_DestroyProcess(PROCESS
);
204 /* exported interface */
205 int LWP_CreateProcess(void (*)(), int, int, char *, const char *, PROCESS
*);
206 int LWP_CurrentProcess(PROCESS
*);
207 int LWP_WaitProcess(void *);
208 int LWP_INTERNALSIGNAL(void *, int);
209 int LWP_DispatchProcess(void);
210 int LWP_GetProcessPriority(PROCESS pid
, int *priority
);
211 int LWP_TerminateProcessSupport(void);
212 int LWP_MwaitProcess(int wcount
, char *evlist
[]);
213 int LWP_StackUsed(PROCESS pid
, int *max
, int *used
);
215 void IOMGR_Sleep(unsigned int);
216 int IOMGR_Select(int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*);
217 long IOMGR_Poll(void);
218 int IOMGR_Cancel(PROCESS
);
219 int IOMGR_Initialize(void);
220 int IOMGR_SoftSig(void (*aproc
)(), char *arock
);
221 int IOMGR_Finalize(void);
222 int IOMGR_Signal (int signo
, char *event
);
223 int IOMGR_CancelSignal (int signo
);
225 int LWP_NewRock(int Tag
, char *Value
);
226 int LWP_GetRock(int Tag
, char **Value
);
229 #endif /* __LWP_INCLUDE_ */