1 /*
2 * Copyright (c) 2023 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 "aot/aot_args.h"
17
18 #include "parcel_macro.h"
19 #include "string_ex.h"
20
21 namespace OHOS {
22 namespace AppExecFwk {
23 namespace {
24 constexpr uint32_t MAX_HSP_VECTOR_SIZE = 10000;
25 }
ReadFromParcel(Parcel & parcel)26 bool HspInfo::ReadFromParcel(Parcel &parcel)
27 {
28 std::u16string bundleNameVal;
29 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, bundleNameVal);
30 bundleName = Str16ToStr8(bundleNameVal);
31 std::u16string moduleNameVal;
32 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, moduleNameVal);
33 moduleName = Str16ToStr8(moduleNameVal);
34 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, versionCode);
35 std::u16string hapPathVal;
36 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, hapPathVal);
37 hapPath = Str16ToStr8(hapPathVal);
38 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, offset);
39 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, length);
40 return true;
41 }
42
Marshalling(Parcel & parcel) const43 bool HspInfo::Marshalling(Parcel &parcel) const
44 {
45 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
46 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
47 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, versionCode);
48 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hapPath));
49 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, offset);
50 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, length);
51 return true;
52 }
53
Unmarshalling(Parcel & parcel)54 HspInfo *HspInfo::Unmarshalling(Parcel &parcel)
55 {
56 HspInfo *hspInfo = new (std::nothrow) HspInfo();
57 if (hspInfo && !hspInfo->ReadFromParcel(parcel)) {
58 APP_LOGE("read HspInfo from parcel failed");
59 delete hspInfo;
60 hspInfo = nullptr;
61 }
62 return hspInfo;
63 }
64
ToString() const65 std::string HspInfo::ToString() const
66 {
67 return "[ bundleName = " + bundleName
68 + ", moduleName = " + moduleName
69 + ", versionCode = " + std::to_string(versionCode)
70 + ", hapPath = " + hapPath
71 + ", offset = " + std::to_string(offset)
72 + ", length = " + std::to_string(length) + "]";
73 }
74
ReadFromParcel(Parcel & parcel)75 bool AOTArgs::ReadFromParcel(Parcel &parcel)
76 {
77 std::u16string bundleNameVal;
78 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, bundleNameVal);
79 bundleName = Str16ToStr8(bundleNameVal);
80 std::u16string moduleNameVal;
81 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, moduleNameVal);
82 moduleName = Str16ToStr8(moduleNameVal);
83 std::u16string compileModeVal;
84 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, compileModeVal);
85 compileMode = Str16ToStr8(compileModeVal);
86 std::u16string hapPathVal;
87 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, hapPathVal);
88 hapPath = Str16ToStr8(hapPathVal);
89 std::u16string coreLibPathVal;
90 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, coreLibPathVal);
91 coreLibPath = Str16ToStr8(coreLibPathVal);
92 std::u16string outputPathVal;
93 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, outputPathVal);
94 outputPath = Str16ToStr8(outputPathVal);
95 std::u16string arkProfilePathVal;
96 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, arkProfilePathVal);
97 arkProfilePath = Str16ToStr8(arkProfilePathVal);
98 std::u16string anFileNameVal;
99 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, anFileNameVal);
100 anFileName = Str16ToStr8(anFileNameVal);
101 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, offset);
102 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, length);
103 uint32_t hspVectorSize = 0;
104 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, hspVectorSize);
105 hspVectorSize = std::min(hspVectorSize, MAX_HSP_VECTOR_SIZE);
106 for (uint32_t i = 0; i < hspVectorSize; ++i) {
107 std::unique_ptr<HspInfo> hspInfoPtr(parcel.ReadParcelable<HspInfo>());
108 if (!hspInfoPtr) {
109 APP_LOGE("read HspInfo failed");
110 return false;
111 }
112 hspVector.emplace_back(*hspInfoPtr);
113 }
114 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, bundleUid);
115 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, bundleGid);
116 std::u16string appIdentifilerVal;
117 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, appIdentifilerVal);
118 appIdentifier = Str16ToStr8(appIdentifilerVal);
119 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isEncryptedBundle);
120 std::u16string optBCRangeVal;
121 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, optBCRangeVal);
122 optBCRangeList = Str16ToStr8(optBCRangeVal);
123 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isScreenOff);
124 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isEnableBaselinePgo);
125 return true;
126 }
127
Marshalling(Parcel & parcel) const128 bool AOTArgs::Marshalling(Parcel &parcel) const
129 {
130 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(bundleName));
131 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(moduleName));
132 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(compileMode));
133 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(hapPath));
134 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(coreLibPath));
135 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(outputPath));
136 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(arkProfilePath));
137 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(anFileName));
138 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, offset);
139 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, length);
140 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, hspVector.size());
141 for (const auto &hspInfo : hspVector) {
142 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &hspInfo);
143 }
144 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, bundleUid);
145 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, bundleGid);
146 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(appIdentifier));
147 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isEncryptedBundle);
148 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(optBCRangeList));
149 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isScreenOff);
150 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, isEnableBaselinePgo);
151 return true;
152 }
153
Unmarshalling(Parcel & parcel)154 AOTArgs *AOTArgs::Unmarshalling(Parcel &parcel)
155 {
156 AOTArgs *aotArgs = new (std::nothrow) AOTArgs();
157 if (aotArgs && !aotArgs->ReadFromParcel(parcel)) {
158 APP_LOGE("read AOTArgs from parcel failed");
159 delete aotArgs;
160 aotArgs = nullptr;
161 }
162 return aotArgs;
163 }
164
ToString() const165 std::string AOTArgs::ToString() const
166 {
167 std::string ret = "[ bundleName = " + bundleName
168 + ", moduleName = " + moduleName
169 + ", compileMode = " + compileMode
170 + ", hapPath = " + hapPath
171 + ", coreLibPath = " + coreLibPath
172 + ", outputPath = " + outputPath
173 + ", arkProfilePath = " + arkProfilePath
174 + ", anFileName = " + anFileName
175 + ", offset = " + std::to_string(offset)
176 + ", length = " + std::to_string(length)
177 + ", bundleUid = " + std::to_string(bundleUid)
178 + ", bundleGid = " + std::to_string(bundleGid)
179 + ", appIdentifier = " + appIdentifier
180 + ", isEncryptedBundle = " + std::to_string(isEncryptedBundle)
181 + ", optBCRangeList = " + optBCRangeList
182 + ", isScreenOff = " + std::to_string(isScreenOff)
183 + ", isEnableBaselinePgo = " + std::to_string(isEnableBaselinePgo) + "]";
184 ret.append(" hspVector = ");
185 for (const auto &hspInfo : hspVector) {
186 ret.append(hspInfo.ToString());
187 }
188 return ret;
189 }
190 } // namespace AppExecFwk
191 } // namespace OHOS
192