linux/kernel/bpf/stackmap.c
/*
 * Parse build id from the note segment. This logic can be shared between
 * 32-bit and 64-bit system, because Elf32_Nhdr and Elf64_Nhdr are
 * identical.
 */
Parse build id from the note segment. This logic can be shared between
32-bit and 64-bit system, because Elf32_Nhdr and Elf64_Nhdr are
identical.
Parse build id from the note segment . This logic can be shared between 32 - bit and 64 - bit system because Elf32_Nhdr and Elf64_Nhdr are identical .
static inline int stack_map_parse_build_id(void *page_addr,
					   unsigned char *build_id,
					   void *note_start,
					   Elf32_Word note_size)
{
	Elf32_Word note_offs = 0, new_offs;
	if (note_start < page_addr || note_start + note_size < note_start)
		return -EINVAL;
	if (note_start + note_size > page_addr + PAGE_SIZE)
		return -EINVAL;
	while (note_offs + sizeof(Elf32_Nhdr) < note_size) {
		Elf32_Nhdr *nhdr = (Elf32_Nhdr *)(note_start + note_offs);
		if (nhdr->n_type == BPF_BUILD_ID &&
		    nhdr->n_namesz == sizeof("GNU") &&
		    nhdr->n_descsz == BPF_BUILD_ID_SIZE) {
			memcpy(build_id,
			       note_start + note_offs +
			       ALIGN(sizeof("GNU"), 4) + sizeof(Elf32_Nhdr),
			       BPF_BUILD_ID_SIZE);
			return 0;
		}
		new_offs = note_offs + sizeof(Elf32_Nhdr) +
			ALIGN(nhdr->n_namesz, 4) + ALIGN(nhdr->n_descsz, 4);
		if (new_offs <= note_offs)  
			break;
		note_offs = new_offs;
	}
	return -EINVAL;
}
static inline int stack_map_parse_build_id ( void * page_addr , unsigned char * build_id , void * note_start , Elf32_Word note_size ) { Elf32_Word note_offs = 0 , new_offs ; if ( note_start < page_addr || note_start + note_size < note_start ) return - EINVAL ; if ( note_start + note_size > page_addr + PAGE_SIZE ) return - EINVAL ; while ( note_offs + sizeof ( Elf32_Nhdr ) < note_size ) { Elf32_Nhdr * nhdr = ( Elf32_Nhdr * ) ( note_start + note_offs ) ; if ( nhdr -> n_type == BPF_BUILD_ID && nhdr -> n_namesz == sizeof ( " " ) && nhdr -> n_descsz == BPF_BUILD_ID_SIZE ) { memcpy ( build_id , note_start + note_offs + ALIGN ( sizeof ( " " ) , 4 ) + sizeof ( Elf32_Nhdr ) , BPF_BUILD_ID_SIZE ) ; return 0 ; } new_offs = note_offs + sizeof ( Elf32_Nhdr ) + ALIGN ( nhdr -> n_namesz , 4 ) + ALIGN ( nhdr -> n_descsz , 4 ) ; if ( new_offs <= note_offs ) break ; note_offs = new_offs ; } return - EINVAL ; }
Parse build id from the note segment.
Parse build id from the note segment .
/* check for overflow */ /* only supports note that fits in the first page */ /* overflow */