• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "minddata/dataset/plugin/shared_lib_util.h"
18 #ifdef __linux__
19 #include <dlfcn.h>
20 #endif
21 namespace mindspore {
22 namespace dataset {
23 #ifdef __linux__
Load(const std::string & name)24 void *SharedLibUtil::Load(const std::string &name) { return dlopen(name.c_str(), RTLD_LAZY); }
FindSym(void * handle,const std::string & name)25 void *SharedLibUtil::FindSym(void *handle, const std::string &name) { return dlsym(handle, name.c_str()); }
Close(void * handle)26 int32_t SharedLibUtil::Close(void *handle) { return dlclose(handle); }
ErrMsg()27 std::string SharedLibUtil::ErrMsg() {
28   char *err_msg = dlerror();
29   return err_msg != nullptr ? std::string(err_msg) : "dlerror() returned a nullptr";
30 }
31 #else  // MindData currently doesn't support loading shared library on platform that doesn't support dlopen
32 void *SharedLibUtil::Load(const std::string &name) { return nullptr; }
33 void *SharedLibUtil::FindSym(void *handle, const std::string &name) { return nullptr; }
34 int32_t SharedLibUtil::Close(void *handle) { return -1; }
35 std::string SharedLibUtil::ErrMsg() { return std::string("Plugin on non-Linux platform is not yet supported."); }
36 #endif
37 }  // namespace dataset
38 }  // namespace mindspore
39