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