[57cd6e]: src / c / unixint.d Maximize Restore History

Download this file

unixint.d    1281 lines (1232 with data), 37.8 kB

   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
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
/* -*- mode: c; c-basic-offset: 8 -*- */
/*
unixint.c -- Unix interrupt interface.
*/
/*
Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya.
Copyright (c) 1990, Giuseppe Attardi.
Copyright (c) 2001, Juan Jose Garcia Ripoll.
ECL is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
See file '../Copyright' for full details.
*/
/**********************************************************************
* HOW WE HANDLE SIGNALS AND EXCEPTIONS
*
* (the following should be correlated with the manual)
*
* POSIX contemplates the notion of "signals", which are events that
* cause a process or a thread to be interrupted. Windows uses the
* term "exception", which includes also a more general kind of
* errors.
*
* In both cases the consequence is that a thread or process may be
* interrupted at any time, either by causes which are intrinsic to
* them (synchronous signals), such as floating point exceptions, or
* extrinsic (asynchronous signals), such as the process being aborted
* by the user.
*
* Of course, those interruptions are not always welcome. When the
* interrupt is delivered and a handler is invoked, the thread or even
* the whole program may be in an inconsistent state. For instance the
* thread may have acquired a lock, or it may be in the process of
* filling the fields of a structure. Understanding this POSIX
* restricts severely what functions can be called from a signal
* handler, thereby limiting its usefulness.
*
* There is a simple solution, which ECL uses, and which is to mark
* sections of code which are interruptible, and in which it is safe
* for the handler to run arbitrary code, protect anything else. In
* principle this "marking" can be done using POSIX functions such as
* pthread_sigmask() or sigprocmask().
*
* However in practice this is slow, as it involves at least a
* function call, resolving thread-local variables, etc, etc, and it
* will not work in Windows. Furthermore, sometimes we want signals to
* be detected but not to be immediately processed. For instance, when
* reading from the terminal we want to be able to interrupt the
* process, but we can not execute the code from the handler, since
* read() may leave the input stream in an inconsistent, or even
* locked state.
*
* Our approach is slightly different: we install our own signal
* hander which reads a single, thread-local variable stored in the
* ecl_process_env()->disable_interrupts. If the variable marks that
* signals should be postponed, then the information about the signal
* is queued. Otherwise the appropriate code is executed: for instance
* invoking the debugger, jumping to a condition handler, quitting,
* etc.
*/
#ifdef __sun__
/* For SA_SIGINFO in Solaris. We could have used _XOPEN_SOURCE=600, but
* this requires C99 and the default GCC for Solaris (3.4.3) does not
* support this C standard. */
# define __EXTENSIONS__
#endif
#include <errno.h>
#include <string.h>
#include <stdio.h>
/* To get APCProc calls */
#define _WIN32_WINNT 0x400
#include <signal.h>
#if defined(_MSC_VER) || defined(__MINGW32__)
# include <windows.h>
#endif
#if !defined(_MSC_VER)
# include <unistd.h>
#endif
#include <ecl/ecl.h>
#ifdef ECL_USE_MPROTECT
# ifndef SA_SIGINFO
# error "We cannot use the mmap code without siginfo"
# endif
# include <sys/mman.h>
#endif
#include <ecl/internal.h>
#include <ecl/ecl-inl.h>
#include <ecl/impl/math_fenv.h>
static struct {
int code;
char *text;
} known_signals[] = {
#ifdef SIGHUP
{ SIGHUP, "+SIGHUP+" },
#endif
#ifdef SIGINT
{ SIGINT, "+SIGINT+" },
#endif
#ifdef SIGQUIT
{ SIGQUIT, "+SIGQUIT+" },
#endif
#ifdef SIGILL
{ SIGILL, "+SIGILL+" },
#endif
#ifdef SIGTRAP
{ SIGTRAP, "+SIGTRAP+" },
#endif
#ifdef SIGABRT
{ SIGABRT, "+SIGABRT+" },
#endif
#ifdef SIGEMT
{ SIGEMT, "+SIGEMT+" },
#endif
#ifdef SIGFPE
{ SIGFPE, "+SIGFPE+" },
#endif
#ifdef SIGKILL
{ SIGKILL, "+SIGKILL+" },
#endif
#ifdef SIGBUS
{ SIGBUS, "+SIGBUS+" },
#endif
#ifdef SIGSEGV
{ SIGSEGV, "+SIGSEGV+" },
#endif
#ifdef SIGSYS
{ SIGSYS, "+SIGSYS+" },
#endif
#ifdef SIGPIPE
{ SIGPIPE, "+SIGPIPE+" },
#endif
#ifdef SIGALRM
{ SIGALRM, "+SIGALRM+" },
#endif
#ifdef SIGTERM
{ SIGTERM, "+SIGTERM+" },
#endif
#ifdef SIGURG
{ SIGURG, "+SIGURG+" },
#endif
#ifdef SIGSTOP
{ SIGSTOP, "+SIGSTOP+" },
#endif
#ifdef SIGTSTP
{ SIGTSTP, "+SIGTSTP+" },
#endif
#ifdef SIGCONT
{ SIGCONT, "+SIGCONT+" },
#endif
#ifdef SIGCHLD
{ SIGCHLD, "+SIGCHLD+" },
#endif
#ifdef SIGTTIN
{ SIGTTIN, "+SIGTTIN+" },
#endif
#ifdef SIGTTOU
{ SIGTTOU, "+SIGTTOU+" },
#endif
#ifdef SIGIO
{ SIGIO, "+SIGIO+" },
#endif
#ifdef SIGXCPU
{ SIGXCPU, "+SIGXCPU+" },
#endif
#ifdef SIGXFSZ
{ SIGXFSZ, "+SIGXFSZ+" },
#endif
#ifdef SIGVTALRM
{ SIGVTALRM, "+SIGVTALRM+" },
#endif
#ifdef SIGPROF
{ SIGPROF, "+SIGPROF+" },
#endif
#ifdef SIGWINCH
{ SIGWINCH, "+SIGWINCH+" },
#endif
#ifdef SIGINFO
{ SIGINFO, "+SIGINFO+" },
#endif
#ifdef SIGUSR1
{ SIGUSR1, "+SIGUSR1+" },
#endif
#ifdef SIGUSR2
{ SIGUSR2, "+SIGUSR2+" },
#endif
#ifdef SIGTHR
{ SIGTHR, "+SIGTHR+" },
#endif
{ -1, "" }
};
#ifdef HAVE_SIGPROCMASK
static sigset_t main_thread_sigmask;
# define handler_fn_protype(name, sig, info, aux) name(sig, info, aux)
# define call_handler(name, sig, info, aux) name(sig, info, aux)
# define reinstall_signal(x,y)
# define copy_siginfo(x,y) memcpy(x, y, sizeof(struct sigaction))
static void
mysignal(int code, void *handler)
{
struct sigaction action;
sigaction(code, NULL, &action);
if (handler == SIG_IGN || handler == SIG_DFL) {
action.sa_handler = handler;
} else {
#ifdef SA_SIGINFO
/* void (*handler)(int, siginfo_t *, void*) */
action.sa_sigaction = handler;
action.sa_flags = SA_SIGINFO;
#else
/* void (*handler)(int) */
action.sa_handler = handler;
action.sa_flags = 0;
#endif
sigfillset(&action.sa_mask);
}
sigaction(code, &action, NULL);
}
#else /* HAVE_SIGPROCMASK */
# define handler_fn_protype(name, sig, info, aux) name(sig)
# define call_handler(name, sig, info, aux) name(sig)
# define mysignal(x,y) signal(x,y)
# define reinstall_signal(x,y) signal(x,y)
# define copy_siginfo(x,y)
#endif
static bool
zombie_process(cl_env_ptr the_env)
{
#ifdef ECL_THREADS
if (the_env == NULL) {
return 1;
} else {
/* When we are exiting a thread, we simply ignore all signals. */
cl_object process = the_env->own_process;
return (process->process.phase == ECL_PROCESS_INACTIVE);
}
#else
return !the_env;
#endif
}
static ECL_INLINE bool
interrupts_disabled_by_C(cl_env_ptr the_env)
{
return the_env->disable_interrupts;
}
static ECL_INLINE bool
interrupts_disabled_by_lisp(cl_env_ptr the_env)
{
return (ecl_option_values[ECL_OPT_BOOTED] &&
ecl_symbol_value(@'ext::*interrupts-enabled*') == Cnil);
}
/* On platforms in which mprotect() works, we block all write access
* to the environment for a cheap check of pending interrupts. On
* other platforms we change the value of disable_interrupts to 3, so
* that we detect changes. */
static ECL_INLINE void
set_guard_page(cl_env_ptr the_env)
{
#if defined(ECL_USE_MPROTECT)
if (mprotect(the_env, sizeof(*the_env), PROT_READ) < 0) {
ecl_internal_error("Unable to mprotect environment.");
}
#elif defined(ECL_USE_GUARD_PAGE)
if (!VirtualProtect(the_env, sizeof(*the_env), PAGE_GUARD, NULL)) {
ecl_internal_error("Unable to mprotect environment.");
}
#endif
}
static cl_object pop_signal(cl_env_ptr env);
static cl_object
handler_fn_protype(lisp_signal_handler, int sig, siginfo_t *info, void *aux)
{
/* The lisp environment might not be installed. */
cl_env_ptr the_env = ecl_process_env();
if (zombie_process(the_env))
return Cnil;
switch (sig) {
case SIGINT:
return @'si::terminal-interrupt';
case SIGFPE: {
cl_object condition = @'arithmetic-error';
int code = 0;
#ifdef _MSC_VER
switch (_fpecode) {
case _FPE_INVALID:
condition = @'floating-point-invalid-operation';
code = FE_INVALID;
break;
case _FPE_OVERFLOW:
condition = @'floating-point-overflow';
code = FE_OVERFLOW;
break;
case _FPE_UNDERFLOW:
condition = @'floating-point-underflow';
code = FE_UNDERFLOW;
break;
case _FPE_ZERODIVIDE:
condition = @'division-by-zero';
code = FE_DIVBYZERO;
break;
}
#else
# if defined(HAVE_FENV_H) & !defined(ECL_AVOID_FENV_H)
code = fetestexcept(FE_ALL_EXCEPT);
if (code & FE_DIVBYZERO) {
condition = @'division-by-zero';
code = FE_DIVBYZERO;
} else if (code & FE_INVALID) {
condition = @'floating-point-invalid-operation';
code = FE_INVALID;
} else if (code & FE_OVERFLOW) {
condition = @'floating-point-overflow';
code = FE_OVERFLOW;
} else if (code & FE_UNDERFLOW) {
condition = @'floating-point-underflow';
code = FE_UNDERFLOW;
} else if (code & FE_INEXACT) {
condition = @'floating-point-inexact';
code = FE_INEXACT;
}
feclearexcept(FE_ALL_EXCEPT);
# endif
#endif /* !_MSC_VER */
#ifdef SA_SIGINFO
if (info) {
if (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV) {
condition = @'division-by-zero';
code = FE_DIVBYZERO;
} else if (info->si_code == FPE_FLTOVF) {
condition = @'floating-point-overflow';
code = FE_OVERFLOW;
} else if (info->si_code == FPE_FLTUND) {
condition = @'floating-point-underflow';
code = FE_UNDERFLOW;
} else if (info->si_code == FPE_FLTRES) {
condition = @'floating-point-inexact';
code = FE_INEXACT;
} else if (info->si_code == FPE_FLTINV) {
condition = @'floating-point-invalid-operation';
code = FE_INVALID;
}
}
#endif
/*
if (code && !(code & the_env->trap_fpe_bits))
condition = Cnil;
*/
si_trap_fpe(@'last', Ct);
return condition;
}
case SIGSEGV:
return @'ext::segmentation-violation';
#ifdef SIGBUS
case SIGBUS:
return @'ext::segmentation-violation';
#endif
#ifdef SIGILL
case SIGILL:
return @'ext::illegal-instruction';
#endif
#ifdef SIGCHLD
case SIGCHLD:
return @'si::wait-for-all-processes';
#endif
default:
return MAKE_FIXNUM(sig);
}
}
#define unblock_signal(env, sig)
#ifdef HAVE_SIGPROCMASK
# undef unblock_signal
static void
unblock_signal(cl_env_ptr the_env, int signal)
{
/*
* We do not really "unblock" the signal, but rather restore
* ECL's default sigmask.
*/
# ifdef ECL_THREADS
pthread_sigmask(SIG_SETMASK, the_env->default_sigmask, NULL);
# else
sigprocmask(SIG_SETMASK, the_env->default_sigmask, NULL);
# endif
}
#endif
ecl_def_ct_base_string(str_ignore_signal,"Ignore signal",13,static,const);
static void
handle_signal_now(cl_object signal_code)
{
switch (type_of(signal_code)) {
case t_fixnum:
cl_cerror(4, str_ignore_signal, @'ext::unix-signal-received',
@':code', signal_code);
break;
case t_symbol:
cl_cerror(2, str_ignore_signal, signal_code);
break;
case t_cfun:
case t_cfunfixed:
case t_cclosure:
case t_bytecodes:
case t_bclosure:
cl_funcall(1, signal_code);
default:
break;
}
}
cl_object
si_handle_signal(cl_object signal_code)
{
handle_signal_now(signal_code);
@(return)
}
static void
handle_all_queued(cl_env_ptr env)
{
while (env->pending_interrupt != Cnil) {
handle_signal_now(pop_signal(env));
}
}
static void
queue_signal(cl_env_ptr env, cl_object code, int allocate)
{
ECL_WITH_SPINLOCK_BEGIN(env, &env->signal_queue_spinlock) {
cl_object record;
if (allocate) {
record = ecl_list1(Cnil);
} else {
record = ECL_CONS_CAR(env->signal_queue);
if (record != Cnil) {
env->signal_queue = ECL_CONS_CDR(record);
}
}
if (record != Cnil) {
ECL_RPLACD(record, env->pending_interrupt);
ECL_RPLACA(record, code);
env->pending_interrupt = record;
}
} ECL_WITH_SPINLOCK_END;
}
static cl_object
pop_signal(cl_env_ptr env)
{
cl_object record, value;
if (env->pending_interrupt == Cnil) {
return Cnil;
}
ECL_WITH_SPINLOCK_BEGIN(env, &env->signal_queue_spinlock) {
record = env->pending_interrupt;
value = ECL_CONS_CAR(record);
env->pending_interrupt = ECL_CONS_CDR(record);
/* Save some conses for future use, to avoid allocating */
if (ECL_SYMBOLP(value) || ECL_FIXNUMP(value)) {
ECL_RPLACD(record, env->signal_queue);
env->signal_queue = record;
}
} ECL_WITH_SPINLOCK_END;
return value;
}
static void
handle_or_queue(cl_env_ptr the_env, cl_object signal_code, int code)
{
if (Null(signal_code) || signal_code == NULL)
return;
/*
* If interrupts are disabled by lisp we are not so eager on
* detecting when the interrupts become enabled again. We
* queue the signal and are done with that.
*/
if (interrupts_disabled_by_lisp(the_env)) {
queue_signal(the_env, signal_code, 0);
}
/*
* If interrupts are disabled by C, and we have not pushed a
* pending signal, save this signal and return.
*/
else if (interrupts_disabled_by_C(the_env)) {
the_env->disable_interrupts = 3;
queue_signal(the_env, signal_code, 0);
set_guard_page(the_env);
}
/*
* If interrupts are enabled, that means we are in a safe area
* and may execute arbitrary lisp code. We can thus call the
* appropriate handlers.
*/
else {
if (code) unblock_signal(the_env, code);
si_trap_fpe(@'last', Ct); /* Clear FPE exception flag */
handle_signal_now(signal_code);
}
}
static void
handler_fn_protype(non_evil_signal_handler, int sig, siginfo_t *siginfo, void *data)
{
int old_errno = errno;
cl_env_ptr the_env;
cl_object signal_object;
reinstall_signal(sig, non_evil_signal_handler);
/* The lisp environment might not be installed. */
the_env = ecl_process_env();
if (zombie_process(the_env))
return;
if (!ecl_option_values[ECL_OPT_BOOTED]) {
ecl_internal_error("Got signal before environment was installed"
" on our thread.");
}
signal_object = call_handler(lisp_signal_handler, sig, siginfo, data);
handle_or_queue(the_env, signal_object, sig);
errno = old_errno;
}
#if defined(ECL_THREADS) && !defined(ECL_MS_WINDOWS_HOST)
static void
handler_fn_protype(process_interrupt_handler, int sig, siginfo_t *siginfo, void *data)
{
int old_errno = errno;
cl_env_ptr the_env;
reinstall_signal(sig, process_interrupt_handler);
/* The lisp environment might not be installed. */
the_env = ecl_process_env();
if (zombie_process(the_env))
return;
if (!Null(the_env->pending_interrupt)) {
if (interrupts_disabled_by_C(the_env)) {
set_guard_page(the_env);
} else if (!interrupts_disabled_by_lisp(the_env)) {
unblock_signal(the_env, sig);
handle_all_queued(the_env);
}
}
errno = old_errno;
}
#endif
static void
handler_fn_protype(sigsegv_handler, int sig, siginfo_t *info, void *aux)
{
int old_errno = errno;
static const char *stack_overflow_msg =
"\n;;;\n;;; Stack overflow.\n"
";;; Jumping to the outermost toplevel prompt\n"
";;;\n\n";
static const char *segv_msg =
"\n;;;\n"
";;; Detected access to protected memory, "
"also kwown as 'bus or segmentation fault'.\n"
";;; Jumping to the outermost toplevel prompt\n"
";;;\n\n";
cl_env_ptr the_env;
reinstall_signal(sig, sigsegv_handler);
if (!ecl_option_values[ECL_OPT_BOOTED]) {
ecl_internal_error("Got signal before environment was installed"
" on our thread.");
}
/* The lisp environment might not be installed. */
the_env = ecl_process_env();
if (zombie_process(the_env))
return;
#if defined(SA_SIGINFO)
# if defined(ECL_USE_MPROTECT)
/* We access the environment when it was protected. That
* means there was a pending signal. */
if (((char*)the_env <= (char*)info->si_addr) &&
((char*)info->si_addr <= (char*)(the_env+1)))
{
mprotect(the_env, sizeof(*the_env), PROT_READ | PROT_WRITE);
the_env->disable_interrupts = 0;
unblock_signal(the_env, sig);
handle_all_queued(the_env);
return;
}
# endif /* ECL_USE_MPROTECT */
# ifdef ECL_DOWN_STACK
if (sig == SIGSEGV &&
(char*)info->si_addr > the_env->cs_barrier &&
(char*)info->si_addr <= the_env->cs_org) {
unblock_signal(the_env, sig);
ecl_unrecoverable_error(the_env, stack_overflow_msg);
return;
}
# else
if (sig == SIGSEGV &&
(char*)info->si_addr < the_env->cs_barrier &&
(char*)info->si_addr >= the_env->cs_org) {
unblock_signal(the_env, sig);
ecl_unrecoverable_error(the_env, stack_overflow_msg);
return;
}
# endif /* ECL_DOWN_STACK */
/* Do not attempt an error handler if we nest two serious
* errors in the same thread */
if (the_env->fault_address == info->si_addr) {
the_env->fault_address = info->si_addr;
unblock_signal(the_env, sig);
ecl_unrecoverable_error(the_env, segv_msg);
} else {
the_env->fault_address = info->si_addr;
handle_or_queue(the_env, @'ext::segmentation-violation', sig);
}
#else
/*
* We cannot distinguish between a stack overflow and a simple
* access violation. Thus we assume the worst case and jump to
* the outermost handler.
*/
unblock_signal(the_env, sig);
ecl_unrecoverable_error(the_env, segv_msg);
#endif /* SA_SIGINFO */
errno = old_errno;
}
cl_object
si_check_pending_interrupts(void)
{
handle_all_queued(ecl_process_env());
@(return)
}
void
ecl_check_pending_interrupts(cl_env_ptr env)
{
handle_all_queued(env);
}
static cl_object
do_catch_signal(int code, cl_object action, cl_object process)
{
if (action == Cnil || action == @':ignore') {
mysignal(code, SIG_IGN);
return Ct;
} else if (action == @':default') {
mysignal(code, SIG_DFL);
return Ct;
} else if (action == Ct || action == @':catch') {
if (code == SIGSEGV) {
mysignal(code, sigsegv_handler);
}
#ifdef SIGBUS
else if (code == SIGBUS) {
mysignal(code, sigsegv_handler);
}
#endif
#ifdef SIGCHLD
else if (code == SIGCHLD) {
# ifndef ECL_THREADS
mysignal(code, non_evil_signal_handler);
# endif
}
#endif
#if defined(ECL_THREADS) && !defined(ECL_MS_WINDOWS_HOST)
else if (code == ecl_option_values[ECL_OPT_TRAP_INTERRUPT_SIGNAL]) {
mysignal(code, process_interrupt_handler);
}
#endif
else {
mysignal(code, non_evil_signal_handler);
}
}
#ifdef HAVE_SIGPROCMASK
# ifdef ECL_THREADS
if (type_of(process) == t_process) {
cl_env_ptr env = process->process.env;
sigset_t *handled_set = (sigset_t *)env->default_sigmask;
if (action == @':mask') {
sigaddset(handled_set, code);
} else if (action == @':unmask') {
sigdelset(handled_set, code);
} else {
return do_catch_signal(code, Ct, process);
}
if (env == ecl_process_env()) {
pthread_sigmask(SIG_SETMASK, handled_set, NULL);
}
return Ct;
}
# endif
{
sigset_t handled_set;
sigprocmask(SIG_SETMASK, NULL, &handled_set);
if (action == @':mask') {
sigaddset(&handled_set, code);
printf(";;; %d masked\n", code);
} else if (action == @':unmask') {
sigdelset(&handled_set, code);
printf(";;; %d unmasked\n", code);
} else {
return do_catch_signal(code, Ct, process);
}
sigprocmask(SIG_SETMASK, &handled_set, NULL);
return Ct;
}
#else
return Cnil;
#endif
}
@(defun ext::catch-signal (code flag &key process)
@
{
cl_object output = Cnil;
int code_int = ecl_to_int(code);
int i;
#ifdef GBC_BOEHM
# ifdef SIGSEGV
if ((code_int == SIGSEGV) && ecl_option_values[ECL_OPT_INCREMENTAL_GC])
FEerror("It is not allowed to change the behavior of SIGSEGV.",
0);
# endif
# ifdef SIGBUS
if (code_int == SIGBUS)
FEerror("It is not allowed to change the behavior of SIGBUS.",
0);
# endif
#endif
#if defined(ECL_THREADS) && !defined(ECL_MS_WINDOWS_HOST)
if (code_int == ecl_option_values[ECL_OPT_THREAD_INTERRUPT_SIGNAL]) {
FEerror("It is not allowed to change the behavior of ~D", 1,
MAKE_FIXNUM(code_int));
}
#endif
for (i = 0; known_signals[i].code >= 0; i++) {
if (known_signals[i].code == code_int) {
output = do_catch_signal(code_int, flag, process);
break;
}
}
@(return output)
}
@)
#ifdef ECL_THREADS
# ifdef ECL_WINDOWS_THREADS
static VOID CALLBACK
wakeup_function(ULONG_PTR foo)
{
cl_env_ptr env = ecl_process_env();
volatile i = env->nvalues;
env->nvalues = i;
}
static VOID CALLBACK
wakeup_noop(ULONG_PTR foo)
{
}
# endif
static bool
do_interrupt_thread(cl_object process)
{
# ifdef ECL_WINDOWS_THREADS
# ifndef ECL_USE_GUARD_PAGE
# error "Cannot implement ecl_interrupt_process without guard pages"
# endif
HANDLE thread = (HANDLE)process->process.thread;
CONTEXT context;
void *trap_address = process->process.env;
DWORD guard = PAGE_GUARD | PAGE_READWRITE;
int ok = 1;
if (SuspendThread(thread) == (DWORD)-1) {
FEwin32_error("Unable to suspend thread ~A", 1,
process);
ok = 0;
goto EXIT;
}
process->process.interrupt = Ct;
if (!VirtualProtect(process->process.env,
sizeof(struct cl_env_struct),
guard,
&guard))
{
FEwin32_error("Unable to protect memory from thread ~A",
1, process);
ok = 0;
}
RESUME:
if (!QueueUserAPC(wakeup_function, thread, 0)) {
FEwin32_error("Unable to queue APC call to thread ~A",
1, process);
ok = 0;
}
if (ResumeThread(thread) == (DWORD)-1) {
FEwin32_error("Unable to resume thread ~A", 1,
process);
ok = 0;
goto EXIT;
}
EXIT:
return ok;
# else
int signal = ecl_option_values[ECL_OPT_THREAD_INTERRUPT_SIGNAL];
if (pthread_kill(process->process.thread, signal)) {
FElibc_error("Unable to interrupt process ~A", 1,
process);
}
return 1;
# endif
}
void
ecl_interrupt_process(cl_object process, cl_object function)
{
/*
* We first ensure that the process is active and running
* and past the initialization phase, where it has set up
* the environment. Then:
* - In Windows it sets up a trap in the stack, so that the
* uncaught exception handler can catch it and process it.
* - In POSIX systems it sends a user level interrupt to
* the thread, which then decides how to act.
*
* If FUNCTION is NIL, we just intend to wake up the process
* from some call to ecl_musleep() Queue the interrupt for any
* process stage that can potentially receive a signal */
if (!Null(function) &&
(process->process.phase >= ECL_PROCESS_BOOTING))
{
function = si_coerce_to_function(function);
queue_signal(process->process.env, function, 1);
}
/* ... but only deliver if the process is still alive */
if (process->process.phase == ECL_PROCESS_ACTIVE)
do_interrupt_thread(process);
}
void
ecl_wakeup_process(cl_object process)
{
# ifdef ECL_WINDOWS_THREADS
HANDLE thread = (HANDLE)process->process.thread;
if (!QueueUserAPC(wakeup_noop, thread, 0)) {
FEwin32_error("Unable to queue APC call to thread ~A",
1, process);
}
# else
do_interrupt_thread(process);
# endif
}
#endif /* ECL_THREADS */
#ifdef ECL_WINDOWS_THREADS
static LPTOP_LEVEL_EXCEPTION_FILTER old_W32_exception_filter = NULL;
LONG WINAPI
_ecl_w32_exception_filter(struct _EXCEPTION_POINTERS* ep)
{
LONG excpt_result;
cl_env_ptr the_env = ecl_process_env();
excpt_result = EXCEPTION_CONTINUE_EXECUTION;
switch (ep->ExceptionRecord->ExceptionCode)
{
/* Access to guard page */
case STATUS_GUARD_PAGE_VIOLATION: {
cl_object process = the_env->own_process;
if (!Null(process->process.interrupt)) {
cl_object signal = pop_signal(the_env);
process->process.interrupt = Cnil;
while (signal != Cnil && signal) {
handle_signal_now(signal);
signal = pop_signal(the_env);
}
return EXCEPTION_CONTINUE_EXECUTION;
}
}
/* Catch all arithmetic exceptions */
case EXCEPTION_INT_DIVIDE_BY_ZERO:
handle_or_queue(the_env, @'division-by-zero', 0);
return EXCEPTION_CONTINUE_EXECUTION;
case EXCEPTION_INT_OVERFLOW:
handle_or_queue(the_env, @'arithmetic-error', 0);
return EXCEPTION_CONTINUE_EXECUTION;
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
handle_or_queue(the_env, @'floating-point-overflow', 0);
return EXCEPTION_CONTINUE_EXECUTION;
case EXCEPTION_FLT_OVERFLOW:
handle_or_queue(the_env, @'floating-point-overflow', 0);
return EXCEPTION_CONTINUE_EXECUTION;
case EXCEPTION_FLT_UNDERFLOW:
handle_or_queue(the_env, @'floating-point-underflow', 0);
return EXCEPTION_CONTINUE_EXECUTION;
case EXCEPTION_FLT_INEXACT_RESULT:
handle_or_queue(the_env, @'floating-point-inexact', 0);
return EXCEPTION_CONTINUE_EXECUTION;
case EXCEPTION_FLT_DENORMAL_OPERAND:
case EXCEPTION_FLT_INVALID_OPERATION:
handle_or_queue(the_env, @'floating-point-invalid-operation', 0);
return EXCEPTION_CONTINUE_EXECUTION;
case EXCEPTION_FLT_STACK_CHECK:
handle_or_queue(the_env, @'arithmetic-error', 0);
return EXCEPTION_CONTINUE_EXECUTION;
/* Catch segmentation fault */
case EXCEPTION_ACCESS_VIOLATION:
handle_or_queue(the_env, @'ext::segmentation-violation', 0);
return EXCEPTION_CONTINUE_EXECUTION;
/* Catch illegal instruction */
case EXCEPTION_ILLEGAL_INSTRUCTION:
handle_or_queue(the_env, @'ext::illegal-instruction', 0);
return EXCEPTION_CONTINUE_EXECUTION;
/* Do not catch anything else */
default:
excpt_result = EXCEPTION_CONTINUE_SEARCH;
break;
}
if (old_W32_exception_filter)
return old_W32_exception_filter(ep);
return excpt_result;
}
static cl_object
W32_handle_in_new_thread(cl_object signal_code)
{
int outside_ecl = ecl_import_current_thread(@'si::handle-signal', Cnil);
mp_process_run_function(3, @'si::handle-signal',
@'si::handle-signal',
signal_code);
if (outside_ecl) ecl_release_current_thread();
}
BOOL WINAPI W32_console_ctrl_handler(DWORD type)
{
switch (type)
{
/* Catch CTRL-C */
case CTRL_C_EVENT: {
cl_object function = SYM_FUN(@'si::terminal-interrupt');
if (function)
W32_handle_in_new_thread(function);
return TRUE;
}
}
return FALSE;
}
#endif /* ECL_WINDOWS_THREADS */
#if defined(ECL_THREADS) && defined(HAVE_SIGPROCMASK)
static cl_object
asynchronous_signal_servicing_thread()
{
const cl_env_ptr the_env = ecl_process_env();
sigset_t handled_set;
cl_object signal_code;
int signo;
int interrupt_signal = 0;
if (ecl_option_values[ECL_OPT_TRAP_INTERRUPT_SIGNAL]) {
interrupt_signal = ecl_option_values[ECL_OPT_THREAD_INTERRUPT_SIGNAL];
}
/*
* We wait here for all signals that are blocked in all other
* threads. It would be desirable to be able to wait for _all_
* signals, but this can not be done for SIGFPE, SIGSEGV, etc.
*/
pthread_sigmask(SIG_SETMASK, NULL, &handled_set);
/*
* Under OS X we also have to explicitely add the signal we
* use to communicate process interrupts. For some unknown
* reason those signals may get lost.
*/
#ifdef SIGCHLD
sigaddset(&handled_set, SIGCHLD);
#endif
if (interrupt_signal) {
sigaddset(&handled_set, interrupt_signal);
pthread_sigmask(SIG_SETMASK, &handled_set, NULL);
}
CL_CATCH_ALL_BEGIN(the_env) {
for (;;) {
/* Waiting may fail! */
int status = sigwait(&handled_set, &signo);
if (status == 0) {
#if 0
if (signo == interrupt_signal) {
/* If we get this signal it may be because
* of two reasons. One is that it is just
* an awake message. Then the queue is empty
* and we continue ... */
signal_code = pop_signal(the_env);
if (Null(signal_code))
continue;
/* ... the other one is that we are being
* interrupted, but this only happens when
* we quit */
break;
}
#else
if (signo == interrupt_signal) {
break;
}
#endif
#ifdef SIGCHLD
if (signo == SIGCHLD) {
si_wait_for_all_processes();
continue;
}
#endif
signal_code = call_handler(lisp_signal_handler, signo,
NULL, NULL);
if (!Null(signal_code)) {
mp_process_run_function(3, @'si::handle-signal',
@'si::handle-signal',
signal_code);
}
}
}
} CL_CATCH_ALL_END;
ecl_return0(the_env);
}
#endif
cl_object
si_trap_fpe(cl_object condition, cl_object flag)
{
cl_env_ptr the_env = ecl_process_env();
#ifndef FE_ALL_EXCEPT
# define FE_ALL_EXCEPT FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID
#endif
const int all = FE_ALL_EXCEPT;
int bits = 0;
if (condition == @'last') {
bits = the_env->trap_fpe_bits;
} else {
if (condition == Ct)
bits = FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID;
else if (condition == @'division-by-zero')
bits = FE_DIVBYZERO;
else if (condition == @'floating-point-overflow')
bits = FE_OVERFLOW;
else if (condition == @'floating-point-underflow')
bits = FE_UNDERFLOW;
else if (condition == @'floating-point-invalid-operation')
bits = FE_INVALID;
else if (condition == @'floating-point-inexact')
bits = FE_INEXACT;
else if (FIXNUMP(condition))
bits = fix(condition) & all;
if (flag == Cnil) {
bits = the_env->trap_fpe_bits & ~bits;
} else {
bits = the_env->trap_fpe_bits | bits;
}
}
#if !defined(ECL_AVOID_FPE_H)
# ifdef HAVE_FENV_H
feclearexcept(all);
# endif
# if defined(ECL_MS_WINDOWS_HOST)
_fpreset();
# endif
# ifdef HAVE_FEENABLEEXCEPT
fedisableexcept(all & ~bits);
feenableexcept(all & bits);
# endif
#endif
the_env->trap_fpe_bits = bits;
@(return MAKE_FIXNUM(bits))
}
/*
* In this code we decide whether to install a process-wide signal
* handler for each of the asynchronous signals (SIGINT, SIGTERM,
* SIGCHLD...) or we block the signal and let the background thread
* detect and process them.
*/
static void
install_asynchronous_signal_handlers()
{
#if defined(ECL_MS_WINDOWS_HOST)
# define async_handler(signal,handler,mask)
#else
# if defined(ECL_THREADS) && defined(HAVE_SIGPROCMASK)
# define async_handler(signal,handler,mask) { \
if (ecl_option_values[ECL_OPT_SIGNAL_HANDLING_THREAD]) { \
sigaddset(mask, signal); \
} else { \
mysignal(signal,handler); \
}}
# else
# define async_handler(signal,handler,mask) \
mysignal(signal,handler)
# endif
#endif
#ifdef HAVE_SIGPROCMASK
sigset_t *sigmask = cl_core.default_sigmask = &main_thread_sigmask;
cl_core.default_sigmask_bytes = sizeof(sigset_t);
# ifdef ECL_THREADS
pthread_sigmask(SIG_SETMASK, NULL, sigmask);
# else
sigprocmask(SIG_SETMASK, NULL, sigmask);
# endif
#endif
#ifdef SIGINT
if (ecl_option_values[ECL_OPT_TRAP_SIGINT]) {
async_handler(SIGINT, non_evil_signal_handler, sigmask);
}
#endif
#ifdef SIGCHLD
if (ecl_option_values[ECL_OPT_TRAP_SIGCHLD]) {
/* We have to set the process signal handler explicitly,
* because on many platforms the default is SIG_IGN. */
mysignal(SIGCHLD, lisp_signal_handler);
async_handler(SIGCHLD, lisp_signal_handler, sigmask);
}
#endif
#ifdef HAVE_SIGPROCMASK
# if defined(ECL_THREADS)
pthread_sigmask(SIG_SETMASK, sigmask, NULL);
# else
sigprocmask(SIG_SETMASK, sigmask, NULL);
# endif
#endif
#ifdef ECL_WINDOWS_THREADS
old_W32_exception_filter =
SetUnhandledExceptionFilter(_ecl_w32_exception_filter);
if (ecl_option_values[ECL_OPT_TRAP_SIGINT]) {
SetConsoleCtrlHandler(W32_console_ctrl_handler, TRUE);
}
#endif
#undef async_handler
}
/*
* In POSIX systems we may set up a background thread that detects
* synchronous signals and spawns a new thread to handle each of them.
*/
static void
install_signal_handling_thread()
{
#if defined(ECL_THREADS) && defined(HAVE_SIGPROCMASK)
ecl_process_env()->default_sigmask = &main_thread_sigmask;
if (ecl_option_values[ECL_OPT_SIGNAL_HANDLING_THREAD]) {
cl_object fun =
ecl_make_cfun((cl_objectfn_fixed)
asynchronous_signal_servicing_thread,
@'si::signal-servicing',
Cnil,
0);
cl_object process =
mp_process_run_function_wait(2,
@'si::signal-servicing',
fun);
if (Null(process)) {
ecl_internal_error("Unable to create signal "
"servicing thread");
}
}
#endif
}
/*
* This routine sets up handlers for all exceptions, such as access to
* restricted regions of memory. They have to be set up before we call
* init_GC().
*/
static void
install_synchronous_signal_handlers()
{
#ifdef SIGBUS
if (ecl_option_values[ECL_OPT_TRAP_SIGBUS]) {
mysignal(SIGBUS, sigsegv_handler);
}
#endif
#ifdef SIGSEGV
if (ecl_option_values[ECL_OPT_TRAP_SIGSEGV]) {
mysignal(SIGSEGV, sigsegv_handler);
}
#endif
#ifdef SIGPIPE
if (ecl_option_values[ECL_OPT_TRAP_SIGPIPE]) {
mysignal(SIGPIPE, non_evil_signal_handler);
}
#endif
#ifdef SIGILL
if (ecl_option_values[ECL_OPT_TRAP_SIGILL]) {
mysignal(SIGILL, non_evil_signal_handler);
}
#endif
/* In order to implement MP:INTERRUPT-PROCESS, MP:PROCESS-KILL
* and the like, we use signals. This sets up a synchronous
* signal handler for that particular signal.
*/
#ifdef SIGRTMIN
# define DEFAULT_THREAD_INTERRUPT_SIGNAL SIGRTMIN + 2
#else
# define DEFAULT_THREAD_INTERRUPT_SIGNAL SIGUSR1
#endif
#if defined(ECL_THREADS) && !defined(ECL_MS_WINDOWS_HOST)
if (ecl_option_values[ECL_OPT_TRAP_INTERRUPT_SIGNAL]) {
int signal = ecl_option_values[ECL_OPT_THREAD_INTERRUPT_SIGNAL];
if (signal == 0) {
signal = DEFAULT_THREAD_INTERRUPT_SIGNAL;
ecl_set_option(ECL_OPT_THREAD_INTERRUPT_SIGNAL,
signal);
}
mysignal(signal, process_interrupt_handler);
#ifdef HAVE_SIGROCMASK
sigdelset(ecl_process_env()->default_sigmask, signal);
pthread_sigmask(SIG_SETMASK, ecl_process_env()->default_sigmask, NULL);
#endif
}
#endif
}
/*
* This routine sets up handlers for floating point exceptions. We
* cannot do it earlier because it requires the memory allocator to
* be set up.
*/
static void
install_fpe_signal_handlers()
{
#ifdef SIGFPE
if (ecl_option_values[ECL_OPT_TRAP_SIGFPE]) {
mysignal(SIGFPE, non_evil_signal_handler);
si_trap_fpe(Ct, Ct);
# ifdef ECL_IEEE_FP
/* By default deactivate errors and accept
* denormals in floating point computations */
si_trap_fpe(@'floating-point-invalid-operation', Cnil);
si_trap_fpe(@'division-by-zero', Cnil);
si_trap_fpe(@'floating-point-overflow', Cnil);
# endif
}
#endif
}
/*
* Create one Common Lisp constant for each signal that we know,
* such as +SIGINT+ for SIGINT, etc.
*/
static void
create_signal_code_constants()
{
int i;
for (i = 0; known_signals[i].code >= 0; i++) {
cl_object name =
_ecl_intern(known_signals[i].text,
cl_core.ext_package);
cl_export2(name, cl_core.ext_package);
si_Xmake_constant(name, MAKE_FIXNUM(known_signals[i].code));
}
}
void
init_unixint(int pass)
{
if (pass == 0) {
install_asynchronous_signal_handlers();
install_synchronous_signal_handlers();
} else {
create_signal_code_constants();
install_fpe_signal_handlers();
install_signal_handling_thread();
ECL_SET(@'ext::*interrupts-enabled*', Ct);
ecl_process_env()->disable_interrupts = 0;
}
}