Add workaround to make possible to close memfds after dlopen

This commit is contained in:
Oleksii Shevchuk 2017-03-06 07:58:06 +02:00
parent fec8025de7
commit ce50ea3230
1 changed files with 17 additions and 1 deletions

View File

@ -189,8 +189,24 @@ void *memdlopen(const char *soname, const char *buffer, size_t size) {
dprint("Library \"%s\" dropped to \"%s\" (memfd=%d) \n", soname, buf, is_memfd);
base = dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
#ifndef NO_MEMFD_DLOPEN_WORKAROUND
if (is_memfd) {
char *fake_path = tempnam("/dev/shm", NULL);
if (!fake_path) {
fake_path = tempnam("/tmp", NULL);
}
if (fake_path) {
if (!symlink(buf, fake_path)) {
strncpy(buf, fake_path, sizeof(buf)-1);
is_memfd = false;
}
free(fake_path);
}
}
#endif
base = dlopen(buf, RTLD_NOW | RTLD_GLOBAL);
if (!is_memfd) {
close(fd);
}