xref: /freebsd/contrib/llvm-project/compiler-rt/lib/orc/dlfcn_wrapper.cpp (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 //===- dlfcn_wrapper.cpp --------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of the ORC runtime support library.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "adt.h"
14 #include "common.h"
15 #include "wrapper_function_utils.h"
16 
17 #include <vector>
18 
19 using namespace __orc_rt;
20 
21 extern "C" const char *__orc_rt_jit_dlerror();
22 extern "C" void *__orc_rt_jit_dlopen(const char *path, int mode);
23 extern "C" int __orc_rt_jit_dlclose(void *dso_handle);
24 
25 ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
26 __orc_rt_jit_dlerror_wrapper(const char *ArgData, size_t ArgSize) {
27   return WrapperFunction<SPSString()>::handle(
28              ArgData, ArgSize,
29              []() { return std::string(__orc_rt_jit_dlerror()); })
30       .release();
31 }
32 
33 ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
34 __orc_rt_jit_dlopen_wrapper(const char *ArgData, size_t ArgSize) {
35   return WrapperFunction<SPSExecutorAddr(SPSString, int32_t)>::handle(
36              ArgData, ArgSize,
37              [](const std::string &Path, int32_t mode) {
38                return ExecutorAddr::fromPtr(
39                    __orc_rt_jit_dlopen(Path.c_str(), mode));
40              })
41       .release();
42 }
43 
44 ORC_RT_INTERFACE orc_rt_CWrapperFunctionResult
45 __orc_rt_jit_dlclose_wrapper(const char *ArgData, size_t ArgSize) {
46   return WrapperFunction<int32_t(SPSExecutorAddr)>::handle(
47              ArgData, ArgSize,
48              [](ExecutorAddr &DSOHandle) {
49                return __orc_rt_jit_dlclose(DSOHandle.toPtr<void *>());
50              })
51       .release();
52 }
53