2 * Copyright 2021 IBM Corp.
4 * This work is licensed under the terms of the GNU GPL, version 2 or (at
5 * your option) any later version. See the COPYING file in the top-level
18 static void error1(const char *filename
, int line
, const char *fmt
, ...)
22 fprintf(stderr
, "%s:%d: ", filename
, line
);
23 vfprintf(stderr
, fmt
, ap
);
24 fprintf(stderr
, "\n");
29 static int __chk_error(const char *filename
, int line
, int ret
)
32 error1(filename
, line
, "%m (ret=%d, errno=%d/%s)",
33 ret
, errno
, strerror(errno
));
38 #define error(fmt, ...) error1(__FILE__, __LINE__, fmt, ## __VA_ARGS__)
40 #define chk_error(ret) __chk_error(__FILE__, __LINE__, (ret))
45 static void sig_handler(int sig
, siginfo_t
*si
, void *puc
)
48 if (si
->si_code
!= 0) {
49 error("unexpected si_code: 0x%x != 0", si
->si_code
);
60 error("unexpected signal 0x%x\n", sig
);
63 int main(int argc
, char **argv
)
65 sigfpe_count
= sigill_count
= 0;
69 /* Set up SIG handler */
70 act
.sa_sigaction
= sig_handler
;
71 sigemptyset(&act
.sa_mask
);
72 act
.sa_flags
= SA_SIGINFO
;
73 chk_error(sigaction(SIGFPE
, &act
, NULL
));
74 chk_error(sigaction(SIGILL
, &act
, NULL
));
77 uint64_t lz
= 0xffffffffffffffffull
;
80 "cgitne %%r13,0\n" /* SIGFPE */
82 "cgitne %%r13,0\n" /* no trap */
85 "citne %%r13,0\n" /* SIGFPE */
87 "citne %%r13,0\n" /* no trap */
90 : [z
] "m" (z
), [lz
] "m" (lz
)
93 if (sigfpe_count
!= 2) {
94 error("unexpected SIGFPE count: %d != 2", sigfpe_count
);
96 if (sigill_count
!= 0) {
97 error("unexpected SIGILL count: %d != 0", sigill_count
);