1 /*
2 * Copyright (c) 2024 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 #include "dynamic_loader.h"
17
18 #include <cstdio>
19 #include <libloaderapi.h>
20 #include <processenv.h>
21
22 namespace {
23 constexpr auto ERROR_BUF_SIZE = 255;
24 static char g_dlError[ERROR_BUF_SIZE] {0};
25 }
26
27 extern "C" {
DynamicLoadLibrary(const char * dlPath,unsigned int mode)28 void* DynamicLoadLibrary(const char* dlPath, unsigned int mode)
29 {
30 return LoadLibraryA(dlPath);
31 }
32
DynamicFindSymbol(void * so,const char * symbol)33 void* DynamicFindSymbol(void* so, const char* symbol)
34 {
35 return (void*)GetProcAddress((HMODULE)so, symbol);
36 }
37
DynamicFreeLibrary(void * so)38 void DynamicFreeLibrary(void* so)
39 {
40 (void)FreeLibrary((HMODULE)so);
41 }
42
DynamicGetError()43 const char* DynamicGetError()
44 {
45 return g_dlError;
46 }
47 }
48