• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 #ifndef FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_EXECUTOR
17 #define FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_EXECUTOR
18 
19 #include <mutex>
20 #include <nlohmann/json.hpp>
21 #include <unordered_map>
22 
23 #include "aot/aot_args.h"
24 #include "appexecfwk_errors.h"
25 #include "nocopyable.h"
26 
27 namespace OHOS {
28 namespace AppExecFwk {
29 struct AOTState {
30     bool running = false;
31     std::string outputPath;
32 };
33 
34 class AOTExecutor final {
35 public:
36     static AOTExecutor& GetInstance();
37     void ExecuteAOT(const AOTArgs &aotArgs, ErrCode &ret, std::vector<uint8_t> &pendSignData);
38     ErrCode PendSignAOT(const std::string &anFileName, const std::vector<uint8_t> &signData) const;
39     ErrCode StopAOT();
40 private:
41     AOTExecutor() = default;
42     ~AOTExecutor() = default;
43     DISALLOW_COPY_AND_MOVE(AOTExecutor);
44 
45     std::string DecToHex(uint32_t decimal) const;
46     bool CheckArgs(const AOTArgs &aotArgs) const;
47     std::string GetAbcRelativePath(const std::string &moduleArkTSMode) const;
48     bool GetAbcFileInfo(const std::string &hapPath, const std::string &moduleArkTSMode,
49         uint32_t &offset, uint32_t &length) const;
50     ErrCode PrepareArgs(const AOTArgs &aotArgs, AOTArgs &completeArgs) const;
51     nlohmann::json GetSubjectInfo(const AOTArgs &aotArgs) const;
52     void MapSysCompArgs(const AOTArgs &aotArgs, std::unordered_map<std::string, std::string> &argsMap);
53     void MapHapArgs(const AOTArgs &aotArgs, std::unordered_map<std::string, std::string> &argsMap);
54     ErrCode EnforceCodeSign(const std::string &anFileName, const std::vector<uint8_t> &signData) const;
55     ErrCode StartAOTCompiler(const AOTArgs &aotArgs, std::vector<uint8_t> &signData);
56     void InitState(const AOTArgs &aotArgs);
57     void ResetState();
58 private:
59     mutable std::mutex stateMutex_;
60     AOTState state_;
61 };
62 }  // namespace AppExecFwk
63 }  // namespace OHOS
64 #endif  // FOUNDATION_BUNDLE_FRAMEWORK_AOT_AOT_EXECUTOR
65