/root/doris/be/src/util/dynamic_util.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // This file is copied from |
18 | | // https://github.com/apache/impala/blob/branch-2.9.0/be/src/util/dynamic-util.cc |
19 | | // and modified by Doris |
20 | | |
21 | | #include "util/dynamic_util.h" |
22 | | |
23 | | #include <dlfcn.h> |
24 | | |
25 | | namespace doris { |
26 | | |
27 | 0 | Status dynamic_lookup(void* handle, const char* symbol, void** fn_ptr) { |
28 | 0 | *(void**)(fn_ptr) = dlsym(handle, symbol); |
29 | 0 | char* error = dlerror(); |
30 | |
|
31 | 0 | if (error != nullptr) { |
32 | 0 | return Status::InternalError("Unable to find {}\ndlerror: {}", symbol, error); |
33 | 0 | } |
34 | | |
35 | 0 | return Status::OK(); |
36 | 0 | } |
37 | | |
38 | 0 | Status dynamic_open(const char* library, void** handle) { |
39 | 0 | int flags = RTLD_NOW; |
40 | |
|
41 | 0 | *handle = dlopen(library, flags); |
42 | |
|
43 | 0 | if (*handle == nullptr) { |
44 | 0 | return Status::InternalError("Unable to load {}\ndlerror: {}", library, dlerror()); |
45 | 0 | } |
46 | | |
47 | 0 | return Status::OK(); |
48 | 0 | } |
49 | | |
50 | 0 | void dynamic_close(void* handle) { |
51 | | // There is an issue of LSAN can't deal well with dlclose(), so we disable LSAN here, more details: |
52 | | // https://github.com/google/sanitizers/issues/89 |
53 | | #if !defined(ADDRESS_SANITIZER) && !defined(LEAK_SANITIZER) |
54 | | dlclose(handle); |
55 | | #endif |
56 | 0 | } |
57 | | |
58 | | } // namespace doris |