1 /* C K U S I G -- Kermit signal handling for Unix and OS/2 systems */
4 Author: Jeffrey Altman (jaltman@secure-endpoints.com),
5 Secure Endpoints Inc., New York City.
7 Copyright (C) 1985, 2004,
8 Trustees of Columbia University in the City of New York.
9 All rights reserved. See the C-Kermit COPYING.TXT file or the
10 copyright text in the ckcmai.c module for disclaimer and permissions.
13 #include "ckcasc.h" /* ASCII character symbols */
14 #include "ckcdeb.h" /* Debug & other symbols */
15 #include "ckcker.h" /* Kermit symbols */
16 #include "ckcnet.h" /* Network symbols */
31 extern ckjmpbuf cmjbuf;
35 #define signal msignal
41 SIGTYP (*msignal(int type, SIGTYP (*func)(int)))(int);
45 /* We know these are set here. MUST unset them before the definitions. */
46 #define signal vsignal
48 SIGTYP (*vsignal(int type, SIGTYP (*func)(int)))(int);
49 int valarm(int interval);
53 #define signal asignal
55 #define SIGALRM (_NUMSIG+1)
57 SIGTYP (*asignal(int type, SIGTYP (*func)(int)))(int);
58 unsigned aalarm(unsigned);
67 mov eax, dword ptr [esp+0x10]
77 exception_filter( void )
79 GetExceptionInformation ;
80 return( EXCEPTION_EXECUTE_HANDLER ) ;
93 cc_execute( ckjptr(sj_buf), ck_sigfunc dofunc, ck_sigfunc failfunc )
95 cc_execute( sj_buf, dofunc, failfunc)
105 sj_buf->retcode = 0 ;
106 sj_buf->Id = GetCurrentThreadId() ;
107 memset( &sj_buf->context, 0, sizeof(CONTEXT) );
108 sj_buf->context.ContextFlags = CONTEXT_FULL ;
110 GetThreadContext(GetCurrentThread(), &(sj_buf->context) ) ;
113 mov ecx,dword ptr [sj_buf]
114 mov dword ptr [ecx+0xc4],esp
116 sj_buf->context.EFlags = 530 ;
117 sj_buf->context.Eip = ckgetIP()+0x0C ;
121 mov eax, dword ptr [sj_buf]
137 cksetjmp(ckjdref(sj_buf))
143 mov esp, ESPToRestore
149 rc = sj_buf->retcode ;
158 __except(exception_filter())
160 debug(F100,"cc_execute __except","",0);
166 longjmp(ckjdref(sj_buf),SIGINT);
174 #endif /* NOCCTRAP */
177 #ifdef CK_ANSIC /* ANSIC C declaration... */
178 alrm_execute(ckjptr(sj_buf),
185 #else /* Not ANSIC C ... */
198 #endif /* CK_ANSIC */
204 _PROTOTYP(SIGTYP (*savhandler), (int));
206 savalrm = alarm(timo);
207 savhandler = signal(SIGALRM, handler);
210 sj_buf->retcode = 0 ;
211 sj_buf->Id = GetCurrentThreadId();
212 memset(&sj_buf->context, 0, sizeof(CONTEXT));
213 sj_buf->context.ContextFlags = CONTEXT_FULL;
215 GetThreadContext(GetCurrentThread(), &(sj_buf->context));
219 mov eax, dword ptr [sj_buf]
236 cksetjmp(ckjdref(sj_buf))
246 __except( exception_filter() )
248 debug(F100,"alrm_execute __except","",0);
249 debug(F111,"exception_filter",
253 longjmp(ckjdref(sj_buf),SIGINT);
261 signal( SIGALRM, savhandler ) ;
266 #ifdef CK_ANSIC /* ANSIC C declaration... */
267 cc_alrm_execute(ckjptr(sj_buf),
274 #else /* Not ANSIC C ... */
276 cc_alrm_execute(sj_buf,
287 #endif /* CK_ANSIC */
289 /* cc_alrm_execute */ {
293 _PROTOTYP(SIGTYP (*savhandler), (int));
294 savalrm = alarm(timo);
295 savhandler = signal( SIGALRM, handler );
298 sj_buf->retcode = 0 ;
299 sj_buf->Id = GetCurrentThreadId() ;
300 memset( &sj_buf->context, 0, sizeof(CONTEXT) );
301 sj_buf->context.ContextFlags = CONTEXT_FULL ;
303 GetThreadContext( GetCurrentThread(), &(sj_buf->context) ) ;
307 mov eax, dword ptr [sj_buf]
324 cksetjmp(ckjdref(sj_buf))
334 __except( exception_filter() )
336 debug(F100,"cc_alrm_execute __except","",0);
342 longjmp(ckjdref(sj_buf),SIGINT) ;
350 signal(SIGALRM,savhandler);