未验证 提交 b0f06550 编写于 作者: O openharmony_ci 提交者: Gitee

!250 add namespace create interface for musl

Merge pull request !250 from hhj/dlns-inf
......@@ -1832,6 +1832,7 @@ musl_src_porting_file = [
"include/sys/sysinfo.h",
"src/internal/dynlink.h",
"include/unistd.h",
"include/dlfcn.h",
"src/internal/pthread_impl.h",
"src/internal/syscall.h",
"src/legacy/ulimit.c",
......
#ifndef _DLFCN_H
#define _DLFCN_H
#ifdef __cplusplus
extern "C" {
#endif
#include <features.h>
#define RTLD_LAZY 1
#define RTLD_NOW 2
#define RTLD_NOLOAD 4
#define RTLD_NODELETE 4096
#define RTLD_GLOBAL 256
#define RTLD_LOCAL 0
#define RTLD_NEXT ((void *)-1)
#define RTLD_DEFAULT ((void *)0)
#define RTLD_DI_LINKMAP 2
int dlclose(void *);
char *dlerror(void);
void *dlopen(const char *, int);
void *dlsym(void *__restrict, const char *__restrict);
/* namespace apis */
typedef const char* Dl_namespace;
void dlns_init(Dl_namespace *, const char *);
/* open dso in given namespace which has own lib search paths
* when namespace is null, it's same to dlopen()
* void to use "default" as namespace, which is the default namespace*/
void *dlopen_ns(Dl_namespace *, const char *, int);
/* create the namespace and set lib search paths of namespace,
* the paths should be splited by ':'. When namespace already exist,
* return error */
int dlns_create(Dl_namespace *, const char *);
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
typedef struct {
const char *dli_fname;
void *dli_fbase;
const char *dli_sname;
void *dli_saddr;
} Dl_info;
int dladdr(const void *, Dl_info *);
int dlinfo(void *, int, void *);
#endif
#if _REDIR_TIME64
__REDIR(dlsym, __dlsym_time64);
#endif
#ifdef __cplusplus
}
#endif
#endif
......@@ -1083,7 +1083,7 @@ static struct dso *load_library(const char *name, struct dso *needed_by)
sys_path = "";
}
}
if (!sys_path) sys_path = "/lib:/usr/local/lib:/usr/lib";
if (!sys_path) sys_path = strdup("/lib:/usr/local/lib:/usr/lib");
fd = path_open(name, sys_path, buf, sizeof buf);
}
pathname = buf;
......@@ -2427,3 +2427,46 @@ static void error(const char *fmt, ...)
__dl_vseterr(fmt, ap);
va_end(ap);
}
void dlns_init(Dl_namespace *ns, const char *name)
{
*ns = name;
}
void *dlopen_ns(Dl_namespace *ns, const char *file, int mode)
{
if (!ns) return NULL;
return dlopen(file, mode);
}
int dlns_create(Dl_namespace *ns,const char *search_path)
{
int sys_length = 0;
int search_length = 0;
char * new_path = NULL;
if (!search_path || !ns) return EINVAL;
sys_length = strlen(sys_path);
search_length = strlen(search_path);
if (search_path[0] != ':'){
sys_length += search_length + 1;
} else {
sys_length += search_length;
}
new_path = malloc(sys_length + 1);
if (!new_path) return ENOMEM;
strcat(new_path, sys_path);
if (search_path[0] != ':') {
strcat(new_path, ":");
}
strcat(new_path, search_path);
free(sys_path);
sys_path = new_path;
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册