3 /* Definitions and prototypes for signal handling */
6 Author: Jeffrey E Altman (jaltman@secure-endpoints.com),
7 Secure Endpoints Inc., New York City.
9 Copyright (C) 1985, 2009,
10 Trustees of Columbia University in the City of New York.
11 All rights reserved. See the C-Kermit COPYING.TXT file or the
12 copyright text in the ckcmai.c module for disclaimer and permissions.
16 #ifndef __HEV__ /* INCL_SEMAPHORE may also define HEV */
18 typedef ULONG HEV; /* hev */
30 HANDLE CompletionSem ;
42 typedef SIGTYP (*ck_sigfunc)(void *);
43 typedef SIGTYP (*ck_sighand)(int);
45 typedef SIGTYP (*ck_sigfunc)();
46 typedef SIGTYP (*ck_sighand)();
49 /* Macros for POSIX vs old-style signal handling. */
52 typedef sigjmp_buf ckjmpbuf;
63 typedef jmp_buf ckjmpbuf;
66 typedef jmp_buf ckjmpbuf;
68 #endif /* CK_POSIX_SIG */
70 Suppose you want to pass the address of a jmp_buf bar to a function foo.
71 Since jmp_buf is normally defined (typedef'd) as an array, you would do
72 it like this: foo(bar), where foo = foo(jmp_buf bar). But suppose a
73 jmp_buf is (say) a struct rather than an array. Then you must do
74 foo(&bar) where foo is foo(jmp_buf * bar). This is controlled here in
75 the traditional fashion, by ifdefs. By default, we assume that jmp_buf
76 is an array. Define the symbol JBNOTARRAY if jmp_buf is not an array.
82 #endif /* JBNOTARRAY */
85 typedef ckjmpbuf * ckjptr;
86 #define ckjaddr(x) & x
87 #define ckjdref(x) * x
89 #define cksetjmp(x) sigsetjmp(x,1)
90 #define cklongjmp(x,y) siglongjmp(x,y)
97 struct _threadinfo * threadinfo;
98 threadinfo = (struct _threadinfo *) TlsGetValue(TlsIndex);
100 if (WaitAndResetSem(threadinfo->DieSem,0)) {
101 ckThreadDie(threadinfo);
102 return 1; /* This should never execute */
106 else debug( F100, "ck_ih() threadinfo is NULL","",0);
112 #define cksetjmp(x) setjmp(x)
113 #define cklongjmp(x,y) longjmp(x,y)
117 cksetjmp( ckjptr jmp ) {
118 extern int isinterrupted;
120 memset( &jmp->context, 0, sizeof(CONTEXT) );
121 jmp->context.ContextFlags = CONTEXT_FULL ;
122 if ( !GetThreadContext( GetCurrentThread(), &jmp->context ) )
123 debug( F101, "cksetjmp GetThreadContext failed","",GetLastError());
124 debug(F101,"cksetjmp returns","",jmp->retcode);
126 return (jmp->retcode);
130 cklongjmp( ckjptr jmp, int retval ) {
131 extern HANDLE tidCommand;
132 extern int ttyfd, mdmtyp ;
133 extern DWORD CommandID;
134 extern int isinterrupted;
138 jmp->retcode = ( retval ? retval : 1 );
139 debug(F101,"about to SetThreadContext for thread","", CommandID);
140 debug(F101,"from Thread","",GetCurrentThreadId());
142 PurgeComm( (HANDLE) ttyfd, PURGE_TXABORT | PURGE_RXABORT );
144 if (SetThreadContext( tidCommand, &jmp->context ))
145 debug(F100,"cklongjmp SetThreadContext success","",0);
147 debug(F101,"cklongjmp SetThreadContext failed","",GetLastError());
149 cmini(1); /* Reset command parser */
150 putkey(13); /* Stuff a carriage return */
151 /* PostEventAvailSem(); */
155 #define cksetjmp(x) setjmp(x)
157 cklongjmp( ckjptr jmp, int retval ) {
158 extern HANDLE tidCommand;
159 extern int ttyfd, mdmtyp;
160 extern DWORD CommandID;
164 PurgeComm( (HANDLE) ttyfd, PURGE_TXABORT | PURGE_RXABORT ) ;
166 memset( &context, 0, sizeof(CONTEXT) );
167 context.ContextFlags = CONTEXT_FULL;
168 if ( !GetThreadContext( tidCommand, &context ) )
169 debug( F101, "cklongjmp GetThreadContext failed","",GetLastError());
171 /* Invalidate the instruction pointer */
172 context.Eip = (unsigned long) crash;
174 debug(F101,"about to SetThreadContext for thread","", CommandID);
175 debug(F101,"from Thread","",GetCurrentThreadId());
176 if (SetThreadContext( tidCommand, &context ))
177 debug(F100,"cklongjmp SetThreadContext success","",0);
179 debug(F101,"cklongjmp SetThreadContext failed","",GetLastError());
184 #define cksetjmp(x) setjmp(x)
185 #define cklongjmp(x,y) longjmp(x,y)
187 #endif /* CK_POSIX_SIG */
188 #else /* jmp_buf is an array */
189 typedef ckjmpbuf ckjptr;
193 #define cksetjmp(x) sigsetjmp(x,1)
194 #define cklongjmp(x,y) siglongjmp(x,y)
196 #define cksetjmp(x) setjmp(x)
197 #define cklongjmp(x,y) longjmp(x,y)
198 #endif /* CK_POSIX_SIG */
199 #endif /* JBNOTARRAY */
201 _PROTOTYP( int cc_execute, (ckjptr, ck_sigfunc, ck_sigfunc) );
202 _PROTOTYP( int alrm_execute,
205 ck_sighand /* handler */,
206 ck_sigfunc, ck_sigfunc) );
207 _PROTOTYP( int cc_alrm_execute,
210 ck_sighand /* handler */,
214 /* End of ckusig.h */