Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at e88ba436e5615f5bb94deecbbb924227b15bbebb 87 lines 1.6 kB view raw
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright 2015, Cyril Bur, IBM Corp. 4 * 5 * This test attempts to see if the VMX registers change across a syscall (fork). 6 */ 7 8#include <altivec.h> 9#include <stdio.h> 10#include <unistd.h> 11#include <sys/syscall.h> 12#include <sys/time.h> 13#include <stdlib.h> 14#include <sys/types.h> 15#include <sys/wait.h> 16#include "utils.h" 17 18vector int varray[] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10,11,12}, 19 {13,14,15,16},{17,18,19,20},{21,22,23,24}, 20 {25,26,27,28},{29,30,31,32},{33,34,35,36}, 21 {37,38,39,40},{41,42,43,44},{45,46,47,48}}; 22 23extern int test_vmx(vector int *varray, pid_t *pid); 24 25int vmx_syscall(void) 26{ 27 pid_t fork_pid; 28 int i; 29 int ret; 30 int child_ret; 31 for (i = 0; i < 1000; i++) { 32 /* test_vmx will fork() */ 33 ret = test_vmx(varray, &fork_pid); 34 if (fork_pid == -1) 35 return -1; 36 if (fork_pid == 0) 37 exit(ret); 38 waitpid(fork_pid, &child_ret, 0); 39 if (ret || child_ret) 40 return 1; 41 } 42 43 return 0; 44} 45 46int test_vmx_syscall(void) 47{ 48 /* 49 * Setup an environment with much context switching 50 */ 51 pid_t pid2; 52 pid_t pid = fork(); 53 int ret; 54 int child_ret; 55 FAIL_IF(pid == -1); 56 57 pid2 = fork(); 58 ret = vmx_syscall(); 59 /* Can't FAIL_IF(pid2 == -1); because we've already forked */ 60 if (pid2 == -1) { 61 /* 62 * Couldn't fork, ensure child_ret is set and is a fail 63 */ 64 ret = child_ret = 1; 65 } else { 66 if (pid2) 67 waitpid(pid2, &child_ret, 0); 68 else 69 exit(ret); 70 } 71 72 ret |= child_ret; 73 74 if (pid) 75 waitpid(pid, &child_ret, 0); 76 else 77 exit(ret); 78 79 FAIL_IF(ret || child_ret); 80 return 0; 81} 82 83int main(int argc, char *argv[]) 84{ 85 return test_harness(test_vmx_syscall, "vmx_syscall"); 86 87}