• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "message_parcel.h"
17 
18 #include <sys/mman.h>
19 #include <unistd.h>
20 
21 #include "iremote_object.h"
22 
23 namespace OHOS {
MessageParcel()24 MessageParcel::MessageParcel() :
25     Parcel(), writeRawDataFd_(-1), readRawDataFd_(-1),
26     kernelMappedWrite_(nullptr), kernelMappedRead_(nullptr),
27     rawData_(nullptr), rawDataSize_(0)
28 {
29 }
30 
MessageParcel(Allocator * allocator)31 MessageParcel::MessageParcel(Allocator* allocator) :
32     Parcel(allocator), writeRawDataFd_(-1), readRawDataFd_(-1),
33     kernelMappedWrite_(nullptr), kernelMappedRead_(nullptr),
34     rawData_(nullptr), rawDataSize_(0)
35 {
36 }
37 
~MessageParcel()38 MessageParcel::~MessageParcel()
39 {
40     if (kernelMappedWrite_ != nullptr) {
41         ::munmap(kernelMappedWrite_, rawDataSize_);
42         kernelMappedWrite_ = nullptr;
43     }
44     if (kernelMappedRead_ != nullptr) {
45         ::munmap(kernelMappedRead_, rawDataSize_);
46         kernelMappedRead_ = nullptr;
47     }
48 
49     if (readRawDataFd_ > 0) {
50         ::close(readRawDataFd_);
51         readRawDataFd_ = -1;
52     }
53     if (writeRawDataFd_ > 0) {
54         ::close(writeRawDataFd_);
55         writeRawDataFd_ = -1;
56     }
57 
58     ClearFileDescriptor();
59 
60     rawData_ = nullptr;
61     rawDataSize_ = 0;
62 }
63 
64 #ifndef CONFIG_IPC_SINGLE
WriteDBinderProxy(const sptr<IRemoteObject> & object,uint32_t handle,uint64_t stubIndex)65 bool MessageParcel::WriteDBinderProxy(const sptr<IRemoteObject>& object, uint32_t handle, uint64_t stubIndex)
66 {
67     (void)object;
68     (void)handle;
69     (void)stubIndex;
70     return false;
71 }
72 #endif
73 
WriteRemoteObject(const sptr<IRemoteObject> & object)74 bool MessageParcel::WriteRemoteObject(const sptr<IRemoteObject>& object)
75 {
76     (void)object;
77     return false;
78 }
79 
ReadRemoteObject()80 sptr<IRemoteObject> MessageParcel::ReadRemoteObject()
81 {
82     return nullptr;
83 }
84 
WriteFileDescriptor(int fd)85 bool MessageParcel::WriteFileDescriptor(int fd)
86 {
87     (void)fd;
88     return false;
89 }
90 
ReadFileDescriptor()91 int MessageParcel::ReadFileDescriptor()
92 {
93     return -1;
94 }
95 
ClearFileDescriptor()96 void MessageParcel::ClearFileDescriptor() {}
97 
ContainFileDescriptors() const98 bool MessageParcel::ContainFileDescriptors() const
99 {
100     return false;
101 }
102 
WriteInterfaceToken(std::u16string name)103 bool MessageParcel::WriteInterfaceToken(std::u16string name)
104 {
105     #ifdef MOCK_WRITE_INTERFACE_TOKEN_RETURN_TRUE
106     return true;
107     #else
108     return false;
109     #endif
110 }
111 
ReadInterfaceToken()112 std::u16string MessageParcel::ReadInterfaceToken()
113 {
114     return ReadString16();
115 }
116 
WriteRawData(const void * data,size_t size)117 bool MessageParcel::WriteRawData(const void* data, size_t size)
118 {
119     (void)data;
120     (void)size;
121     return false;
122 }
123 
RestoreRawData(std::shared_ptr<char> rawData,size_t size)124 bool MessageParcel::RestoreRawData(std::shared_ptr<char> rawData, size_t size)
125 {
126     (void)rawData;
127     (void)size;
128     return false;
129 }
130 
ReadRawData(size_t size)131 const void* MessageParcel::ReadRawData(size_t size)
132 {
133     (void)size;
134     return nullptr;
135 }
136 
GetRawData() const137 const void* MessageParcel::GetRawData() const
138 {
139     return nullptr;
140 }
141 
GetRawDataSize() const142 size_t MessageParcel::GetRawDataSize() const
143 {
144     return rawDataSize_;
145 }
146 
GetRawDataCapacity() const147 size_t MessageParcel::GetRawDataCapacity() const
148 {
149     return MAX_RAWDATA_SIZE;
150 }
151 
WriteNoException()152 void MessageParcel::WriteNoException()
153 {
154     WriteInt32(0);
155 }
156 
ReadException()157 int32_t MessageParcel::ReadException()
158 {
159     return ReadInt32();
160 }
161 
WriteAshmem(sptr<Ashmem> ashmem)162 bool MessageParcel::WriteAshmem(sptr<Ashmem> ashmem)
163 {
164     (void)ashmem;
165     return false;
166 }
167 
ReadAshmem()168 sptr<Ashmem> MessageParcel::ReadAshmem()
169 {
170     return nullptr;
171 }
172 
Append(MessageParcel & data)173 bool MessageParcel::Append(MessageParcel& data)
174 {
175     (void)data;
176     return false;
177 }
178 } // namespace OHOS
179