1 /** 2 * Copyright (c) 2021-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 PANDA_PLUGINS_ETS_RUNTIME_ETS_NATIVE_LIBRARY_PROVIDER_H_ 17 #define PANDA_PLUGINS_ETS_RUNTIME_ETS_NATIVE_LIBRARY_PROVIDER_H_ 18 19 #include <string> 20 #include "libpandabase/os/mutex.h" 21 #include "plugins/ets/runtime/ets_native_library.h" 22 #include "plugins/ets/runtime/napi/ets_napi.h" 23 #include "runtime/include/mem/panda_containers.h" 24 25 namespace ark::ets { 26 class NativeLibraryProvider { 27 public: 28 NativeLibraryProvider() = default; 29 ~NativeLibraryProvider() = default; 30 31 NO_COPY_SEMANTIC(NativeLibraryProvider); 32 NO_MOVE_SEMANTIC(NativeLibraryProvider); 33 34 std::optional<std::string> LoadLibrary(EtsEnv *env, const PandaString &name, bool shouldVerifyPermission, 35 const PandaString &fileName); 36 void *ResolveSymbol(const PandaString &name) const; 37 38 PandaVector<PandaString> GetLibraryPath() const; 39 void SetLibraryPath(const PandaVector<PandaString> &pathes); 40 void AddLibraryPath(const PandaString &path); 41 42 private: 43 mutable os::memory::RWLock lock_; 44 std::optional<std::string> CallAniCtor(EtsEnv *env, const EtsNativeLibrary *lib); 45 std::optional<std::string> GetCallerClassName(EtsEnv *env); 46 bool CheckLibraryPermission(EtsEnv *env, const PandaString &fileName); 47 PandaSet<EtsNativeLibrary> libraries_ GUARDED_BY(lock_); 48 PandaVector<PandaString> libraryPath_ GUARDED_BY(lock_); 49 }; 50 } // namespace ark::ets 51 52 #endif // PANDA_PLUGINS_ETS_RUNTIME_ETS_NATIVE_LIBRARY_PROVIDER_H_ 53