OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "crazy_linker_ashmem.h" |
| 6 |
| 7 #include <fcntl.h> |
| 8 #include <string.h> |
| 9 #include <sys/ioctl.h> |
| 10 #include <sys/stat.h> |
| 11 #include <sys/types.h> |
| 12 #include <unistd.h> |
| 13 |
| 14 #include <linux/ashmem.h> |
| 15 |
| 16 #include "crazy_linker_system.h" |
| 17 |
| 18 namespace crazy { |
| 19 |
| 20 bool AshmemRegion::Allocate(size_t region_size, const char* region_name) { |
| 21 int fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDWR)); |
| 22 if (fd < 0) |
| 23 return false; |
| 24 |
| 25 if (ioctl(fd, ASHMEM_SET_SIZE, region_size) < 0) |
| 26 goto ERROR; |
| 27 |
| 28 if (region_name) { |
| 29 char buf[256]; |
| 30 strlcpy(buf, region_name, sizeof(buf)); |
| 31 if (ioctl(fd, ASHMEM_SET_NAME, buf) < 0) |
| 32 goto ERROR; |
| 33 } |
| 34 |
| 35 Reset(fd); |
| 36 return true; |
| 37 |
| 38 ERROR: |
| 39 ::close(fd); |
| 40 return false; |
| 41 } |
| 42 |
| 43 bool AshmemRegion::SetProtectionFlags(int prot) { |
| 44 return ioctl(fd_, ASHMEM_SET_PROT_MASK, prot) == 0; |
| 45 } |
| 46 } // namespace crazy |
OLD | NEW |