예제 #1
0
/*
 * This routine returns the a pointer to the data for the named segment
 * if it exist in the mach header passed to it.  Also it returns
 * the size of the segment data indirectly through the pointer size.
 * Otherwise it returns zero for the pointer and the size.
 */
void *
getsegdatafromheader(
    kernel_mach_header_t *mhp,
	const char *segname,
	unsigned long *size)
{
	const kernel_segment_command_t *sc;
	void *result;

	sc = getsegbynamefromheader(mhp, segname);
	if(sc == (kernel_segment_command_t *)0){
	    *size = 0;
	    return((char *)0);
	}
	*size = sc->vmsize;
	result = (void *)sc->vmaddr;
	return result;
}
예제 #2
0
/*
 * Return the address of the named Mach-O segment from the currently
 * executing kernel kernel, or NULL.
 */
kernel_segment_command_t *
getsegbyname(const char *seg_name)
{
	return(getsegbynamefromheader(&_mh_execute_header, seg_name));
}
예제 #3
0
파일: fbt.c 프로젝트: 0xffea/xnu
void
fbt_init( void )
{

	PE_parse_boot_argn("DisableFBT", &gDisableFBT, sizeof (gDisableFBT));

	if (0 == gDisableFBT)
	{
		int majdevno = cdevsw_add(FBT_MAJOR, &fbt_cdevsw);
		unsigned long size = 0, header_size, round_size;
	   	kern_return_t ret;
		void *p, *q;
		
		if (majdevno < 0) {
			printf("fbt_init: failed to allocate a major number!\n");
			return;
		}

		/*
		 * Capture the kernel's mach_header in its entirety and the contents of
		 * its LINKEDIT segment (and only that segment). This is sufficient to
		 * build all the fbt probes lazily the first time a client looks to
		 * the fbt provider. Remeber these on the global struct modctl g_fbt_kernctl.
		 */
		header_size = sizeof(kernel_mach_header_t) + _mh_execute_header.sizeofcmds;
		p = getsegdatafromheader(&_mh_execute_header, SEG_LINKEDIT, &size);

        round_size = round_page(header_size + size);
		/* "q" will accomodate copied kernel_mach_header_t, its load commands, and LINKEIT segment. */
		ret = kmem_alloc_pageable(kernel_map, (vm_offset_t *)&q, round_size);

		if (p && (ret == KERN_SUCCESS)) {
			kernel_segment_command_t *sgp;

			bcopy( (void *)&_mh_execute_header, q, header_size);
			bcopy( p, (char *)q + header_size, size);

			sgp = getsegbynamefromheader(q, SEG_LINKEDIT);

			if (sgp) {
				sgp->vmaddr = (uintptr_t)((char *)q + header_size);
				g_fbt_kernctl.address = (vm_address_t)q;
				g_fbt_kernctl.size = header_size + size;
			} else {
				kmem_free(kernel_map, (vm_offset_t)q, round_size);
				g_fbt_kernctl.address = (vm_address_t)NULL;
				g_fbt_kernctl.size = 0;
			}
		} else {
			if (ret == KERN_SUCCESS)
				kmem_free(kernel_map, (vm_offset_t)q, round_size);
			g_fbt_kernctl.address = (vm_address_t)NULL;
			g_fbt_kernctl.size = 0;
		}

		strncpy((char *)&(g_fbt_kernctl.mod_modname), "mach_kernel", KMOD_MAX_NAME);
		((char *)&(g_fbt_kernctl.mod_modname))[KMOD_MAX_NAME -1] = '\0';

		fbt_attach( (dev_info_t	*)(uintptr_t)majdevno, DDI_ATTACH );

		gDisableFBT = 1; /* Ensure this initialization occurs just one time. */
	}
	else
		printf("fbt_init: DisableFBT non-zero, no FBT probes will be provided.\n");
}