mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-08 20:56:13 +00:00
Move dlfcn.h availability check to platform_common.h (#1134)
This commit is contained in:
parent
814a76ee89
commit
d9d0777051
|
@ -65,6 +65,14 @@ BH_VPRINTF(const char *format, va_list ap);
|
||||||
#define NULL (void *)0
|
#define NULL (void *)0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(BH_HAS_DLFCN)
|
||||||
|
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
|
||||||
|
#define BH_HAS_DLFCN 1
|
||||||
|
#else
|
||||||
|
#define BH_HAS_DLFCN 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
|
|
||||||
#ifndef true
|
#ifndef true
|
||||||
|
|
|
@ -41,6 +41,12 @@ typedef pthread_t korp_thread;
|
||||||
#define os_printf printf
|
#define os_printf printf
|
||||||
#define os_vprintf vprintf
|
#define os_vprintf vprintf
|
||||||
|
|
||||||
|
#if defined(CONFIG_LIBC_DLFCN)
|
||||||
|
#define BH_HAS_DLFCN 1
|
||||||
|
#else
|
||||||
|
#define BH_HAS_DLFCN 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/* On NuttX, time_t is uint32_t */
|
/* On NuttX, time_t is uint32_t */
|
||||||
#define BH_TIME_T_MAX 0xffffffff
|
#define BH_TIME_T_MAX 0xffffffff
|
||||||
|
|
||||||
|
|
|
@ -8,14 +8,15 @@
|
||||||
#endif
|
#endif
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
|
|
||||||
#include <dlfcn.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "bh_platform.h"
|
#include "bh_platform.h"
|
||||||
#include "bh_read_file.h"
|
#include "bh_read_file.h"
|
||||||
#include "wasm_export.h"
|
#include "wasm_export.h"
|
||||||
|
|
||||||
|
#if BH_HAS_DLFCN
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static int app_argc;
|
static int app_argc;
|
||||||
static char **app_argv;
|
static char **app_argv;
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ print_help()
|
||||||
printf(" for example:\n");
|
printf(" for example:\n");
|
||||||
printf(" --addr-pool=1.2.3.4/15,2.3.4.5/16\n");
|
printf(" --addr-pool=1.2.3.4/15,2.3.4.5/16\n");
|
||||||
#endif
|
#endif
|
||||||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
|
#if BH_HAS_DLFCN
|
||||||
printf(" --native-lib=<lib> Register native libraries to the WASM module, which\n");
|
printf(" --native-lib=<lib> Register native libraries to the WASM module, which\n");
|
||||||
printf(" are shared object (.so) files, for example:\n");
|
printf(" are shared object (.so) files, for example:\n");
|
||||||
printf(" --native-lib=test1.so --native-lib=test2.so\n");
|
printf(" --native-lib=test1.so --native-lib=test2.so\n");
|
||||||
|
@ -182,7 +183,7 @@ validate_env_str(char *env)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
|
#if BH_HAS_DLFCN
|
||||||
typedef uint32 (*get_native_lib_func)(char **p_module_name,
|
typedef uint32 (*get_native_lib_func)(char **p_module_name,
|
||||||
NativeSymbol **p_native_symbols);
|
NativeSymbol **p_native_symbols);
|
||||||
|
|
||||||
|
@ -232,7 +233,7 @@ load_and_register_native_libs(const char **native_lib_list,
|
||||||
|
|
||||||
return native_handle_count;
|
return native_handle_count;
|
||||||
}
|
}
|
||||||
#endif /* end of defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) */
|
#endif /* BH_HAS_DLFCN */
|
||||||
|
|
||||||
#if WASM_ENABLE_MULTI_MODULE != 0
|
#if WASM_ENABLE_MULTI_MODULE != 0
|
||||||
static char *
|
static char *
|
||||||
|
@ -309,7 +310,7 @@ main(int argc, char *argv[])
|
||||||
const char *addr_pool[8] = { NULL };
|
const char *addr_pool[8] = { NULL };
|
||||||
uint32 addr_pool_size = 0;
|
uint32 addr_pool_size = 0;
|
||||||
#endif
|
#endif
|
||||||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
|
#if BH_HAS_DLFCN
|
||||||
const char *native_lib_list[8] = { NULL };
|
const char *native_lib_list[8] = { NULL };
|
||||||
uint32 native_lib_count = 0;
|
uint32 native_lib_count = 0;
|
||||||
void *native_handle_list[8] = { NULL };
|
void *native_handle_list[8] = { NULL };
|
||||||
|
@ -403,7 +404,7 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* WASM_ENABLE_LIBC_WASI */
|
#endif /* WASM_ENABLE_LIBC_WASI */
|
||||||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
|
#if BH_HAS_DLFCN
|
||||||
else if (!strncmp(argv[0], "--native-lib=", 13)) {
|
else if (!strncmp(argv[0], "--native-lib=", 13)) {
|
||||||
if (argv[0][13] == '\0')
|
if (argv[0][13] == '\0')
|
||||||
return print_help();
|
return print_help();
|
||||||
|
@ -485,7 +486,7 @@ main(int argc, char *argv[])
|
||||||
bh_log_set_verbose_level(log_verbose_level);
|
bh_log_set_verbose_level(log_verbose_level);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
|
#if BH_HAS_DLFCN
|
||||||
native_handle_count = load_and_register_native_libs(
|
native_handle_count = load_and_register_native_libs(
|
||||||
native_lib_list, native_lib_count, native_handle_list);
|
native_lib_list, native_lib_count, native_handle_list);
|
||||||
#endif
|
#endif
|
||||||
|
@ -564,7 +565,7 @@ fail2:
|
||||||
os_munmap(wasm_file_buf, wasm_file_size);
|
os_munmap(wasm_file_buf, wasm_file_size);
|
||||||
|
|
||||||
fail1:
|
fail1:
|
||||||
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE)
|
#if BH_HAS_DLFCN
|
||||||
/* unload the native libraries */
|
/* unload the native libraries */
|
||||||
for (native_handle_idx = 0; native_handle_idx < native_handle_count;
|
for (native_handle_idx = 0; native_handle_idx < native_handle_count;
|
||||||
native_handle_idx++)
|
native_handle_idx++)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user