• 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 #ifndef ECMASCRIPT_JSPANDAFILE_QUICK_FIX_MANAGER_H
16 #define ECMASCRIPT_JSPANDAFILE_QUICK_FIX_MANAGER_H
17 
18 #include "ecmascript/jspandafile/quick_fix_loader.h"
19 
20 namespace panda::ecmascript {
21 class QuickFixManager {
22 public:
23     using QuickFixQueryCallBack = bool (*)(std::string, std::string &, void **, size_t);
24 
25     QuickFixManager() = default;
26     ~QuickFixManager();
27 
28     void RegisterQuickFixQueryFunc(const QuickFixQueryCallBack callBack);
29     void LoadPatchIfNeeded(JSThread *thread, const std::string &baseFileName);
30     bool LoadPatch(JSThread *thread, const std::string &patchFileName, const std::string &baseFileName);
31     bool LoadPatch(JSThread *thread, const std::string &patchFileName, const void *patchBuffer, size_t patchSize,
32                    const std::string &baseFileName);
33     bool UnloadPatch(JSThread *thread, const std::string &patchFileName);
34     bool IsQuickFixCausedException(JSThread *thread,
35                                    const JSHandle<JSTaggedValue> &exceptionInfo,
36                                    const std::string &patchFileName);
37 private:
38     // check whether the callback is registered.
HasQueryQuickFixInfoFunc()39     bool HasQueryQuickFixInfoFunc() const
40     {
41         return callBack_ != nullptr;
42     }
43 
44     // check whether the patch is loaded.
HasLoadedPatch(std::string & patchFileName)45     inline bool HasLoadedPatch(std::string &patchFileName) const
46     {
47         return quickFixLoaders_.find(patchFileName) != quickFixLoaders_.end();
48     }
49 
50     CUnorderedSet<CString> ParseStackInfo(const CString &stackInfo);
51 
52     // For multi patch.
53     // key: patchFileName, value: QuickFixLoader of this patch.
54     CMap<std::string, QuickFixLoader*> quickFixLoaders_;
55     QuickFixQueryCallBack callBack_ {nullptr};
56 };
57 }  // namespace panda::ecmascript
58 #endif // ECMASCRIPT_JSPANDAFILE_QUICK_FIX_MANAGER_H