Skip to content

Commit

Permalink
用更简单的办法关闭dlopen和dlsym
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Mar 10, 2017
1 parent 729fc82 commit b46a420
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 42 deletions.
21 changes: 0 additions & 21 deletions build/luajit-2.1.0b2/src/lib_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,21 @@

static void ll_unloadlib(void *lib)
{
#if defined(LJ_TARGET_IOS)
(void)(lib);
#else
dlclose(lib);
#endif
}

static void *ll_load(lua_State *L, const char *path, int gl)
{
#if defined(LJ_TARGET_IOS)
(void)(path);
lua_pushstring(L, "dlopen is forbidden in ios");
return NULL;
#else
void *lib = dlopen(path, RTLD_NOW | (gl ? RTLD_GLOBAL : RTLD_LOCAL));
if (lib == NULL) lua_pushstring(L, dlerror());
return lib;
#endif
}

static lua_CFunction ll_sym(lua_State *L, void *lib, const char *sym)
{
#if defined(LJ_TARGET_IOS)
(void)(lib);(void)(sym);
lua_pushstring(L, "dlsym is forbidden in ios");
return NULL;
#else
lua_CFunction f = (lua_CFunction)dlsym(lib, sym);
if (f == NULL) lua_pushstring(L, dlerror());
return f;
#endif
}

static const char *ll_bcsym(void *lib, const char *sym)
Expand All @@ -78,12 +62,7 @@ static const char *ll_bcsym(void *lib, const char *sym)
#elif LJ_TARGET_OSX || LJ_TARGET_BSD
if (lib == NULL) lib = (void *)(intptr_t)-2;
#endif
#if defined(LJ_TARGET_IOS)
(void)(lib);(void)(sym);
return NULL;
#else
return (const char *)dlsym(lib, sym);
#endif
}

#elif LJ_TARGET_WINDOWS
Expand Down
4 changes: 4 additions & 0 deletions build/luajit-2.1.0b2/src/lj_arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@
#define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX)
#define LJ_TARGET_IOS (LJ_TARGET_OSX && (LUAJIT_TARGET == LUAJIT_ARCH_ARM || LUAJIT_TARGET == LUAJIT_ARCH_ARM64))
#define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS)
#if LJ_TARGET_IOS
#define LJ_TARGET_DLOPEN 0
#else
#define LJ_TARGET_DLOPEN LJ_TARGET_POSIX
#endif

#ifdef __CELLOS_LV2__
#define LJ_TARGET_PS3 1
Expand Down
21 changes: 0 additions & 21 deletions build/luajit-2.1.0b2/src/lj_clib.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ LJ_NORET LJ_NOINLINE static void clib_error_(lua_State *L)
#define CLIB_SOEXT "%s.so"
#endif

#if !defined(LJ_TARGET_IOS)
static const char *clib_extname(lua_State *L, const char *name)
{
if (!strchr(name, '/')
Expand All @@ -78,9 +77,7 @@ static const char *clib_extname(lua_State *L, const char *name)
}
return name;
}
#endif

#if !defined(LJ_TARGET_IOS)
/* Check for a recognized ld script line. */
static const char *clib_check_lds(lua_State *L, const char *buf)
{
Expand All @@ -93,9 +90,7 @@ static const char *clib_check_lds(lua_State *L, const char *buf)
}
return NULL;
}
#endif

#if !defined(LJ_TARGET_IOS)
/* Quick and dirty solution to resolve shared library name from ld script. */
static const char *clib_resolve_lds(lua_State *L, const char *name)
{
Expand All @@ -117,15 +112,9 @@ static const char *clib_resolve_lds(lua_State *L, const char *name)
}
return p;
}
#endif

static void *clib_loadlib(lua_State *L, const char *name, int global)
{
#if defined(LJ_TARGET_IOS)
(void)(name);
lj_err_callermsg(L, "dlopen is forbidden in ios");
return NULL;
#else
void *h = dlopen(clib_extname(L, name),
RTLD_LAZY | (global?RTLD_GLOBAL:RTLD_LOCAL));
if (!h) {
Expand All @@ -139,28 +128,18 @@ static void *clib_loadlib(lua_State *L, const char *name, int global)
lj_err_callermsg(L, err);
}
return h;
#endif
}

static void clib_unloadlib(CLibrary *cl)
{
#if defined(LJ_TARGET_IOS)
(void)(cl);
#else
if (cl->handle && cl->handle != CLIB_DEFHANDLE)
dlclose(cl->handle);
#endif
}

static void *clib_getsym(CLibrary *cl, const char *name)
{
#if defined(LJ_TARGET_IOS)
(void)(cl);(void)(name);
return NULL;
#else
void *p = dlsym(cl->handle, name);
return p;
#endif
}

#elif LJ_TARGET_WINDOWS
Expand Down

0 comments on commit b46a420

Please sign in to comment.