0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <stdlib.h>
0021 #include <stdio.h>
0022 #include <signal.h>
0023 #include <unistd.h>
0024
0025 #include <altivec.h>
0026
0027 #include "utils.h"
0028 #include "tm.h"
0029
0030 #define MAX_ATTEMPT 500000
0031
0032 #define NV_GPR_REGS 18
0033 #define R14 14
0034
0035 long tm_signal_self_context_load(pid_t pid, long *gprs, double *fps, vector int *vms, vector int *vss);
0036
0037 static sig_atomic_t fail, broken;
0038
0039
0040 static long gprs[] = {
0041
0042
0043 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
0044
0045
0046 -1,-2,-3,-4,-5,-6,-7,-8,-9,-10,-11,-12,-13,-14,-15,-16,-17,-18
0047 };
0048
0049 static void signal_usr1(int signum, siginfo_t *info, void *uc)
0050 {
0051 int i;
0052 ucontext_t *ucp = uc;
0053 ucontext_t *tm_ucp = ucp->uc_link;
0054
0055
0056 for (i = 0; i < NV_GPR_REGS; i++) {
0057 fail = (ucp->uc_mcontext.gp_regs[R14 + i] != gprs[i]);
0058 if (fail) {
0059 broken = 1;
0060 printf("GPR%d (1st context) == %lu instead of %lu (expected)\n",
0061 R14 + i, ucp->uc_mcontext.gp_regs[R14 + i], gprs[i]);
0062 }
0063 }
0064
0065
0066 for (i = 0; i < NV_GPR_REGS; i++) {
0067 fail = (tm_ucp->uc_mcontext.gp_regs[R14 + i] != gprs[NV_GPR_REGS + i]);
0068 if (fail) {
0069 broken = 1;
0070 printf("GPR%d (2nd context) == %lu instead of %lu (expected)\n",
0071 R14 + i, tm_ucp->uc_mcontext.gp_regs[R14 + i], gprs[NV_GPR_REGS + i]);
0072 }
0073 }
0074 }
0075
0076 static int tm_signal_context_chk_gpr()
0077 {
0078 struct sigaction act;
0079 int i;
0080 long rc;
0081 pid_t pid = getpid();
0082
0083 SKIP_IF(!have_htm());
0084 SKIP_IF(htm_is_synthetic());
0085
0086 act.sa_sigaction = signal_usr1;
0087 sigemptyset(&act.sa_mask);
0088 act.sa_flags = SA_SIGINFO;
0089 if (sigaction(SIGUSR1, &act, NULL) < 0) {
0090 perror("sigaction sigusr1");
0091 exit(1);
0092 }
0093
0094 i = 0;
0095 while (i < MAX_ATTEMPT && !broken) {
0096
0097
0098
0099
0100
0101
0102 rc = tm_signal_self_context_load(pid, gprs, NULL, NULL, NULL);
0103 FAIL_IF(rc != pid);
0104 i++;
0105 }
0106
0107 return broken;
0108 }
0109
0110 int main(void)
0111 {
0112 return test_harness(tm_signal_context_chk_gpr, "tm_signal_context_chk_gpr");
0113 }