FreeBSD/lib/libkvm/kvm_powerpc64.c
/*
 * Map the ELF headers into the process' address space. We do this in two
 * steps: first the ELF header itself and using that information the whole
 * set of headers.
 */
Map the ELF headers into the process' address space. We do this in two
steps: first the ELF header itself and using that information the whole
set of headers.
Map the ELF headers into the process ' address space . We do this in two steps : first the ELF header itself and using that information the whole set of headers .
static int
powerpc_maphdrs(kvm_t *kd)
{
	struct vmstate *vm;
	size_t mapsz;
	vm = kd->vmst;
	vm->mapsz = sizeof(*vm->eh) + sizeof(struct kerneldumpheader);
	vm->map = mmap(NULL, vm->mapsz, PROT_READ, MAP_PRIVATE, kd->pmfd, 0);
	if (vm->map == MAP_FAILED) {
		_kvm_err(kd, kd->program, "cannot map corefile");
		return (-1);
	}
	vm->dmphdrsz = 0;
	vm->eh = vm->map;
	if (!valid_elf_header(vm->eh)) {
		vm->dmphdrsz = dump_header_size(vm->map);
		if (vm->dmphdrsz == 0)
			goto inval;
		vm->eh = (void *)((uintptr_t)vm->map + vm->dmphdrsz);
		if (!valid_elf_header(vm->eh))
			goto inval;
	}
	mapsz = be16toh(vm->eh->e_phentsize) * be16toh(vm->eh->e_phnum) +
	    be64toh(vm->eh->e_phoff);
	munmap(vm->map, vm->mapsz);
	vm->mapsz = vm->dmphdrsz + mapsz;
	vm->map = mmap(NULL, vm->mapsz, PROT_READ, MAP_PRIVATE, kd->pmfd, 0);
	if (vm->map == MAP_FAILED) {
		_kvm_err(kd, kd->program, "cannot map corefile headers");
		return (-1);
	}
	vm->eh = (void *)((uintptr_t)vm->map + vm->dmphdrsz);
	vm->ph = (void *)((uintptr_t)vm->eh +
	    (uintptr_t)be64toh(vm->eh->e_phoff));
	return (0);
 inval:
	_kvm_err(kd, kd->program, "invalid corefile");
	return (-1);
}
static int powerpc_maphdrs ( kvm_t * kd ) { struct vmstate * vm ; size_t mapsz ; vm = kd -> vmst ; vm -> mapsz = sizeof ( * vm -> eh ) + sizeof ( struct kerneldumpheader ) ; vm -> map = mmap ( NULL , vm -> mapsz , PROT_READ , MAP_PRIVATE , kd -> pmfd , 0 ) ; if ( vm -> map == MAP_FAILED ) { _kvm_err ( kd , kd -> program , " " ) ; return ( -1 ) ; } vm -> dmphdrsz = 0 ; vm -> eh = vm -> map ; if ( ! valid_elf_header ( vm -> eh ) ) { vm -> dmphdrsz = dump_header_size ( vm -> map ) ; if ( vm -> dmphdrsz == 0 ) goto inval ; vm -> eh = ( void * ) ( ( uintptr_t ) vm -> map + vm -> dmphdrsz ) ; if ( ! valid_elf_header ( vm -> eh ) ) goto inval ; } mapsz = be16toh ( vm -> eh -> e_phentsize ) * be16toh ( vm -> eh -> e_phnum ) + be64toh ( vm -> eh -> e_phoff ) ; munmap ( vm -> map , vm -> mapsz ) ; vm -> mapsz = vm -> dmphdrsz + mapsz ; vm -> map = mmap ( NULL , vm -> mapsz , PROT_READ , MAP_PRIVATE , kd -> pmfd , 0 ) ; if ( vm -> map == MAP_FAILED ) { _kvm_err ( kd , kd -> program , " " ) ; return ( -1 ) ; } vm -> eh = ( void * ) ( ( uintptr_t ) vm -> map + vm -> dmphdrsz ) ; vm -> ph = ( void * ) ( ( uintptr_t ) vm -> eh + ( uintptr_t ) be64toh ( vm -> eh -> e_phoff ) ) ; return ( 0 ) ; inval : _kvm_err ( kd , kd -> program , " " ) ; return ( -1 ) ; }
Map the ELF headers into the process' address space.
Map the ELF headers into the process ' address space .
/*
		 * Hmmm, no ELF header. Maybe we still have a dump header.
		 * This is normal when the core file wasn't created by
		 * savecore(8), but instead was dumped over TFTP. We can
		 * easily skip the dump header...
		 */ /* Map all headers. */