File: ckusig.c

package info (click to toggle)
ckermit 193-3
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 6,180 kB
  • ctags: 8,803
  • sloc: ansic: 118,504; makefile: 2,474; sh: 52
file content (345 lines) | stat: -rw-r--r-- 7,497 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
/* C K U S I G  --  Kermit signal handling for Unix and OS/2 systems */

/*
  Author: Jeffrey Altman (jaltman@columbia.edu),
  Columbia University Academic Information Systems, New York City.

  Copyright (C) 1985, 1998, Trustees of Columbia University in the City of New
  York.  The C-Kermit software may not be, in whole or in part, licensed or
  sold for profit as a software product itself, nor may it be included in or
  distributed with commercial products or otherwise distributed by commercial
  concerns to their clients or customers without written permission of the
  Office of Kermit Development and Distribution, Columbia University.  This
  copyright notice must not be removed, altered, or obscured.
*/
#include "ckcsym.h"
#include "ckcasc.h"			/* ASCII character symbols */
#include "ckcdeb.h"			/* Debug & other symbols */
#include "ckcker.h"			/* Kermit symbols */
#include "ckcnet.h"			/* Network symbols */
#ifndef NOSPL
#include "ckuusr.h"
#endif /* NOSPL */

#include <signal.h>
#ifdef NT
#include <setjmpex.h>
#include <excpt.h>
#else /* NT */
#include <setjmp.h>
#endif /* NT */
#include "ckcsig.h"

#ifdef NOCCTRAP
extern ckjmpbuf cmjbuf;
#endif /* NOCCTRAP */

#ifdef MAC
#define signal msignal
#define SIGTYP long
#define alarm malarm
#define SIG_IGN 0
#define SIGALRM 1
#define SIGINT  2
SIGTYP (*msignal(int type, SIGTYP (*func)(int)))(int);
#endif /* MAC */

#ifdef STRATUS
/* We know these are set here.  MUST unset them before the definitions. */
#define signal vsignal
#define alarm valarm
SIGTYP (*vsignal(int type, SIGTYP (*func)(int)))(int);
int valarm(int interval);
#endif /* STRATUS */

#ifdef AMIGA
#define signal asignal
#define alarm aarlarm
#define SIGALRM (_NUMSIG+1)
#define SIGTYP void
SIGTYP (*asignal(int type, SIGTYP (*func)(int)))(int);
unsigned aalarm(unsigned);
#endif /* AMIGA */

#ifdef NTASM
DWORD
ckgetIP(void)
{
   __asm 
   {
      mov eax, dword ptr [esp+0x10]
      jmp ckgetIP + 0x18
   }
   return 1;

}
#endif /* NTASM */

#ifdef NT
DWORD
exception_filter( void ) 
{
   GetExceptionInformation ;
   return( EXCEPTION_EXECUTE_HANDLER ) ;
}
void
crash( void ) 
{
   int x = 0, y = 0 ;
    x / y ;
}
#endif /* NT */

#ifndef NOCCTRAP
int
#ifdef CK_ANSIC
cc_execute( ckjptr(sj_buf), ck_sigfunc dofunc, ck_sigfunc failfunc ) 
#else
cc_execute( sj_buf, dofunc, failfunc)
    ckjptr(sj_buf);
    ck_sigfunc dofunc;
    ck_sigfunc failfunc;
#endif /* CK_ANSIC */
/* cc_execute */ {
    int rc = 0 ;
#ifdef NTASM
   DWORD Eip, Esp ;
    isinterrupted = 0;
    sj_buf->retcode = 0 ;
    sj_buf->Id = GetCurrentThreadId() ;
    memset( &sj_buf->context, 0, sizeof(CONTEXT) );
    sj_buf->context.ContextFlags = CONTEXT_FULL ;
#ifndef COMMENT
    GetThreadContext(GetCurrentThread(), &(sj_buf->context) ) ;
    __asm
    {
          mov       ecx,dword ptr [sj_buf]
          mov       dword ptr [ecx+0xc4],esp
    }
   sj_buf->context.EFlags = 530 ;
   sj_buf->context.Eip = ckgetIP()+0x0C ;
#else /* COMMENT */
   __asm 
   {
      mov eax, dword ptr [sj_buf]
      push eax
      mov eax, 0xfffffffe
      push eax
      mov eax, 0x00000039
      mov edx,esp
      int 0x2e
      pop eax
      pop eax
   }
#endif /* COMMENT */
#endif /* NTASM */
    if (
#ifdef NTASM
         isinterrupted
#else
		 cksetjmp(ckjdref(sj_buf))
#endif /* NTASM */
		 ) {
#ifdef NTASM
          __asm
            {
                mov esp, ESPToRestore 
            }
            isinterrupted = 0 ;
#endif /* NTASM */
            (*failfunc)(NULL) ;
#ifdef NTASM
             rc = sj_buf->retcode ;
#else /* NTASM */
             rc = -1 ;
#endif  /* NTASM */
         } else {			
#ifdef NT
            __try {
               (*dofunc)(NULL) ;
            } 
            __except( exception_filter() )
            {
               debug(F100,"cc_execute __except","",0);
               debug(F111,"exception_filter","_exception_code", GetExceptionCode() ) ;
               longjmp(ckjdref(sj_buf),SIGINT) ;
            }
#else /* NT */
            (*dofunc)(NULL) ;
#endif /* NT */
         }
   return rc ;
}
#endif /* NOCCTRAP */

int
#ifdef CK_ANSIC				/* ANSIC C declaration... */
alrm_execute(ckjptr(sj_buf),
	     int timo,
	     ck_sighand handler,
	     ck_sigfunc dofunc,
	     ck_sigfunc failfunc
	     ) 

#else /* Not ANSIC C ... */

alrm_execute(sj_buf,
	     timo,
	     handler,
	     dofunc,
	     failfunc
	     )
    ckjptr(sj_buf);
    int timo;
    ck_sighand handler;
    ck_sigfunc dofunc;
    ck_sigfunc failfunc;
#endif /* CK_ANSIC */

/* alrm_execute */ {

    int rc = 0;
    int savalrm = 0;
_PROTOTYP(SIGTYP (*savhandler), (int));

    savalrm = alarm(timo);
    savhandler = signal(SIGALRM, handler);

#ifdef NTASM
    sj_buf->retcode = 0 ;
    sj_buf->Id = GetCurrentThreadId();
    memset(&sj_buf->context, 0, sizeof(CONTEXT));
    sj_buf->context.ContextFlags = CONTEXT_FULL;
#ifndef COMMENT
    GetThreadContext(GetCurrentThread(), &(sj_buf->context));
#else
   __asm 
   {
      mov eax, dword ptr [sj_buf]
      push eax
      mov eax, 0xfffffffe
      push eax
      mov eax, 0x00000039
      mov edx,esp
      int 0x2e
      pop eax
      pop eax
   }
#endif
    isinterrupted = 0;
#endif /* NTASM */
    if (
#ifdef NTASM
		 sj_buf->retcode
#else
		 cksetjmp(ckjdref(sj_buf))
#endif /* NTASM */
		) {
	(*failfunc)(NULL) ;
	rc = -1 ;
    } else {	
#ifdef NT 
       __try {
          (*dofunc)(NULL) ;
       } 
       __except( exception_filter() )
       {
          debug(F100,"alrm_execute __except","",0);
          debug(F111,"exception_filter","_exception_code", GetExceptionCode() ) ;
          longjmp(ckjdref(sj_buf),SIGINT) ;
       }
#else /* NT */
       (*dofunc)(NULL) ;
#endif /* NT */
    }
    alarm(savalrm) ;
    if ( savhandler )
        signal( SIGALRM, savhandler ) ;
    return rc ;
}

int
#ifdef CK_ANSIC				/* ANSIC C declaration... */
cc_alrm_execute(ckjptr(sj_buf),
		int timo,
		ck_sighand handler,
		ck_sigfunc dofunc,
		ck_sigfunc failfunc
		) 

#else /* Not ANSIC C ... */

cc_alrm_execute(sj_buf,
	     timo,
	     handler,
	     dofunc,
	     failfunc
	     )
    ckjptr(sj_buf);
    int timo;
    ck_sighand handler;
    ck_sigfunc dofunc;
    ck_sigfunc failfunc;
#endif /* CK_ANSIC */

/* cc_alrm_execute */ {

    int rc = 0;
    int savalrm = 0;
_PROTOTYP(SIGTYP (*savhandler), (int));
    savalrm = alarm(timo);
    savhandler = signal( SIGALRM, handler );

#ifdef NTASM
    sj_buf->retcode = 0 ;
    sj_buf->Id = GetCurrentThreadId() ;
    memset( &sj_buf->context, 0, sizeof(CONTEXT) );
    sj_buf->context.ContextFlags = CONTEXT_FULL ;
#ifndef COMMENT
    GetThreadContext( GetCurrentThread(), &(sj_buf->context) ) ;
#else
   __asm 
   {
      mov eax, dword ptr [sj_buf]
      push eax
      mov eax, 0xfffffffe
      push eax
      mov eax, 0x00000039
      mov edx,esp
      int 0x2e
      pop eax
      pop eax
   }
#endif
    isinterrupted = 0;
#endif /* NTASM */
    if (
#ifdef NTASM
		 sj_buf->retcode
#else
		 cksetjmp(ckjdref(sj_buf))
#endif /* NTASM */
		) {
	(*failfunc)(NULL) ;
	rc = -1 ;
    } else {			
#ifdef NT
       __try {
          (*dofunc)(NULL) ;
       } 
       __except( exception_filter() )
       {
          debug(F100,"cc_alrm_execute __except","",0);
          debug(F111,"exception_filter","_exception_code", GetExceptionCode() ) ;
          longjmp(ckjdref(sj_buf),SIGINT) ;
       }
#else /* NT */
       (*dofunc)(NULL) ;
#endif /* NT */
    }
    alarm(savalrm) ;
    if ( savhandler )
      signal( SIGALRM, savhandler ) ;
    return rc ;
}