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 #ifndef CRAZY_LINKER_ASHMEM_H |
| 6 #define CRAZY_LINKER_ASHMEM_H |
| 7 |
| 8 #include <unistd.h> |
| 9 |
| 10 namespace crazy { |
| 11 |
| 12 // Helper class to hold a scoped ashmem region file descriptor. |
| 13 class AshmemRegion { |
| 14 public: |
| 15 AshmemRegion() : fd_(-1) {} |
| 16 |
| 17 ~AshmemRegion() { |
| 18 Reset(-1); |
| 19 } |
| 20 |
| 21 int Get() const { return fd_; } |
| 22 |
| 23 int Release() { |
| 24 int ret = fd_; |
| 25 fd_ = -1; |
| 26 return ret; |
| 27 } |
| 28 |
| 29 void Reset(int fd) { |
| 30 if (fd_ != -1) { |
| 31 ::close(fd_); |
| 32 } |
| 33 fd_ = fd; |
| 34 } |
| 35 |
| 36 // Try to allocate a new ashmem region of |region_size| |
| 37 // (page-aligned) bytes. |region_name| is optional, if not NULL |
| 38 // it will be the name of the region (only used for debugging). |
| 39 // Returns true on success, false otherwise. |
| 40 bool Allocate(size_t region_size, const char* region_name); |
| 41 |
| 42 // Change the protection flags of the region. Returns true on success. |
| 43 bool SetProtectionFlags(int prot_flags); |
| 44 |
| 45 private: |
| 46 AshmemRegion(const AshmemRegion& other); |
| 47 AshmemRegion& operator=(const AshmemRegion& other); |
| 48 |
| 49 int fd_; |
| 50 }; |
| 51 |
| 52 } // namespace crazy |
| 53 |
| 54 #endif // CRAZY_LINKER_ASHMEM_H |
OLD | NEW |