Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 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 | |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 17 | #ifndef ANDROID_HARDWARE_PARCEL_H |
| 18 | #define ANDROID_HARDWARE_PARCEL_H |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 19 | |
Christopher Wiley | f3cc26d | 2016-01-28 16:56:53 -0800 | [diff] [blame] | 20 | #include <string> |
Casey Dahlin | d0f31e5 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 23 | #include <cutils/native_handle.h> |
| 24 | #include <utils/Errors.h> |
| 25 | #include <utils/RefBase.h> |
| 26 | #include <utils/String16.h> |
Martijn Coenen | fd51ebb | 2016-07-05 17:00:39 +0200 | [diff] [blame] | 27 | |
Martijn Coenen | 4080edc | 2016-05-04 14:17:02 +0200 | [diff] [blame] | 28 | #include <hwbinder/IInterface.h> |
Casey Dahlin | 375de4a | 2015-10-27 18:33:56 -0700 | [diff] [blame] | 29 | |
Steven Moreland | b5f6e00 | 2021-02-26 01:51:20 +0000 | [diff] [blame] | 30 | // WARNING: this code is part of libhwbinder, a fork of libbinder. Generally, |
| 31 | // this means that it is only relevant to HIDL. Any AIDL- or libbinder-specific |
| 32 | // code should not try to use these things. |
| 33 | |
Martijn Coenen | 455e27d | 2017-04-18 15:53:51 -0700 | [diff] [blame] | 34 | struct binder_buffer_object; |
Steven Moreland | 48adadd | 2019-09-05 17:04:38 -0700 | [diff] [blame] | 35 | struct flat_binder_object; |
Martijn Coenen | 455e27d | 2017-04-18 15:53:51 -0700 | [diff] [blame] | 36 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 37 | // --------------------------------------------------------------------------- |
| 38 | namespace android { |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 39 | namespace hardware { |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 40 | |
Steven Moreland | 48adadd | 2019-09-05 17:04:38 -0700 | [diff] [blame] | 41 | #ifdef BINDER_IPC_32BIT |
Steven Moreland | d9bdb65 | 2019-09-17 15:42:45 -0700 | [diff] [blame] | 42 | typedef unsigned int binder_size_t; |
| 43 | typedef unsigned int binder_uintptr_t; |
Steven Moreland | 48adadd | 2019-09-05 17:04:38 -0700 | [diff] [blame] | 44 | #else |
Steven Moreland | d9bdb65 | 2019-09-17 15:42:45 -0700 | [diff] [blame] | 45 | typedef unsigned long long binder_size_t; |
| 46 | typedef unsigned long long binder_uintptr_t; |
Steven Moreland | 48adadd | 2019-09-05 17:04:38 -0700 | [diff] [blame] | 47 | #endif |
| 48 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 49 | class IBinder; |
Brad Fitzpatrick | c1f5bf8 | 2010-07-27 09:49:11 -0700 | [diff] [blame] | 50 | class IPCThreadState; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 51 | class ProcessState; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 52 | class TextOutput; |
| 53 | |
Mathias Agopian | 0d8e2e4 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 54 | class Parcel { |
Serban Constantinescu | 4ca5baf | 2013-11-05 16:53:55 +0000 | [diff] [blame] | 55 | friend class IPCThreadState; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 56 | public: |
Jeff Brown | 8a11ee5 | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 57 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 58 | Parcel(); |
| 59 | ~Parcel(); |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 60 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 61 | const uint8_t* data() const; |
| 62 | size_t dataSize() const; |
| 63 | size_t dataAvail() const; |
| 64 | size_t dataPosition() const; |
| 65 | size_t dataCapacity() const; |
Dianne Hackborn | abc3cf4 | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 66 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 67 | status_t setDataSize(size_t size); |
| 68 | void setDataPosition(size_t pos) const; |
| 69 | status_t setDataCapacity(size_t size); |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 70 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 71 | status_t setData(const uint8_t* buffer, size_t len); |
| 72 | |
Steven Moreland | a80270c | 2020-11-19 21:08:28 +0000 | [diff] [blame] | 73 | // Zeros data when reallocating. Other mitigations may be added |
| 74 | // in the future. |
| 75 | // |
| 76 | // WARNING: some read methods may make additional copies of data. |
| 77 | // In order to verify this, heap dumps should be used. |
| 78 | void markSensitive() const; |
| 79 | |
Brad Fitzpatrick | 94c3634 | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 80 | // Writes the RPC header. |
Steven Moreland | 334305b | 2016-11-11 12:31:31 -0800 | [diff] [blame] | 81 | status_t writeInterfaceToken(const char* interface); |
Brad Fitzpatrick | 3f4ef59 | 2010-07-07 16:06:39 -0700 | [diff] [blame] | 82 | |
Brad Fitzpatrick | 94c3634 | 2010-06-18 13:07:53 -0700 | [diff] [blame] | 83 | // Parses the RPC header, returning true if the interface name |
| 84 | // in the header matches the expected interface from the caller. |
Martijn Coenen | 5c6fe25 | 2017-01-18 15:33:31 +0100 | [diff] [blame] | 85 | bool enforceInterface(const char* interface) const; |
Mathias Agopian | a6286c3 | 2009-05-22 19:00:22 -0700 | [diff] [blame] | 86 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 87 | void freeData(); |
| 88 | |
Arve Hjønnevåg | a544070 | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 89 | private: |
| 90 | const binder_size_t* objects() const; |
| 91 | |
| 92 | public: |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 93 | size_t objectsCount() const; |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 94 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 95 | status_t errorCheck() const; |
| 96 | void setError(status_t err); |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 97 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 98 | status_t write(const void* data, size_t len); |
| 99 | void* writeInplace(size_t len); |
| 100 | status_t writeUnpadded(const void* data, size_t len); |
Andreas Huber | 85af321 | 2016-08-05 14:30:52 -0700 | [diff] [blame] | 101 | status_t writeInt8(int8_t val); |
| 102 | status_t writeUint8(uint8_t val); |
| 103 | status_t writeInt16(int16_t val); |
| 104 | status_t writeUint16(uint16_t val); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 105 | status_t writeInt32(int32_t val); |
Dan Stoza | ff4c1b7 | 2014-12-01 10:01:10 -0800 | [diff] [blame] | 106 | status_t writeUint32(uint32_t val); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 107 | status_t writeInt64(int64_t val); |
Ronghua Wu | 5c2eeca | 2015-03-16 11:11:07 -0700 | [diff] [blame] | 108 | status_t writeUint64(uint64_t val); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 109 | status_t writeFloat(float val); |
| 110 | status_t writeDouble(double val); |
| 111 | status_t writeCString(const char* str); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 112 | status_t writeString16(const String16& str); |
Casey Dahlin | 00c4068 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 113 | status_t writeString16(const std::unique_ptr<String16>& str); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 114 | status_t writeString16(const char16_t* str, size_t len); |
| 115 | status_t writeStrongBinder(const sp<IBinder>& val); |
Casey Dahlin | 458afaf | 2015-10-15 15:44:59 -0700 | [diff] [blame] | 116 | status_t writeBool(bool val); |
Jeff Brown | 8a11ee5 | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 117 | |
Martijn Coenen | 249b02b | 2016-07-28 16:25:10 +0200 | [diff] [blame] | 118 | template<typename T> |
Martijn Coenen | 9d679d6 | 2017-01-10 16:44:24 +0100 | [diff] [blame] | 119 | status_t writeObject(const T& val); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 120 | |
Andreas Huber | 85af321 | 2016-08-05 14:30:52 -0700 | [diff] [blame] | 121 | status_t writeBuffer(const void *buffer, size_t length, size_t *handle); |
| 122 | status_t writeEmbeddedBuffer(const void *buffer, size_t length, size_t *handle, |
Martijn Coenen | 249b02b | 2016-07-28 16:25:10 +0200 | [diff] [blame] | 123 | size_t parent_buffer_handle, size_t parent_offset); |
Yifan Hong | 517105d | 2016-10-27 13:15:22 -0700 | [diff] [blame] | 124 | public: |
Martijn Coenen | fd51ebb | 2016-07-05 17:00:39 +0200 | [diff] [blame] | 125 | status_t writeEmbeddedNativeHandle(const native_handle_t *handle, |
Martijn Coenen | 249b02b | 2016-07-28 16:25:10 +0200 | [diff] [blame] | 126 | size_t parent_buffer_handle, size_t parent_offset); |
Martijn Coenen | 455e27d | 2017-04-18 15:53:51 -0700 | [diff] [blame] | 127 | status_t writeNativeHandleNoDup(const native_handle* handle, bool embedded, |
| 128 | size_t parent_buffer_handle = 0, |
| 129 | size_t parent_offset = 0); |
Martijn Coenen | fd51ebb | 2016-07-05 17:00:39 +0200 | [diff] [blame] | 130 | status_t writeNativeHandleNoDup(const native_handle* handle); |
Brad Fitzpatrick | 67aa5c9 | 2010-07-13 15:33:35 -0700 | [diff] [blame] | 131 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 132 | status_t read(void* outData, size_t len) const; |
| 133 | const void* readInplace(size_t len) const; |
Andreas Huber | 85af321 | 2016-08-05 14:30:52 -0700 | [diff] [blame] | 134 | status_t readInt8(int8_t *pArg) const; |
| 135 | status_t readUint8(uint8_t *pArg) const; |
| 136 | status_t readInt16(int16_t *pArg) const; |
| 137 | status_t readUint16(uint16_t *pArg) const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 138 | int32_t readInt32() const; |
| 139 | status_t readInt32(int32_t *pArg) const; |
Dan Stoza | ff4c1b7 | 2014-12-01 10:01:10 -0800 | [diff] [blame] | 140 | uint32_t readUint32() const; |
| 141 | status_t readUint32(uint32_t *pArg) const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 142 | int64_t readInt64() const; |
| 143 | status_t readInt64(int64_t *pArg) const; |
Ronghua Wu | 5c2eeca | 2015-03-16 11:11:07 -0700 | [diff] [blame] | 144 | uint64_t readUint64() const; |
| 145 | status_t readUint64(uint64_t *pArg) const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 146 | float readFloat() const; |
| 147 | status_t readFloat(float *pArg) const; |
| 148 | double readDouble() const; |
| 149 | status_t readDouble(double *pArg) const; |
Martijn Coenen | 5c6fe25 | 2017-01-18 15:33:31 +0100 | [diff] [blame] | 150 | |
Casey Dahlin | 458afaf | 2015-10-15 15:44:59 -0700 | [diff] [blame] | 151 | bool readBool() const; |
| 152 | status_t readBool(bool *pArg) const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 153 | const char* readCString() const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 154 | String16 readString16() const; |
Casey Dahlin | d0f31e5 | 2015-10-19 18:12:18 -0700 | [diff] [blame] | 155 | status_t readString16(String16* pArg) const; |
Casey Dahlin | 00c4068 | 2015-11-25 15:09:45 -0800 | [diff] [blame] | 156 | status_t readString16(std::unique_ptr<String16>* pArg) const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 157 | const char16_t* readString16Inplace(size_t* outLen) const; |
| 158 | sp<IBinder> readStrongBinder() const; |
Casey Dahlin | 375de4a | 2015-10-27 18:33:56 -0700 | [diff] [blame] | 159 | status_t readStrongBinder(sp<IBinder>* val) const; |
Christopher Wiley | 32fc37f | 2016-03-08 10:49:51 -0800 | [diff] [blame] | 160 | status_t readNullableStrongBinder(sp<IBinder>* val) const; |
Mathias Agopian | 0d8e2e4 | 2013-07-29 21:24:40 -0700 | [diff] [blame] | 161 | |
Martijn Coenen | 249b02b | 2016-07-28 16:25:10 +0200 | [diff] [blame] | 162 | template<typename T> |
Martijn Coenen | 455e27d | 2017-04-18 15:53:51 -0700 | [diff] [blame] | 163 | const T* readObject(size_t *objects_offset = nullptr) const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 164 | |
Martijn Coenen | 455e27d | 2017-04-18 15:53:51 -0700 | [diff] [blame] | 165 | status_t readBuffer(size_t buffer_size, size_t *buffer_handle, |
| 166 | const void **buffer_out) const; |
| 167 | status_t readNullableBuffer(size_t buffer_size, size_t *buffer_handle, |
| 168 | const void **buffer_out) const; |
| 169 | status_t readEmbeddedBuffer(size_t buffer_size, size_t *buffer_handle, |
Martijn Coenen | 9d679d6 | 2017-01-10 16:44:24 +0100 | [diff] [blame] | 170 | size_t parent_buffer_handle, size_t parent_offset, |
| 171 | const void **buffer_out) const; |
Martijn Coenen | 455e27d | 2017-04-18 15:53:51 -0700 | [diff] [blame] | 172 | status_t readNullableEmbeddedBuffer(size_t buffer_size, |
| 173 | size_t *buffer_handle, |
Martijn Coenen | 9d679d6 | 2017-01-10 16:44:24 +0100 | [diff] [blame] | 174 | size_t parent_buffer_handle, |
| 175 | size_t parent_offset, |
| 176 | const void **buffer_out) const; |
| 177 | |
Martijn Coenen | 9d679d6 | 2017-01-10 16:44:24 +0100 | [diff] [blame] | 178 | status_t readEmbeddedNativeHandle(size_t parent_buffer_handle, |
| 179 | size_t parent_offset, const native_handle_t **handle) const; |
| 180 | status_t readNullableEmbeddedNativeHandle(size_t parent_buffer_handle, |
| 181 | size_t parent_offset, const native_handle_t **handle) const; |
| 182 | status_t readNativeHandleNoDup(const native_handle_t **handle) const; |
| 183 | status_t readNullableNativeHandleNoDup(const native_handle_t **handle) const; |
| 184 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 185 | // Explicitly close all file descriptors in the parcel. |
| 186 | void closeFileDescriptors(); |
Dianne Hackborn | 492acff | 2014-11-11 12:22:53 -0800 | [diff] [blame] | 187 | |
| 188 | // Debugging: get metrics on current allocations. |
| 189 | static size_t getGlobalAllocSize(); |
| 190 | static size_t getGlobalAllocCount(); |
| 191 | |
Arve Hjønnevåg | a544070 | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 192 | private: |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 193 | // Below is a cache that records some information about all actual buffers |
| 194 | // in this parcel. |
| 195 | struct BufferInfo { |
| 196 | size_t index; |
| 197 | binder_uintptr_t buffer; |
| 198 | binder_uintptr_t bufend; // buffer + length |
| 199 | }; |
| 200 | // value of mObjectSize when mBufCache is last updated. |
| 201 | mutable size_t mBufCachePos; |
| 202 | mutable std::vector<BufferInfo> mBufCache; |
| 203 | // clear mBufCachePos and mBufCache. |
| 204 | void clearCache() const; |
| 205 | // update mBufCache for all objects between mBufCachePos and mObjectsSize |
| 206 | void updateCache() const; |
Martijn Coenen | 455e27d | 2017-04-18 15:53:51 -0700 | [diff] [blame] | 207 | |
| 208 | bool verifyBufferObject(const binder_buffer_object *buffer_obj, |
| 209 | size_t size, uint32_t flags, size_t parent, |
| 210 | size_t parentOffset) const; |
| 211 | |
| 212 | status_t readBuffer(size_t buffer_size, size_t *buffer_handle, |
| 213 | uint32_t flags, size_t parent, size_t parentOffset, |
| 214 | const void **buffer_out) const; |
| 215 | |
| 216 | status_t readNullableNativeHandleNoDup(const native_handle_t **handle, |
| 217 | bool embedded, |
| 218 | size_t parent_buffer_handle = 0, |
| 219 | size_t parent_offset = 0) const; |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 220 | public: |
| 221 | |
| 222 | // The following two methods attempt to find if a chunk of memory ("buffer") |
| 223 | // is written / read before (by (read|write)(Embedded)?Buffer methods. ) |
| 224 | // 1. Call findBuffer if the chunk of memory could be a small part of a larger |
| 225 | // buffer written before (for example, an element of a hidl_vec). The |
| 226 | // method will also ensure that the end address (ptr + length) is also |
| 227 | // within the buffer. |
| 228 | // 2. Call quickFindBuffer if the buffer could only be written previously |
| 229 | // by itself (for example, the mBuffer field of a hidl_vec). No lengths |
| 230 | // are checked. |
| 231 | status_t findBuffer(const void *ptr, |
| 232 | size_t length, |
| 233 | bool *found, |
| 234 | size_t *handle, |
| 235 | size_t *offset // valid if found |
| 236 | ) const; |
| 237 | status_t quickFindBuffer(const void *ptr, |
| 238 | size_t *handle // valid if found |
| 239 | ) const; |
Yifan Hong | 1a3127d | 2016-09-27 15:46:52 -0700 | [diff] [blame] | 240 | |
| 241 | private: |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 242 | bool validateBufferChild(size_t child_buffer_handle, |
| 243 | size_t child_offset) const; |
| 244 | bool validateBufferParent(size_t parent_buffer_handle, |
| 245 | size_t parent_offset) const; |
| 246 | |
| 247 | private: |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 248 | typedef void (*release_func)(Parcel* parcel, |
| 249 | const uint8_t* data, size_t dataSize, |
Arve Hjønnevåg | a544070 | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 250 | const binder_size_t* objects, size_t objectsSize, |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 251 | void* cookie); |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 252 | |
Arve Hjønnevåg | a544070 | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 253 | uintptr_t ipcData() const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 254 | size_t ipcDataSize() const; |
Arve Hjønnevåg | a544070 | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 255 | uintptr_t ipcObjects() const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 256 | size_t ipcObjectsCount() const; |
Martijn Coenen | d39a168 | 2016-06-03 21:27:28 +0200 | [diff] [blame] | 257 | size_t ipcBufferSize() const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 258 | void ipcSetDataReference(const uint8_t* data, size_t dataSize, |
Arve Hjønnevåg | a544070 | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 259 | const binder_size_t* objects, size_t objectsCount, |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 260 | release_func relFunc, void* relCookie); |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 261 | |
Arve Hjønnevåg | a544070 | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 262 | public: |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 263 | void print(TextOutput& to, uint32_t flags = 0) const; |
Jeff Brown | 8a11ee5 | 2011-09-23 21:17:56 -0700 | [diff] [blame] | 264 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 265 | private: |
| 266 | Parcel(const Parcel& o); |
| 267 | Parcel& operator=(const Parcel& o); |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 268 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 269 | status_t finishWrite(size_t len); |
| 270 | void releaseObjects(); |
| 271 | void acquireObjects(); |
| 272 | status_t growData(size_t len); |
| 273 | status_t restartWrite(size_t desired); |
| 274 | status_t continueWrite(size_t desired); |
Serban Constantinescu | 4ca5baf | 2013-11-05 16:53:55 +0000 | [diff] [blame] | 275 | status_t writePointer(uintptr_t val); |
| 276 | status_t readPointer(uintptr_t *pArg) const; |
| 277 | uintptr_t readPointer() const; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 278 | void freeDataNoInit(); |
| 279 | void initState(); |
| 280 | void scanForFds() const; |
Yifan Hong | 38d4124 | 2016-08-29 12:51:23 -0700 | [diff] [blame] | 281 | |
Andreas Huber | f79b77e | 2009-08-17 13:33:27 -0700 | [diff] [blame] | 282 | template<class T> |
| 283 | status_t readAligned(T *pArg) const; |
| 284 | |
| 285 | template<class T> T readAligned() const; |
| 286 | |
| 287 | template<class T> |
| 288 | status_t writeAligned(T val); |
| 289 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 290 | status_t mError; |
| 291 | uint8_t* mData; |
| 292 | size_t mDataSize; |
| 293 | size_t mDataCapacity; |
| 294 | mutable size_t mDataPos; |
Arve Hjønnevåg | a544070 | 2014-01-28 20:12:59 -0800 | [diff] [blame] | 295 | binder_size_t* mObjects; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 296 | size_t mObjectsSize; |
| 297 | size_t mObjectsCapacity; |
| 298 | mutable size_t mNextObjectHint; |
Steven Moreland | d6ec2e8 | 2019-05-28 17:28:50 -0700 | [diff] [blame] | 299 | |
| 300 | [[deprecated]] size_t mNumRef; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 301 | |
| 302 | mutable bool mFdsKnown; |
| 303 | mutable bool mHasFds; |
Dianne Hackborn | abc3cf4 | 2011-09-28 23:19:47 -0400 | [diff] [blame] | 304 | bool mAllowFds; |
Christopher Tate | 8d24568 | 2016-03-24 16:03:44 -0700 | [diff] [blame] | 305 | |
Steven Moreland | a80270c | 2020-11-19 21:08:28 +0000 | [diff] [blame] | 306 | // if this parcelable is involved in a secure transaction, force the |
| 307 | // data to be overridden with zero when deallocated |
| 308 | mutable bool mDeallocZero; |
| 309 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 310 | release_func mOwner; |
| 311 | void* mOwnerCookie; |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 312 | }; |
Mathias Agopian | 0a84ac8 | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 313 | // --------------------------------------------------------------------------- |
| 314 | |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 315 | inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel) |
| 316 | { |
| 317 | parcel.print(to); |
| 318 | return to; |
| 319 | } |
| 320 | |
| 321 | // --------------------------------------------------------------------------- |
| 322 | |
| 323 | // Generic acquire and release of objects. |
| 324 | void acquire_object(const sp<ProcessState>& proc, |
Ian Pedowitz | 2a3fccc | 2015-10-22 22:08:10 +0000 | [diff] [blame] | 325 | const flat_binder_object& obj, const void* who); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 326 | void release_object(const sp<ProcessState>& proc, |
Ian Pedowitz | 2a3fccc | 2015-10-22 22:08:10 +0000 | [diff] [blame] | 327 | const flat_binder_object& obj, const void* who); |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 328 | |
| 329 | void flatten_binder(const sp<ProcessState>& proc, |
| 330 | const sp<IBinder>& binder, flat_binder_object* out); |
| 331 | void flatten_binder(const sp<ProcessState>& proc, |
| 332 | const wp<IBinder>& binder, flat_binder_object* out); |
| 333 | status_t unflatten_binder(const sp<ProcessState>& proc, |
| 334 | const flat_binder_object& flat, sp<IBinder>* out); |
| 335 | status_t unflatten_binder(const sp<ProcessState>& proc, |
| 336 | const flat_binder_object& flat, wp<IBinder>* out); |
| 337 | |
Steven Moreland | 7173a4c | 2019-09-26 15:55:02 -0700 | [diff] [blame] | 338 | } // namespace hardware |
| 339 | } // namespace android |
Mathias Agopian | 1647570 | 2009-05-19 19:08:10 -0700 | [diff] [blame] | 340 | |
| 341 | // --------------------------------------------------------------------------- |
| 342 | |
Martijn Coenen | f75a23d | 2016-08-01 11:55:17 +0200 | [diff] [blame] | 343 | #endif // ANDROID_HARDWARE_PARCEL_H |