1 /*
2  * Copyright (C) 2021 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 "invoker_rawdata.h"
17 
18 #include "memory"
19 #include "new"
20 #include "ipc_debug.h"
21 #include "log_tags.h"
22 
23 namespace OHOS {
24 static constexpr OHOS::HiviewDFX::HiLogLabel LOG_LABEL = { LOG_CORE, LOG_ID_RPC_DBINDER_INVOKER, "InvokerRawData" };
25 static constexpr size_t MAX_RAWDATA_SIZE = 128 * 1024 * 1024; // 128M
26 
InvokerRawData(size_t size)27 InvokerRawData::InvokerRawData(size_t size)
28 {
29     if (size == 0 || size > MAX_RAWDATA_SIZE) {
30         ZLOGE(LOG_LABEL, "size:%{public}zu not ok", size);
31         return;
32     }
33     /* size is guaranteed by caller, in MessageParcel max size is 1G */
34     data_.reset(reinterpret_cast<char *>(::operator new(size)));
35     size_ = size;
36 }
37 
~InvokerRawData()38 InvokerRawData::~InvokerRawData()
39 {
40     data_ = nullptr;
41 }
42 
GetData() const43 std::shared_ptr<char> InvokerRawData::GetData() const
44 {
45     return data_;
46 }
47 
GetSize() const48 size_t InvokerRawData::GetSize() const
49 {
50     return size_;
51 }
52 } // namespace OHOS