• 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     (void)name;
106     #ifdef MOCK_WRITE_INTERFACE_TOKEN_RETURN_TRUE
107     return true;
108     #else
109     return false;
110     #endif
111 }
112 
ReadInterfaceToken()113 std::u16string MessageParcel::ReadInterfaceToken()
114 {
115     return ReadString16();
116 }
117 
WriteRawData(const void * data,size_t size)118 bool MessageParcel::WriteRawData(const void* data, size_t size)
119 {
120     (void)data;
121     (void)size;
122     return false;
123 }
124 
RestoreRawData(std::shared_ptr<char> rawData,size_t size)125 bool MessageParcel::RestoreRawData(std::shared_ptr<char> rawData, size_t size)
126 {
127     (void)rawData;
128     (void)size;
129     return false;
130 }
131 
ReadRawData(size_t size)132 const void* MessageParcel::ReadRawData(size_t size)
133 {
134     (void)size;
135     return nullptr;
136 }
137 
GetRawData() const138 const void* MessageParcel::GetRawData() const
139 {
140     return nullptr;
141 }
142 
GetRawDataSize() const143 size_t MessageParcel::GetRawDataSize() const
144 {
145     return rawDataSize_;
146 }
147 
GetRawDataCapacity() const148 size_t MessageParcel::GetRawDataCapacity() const
149 {
150     return MAX_RAWDATA_SIZE;
151 }
152 
WriteNoException()153 void MessageParcel::WriteNoException()
154 {
155     WriteInt32(0);
156 }
157 
ReadException()158 int32_t MessageParcel::ReadException()
159 {
160     return ReadInt32();
161 }
162 
WriteAshmem(sptr<Ashmem> ashmem)163 bool MessageParcel::WriteAshmem(sptr<Ashmem> ashmem)
164 {
165     (void)ashmem;
166     return false;
167 }
168 
ReadAshmem()169 sptr<Ashmem> MessageParcel::ReadAshmem()
170 {
171     return nullptr;
172 }
173 
Append(MessageParcel & data)174 bool MessageParcel::Append(MessageParcel& data)
175 {
176     (void)data;
177     return false;
178 }
179 } // namespace OHOS
180