~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/powerpc/ptrace/ptrace-gpr.c

Version: ~ [ linux-5.12-rc7 ] ~ [ linux-5.11.13 ] ~ [ linux-5.10.29 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.111 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.186 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.230 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.266 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.266 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * Ptrace test for GPR/FPR registers
  3  *
  4  * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
  5  *
  6  * This program is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU General Public License
  8  * as published by the Free Software Foundation; either version
  9  * 2 of the License, or (at your option) any later version.
 10  */
 11 #include "ptrace.h"
 12 #include "ptrace-gpr.h"
 13 #include "reg.h"
 14 
 15 /* Tracer and Tracee Shared Data */
 16 int shm_id;
 17 int *cptr, *pptr;
 18 
 19 float a = FPR_1;
 20 float b = FPR_2;
 21 float c = FPR_3;
 22 
 23 void gpr(void)
 24 {
 25         unsigned long gpr_buf[18];
 26         float fpr_buf[32];
 27 
 28         cptr = (int *)shmat(shm_id, NULL, 0);
 29 
 30         asm __volatile__(
 31                 ASM_LOAD_GPR_IMMED(gpr_1)
 32                 ASM_LOAD_FPR_SINGLE_PRECISION(flt_1)
 33                 :
 34                 : [gpr_1]"i"(GPR_1), [flt_1] "r" (&a)
 35                 : "memory", "r6", "r7", "r8", "r9", "r10",
 36                 "r11", "r12", "r13", "r14", "r15", "r16", "r17",
 37                 "r18", "r19", "r20", "r21", "r22", "r23", "r24",
 38                 "r25", "r26", "r27", "r28", "r29", "r30", "r31"
 39                 );
 40 
 41         cptr[1] = 1;
 42 
 43         while (!cptr[0])
 44                 asm volatile("" : : : "memory");
 45 
 46         shmdt((void *)cptr);
 47         store_gpr(gpr_buf);
 48         store_fpr_single_precision(fpr_buf);
 49 
 50         if (validate_gpr(gpr_buf, GPR_3))
 51                 exit(1);
 52 
 53         if (validate_fpr_float(fpr_buf, c))
 54                 exit(1);
 55 
 56         exit(0);
 57 }
 58 
 59 int trace_gpr(pid_t child)
 60 {
 61         unsigned long gpr[18];
 62         unsigned long fpr[32];
 63 
 64         FAIL_IF(start_trace(child));
 65         FAIL_IF(show_gpr(child, gpr));
 66         FAIL_IF(validate_gpr(gpr, GPR_1));
 67         FAIL_IF(show_fpr(child, fpr));
 68         FAIL_IF(validate_fpr(fpr, FPR_1_REP));
 69         FAIL_IF(write_gpr(child, GPR_3));
 70         FAIL_IF(write_fpr(child, FPR_3_REP));
 71         FAIL_IF(stop_trace(child));
 72 
 73         return TEST_PASS;
 74 }
 75 
 76 int ptrace_gpr(void)
 77 {
 78         pid_t pid;
 79         int ret, status;
 80 
 81         shm_id = shmget(IPC_PRIVATE, sizeof(int) * 2, 0777|IPC_CREAT);
 82         pid = fork();
 83         if (pid < 0) {
 84                 perror("fork() failed");
 85                 return TEST_FAIL;
 86         }
 87         if (pid == 0)
 88                 gpr();
 89 
 90         if (pid) {
 91                 pptr = (int *)shmat(shm_id, NULL, 0);
 92                 while (!pptr[1])
 93                         asm volatile("" : : : "memory");
 94 
 95                 ret = trace_gpr(pid);
 96                 if (ret) {
 97                         kill(pid, SIGTERM);
 98                         shmdt((void *)pptr);
 99                         shmctl(shm_id, IPC_RMID, NULL);
100                         return TEST_FAIL;
101                 }
102 
103                 pptr[0] = 1;
104                 shmdt((void *)pptr);
105 
106                 ret = wait(&status);
107                 shmctl(shm_id, IPC_RMID, NULL);
108                 if (ret != pid) {
109                         printf("Child's exit status not captured\n");
110                         return TEST_FAIL;
111                 }
112 
113                 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
114                         TEST_PASS;
115         }
116 
117         return TEST_PASS;
118 }
119 
120 int main(int argc, char *argv[])
121 {
122         return test_harness(ptrace_gpr, "ptrace_gpr");
123 }
124 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp