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
|
/* C K C S I G . H */
/* Definitions and prototypes for signal handling */
/*
Author: Jeffrey E Altman (jaltman@secure-endpoints.com),
Secure Endpoints Inc., New York City.
Copyright (C) 1985, 2009,
Trustees of Columbia University in the City of New York.
All rights reserved. See the C-Kermit COPYING.TXT file or the
copyright text in the ckcmai.c module for disclaimer and permissions.
*/
#ifdef OS2
#ifndef NT
#ifndef __HEV__ /* INCL_SEMAPHORE may also define HEV */
#define __HEV__
typedef ULONG HEV; /* hev */
typedef HEV *PHEV;
#endif /* __HEV__ */
#endif /* NT */
struct _threadinfo {
int inuse;
int child;
int sibling;
#ifdef NT
HANDLE id;
HANDLE handle;
HANDLE parent;
HANDLE CompletionSem ;
HANDLE DieSem ;
#else /* NT */
TID id;
TID parent;
HEV CompletionSem;
HEV DieSem;
#endif /* NT */
};
#endif /* OS2 */
#ifdef CK_ANSIC
typedef SIGTYP (*ck_sigfunc)(void *);
typedef SIGTYP (*ck_sighand)(int);
#else
typedef SIGTYP (*ck_sigfunc)();
typedef SIGTYP (*ck_sighand)();
#endif /* CK_ANSIC */
/* Macros for POSIX vs old-style signal handling. */
#ifdef CK_POSIX_SIG
typedef sigjmp_buf ckjmpbuf;
#else
#ifdef NT
#define NOCRYPT
#include <windows.h>
#ifdef NTASM
typedef struct {
CONTEXT context;
DWORD retcode;
} ckjmpbuf;
#else /* NTASM */
typedef jmp_buf ckjmpbuf;
#endif /* NTASM */
#else
typedef jmp_buf ckjmpbuf;
#endif
#endif /* CK_POSIX_SIG */
/*
Suppose you want to pass the address of a jmp_buf bar to a function foo.
Since jmp_buf is normally defined (typedef'd) as an array, you would do
it like this: foo(bar), where foo = foo(jmp_buf bar). But suppose a
jmp_buf is (say) a struct rather than an array. Then you must do
foo(&bar) where foo is foo(jmp_buf * bar). This is controlled here in
the traditional fashion, by ifdefs. By default, we assume that jmp_buf
is an array. Define the symbol JBNOTARRAY if jmp_buf is not an array.
*/
#ifndef JBNOTARRAY
#ifdef NT
#define JBNOTARRAY
#endif /* NT */
#endif /* JBNOTARRAY */
#ifdef JBNOTARRAY
typedef ckjmpbuf * ckjptr;
#define ckjaddr(x) & x
#define ckjdref(x) * x
#ifdef CK_POSIX_SIG
#define cksetjmp(x) sigsetjmp(x,1)
#define cklongjmp(x,y) siglongjmp(x,y)
#else
#ifdef NT
__inline int
ck_ih(void) {
extern int TlsIndex;
#ifdef NTSIG
struct _threadinfo * threadinfo;
threadinfo = (struct _threadinfo *) TlsGetValue(TlsIndex);
if (threadinfo) {
if (WaitAndResetSem(threadinfo->DieSem,0)) {
ckThreadDie(threadinfo);
return 1; /* This should never execute */
}
}
#ifdef COMMENT
else debug( F100, "ck_ih() threadinfo is NULL","",0);
#endif /* COMMENT */
#endif /* NTSIG */
return 0;
}
#ifdef NTSIG
#define cksetjmp(x) setjmp(x)
#define cklongjmp(x,y) longjmp(x,y)
#else /* NTSIG */
#ifdef NTASM
__inline DWORD
cksetjmp( ckjptr jmp ) {
extern int isinterrupted;
jmp->retcode = 0;
memset( &jmp->context, 0, sizeof(CONTEXT) );
jmp->context.ContextFlags = CONTEXT_FULL ;
if ( !GetThreadContext( GetCurrentThread(), &jmp->context ) )
debug( F101, "cksetjmp GetThreadContext failed","",GetLastError());
debug(F101,"cksetjmp returns","",jmp->retcode);
isinterrupted = 0;
return (jmp->retcode);
}
__inline void
cklongjmp( ckjptr jmp, int retval ) {
extern HANDLE tidCommand;
extern int ttyfd, mdmtyp ;
extern DWORD CommandID;
extern int isinterrupted;
connoi();
isinterrupted = 1;
jmp->retcode = ( retval ? retval : 1 );
debug(F101,"about to SetThreadContext for thread","", CommandID);
debug(F101,"from Thread","",GetCurrentThreadId());
if ( mdmtyp >= 0 ) {
PurgeComm( (HANDLE) ttyfd, PURGE_TXABORT | PURGE_RXABORT );
}
if (SetThreadContext( tidCommand, &jmp->context ))
debug(F100,"cklongjmp SetThreadContext success","",0);
else
debug(F101,"cklongjmp SetThreadContext failed","",GetLastError());
msleep(50);
cmini(1); /* Reset command parser */
putkey(13); /* Stuff a carriage return */
/* PostEventAvailSem(); */
}
#else /* NTASM */
void crash( void ) ;
#define cksetjmp(x) setjmp(x)
__inline void
cklongjmp( ckjptr jmp, int retval ) {
extern HANDLE tidCommand;
extern int ttyfd, mdmtyp;
extern DWORD CommandID;
CONTEXT context;
if ( mdmtyp >= 0 ) {
PurgeComm( (HANDLE) ttyfd, PURGE_TXABORT | PURGE_RXABORT ) ;
}
memset( &context, 0, sizeof(CONTEXT) );
context.ContextFlags = CONTEXT_FULL;
if ( !GetThreadContext( tidCommand, &context ) )
debug( F101, "cklongjmp GetThreadContext failed","",GetLastError());
/* Invalidate the instruction pointer */
context.Eip = (unsigned long) crash;
debug(F101,"about to SetThreadContext for thread","", CommandID);
debug(F101,"from Thread","",GetCurrentThreadId());
if (SetThreadContext( tidCommand, &context ))
debug(F100,"cklongjmp SetThreadContext success","",0);
else
debug(F101,"cklongjmp SetThreadContext failed","",GetLastError());
}
#endif /* NTASM */
#endif /* NTSIG */
#else /* NT */
#define cksetjmp(x) setjmp(x)
#define cklongjmp(x,y) longjmp(x,y)
#endif /* NT */
#endif /* CK_POSIX_SIG */
#else /* jmp_buf is an array */
typedef ckjmpbuf ckjptr;
#define ckjaddr(x) x
#define ckjdref(x) x
#ifdef CK_POSIX_SIG
#define cksetjmp(x) sigsetjmp(x,1)
#define cklongjmp(x,y) siglongjmp(x,y)
#else
#define cksetjmp(x) setjmp(x)
#define cklongjmp(x,y) longjmp(x,y)
#endif /* CK_POSIX_SIG */
#endif /* JBNOTARRAY */
_PROTOTYP( int cc_execute, (ckjptr, ck_sigfunc, ck_sigfunc) );
_PROTOTYP( int alrm_execute,
(ckjptr,
int /* timo */,
ck_sighand /* handler */,
ck_sigfunc, ck_sigfunc) );
_PROTOTYP( int cc_alrm_execute,
(ckjptr,
int /* timo */,
ck_sighand /* handler */,
ck_sigfunc,
ck_sigfunc) );
/* End of ckusig.h */
|