Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/mach-dep/signal-util.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/mach-dep/signal-util.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 569 - (view) (download) (as text)

1 : monnier 249 /* signal-util.c
2 :     *
3 :     * COPYRIGHT (c) 1995 by AT&T Bell Laboratories.
4 :     *
5 :     * System independent utility routines for supporting signals and
6 :     * software polling.
7 :     */
8 :    
9 :     #include <stdio.h>
10 :     #include "ml-base.h"
11 :     #include "ml-limits.h"
12 :     #include "ml-state.h"
13 :     #include "vproc-state.h"
14 :     #include "ml-objects.h"
15 :     #include "ml-signals.h"
16 :     #include "system-signals.h"
17 :    
18 :    
19 :     /* ChooseSignal:
20 :     *
21 :     * Choose which signal to pass to the ML handler and setup the ML state
22 :     * vector accordingly.
23 :     * WARNING: This should be called with signals masked to avoid race
24 :     * conditions.
25 :     */
26 :     void ChooseSignal (vproc_state_t *vsp)
27 :     {
28 :     ASSERT(vsp->vp_numInQ > 0);
29 :    
30 :     /* record the signal and count */
31 :     vsp->vp_sigCode = vsp->vp_pendingSigQ[vsp->vp_nextPendingSig].sigNum;
32 :     vsp->vp_sigCount = vsp->vp_pendingSigQ[vsp->vp_nextPendingSig].count;
33 :     if (IS_SYSTEM_SIG(vsp->vp_sigCode))
34 : monnier 439 vsp->vp_numPendingSysSigs -= vsp->vp_sigCount;
35 :     else
36 : monnier 249 vsp->vp_numPendingSigs -= vsp->vp_sigCount;
37 :    
38 :     /* advance the pending queue */
39 :     if ((--vsp->vp_numInQ == 0) || (++vsp->vp_nextPendingSig == NUM_SIGS))
40 :     vsp->vp_nextPendingSig = 0;
41 :    
42 :     #ifdef SIGNAL_DEBUG
43 :     SayDebug ("ChooseSignal: sig = %d, count = %d\n",
44 :     vsp->vp_sigCode, vsp->vp_sigCount);
45 :     #endif
46 :    
47 :     } /* end of ChooseSignal */
48 :    
49 :    
50 :     /* EnqueueSignal:
51 :     *
52 :     * Add a signal to the pending queue; if the signal is already present, then
53 :     * bump its count.
54 :     */
55 :     void EnqueueSignal (vproc_state_t *vsp, int sigCode)
56 :     {
57 :     int i, j;
58 :    
59 :     #ifdef SIGNAL_DEBUG
60 :     SayDebug("EnqueueSignal: numInQ = %d, sig = %d\n", vsp->vp_numInQ, sigCode);
61 :     #endif
62 :    
63 :     ASSERT(vsp->vp_numInQ >= 0);
64 :    
65 :     for (i = vsp->vp_nextPendingSig, j = vsp->vp_numInQ; --j >= 0; ) {
66 :     if (vsp->vp_pendingSigQ[i].sigNum == sigCode)
67 :     break;
68 :     if (++i == NUM_SIGS) i = 0;
69 :     }
70 :     if (j < 0) {
71 :     vsp->vp_pendingSigQ[i].sigNum = sigCode;
72 :     vsp->vp_pendingSigQ[i].count = 1;
73 :     vsp->vp_numInQ++;
74 :     }
75 :     else
76 :     vsp->vp_pendingSigQ[i].count++;
77 :    
78 :     } /* end of EnqueueSignal */
79 :    
80 :    
81 :     /* MakeResumeCont:
82 :     *
83 :     * Build the resume continuation for a signal or poll event handler.
84 :     * This closure contains the address of the resume entry-point and
85 :     * the registers from the ML State.
86 :     *
87 :     * At least 4K avail. heap assumed.
88 :     */
89 :     ml_val_t MakeResumeCont (ml_state_t *msp, ml_val_t resume[])
90 :     {
91 :     /* allocate the resumption closure */
92 :     ML_AllocWrite(msp, 0, MAKE_DESC(10, DTAG_record));
93 :     ML_AllocWrite(msp, 1, PTR_CtoML(resume));
94 :     ML_AllocWrite(msp, 2, msp->ml_arg);
95 :     ML_AllocWrite(msp, 3, msp->ml_cont);
96 :     ML_AllocWrite(msp, 4, msp->ml_closure);
97 :     ML_AllocWrite(msp, 5, msp->ml_linkReg);
98 :     ML_AllocWrite(msp, 6, msp->ml_pc);
99 :     ML_AllocWrite(msp, 7, msp->ml_exnCont);
100 :     ML_AllocWrite(msp, 8, msp->ml_varReg);
101 :     ML_AllocWrite(msp, 9, msp->ml_calleeSave[0]);
102 :     ML_AllocWrite(msp, 10, msp->ml_calleeSave[1]);
103 :     ML_AllocWrite(msp, 11, msp->ml_calleeSave[2]);
104 :    
105 :     return ML_Alloc(msp, 11);
106 :    
107 :     } /* end of MakeResumeCont */
108 :    
109 :    
110 :     /* MakeHandlerArg:
111 :     *
112 :     * Build the argument record for the ML signal handler. It has the type
113 :     *
114 :     * val sigHandler : (int * int * unit cont) -> 'a
115 :     *
116 :     * The first argument is the signal code, the second is the signal count and the
117 :     * third is the resumption continuation. The ML signal handler should never
118 :     * return.
119 :     * NOTE: maybe this should be combined with ChooseSignal???
120 :     */
121 :     ml_val_t MakeHandlerArg (ml_state_t *msp, ml_val_t resume[])
122 :     {
123 :     ml_val_t resumeCont, arg;
124 :     vproc_state_t *vsp = msp->ml_vproc;
125 :    
126 :     resumeCont = MakeResumeCont(msp, resume);
127 :    
128 :     /* allocate the ML signal handler's argument record */
129 :     REC_ALLOC3(msp, arg,
130 :     INT_CtoML(vsp->vp_sigCode), INT_CtoML(vsp->vp_sigCount),
131 :     resumeCont);
132 :    
133 :     #ifdef SIGNAL_DEBUG
134 :     SayDebug ("MakeHandlerArg: resumeC = %#x, arg = %#x\n", resumeCont, arg);
135 :     #endif
136 :     return arg;
137 :    
138 :     } /* end of MakeHandlerArg */
139 :    
140 :    
141 :     /* LoadResumeState:
142 :     *
143 :     * Load the ML state with the state preserved in resumption continuation
144 :     * made by MakeResumeCont.
145 :     */
146 :     void LoadResumeState (ml_state_t *msp)
147 :     {
148 :     ml_val_t *contClosure;
149 :     #ifdef SIGNAL_DEBUG
150 :     SayDebug ("LoadResumeState:\n");
151 :     #endif
152 :    
153 :     contClosure = PTR_MLtoC(ml_val_t, msp->ml_closure);
154 :    
155 : monnier 439 msp->ml_arg = contClosure[1];
156 :     msp->ml_cont = contClosure[2];
157 :     msp->ml_closure = contClosure[3];
158 :     msp->ml_linkReg = contClosure[4];
159 :     msp->ml_pc = contClosure[5];
160 :     msp->ml_exnCont = contClosure[6];
161 :     msp->ml_varReg = contClosure[7];
162 :     msp->ml_calleeSave[0] = contClosure[8];
163 :     msp->ml_calleeSave[1] = contClosure[9];
164 :     msp->ml_calleeSave[2] = contClosure[10];
165 : monnier 249
166 :     } /* end of LoadResumeState */
167 :    
168 :    
169 :     /* GCSignal:
170 :     *
171 :     * Record a garbage collection signal (if enabled). Return true, if a signal
172 :     * was recorded.
173 :     */
174 :     bool_t GCSignal (vproc_state_t *vsp)
175 :     {
176 :     if (vsp->vp_gcSigState == ML_SIG_ENABLED) {
177 :     vsp->vp_numPendingSigs++;
178 :     EnqueueSignal (vsp, RUNSIG_GC);
179 :     return TRUE;
180 :     }
181 :     else
182 :     return FALSE;
183 :    
184 :     } /* end of GCSignal */
185 :    

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0