1 // SPDX-License-Identifier: GPL-2.0-only
2 #define THIS_PROGRAM "./vstate_exec_nolibc"
4 int main(int argc, char **argv)
6 int rc, pid, status, test_inherit = 0;
8 char *exec_argv[2], *exec_envp[2];
13 ctrl = my_syscall1(__NR_prctl, PR_RISCV_V_GET_CONTROL);
15 puts("PR_RISCV_V_GET_CONTROL is not supported\n");
22 puts("fork failed\n");
28 exec_argv[0] = THIS_PROGRAM;
32 /* launch the program again to check inherit */
33 rc = execve(THIS_PROGRAM, exec_argv, exec_envp);
35 puts("child execve failed\n");
43 puts("fork failed\n");
48 rc = my_syscall1(__NR_prctl, PR_RISCV_V_GET_CONTROL);
50 puts("child's vstate_ctrl not equal to parent's\n");
53 asm volatile (".option push\n\t"
54 ".option arch, +v\n\t"
55 "vsetvli x0, x0, e32, m8, ta, ma\n\t"
62 rc = waitpid(-1, &status, 0);
64 if (WIFEXITED(status) && WEXITSTATUS(status) == -1) {
65 puts("child exited abnormally\n");
69 if (WIFSIGNALED(status)) {
70 if (WTERMSIG(status) != SIGILL) {
71 puts("child was terminated by unexpected signal\n");
75 if ((ctrl & PR_RISCV_V_VSTATE_CTRL_CUR_MASK) != PR_RISCV_V_VSTATE_CTRL_OFF) {
76 puts("child signaled by illegal V access but vstate_ctrl is not off\n");
80 /* child terminated, and its vstate_ctrl is off */
84 ctrl_c = WEXITSTATUS(status);
86 if (ctrl & PR_RISCV_V_VSTATE_CTRL_INHERIT) {
87 if (!(ctrl_c & PR_RISCV_V_VSTATE_CTRL_INHERIT)) {
88 puts("parent has inherit bit, but child has not\n");
92 rc = (ctrl & PR_RISCV_V_VSTATE_CTRL_NEXT_MASK) >> 2;
93 if (rc != PR_RISCV_V_VSTATE_CTRL_DEFAULT) {
94 if (rc != (ctrl_c & PR_RISCV_V_VSTATE_CTRL_CUR_MASK)) {
95 puts("parent's next setting does not equal to child's\n");
99 if (!(ctrl & PR_RISCV_V_VSTATE_CTRL_INHERIT)) {
100 if ((ctrl_c & PR_RISCV_V_VSTATE_CTRL_NEXT_MASK) !=
101 PR_RISCV_V_VSTATE_CTRL_DEFAULT) {
102 puts("must clear child's next vstate_ctrl if !inherit\n");