Exemple #1
0
void
fbt_init( void )
{
	if (0 == fbt_inited)
	{
		int majdevno = cdevsw_add(FBT_MAJOR, &fbt_cdevsw);
		
		if (majdevno < 0) {
			printf("fbt_init: failed to allocate a major number!\n");
			return;
		}
		
		PE_parse_boot_argn("IgnoreFBTBlacklist", &ignore_fbt_blacklist, sizeof (ignore_fbt_blacklist));

		fbt_attach( (dev_info_t	*)(uintptr_t)majdevno, DDI_ATTACH );
		
		fbt_inited = 1; /* Ensure this initialization occurs just one time. */
	}
	else
		panic("fbt_init: called twice!\n");
}
Exemple #2
0
Fichier : fbt.c Projet : 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");
}