-
Notifications
You must be signed in to change notification settings - Fork 392
/
omrsignalTest.cpp
1508 lines (1274 loc) · 52.8 KB
/
omrsignalTest.cpp
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
/*******************************************************************************
* Copyright (c) 1991, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at http://eclipse.org/legal/epl-2.0
* or the Apache License, Version 2.0 which accompanies this distribution
* and is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License, v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception [1] and GNU General Public
* License, version 2 with the OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
/*
* $RCSfile: omrsignalTest.c,v $
* $Revision: 1.66 $
* $Date: 2013-03-21 14:42:10 $
*/
/**
* @file
* @ingroup PortTest
* @brief Verify port library signal handling.
*
* Exercise the API for port library signal handling. These functions
* can be found in the file @ref omrsignal.c
*
*/
#include <signal.h>
#if defined(OMR_OS_WINDOWS)
#include <process.h>
#endif /* defined(OMR_OS_WINDOWS) */
#if defined(J9ZOS390) && !defined(OMR_EBCDIC)
#include "atoe.h"
#endif
#include <string.h>
#include <stdlib.h>
#include "fltconst.h"
#include "omrthread.h"
#include "testHelpers.hpp"
#include "testProcessHelpers.hpp"
#include "omrport.h"
#define SIG_TEST_SIZE_EXENAME 1024
#if defined(OMR_PORT_ASYNC_HANDLER)
#if defined(OMR_OS_WINDOWS)
#define GET_PID() _getpid()
#else /* defined(OMR_OS_WINDOWS) */
#define GET_PID() getpid()
#endif /* defined(OMR_OS_WINDOWS) */
extern PortTestEnvironment *portTestEnv;
struct PortSigMap {
uint32_t portLibSignalNo;
const char *portLibSignalString ;
int osSignalNo;
const char *osSignalString;
} PortSigMap;
struct PortSigMap testSignalMap[] = {
#if defined(OMR_OS_WINDOWS)
{OMRPORT_SIG_FLAG_SIGQUIT, "OMRPORT_SIG_FLAG_SIGQUIT", SIGBREAK, "SIGBREAK"}
#else /* defined(OMR_OS_WINDOWS) */
{OMRPORT_SIG_FLAG_SIGQUIT, "OMRPORT_SIG_FLAG_SIGQUIT", SIGQUIT, "SIGQUIT"}
#endif /* defined(OMR_OS_WINDOWS) */
, {OMRPORT_SIG_FLAG_SIGABRT, "OMRPORT_SIG_FLAG_SIGABRT", SIGABRT, "SIGABRT"}
, {OMRPORT_SIG_FLAG_SIGTERM, "OMRPORT_SIG_FLAG_SIGTERM", SIGTERM, "SIGTERM"}
#if defined(AIXPPC)
, {OMRPORT_SIG_FLAG_SIGRECONFIG, "OMRPORT_SIG_FLAG_SIGRECONFIG", SIGRECONFIG, "SIGRECONFIG"}
#endif /* defined(AIXPPC) */
, {OMRPORT_SIG_FLAG_SIGINT, "OMRPORT_SIG_FLAG_SIGINT", SIGINT, "SIGINT"}
};
typedef struct AsyncHandlerInfo {
uint32_t expectedType;
const char *testName;
omrthread_monitor_t *monitor;
uint32_t controlFlag;
} AsyncHandlerInfo;
static uintptr_t asyncTestHandler1(struct OMRPortLibrary *portLibrary, uint32_t gpType, void *gpInfo, void *userData);
static uintptr_t asyncTestHandler2(struct OMRPortLibrary *portLibrary, uint32_t gpType, void *gpInfo, void *userData);
static void injectSignal(struct OMRPortLibrary *portLibrary, int pid, int signal);
#endif /* defined(OMR_PORT_ASYNC_HANDLER) */
typedef struct SigProtectHandlerInfo {
uint32_t expectedType;
uintptr_t returnValue;
const char *testName;
} SigProtectHandlerInfo;
static U_32 portTestOptionsGlobal;
#if defined(OMR_PORT_ASYNC_HANDLER)
/* Sets the controlFlag to 1 such that we can test that it was actually invoked.
*
* Synchronizes using AsyncHandlerInfo->monitor.
*/
static uintptr_t
asyncTestHandler1(struct OMRPortLibrary *portLibrary, uint32_t gpType, void *handlerInfo, void *userData)
{
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
AsyncHandlerInfo *info = (AsyncHandlerInfo *) userData;
const char *testName = info->testName;
omrthread_monitor_t monitor = *(info->monitor);
omrthread_monitor_enter(monitor);
portTestEnv->changeIndent(2);
portTestEnv->log("asyncTestHandler1 invoked (type = 0x%x)\n", gpType);
if (info->expectedType != gpType) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "asyncTestHandler1 -- incorrect type. Expecting 0x%x, got 0x%x\n", info->expectedType, gpType);
}
portTestEnv->changeIndent(-2);
info->controlFlag = 1;
omrthread_monitor_notify(monitor);
omrthread_monitor_exit(monitor);
return 0;
}
/* Sets the controlFlag to 1 such that we can test that it was actually invoked.
*
* Synchronizes using AsyncHandlerInfo->monitor.
*/
static uintptr_t
asyncTestHandler2(struct OMRPortLibrary *portLibrary, uint32_t gpType, void *handlerInfo, void *userData)
{
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
AsyncHandlerInfo *info = (AsyncHandlerInfo *) userData;
const char *testName = info->testName;
omrthread_monitor_t monitor = *(info->monitor);
omrthread_monitor_enter(monitor);
portTestEnv->changeIndent(2);
portTestEnv->log("asyncTestHandler2 invoked (type = 0x%x)\n", gpType);
if (info->expectedType != gpType) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "asyncTestHandler2 -- incorrect type. Expecting 0x%x, got 0x%x\n", info->expectedType, gpType);
}
portTestEnv->changeIndent(-2);
info->controlFlag = 1;
omrthread_monitor_notify(monitor);
omrthread_monitor_exit(monitor);
return 0;
}
static void
injectSignal(struct OMRPortLibrary *portLibrary, int pid, int signal)
{
/* This is run by the child process. To see the tty_printf output on the
* console, set OMRPORT_PROCESS_INHERIT_STDOUT | OMRPORT_PROCESS_INHERIT_STDIN
* in the options passed into j9process_create() in launchChildProcess
* (in testProcessHelpers.c).
*/
portTestEnv->log("\t\tCHILD: calling kill: %i %i\n", pid, signal);
#if !defined(OMR_OS_WINDOWS)
kill(pid, signal);
#endif /* !defined(OMR_OS_WINDOWS) */
return;
}
#endif /* defined(OMR_PORT_ASYNC_HANDLER) */
/**
* Verify port library signal handling.
*
* @param[in] portLibrary the port library under test
* @param[in] exeName the executable that invoked the test
* @param[in arg either NULL or of the form omrsig_injectSignal_<pid>_<signal>
*
* @return 0 on success, -1 on failure
*/
int32_t
omrsig_runTests(struct OMRPortLibrary *portLibrary, char *exeName, char *argument)
{
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
portTestOptionsGlobal = omrsig_get_options();
#if defined(OMR_PORT_ASYNC_HANDLER) && !defined(OMR_OS_WINDOWS)
if (argument != NULL) {
if (1 == startsWith(argument, "omrsig_injectSignal")) {
char *scratch = NULL;
int pid = 0;
int signal = 0;
char *strTokSavePtr = NULL;
/* Consume "omrsig". */
(void)strtok_r(argument, "_", &strTokSavePtr);
/* Consume "injectSignal". */
(void)strtok_r(NULL, "_", &strTokSavePtr);
/* Consume PID. */
scratch = strtok_r(NULL, "_", &strTokSavePtr);
pid = atoi(scratch);
/* Consume signal number. */
scratch = strtok_r(NULL, "_", &strTokSavePtr);
signal = atoi(scratch);
injectSignal(OMRPORTLIB, pid, signal);
/* Return value is insignificant. */
return TEST_PASS;
}
}
#endif /* defined(OMR_PORT_ASYNC_HANDLER) && !defined(OMR_OS_WINDOWS) */
return 0;
}
/*
* Test that a named register has the correct type, and exists correctly.
* If platform is not NULL and is not the current platform, the register MUST be undefined.
* Otherwise the register must be expectedKind, or it may be undefined if optional is TRUE.
*/
static void
validatePlatformRegister(struct OMRPortLibrary *portLibrary, void *gpInfo, uint32_t category, int32_t index, uint32_t expectedKind, uintptr_t optional, const char *platform, const char *testName)
{
uint32_t infoKind;
void *value;
const char *name;
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
infoKind = omrsig_info(gpInfo, category, index, &name, &value);
if ((platform == NULL) || (strcmp(platform, omrsysinfo_get_CPU_architecture()) == 0)) {
if (infoKind == OMRPORT_SIG_VALUE_UNDEFINED) {
if (optional == FALSE) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "Required platform register %d is undefined\n", index);
}
} else if (infoKind != expectedKind) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "Platform register %d type is not %u. It is %u\n", index, expectedKind, infoKind);
}
} else {
if (infoKind != OMRPORT_SIG_VALUE_UNDEFINED) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "OMRPORT_SIG_GPR_X86_EDI type is not OMRPORT_SIG_VALUE_UNDEFINED. It is %u\n", infoKind);
}
}
}
void
validateGPInfo(struct OMRPortLibrary *portLibrary, uint32_t gpType, omrsig_handler_fn handler, void *gpInfo, const char *testName)
{
uint32_t category;
void *value;
const char *name;
uint32_t index;
uint32_t infoKind;
const char *arch;
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
for (category = 0; category < OMRPORT_SIG_NUM_CATEGORIES; category++) {
uint32_t infoCount;
infoCount = omrsig_info_count(gpInfo, category);
for (index = 0; index < infoCount; index++) {
infoKind = omrsig_info(gpInfo, category, index, &name, &value);
switch (infoKind) {
case OMRPORT_SIG_VALUE_16:
portTestEnv->log("info %u:%u: %s=%04X\n", category, index, name, *(U_16 *)value);
break;
case OMRPORT_SIG_VALUE_32:
portTestEnv->log("info %u:%u: %s=%08.8x\n", category, index, name, *(uint32_t *)value);
break;
case OMRPORT_SIG_VALUE_64:
portTestEnv->log("info %u:%u: %s=%016.16llx\n", category, index, name, *(uint64_t *)value);
break;
case OMRPORT_SIG_VALUE_STRING:
portTestEnv->log("info %u:%u: %s=%s\n", category, index, name, (const char *)value);
break;
case OMRPORT_SIG_VALUE_ADDRESS:
portTestEnv->log("info %u:%u: %s=%p\n", category, index, name, *(void **)value);
break;
case OMRPORT_SIG_VALUE_FLOAT_64:
/* make sure when casting to a float that we get least significant 32-bits. */
portTestEnv->log(
"info %u:%u: %s=%016.16llx (f: %f, d: %e)\n",
category, index, name,
*(uint64_t *)value, (float)LOW_U32_FROM_DBL_PTR(value), *(double *)value);
break;
case OMRPORT_SIG_VALUE_128:
{
const U_128 *const v = (U_128 *)value;
const uint64_t h = v->high64;
const uint64_t l = v->low64;
portTestEnv->log("info %u:%u: %s=%016.16llx%016.16llx\n", category, index, name, h, l);
}
break;
case OMRPORT_SIG_VALUE_UNDEFINED:
outputErrorMessage(PORTTEST_ERROR_ARGS, "Undefined value in info (%u:%u, name=%s)\n", category, index, name);
break;
default:
outputErrorMessage(PORTTEST_ERROR_ARGS, "Unrecognized type in info (%u:%u, name=%s, type=%u)\n", category, index, name, infoKind);
break;
}
}
infoKind = omrsig_info(gpInfo, category, index, &name, &value);
if (infoKind != OMRPORT_SIG_VALUE_UNDEFINED) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "Unexpected data after end of info (%u:%u, name=%s, type=%u)\n", category, index, name, infoKind);
}
}
/* test the known names */
infoKind = omrsig_info(gpInfo, OMRPORT_SIG_SIGNAL, OMRPORT_SIG_SIGNAL_TYPE, &name, &value);
if (infoKind != OMRPORT_SIG_VALUE_32) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "OMRPORT_SIG_SIGNAL_TYPE type is not OMRPORT_SIG_VALUE_32. It is %u\n", infoKind);
} else if (*(uint32_t *)value != gpType) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "OMRPORT_SIG_SIGNAL_TYPE is incorrect. Expecting %u, got %u\n", gpType, *(uint32_t *)value);
}
infoKind = omrsig_info(gpInfo, OMRPORT_SIG_SIGNAL, OMRPORT_SIG_SIGNAL_HANDLER, &name, &value);
if (infoKind != OMRPORT_SIG_VALUE_ADDRESS) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "OMRPORT_SIG_SIGNAL_HANDLER type is not OMRPORT_SIG_VALUE_ADDRESS. It is %u\n", infoKind);
} else if (*(omrsig_handler_fn *)value != handler) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "OMRPORT_SIG_SIGNAL_HANDLER is incorrect. Expecting %p, got %p\n", handler, *(omrsig_handler_fn *)value);
}
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_MODULE, OMRPORT_SIG_MODULE_NAME, OMRPORT_SIG_VALUE_STRING, TRUE, NULL, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_SIGNAL, OMRPORT_SIG_SIGNAL_ERROR_VALUE, OMRPORT_SIG_VALUE_32, TRUE, NULL, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_SIGNAL, OMRPORT_SIG_SIGNAL_ADDRESS, OMRPORT_SIG_VALUE_ADDRESS, TRUE, NULL, testName);
portTestOptionsGlobal = omrsig_get_options();
if (0 != (OMRPORT_SIG_OPTIONS_ZOS_USE_CEEHDLR & portTestOptionsGlobal)) {
/* The LE condition handler message number is a U_16 */
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_SIGNAL, OMRPORT_SIG_SIGNAL_PLATFORM_SIGNAL_TYPE, OMRPORT_SIG_VALUE_16, TRUE, NULL, testName);
} else {
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_SIGNAL, OMRPORT_SIG_SIGNAL_PLATFORM_SIGNAL_TYPE, OMRPORT_SIG_VALUE_32, TRUE, NULL, testName);
}
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_SIGNAL, OMRPORT_SIG_SIGNAL_INACCESSIBLE_ADDRESS, OMRPORT_SIG_VALUE_ADDRESS, TRUE, NULL, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_PC, OMRPORT_SIG_VALUE_ADDRESS, FALSE, NULL, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_SP, OMRPORT_SIG_VALUE_ADDRESS, TRUE, NULL, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_BP, OMRPORT_SIG_VALUE_ADDRESS, TRUE, NULL, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_S390_BEA, OMRPORT_SIG_VALUE_ADDRESS, TRUE, NULL, testName);
/*
* x86 registers
*/
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_X86_EDI, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_X86, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_X86_ESI, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_X86, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_X86_EAX, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_X86, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_X86_EBX, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_X86, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_X86_ECX, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_X86, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_X86_EDX, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_X86, testName);
/*
* AMD64 registers
*/
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_RDI, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_RSI, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_RAX, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_RBX, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_RCX, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_RDX, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_R8, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_R9, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_R10, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_R11, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_R12, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_R13, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_R14, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_GPR, OMRPORT_SIG_GPR_AMD64_R15, OMRPORT_SIG_VALUE_ADDRESS, FALSE, OMRPORT_ARCH_HAMMER, testName);
/*
* PowerPC registers
*/
/* these registers are valid on both PPC32 and PPC64, so use whichever we're running on if we are on a PPC */
arch = OMRPORT_ARCH_PPC;
if (0 == strcmp(OMRPORT_ARCH_PPC64, omrsysinfo_get_CPU_architecture())) {
arch = OMRPORT_ARCH_PPC64;
} else if (0 == strcmp(OMRPORT_ARCH_PPC64LE, omrsysinfo_get_CPU_architecture())) {
arch = OMRPORT_ARCH_PPC64LE;
}
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_POWERPC_LR, OMRPORT_SIG_VALUE_ADDRESS, FALSE, arch, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_POWERPC_MSR, OMRPORT_SIG_VALUE_ADDRESS, TRUE, arch, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_POWERPC_CTR, OMRPORT_SIG_VALUE_ADDRESS, TRUE, arch, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_POWERPC_CR, OMRPORT_SIG_VALUE_ADDRESS, TRUE, arch, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_POWERPC_FPSCR, OMRPORT_SIG_VALUE_ADDRESS, TRUE, arch, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_POWERPC_XER, OMRPORT_SIG_VALUE_ADDRESS, TRUE, arch, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_POWERPC_DAR, OMRPORT_SIG_VALUE_ADDRESS, TRUE, arch, testName);
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_POWERPC_DSIR, OMRPORT_SIG_VALUE_ADDRESS, TRUE, arch, testName);
/* this one is PPC32 only */
validatePlatformRegister(OMRPORTLIB, gpInfo, OMRPORT_SIG_CONTROL, OMRPORT_SIG_CONTROL_POWERPC_MQ, OMRPORT_SIG_VALUE_ADDRESS, TRUE, OMRPORT_ARCH_PPC, testName);
}
static uintptr_t
sampleFunction(OMRPortLibrary *portLibrary, void *arg)
{
return 8096;
}
static uintptr_t
simpleHandlerFunction(struct OMRPortLibrary *portLibrary, uint32_t gpType, void *gpInfo, void *handler_arg)
{
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
SigProtectHandlerInfo *info = (SigProtectHandlerInfo *)handler_arg;
const char *testName = info->testName;
portTestEnv->log("simpleHandlerFunction invoked (type = 0x%x)\n", gpType);
if (info->expectedType != gpType) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "simpleHandlerFunction -- incorrect type. Expecting 0x%x, got 0x%x\n", info->expectedType, gpType);
}
validateGPInfo(OMRPORTLIB, gpType, simpleHandlerFunction, gpInfo, testName);
return info->returnValue;
}
static uintptr_t
currentSigNumHandlerFunction(struct OMRPortLibrary *portLibrary, uint32_t gpType, void *gpInfo, void *handler_arg)
{
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
SigProtectHandlerInfo *info = (SigProtectHandlerInfo *)handler_arg;
intptr_t currentSigNum = omrsig_get_current_signal();
const char *testName = info->testName;
if (currentSigNum < 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "currentSigNumHandlerFunction -- omrsig_get_current_signal call failed\n");
return OMRPORT_SIG_EXCEPTION_CONTINUE_SEARCH;
}
if (gpType != (uint32_t) currentSigNum) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "currentSigNumHandlerFunction -- unexpected value for current signal. Expecting 0x%x, got 0x%x\n", gpType, (uint32_t)currentSigNum);
return OMRPORT_SIG_EXCEPTION_CONTINUE_SEARCH;
}
return OMRPORT_SIG_EXCEPTION_RETURN;
}
static uintptr_t
crashingHandlerFunction(struct OMRPortLibrary *portLibrary, uint32_t gpType, void *gpInfo, void *handler_arg)
{
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
const char *testName = (const char *)handler_arg;
static int recursive = 0;
portTestEnv->log("crashingHandlerFunction invoked (type = 0x%x)\n", gpType);
if (recursive++) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "handler invoked recursively\n");
return OMRPORT_SIG_EXCEPTION_CONTINUE_SEARCH;
}
raiseSEGV(OMRPORTLIB, handler_arg);
outputErrorMessage(PORTTEST_ERROR_ARGS, "unreachable\n");
return OMRPORT_SIG_EXCEPTION_CONTINUE_SEARCH;
}
static uintptr_t
nestedTestCatchSEGV(OMRPortLibrary *portLibrary, void *arg)
{
uint32_t flags = OMRPORT_SIG_FLAG_MAY_RETURN | OMRPORT_SIG_FLAG_SIGSEGV;
const char *testName = (const char *)arg;
int i;
uint32_t protectResult;
uintptr_t result;
SigProtectHandlerInfo handlerInfo;
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
for (i = 0; i < 3; i++) {
handlerInfo.expectedType = OMRPORT_SIG_FLAG_SIGSEGV;
handlerInfo.returnValue = OMRPORT_SIG_EXCEPTION_RETURN;
handlerInfo.testName = testName;
protectResult = omrsig_protect(
raiseSEGV, (void *)testName,
simpleHandlerFunction, &handlerInfo,
flags,
&result);
if (protectResult != OMRPORT_SIG_EXCEPTION_OCCURRED) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected OMRPORT_SIG_EXCEPTION_OCCURRED return value\n");
}
if (result != 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected 0 in *result\n");
}
}
}
return 8096;
}
static uintptr_t
nestedTestCatchNothing(OMRPortLibrary *portLibrary, void *arg)
{
uint32_t flags = 0;
const char *testName = (const char *)arg;
uintptr_t result;
SigProtectHandlerInfo handlerInfo;
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
handlerInfo.expectedType = 0;
handlerInfo.returnValue = OMRPORT_SIG_EXCEPTION_RETURN;
handlerInfo.testName = testName;
(void)omrsig_protect(
raiseSEGV, (void *)testName,
simpleHandlerFunction, &handlerInfo,
flags,
&result);
outputErrorMessage(PORTTEST_ERROR_ARGS, "this should be unreachable\n");
}
return 8096;
}
static uintptr_t
nestedTestCatchAndIgnore(OMRPortLibrary *portLibrary, void *arg)
{
uint32_t flags = OMRPORT_SIG_FLAG_SIGSEGV;
const char *testName = (const char *)arg;
uintptr_t result;
SigProtectHandlerInfo handlerInfo;
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
handlerInfo.expectedType = OMRPORT_SIG_FLAG_SIGSEGV;
handlerInfo.returnValue = OMRPORT_SIG_EXCEPTION_CONTINUE_SEARCH;
handlerInfo.testName = testName;
(void)omrsig_protect(
raiseSEGV, (void *)testName,
simpleHandlerFunction, &handlerInfo,
flags,
&result);
outputErrorMessage(PORTTEST_ERROR_ARGS, "this should be unreachable\n");
}
return 8096;
}
static uintptr_t
nestedTestCatchAndContinueSearch(OMRPortLibrary *portLibrary, void *arg)
{
uint32_t flags = OMRPORT_SIG_FLAG_SIGSEGV | OMRPORT_SIG_FLAG_MAY_RETURN;
const char *testName = (const char *)arg;
uint32_t protectResult;
uintptr_t result;
SigProtectHandlerInfo handlerInfo;
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
handlerInfo.expectedType = OMRPORT_SIG_FLAG_SIGSEGV;
handlerInfo.returnValue = OMRPORT_SIG_EXCEPTION_CONTINUE_SEARCH;
handlerInfo.testName = testName;
protectResult = omrsig_protect(
raiseSEGV, (void *)testName,
simpleHandlerFunction, &handlerInfo,
flags,
&result);
if (protectResult != OMRPORT_SIG_EXCEPTION_OCCURRED) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected OMRPORT_SIG_EXCEPTION_OCCURRED return value\n");
}
}
return 0;
}
static uintptr_t
nestedTestCatchAndCrash(OMRPortLibrary *portLibrary, void *arg)
{
uint32_t flags = OMRPORT_SIG_FLAG_SIGSEGV;
const char *testName = (const char *)arg;
uintptr_t result;
OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
(void)omrsig_protect(
raiseSEGV, (void *)testName,
crashingHandlerFunction, (void *)testName,
flags,
&result);
outputErrorMessage(PORTTEST_ERROR_ARGS, "this should be unreachable\n");
}
return 8096;
}
/*
* Test that we can protect against the flags:
* 0,
* 0 | OMRPORT_SIG_FLAG_MAY_RETURN,
* 0 | OMRPORT_SIG_FLAG_MAY_CONTINUE_EXECUTION,
* 0 | OMRPORT_SIG_FLAG_MAY_RETURN | OMRPORT_SIG_FLAG_MAY_CONTINUE_EXECUTION
*
*/
TEST(PortSigTest, sig_test0)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
const char *testName = "omrsig_test0";
reportTestEntry(OMRPORTLIB, testName);
if (!omrsig_can_protect(0)) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->can_protect() must always support 0\n");
}
if (!omrsig_can_protect(OMRPORT_SIG_FLAG_MAY_RETURN)) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->can_protect() must always support 0 | OMRPORT_SIG_FLAG_MAY_RETURN\n");
}
if (!omrsig_can_protect(OMRPORT_SIG_FLAG_MAY_CONTINUE_EXECUTION)) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->can_protect() must always support 0 | OMRPORT_SIG_FLAG_MAY_CONTINUE_EXECUTION\n");
# if defined(J9ZOS390)
/* z/OS does not always support this, however, pltest should never be run under a configuration that does not support it.
* See implementation of omrsig_can_proctect() and omrsig_startup()
*/
portTestEnv->log("OMRPORT_SIG_FLAG_MAY_CONTINUE_EXECUTION is not supported if the default settings for TRAP(ON,SPIE) have been changed. The should both be set to 1\n");
#endif
}
if (!omrsig_can_protect(OMRPORT_SIG_FLAG_MAY_RETURN | OMRPORT_SIG_FLAG_MAY_CONTINUE_EXECUTION)) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->can_protect() must always support 0 | OMRPORT_SIG_FLAG_MAY_RETURN | OMRPORT_SIG_FLAG_MAY_CONTINUE_EXECUTION\n");
# if defined(J9ZOS390)
portTestEnv->log("OMRPORT_SIG_FLAG_MAY_CONTINUE_EXECUTION is not supported if the default settings for TRAP(ON,SPIE) have been changed. The should both be set to 1\n");
#endif
}
reportTestExit(OMRPORTLIB, testName);
}
/*
* Test protecting (and running) a function that does not fault
*
*/
TEST(PortSigTest, sig_test1)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
uintptr_t result = 1;
uint32_t protectResult;
const char *testName = "omrsig_test1";
SigProtectHandlerInfo handlerInfo;
reportTestEntry(OMRPORTLIB, testName);
if (!omrsig_can_protect(0)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
/* test running a function which does not fault */
handlerInfo.expectedType = 0;
handlerInfo.returnValue = OMRPORT_SIG_EXCEPTION_CONTINUE_SEARCH;
handlerInfo.testName = testName;
protectResult = omrsig_protect(
sampleFunction, NULL,
simpleHandlerFunction, &handlerInfo,
0, /* protect from nothing */
&result);
if (protectResult != 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected 0 return value\n");
}
if (result != 8096) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- protected function did not execute correctly\n");
}
}
reportTestExit(OMRPORTLIB, testName);
}
/*
* Test protecting (and running) a function that raises a segv
*
*/
TEST(PortSigTest, sig_test2)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
uintptr_t result = 1;
uint32_t protectResult;
uint32_t flags = OMRPORT_SIG_FLAG_MAY_RETURN | OMRPORT_SIG_FLAG_SIGSEGV;
const char *testName = "omrsig_test2";
SigProtectHandlerInfo handlerInfo;
reportTestEntry(OMRPORTLIB, testName);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
/* test running a function that raises a segv */
handlerInfo.expectedType = OMRPORT_SIG_FLAG_SIGSEGV;
handlerInfo.returnValue = OMRPORT_SIG_EXCEPTION_RETURN;
handlerInfo.testName = testName;
protectResult = omrsig_protect(
raiseSEGV, (void *)testName,
simpleHandlerFunction, &handlerInfo,
flags,
&result);
if (protectResult != OMRPORT_SIG_EXCEPTION_OCCURRED) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected OMRPORT_SIG_EXCEPTION_OCCURRED return value\n");
}
if (result != 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected 0 in *result\n");
}
}
reportTestExit(OMRPORTLIB, testName);
}
/*
* Test protecting Function A against a SEGV with handler HA. A in turn protects Function B
* against a SEGV with handler HB. Function B raises a sigsegv. HB should handle it, returning
* OMRPORT_SIG_EXCEPTION_RETURN, control ends up after the call to omrsig_protect in B.
* B then returns normally to A and then omrsigTest3.
* A checks:
* omrsig_protect returns OMRPORT_SIG_EXCEPTION_OCCURRED
* *result parameter to omrsig_protect call is 0 after call.
*
* ->SEGV
* | |
* | |
* | -->HB
* B |
* ^ ---<-
* | |
* A<-- HA
* ^
* |
* |
* omrsig_test3
*/
TEST(PortSigTest, sig_test3)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
uintptr_t result = 1;
uint32_t protectResult;
uint32_t flags = OMRPORT_SIG_FLAG_MAY_RETURN | OMRPORT_SIG_FLAG_SIGSEGV;
const char *testName = "omrsig_test3";
SigProtectHandlerInfo handlerInfo;
reportTestEntry(OMRPORTLIB, testName);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
handlerInfo.expectedType = 0;
handlerInfo.returnValue = 0;
handlerInfo.testName = testName;
protectResult = omrsig_protect(
nestedTestCatchSEGV, (void *)testName,
simpleHandlerFunction, &handlerInfo,
flags,
&result);
if (protectResult != 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected 0 return value\n");
}
if (result != 8096) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected 8096 in *result\n");
}
}
reportTestExit(OMRPORTLIB, testName);
}
/*
* Test protecting Function A against a SEGV with handler HA. A in turn protects Function B against
* nothing with handler HB. Function B raises a sigsegv. HB won't get invoked because it was not protecting against anything
* so HA will be invoked, and return control to A (and then omrsig_test4).
*
* ->SEGV--->--
* | |
* | |
* B HB |
* ^ |
* | |
* | |
* A<------HA-<-
* ^
* |
* |
* omrsig_test4
*/
TEST(PortSigTest, sig_test4)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
uintptr_t result = 1;
uint32_t protectResult;
uint32_t flags = OMRPORT_SIG_FLAG_MAY_RETURN | OMRPORT_SIG_FLAG_SIGSEGV;
const char *testName = "omrsig_test4";
SigProtectHandlerInfo handlerInfo;
reportTestEntry(OMRPORTLIB, testName);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
/* test running a function which does not fault */
handlerInfo.expectedType = OMRPORT_SIG_FLAG_SIGSEGV;
handlerInfo.returnValue = OMRPORT_SIG_EXCEPTION_RETURN;
handlerInfo.testName = testName;
protectResult = omrsig_protect(
nestedTestCatchNothing, (void *)testName,
simpleHandlerFunction, &handlerInfo,
flags,
&result);
if (protectResult != OMRPORT_SIG_EXCEPTION_OCCURRED) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected OMRPORT_SIG_EXCEPTION_OCCURRED return value\n");
}
if (result != 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected 0 in *result\n");
}
}
reportTestExit(OMRPORTLIB, testName);
}
/*
* Test protecting Function A against a SEGV with handler HA. A in turn protects Function B
* against a SEGV with handler HB. Function B raises a sigsegv. HB gets invoked, returns OMRPORT_SIG_EXCEPTION_CONTINUE_SEARCH
* so that HA gets invoked, which then returns control to A (and then omrsig_test5).
*
* ->SEGV
* | |
* | |
* B -->HB
* ^ |
* | |
* | |
* A<----<-HA
* ^
* |
* |
* omrsig_test5
*
*/
TEST(PortSigTest, sig_test5)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
uintptr_t result = 1;
uint32_t protectResult;
uint32_t flags = OMRPORT_SIG_FLAG_MAY_RETURN | OMRPORT_SIG_FLAG_SIGSEGV;
const char *testName = "omrsig_test5";
SigProtectHandlerInfo handlerInfo;
reportTestEntry(OMRPORTLIB, testName);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
handlerInfo.expectedType = OMRPORT_SIG_FLAG_SIGSEGV;
handlerInfo.returnValue = OMRPORT_SIG_EXCEPTION_RETURN;
handlerInfo.testName = testName;
protectResult = omrsig_protect(
nestedTestCatchAndIgnore, (void *)testName,
simpleHandlerFunction, &handlerInfo,
flags,
&result);
if (protectResult != OMRPORT_SIG_EXCEPTION_OCCURRED) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected OMRPORT_SIG_EXCEPTION_OCCURRED return value\n");
}
if (result != 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected 0 in *result\n");
}
}
reportTestExit(OMRPORTLIB, testName);
}
/*
* ->SEGV->-
* | |
* | |
* B -->HB-->--SEGV->-
* ^ |
* | |
* | |
* | |
* | |
* A<---<--HA----<---------
* ^
* |
* |
* omrsig_test6
*/
TEST(PortSigTest, sig_test6)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
uintptr_t result = 1;
uint32_t protectResult;
uint32_t flags = OMRPORT_SIG_FLAG_MAY_RETURN | OMRPORT_SIG_FLAG_SIGSEGV;
const char *testName = "omrsig_test6";
SigProtectHandlerInfo handlerInfo;
reportTestEntry(OMRPORTLIB, testName);
if (!omrsig_can_protect(flags)) {
operationNotSupported(OMRPORTLIB, "the specified signals are");
} else {
handlerInfo.expectedType = OMRPORT_SIG_FLAG_SIGSEGV;
handlerInfo.returnValue = OMRPORT_SIG_EXCEPTION_RETURN;
handlerInfo.testName = testName;
protectResult = omrsig_protect(
nestedTestCatchAndCrash, (void *)testName,
simpleHandlerFunction, &handlerInfo,
flags,
&result);
if (protectResult != OMRPORT_SIG_EXCEPTION_OCCURRED) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected OMRPORT_SIG_EXCEPTION_OCCURRED return value\n");
}
if (result != 0) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "portLibrary->sig_protect -- expected 0 in *result\n");
}
#if 0
/* CMVC 126838
* Verify that the current signal is still valid. There's no public API, so
* to run this test you need to port/unix/omrsignal.c (remove static from declaration of tlsKeyCurrentSignal)
* and add "<export name="tlsKeyCurrentSignal" />" to port/module.xml, to export tlsKeyCurrentSignal.
*/
#if !defined(OMR_OS_WINDOWS)
{
extern omrthread_tls_key_t tlsKeyCurrentSignal;
int signo = (int)(uintptr_t)omrthread_tls_get(omrthread_self(), tlsKeyCurrentSignal);
int expectedSigno = 0;
portTestEnv->log("\n testing current signal\n");
if (signo != expectedSigno) {
outputErrorMessage(PORTTEST_ERROR_ARGS, "currentSignal corrupt -- got: %d expected: %d\n", signo, expectedSigno);
}
}
#endif /* !defined(OMR_OS_WINDOWS) */
#endif
}
reportTestExit(OMRPORTLIB, testName);
}
/*
* Test the exposure of the currently handled signal
*
*/
TEST(PortSigTest, sig_test7)
{
OMRPORT_ACCESS_FROM_OMRPORT(portTestEnv->getPortLibrary());
uintptr_t result = 1;
uint32_t protectResult;