FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
unified-runtime/source/common/linux/ur_lib_loader.cpp at main · bashbaug/unified-runtime · GitHub
bashbaug
/
unified-runtime
Public
forked from
oneapi-src/unified-runtime
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
unified-runtime
/
source
/
common
/
linux
/
ur_lib_loader.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (66 loc) · 2.06 KB
Breadcrumbs
unified-runtime
/
source
/
common
/
linux
/
ur_lib_loader.cpp
Copy path
File metadata and controls
73 lines (66 loc) · 2.06 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
*
* Copyright (C) 2023 Intel Corporation
*
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
* See LICENSE.TXT
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*/
#
include
<
dlfcn.h
>
#
if
__has_include(<link.h>)
#
include
<
link.h
>
#
define
ADD_FULL_PATH_LOG
#
endif
#
include
"
logger/ur_logger.hpp
"
#
include
"
ur_lib_loader.hpp
"
#
define
DEEP_BIND_ENV
"
UR_ADAPTERS_DEEP_BIND
"
namespace
ur_loader
{
void
LibLoader::freeAdapterLibrary
(
HMODULE
handle) {
if
(handle) {
int
res =
dlclose
(handle);
if
(res) {
logger::error
(
"
Failed to unload the library with the handle at address {}
"
,
handle);
}
else
{
logger::info
(
"
unloaded adapter 0x{}
"
, handle);
}
}
}
std::unique_ptr<
HMODULE
, LibLoader::lib_dtor>
LibLoader::loadAdapterLibrary
(
const
char
*name) {
int
mode =
RTLD_LAZY
|
RTLD_LOCAL
;
#
if
!defined(__APPLE__)
bool
deepbind =
getenv_tobool
(
DEEP_BIND_ENV
);
if
(deepbind) {
#
if
defined(SANITIZER_ANY)
logger::warning
(
"
Enabling RTLD_DEEPBIND while running under a sanitizer is likely
"
"
to cause issues. Consider disabling {} environment variable.
"
,
DEEP_BIND_ENV
);
#
endif
mode |=
RTLD_DEEPBIND
;
}
#
endif
HMODULE
handle =
dlopen
(name, mode);
if
(!handle) {
char
*err =
dlerror
();
logger::info
(
"
failed to load adapter '{}' with error: {}
"
, name,
err ? err :
"
unknown error
"
);
}
else
{
#
if
defined(ADD_FULL_PATH_LOG)
struct
link_map
*dlinfo_map;
if
(
dlinfo
(handle,
RTLD_DI_LINKMAP
, &dlinfo_map) ==
0
) {
logger::info
(
"
loaded adapter 0x{} ({}) from {}
"
, handle, name,
dlinfo_map->
l_name
);
}
else
#
endif
logger::info
(
"
loaded adapter 0x{} ({})
"
, handle, name);
}
return
std::unique_ptr<
HMODULE
, LibLoader::lib_dtor>(handle);
}
void
*
LibLoader::getFunctionPtr
(
HMODULE
handle,
const
char
*func_name) {
return
dlsym
(handle, func_name);
}
}
//
namespace ur_loader
Back
|
FazBrowse Home
|
New Git URL