[PATCH 2/2] dlfcn,elf: implement dlmem() function [BZ #11767]
stsp
stsp2@yandex.ru
Sat Mar 18 17:28:08 GMT 2023
13.02.2023 18:45, Florian Weimer пишет:
> On the Google branches, there is somewhat similar functionality, in the
> form of dlopen_with_offset.
I'll list dlopen_with_offset() below.
> Your patch seems to allow the creation of fully unnamed link maps
> (especially if the shared object being loaded does not come with
> DT_SONAME). I think we need to discuss the consequences of that. This
> feature could be independently useful to some applications, to the
> extent that they would use dlmem just for that purposes (even for files
> that are stored on disk).
Probably, but in v9 I added a possibility
to specify an object name for dlmem().
It also has an fdlopen() impl as a test-case.
So dlopen_with_offset():
static void *
dlopen_with_offset (int fd, int flags, off_t offset)
{
off_t len;
void *addr;
void *handle;
len = lseek (fd, 0, SEEK_END);
lseek (fd, 0, SEEK_SET);
if (len <= offset)
return NULL;
len -= offset;
addr = mmap (NULL, len, PROT_READ, MAP_PRIVATE, fd, offset);
if (addr == MAP_FAILED)
return NULL;
handle = dlmem (addr, len, flags, NULL);
munmap (addr, len);
return handle;
}
Should I add it to a test-case or fdlopen()
is enough?
More information about the Libc-alpha
mailing list