Exemplo n.º 1
0
static int _new_file(DL * dl, char const * pathname)
{
	Elf_Phdr * phdr;
	size_t i;
	ssize_t len;

	dl->fd = open(pathname, O_RDONLY);
	dl->path = strdup(pathname);
	if(dl->fd < 0 || dl->path == NULL)
		return _dl_error_set_errno(-1);
	/* read the ELF header */
	if(_file_read_ehdr(dl->fd, &dl->ehdr) != 0)
		return -1;
	/* read the program headers */
	if((phdr = _dl_load(dl, dl->ehdr.e_phoff, sizeof(*phdr)
					* dl->ehdr.e_phnum)) == NULL)
		return -1;
	for(i = 0; i < dl->ehdr.e_phnum; i++)
	{
		if(phdr[i].p_type != PT_LOAD)
			continue;
		if(phdr[i].p_filesz > phdr[i].p_memsz)
		{
			free(phdr);
			return _dl_error_set(DE_INVALID_FORMAT, -1);
		}
		if(_file_mmap(dl, &phdr[i]) == 0)
			continue;
		free(phdr);
		return -1;
	}
	free(phdr);
	/* read the section headers */
	if((len = dl->ehdr.e_shnum * sizeof(*dl->shdr)) < 0) /* XXX relevant? */
		return _dl_error_set(DE_INVALID_FORMAT, -1);
	if((dl->shdr = _dl_load(dl, dl->ehdr.e_shoff, len)) == NULL)
		return -1;
	if(_file_symbols(dl) != 0 || _file_relocations(dl) != 0)
		return -1;
	return 0;
}
Exemplo n.º 2
0
void *file_mmap_share(struct file *file, uint64_t size)
{
	return _file_mmap(file, size, MAP_SHARED);
}