linux/kernel/bpf/stackmap.c
/* Parse build ID of ELF file mapped to vma */
Parse build ID of ELF file mapped to vma
Parse build ID of ELF file mapped to vma
static int stack_map_get_build_id(struct vm_area_struct *vma,
				  unsigned char *build_id)
{
	Elf32_Ehdr *ehdr;
	struct page *page;
	void *page_addr;
	int ret;
	if (!vma->vm_file)
		return -EINVAL;
	page = find_get_page(vma->vm_file->f_mapping, 0);
	if (!page)
		return -EFAULT;	
	ret = -EINVAL;
	page_addr = page_address(page);
	ehdr = (Elf32_Ehdr *)page_addr;
	if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0)
		goto out;
	if (ehdr->e_type != ET_EXEC && ehdr->e_type != ET_DYN)
		goto out;
	if (ehdr->e_ident[EI_CLASS] == ELFCLASS32)
		ret = stack_map_get_build_id_32(page_addr, build_id);
	else if (ehdr->e_ident[EI_CLASS] == ELFCLASS64)
		ret = stack_map_get_build_id_64(page_addr, build_id);
out:
	put_page(page);
	return ret;
}
static int stack_map_get_build_id ( struct vm_area_struct * vma , unsigned char * build_id ) { Elf32_Ehdr * ehdr ; struct page * page ; void * page_addr ; int ret ; if ( ! vma -> vm_file ) return - EINVAL ; page = find_get_page ( vma -> vm_file -> f_mapping , 0 ) ; if ( ! page ) return - EFAULT ; ret = - EINVAL ; page_addr = page_address ( page ) ; ehdr = ( Elf32_Ehdr * ) page_addr ; if ( memcmp ( ehdr -> e_ident , ELFMAG , SELFMAG ) != 0 ) goto out ; if ( ehdr -> e_type != ET_EXEC && ehdr -> e_type != ET_DYN ) goto out ; if ( ehdr -> e_ident [ EI_CLASS ] == ELFCLASS32 ) ret = stack_map_get_build_id_32 ( page_addr , build_id ) ; else if ( ehdr -> e_ident [ EI_CLASS ] == ELFCLASS64 ) ret = stack_map_get_build_id_64 ( page_addr , build_id ) ; out : put_page ( page ) ; return ret ; }
Parse build ID of ELF file mapped to vma
Parse build ID of ELF file mapped to vma
/* only works for page backed storage  */ /* page not mapped */ /* compare magic x7f "ELF" */ /* only support executable file and shared object file */