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

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/riscv/vector/vstate_exec_nolibc.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 
  3 #include <linux/wait.h>
  4 
  5 #define THIS_PROGRAM "./vstate_exec_nolibc"
  6 
  7 int main(int argc, char **argv)
  8 {
  9         int rc, pid, status, test_inherit = 0;
 10         long ctrl, ctrl_c;
 11         char *exec_argv[2], *exec_envp[2];
 12 
 13         if (argc > 1)
 14                 test_inherit = 1;
 15 
 16         ctrl = my_syscall1(__NR_prctl, PR_RISCV_V_GET_CONTROL);
 17         if (ctrl < 0) {
 18                 puts("PR_RISCV_V_GET_CONTROL is not supported\n");
 19                 return ctrl;
 20         }
 21 
 22         if (test_inherit) {
 23                 pid = fork();
 24                 if (pid == -1) {
 25                         puts("fork failed\n");
 26                         exit(-1);
 27                 }
 28 
 29                 /* child  */
 30                 if (!pid) {
 31                         exec_argv[0] = THIS_PROGRAM;
 32                         exec_argv[1] = NULL;
 33                         exec_envp[0] = NULL;
 34                         exec_envp[1] = NULL;
 35                         /* launch the program again to check inherit */
 36                         rc = execve(THIS_PROGRAM, exec_argv, exec_envp);
 37                         if (rc) {
 38                                 puts("child execve failed\n");
 39                                 exit(-1);
 40                         }
 41                 }
 42 
 43         } else {
 44                 pid = fork();
 45                 if (pid == -1) {
 46                         puts("fork failed\n");
 47                         exit(-1);
 48                 }
 49 
 50                 if (!pid) {
 51                         rc = my_syscall1(__NR_prctl, PR_RISCV_V_GET_CONTROL);
 52                         if (rc != ctrl) {
 53                                 puts("child's vstate_ctrl not equal to parent's\n");
 54                                 exit(-1);
 55                         }
 56                         asm volatile (".option push\n\t"
 57                                       ".option arch, +v\n\t"
 58                                       "vsetvli x0, x0, e32, m8, ta, ma\n\t"
 59                                       ".option pop\n\t"
 60                                       );
 61                         exit(ctrl);
 62                 }
 63         }
 64 
 65         rc = waitpid(-1, &status, 0);
 66 
 67         if (WIFEXITED(status) && WEXITSTATUS(status) == -1) {
 68                 puts("child exited abnormally\n");
 69                 exit(-1);
 70         }
 71 
 72         if (WIFSIGNALED(status)) {
 73                 if (WTERMSIG(status) != SIGILL) {
 74                         puts("child was terminated by unexpected signal\n");
 75                         exit(-1);
 76                 }
 77 
 78                 if ((ctrl & PR_RISCV_V_VSTATE_CTRL_CUR_MASK) != PR_RISCV_V_VSTATE_CTRL_OFF) {
 79                         puts("child signaled by illegal V access but vstate_ctrl is not off\n");
 80                         exit(-1);
 81                 }
 82 
 83                 /* child terminated, and its vstate_ctrl is off */
 84                 exit(ctrl);
 85         }
 86 
 87         ctrl_c = WEXITSTATUS(status);
 88         if (test_inherit) {
 89                 if (ctrl & PR_RISCV_V_VSTATE_CTRL_INHERIT) {
 90                         if (!(ctrl_c & PR_RISCV_V_VSTATE_CTRL_INHERIT)) {
 91                                 puts("parent has inherit bit, but child has not\n");
 92                                 exit(-1);
 93                         }
 94                 }
 95                 rc = (ctrl & PR_RISCV_V_VSTATE_CTRL_NEXT_MASK) >> 2;
 96                 if (rc != PR_RISCV_V_VSTATE_CTRL_DEFAULT) {
 97                         if (rc != (ctrl_c & PR_RISCV_V_VSTATE_CTRL_CUR_MASK)) {
 98                                 puts("parent's next setting does not equal to child's\n");
 99                                 exit(-1);
100                         }
101 
102                         if (!(ctrl & PR_RISCV_V_VSTATE_CTRL_INHERIT)) {
103                                 if ((ctrl_c & PR_RISCV_V_VSTATE_CTRL_NEXT_MASK) !=
104                                     PR_RISCV_V_VSTATE_CTRL_DEFAULT) {
105                                         puts("must clear child's next vstate_ctrl if !inherit\n");
106                                         exit(-1);
107                                 }
108                         }
109                 }
110         }
111         return ctrl;
112 }
113 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php