| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 /* | 8 /* |
| 9 * Implementation of the user-space ashmem API for devices, which have our | 9 * Implementation of the user-space ashmem API for devices, which have our |
| 10 * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version, | 10 * ashmem-enabled kernel. See ashmem-sim.c for the "fake" tmp-based version, |
| 11 * used by the simulator. | 11 * used by the simulator. |
| 12 */ | 12 */ |
| 13 | 13 |
| 14 #include <android/ashmem.h> | 14 #include <android/ashmem.h> |
| 15 | 15 |
| 16 #include <unistd.h> | 16 #include <unistd.h> |
| 17 #include <string.h> | 17 #include <string.h> |
| 18 #include <sys/types.h> | 18 #include <sys/types.h> |
| 19 #include <sys/stat.h> | 19 #include <sys/stat.h> |
| 20 #include <sys/ioctl.h> | 20 #include <sys/ioctl.h> |
| 21 #include <fcntl.h> | 21 #include <fcntl.h> |
| 22 | 22 |
| 23 #include <linux/ashmem.h> | 23 #include <linux/ashmem.h> |
| 24 | 24 |
| 25 #include <SkTypes.h> // SkASSERT |
| 26 |
| 25 #define ASHMEM_DEVICE "/dev/ashmem" | 27 #define ASHMEM_DEVICE "/dev/ashmem" |
| 26 | 28 |
| 27 /* | 29 /* |
| 28 * ashmem_create_region - creates a new ashmem region and returns the file | 30 * ashmem_create_region - creates a new ashmem region and returns the file |
| 29 * descriptor, or <0 on error | 31 * descriptor, or <0 on error |
| 30 * | 32 * |
| 31 * `name' is an optional label to give the region (visible in /proc/pid/maps) | 33 * `name' is an optional label to give the region (visible in /proc/pid/maps) |
| 32 * `size' is the size of the region, in page-aligned bytes | 34 * `size' is the size of the region, in page-aligned bytes |
| 33 */ | 35 */ |
| 34 int ashmem_create_region(const char *name, size_t size) | 36 int ashmem_create_region(const char *name, size_t size) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 59 return ret; | 61 return ret; |
| 60 } | 62 } |
| 61 | 63 |
| 62 int ashmem_set_prot_region(int fd, int prot) | 64 int ashmem_set_prot_region(int fd, int prot) |
| 63 { | 65 { |
| 64 return ioctl(fd, ASHMEM_SET_PROT_MASK, prot); | 66 return ioctl(fd, ASHMEM_SET_PROT_MASK, prot); |
| 65 } | 67 } |
| 66 | 68 |
| 67 int ashmem_pin_region(int fd, size_t offset, size_t len) | 69 int ashmem_pin_region(int fd, size_t offset, size_t len) |
| 68 { | 70 { |
| 69 struct ashmem_pin pin = { offset, len }; | 71 // Skia only calls this when offset=len=0. |
| 72 struct ashmem_pin pin = { static_cast<__u32>(offset), |
| 73 static_cast<__u32>(len) }; |
| 74 SkASSERT(pin.offset == offset && pin.len == len); |
| 70 return ioctl(fd, ASHMEM_PIN, &pin); | 75 return ioctl(fd, ASHMEM_PIN, &pin); |
| 71 } | 76 } |
| 72 | 77 |
| 73 int ashmem_unpin_region(int fd, size_t offset, size_t len) | 78 int ashmem_unpin_region(int fd, size_t offset, size_t len) |
| 74 { | 79 { |
| 75 struct ashmem_pin pin = { offset, len }; | 80 // Skia only calls this when offset=len=0. |
| 81 struct ashmem_pin pin = { static_cast<__u32>(offset), |
| 82 static_cast<__u32>(len) }; |
| 83 SkASSERT(pin.offset == offset && pin.len == len); |
| 76 return ioctl(fd, ASHMEM_UNPIN, &pin); | 84 return ioctl(fd, ASHMEM_UNPIN, &pin); |
| 77 } | 85 } |
| 78 | 86 |
| 79 int ashmem_get_size_region(int fd) | 87 int ashmem_get_size_region(int fd) |
| 80 { | 88 { |
| 81 return ioctl(fd, ASHMEM_GET_SIZE, NULL); | 89 return ioctl(fd, ASHMEM_GET_SIZE, NULL); |
| 82 } | 90 } |
| 83 | 91 |
| 84 int ashmem_purge_all_caches(int fd) | 92 int ashmem_purge_all_caches(int fd) |
| 85 { | 93 { |
| 86 return ioctl(fd, ASHMEM_PURGE_ALL_CACHES, NULL); | 94 return ioctl(fd, ASHMEM_PURGE_ALL_CACHES, NULL); |
| 87 } | 95 } |
| OLD | NEW |