FreeBSD/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c
/*
 * Obtain a chunk of scratch space in the address space of the target process.
 */
Obtain a chunk of scratch space in the address space of the target process.
Obtain a chunk of scratch space in the address space of the target process .
fasttrap_scrspace_t *
fasttrap_scraddr(struct thread *td, fasttrap_proc_t *fprc)
{
	fasttrap_scrblock_t *scrblk;
	fasttrap_scrspace_t *scrspc;
	struct proc *p;
	vm_offset_t addr;
	int error, i;
	scrspc = NULL;
	if (td->t_dtrace_sscr != NULL) {
		scrspc = (fasttrap_scrspace_t *)td->t_dtrace_sscr;
		return (scrspc);
	}
	p = td->td_proc;
	mutex_enter(&fprc->ftpc_mtx);
	if (LIST_EMPTY(&fprc->ftpc_fscr)) {
		addr = 0;
		error = vm_map_find(&p->p_vmspace->vm_map, NULL, 0, &addr,
		    FASTTRAP_SCRBLOCK_SIZE, 0, VMFS_ANY_SPACE, VM_PROT_ALL,
		    VM_PROT_ALL, 0);
		if (error != KERN_SUCCESS)
			goto done;
		scrblk = malloc(sizeof(*scrblk), M_SOLARIS, M_WAITOK);
		scrblk->ftsb_addr = addr;
		LIST_INSERT_HEAD(&fprc->ftpc_scrblks, scrblk, ftsb_next);
		for (i = 0;
		    i < FASTTRAP_SCRBLOCK_SIZE / FASTTRAP_SCRSPACE_SIZE; i++) {
			scrspc = malloc(sizeof(*scrspc), M_SOLARIS, M_WAITOK);
			scrspc->ftss_addr = addr +
			    i * FASTTRAP_SCRSPACE_SIZE;
			LIST_INSERT_HEAD(&fprc->ftpc_fscr, scrspc,
			    ftss_next);
		}
	}
	scrspc = LIST_FIRST(&fprc->ftpc_fscr);
	LIST_REMOVE(scrspc, ftss_next);
	LIST_INSERT_HEAD(&fprc->ftpc_ascr, scrspc, ftss_next);
	td->t_dtrace_sscr = scrspc;
done:
	mutex_exit(&fprc->ftpc_mtx);
	return (scrspc);
}
fasttrap_scrspace_t * fasttrap_scraddr ( struct thread * td , fasttrap_proc_t * fprc ) { fasttrap_scrblock_t * scrblk ; fasttrap_scrspace_t * scrspc ; struct proc * p ; vm_offset_t addr ; int error , i ; scrspc = NULL ; if ( td -> t_dtrace_sscr != NULL ) { scrspc = ( fasttrap_scrspace_t * ) td -> t_dtrace_sscr ; return ( scrspc ) ; } p = td -> td_proc ; mutex_enter ( & fprc -> ftpc_mtx ) ; if ( LIST_EMPTY ( & fprc -> ftpc_fscr ) ) { addr = 0 ; error = vm_map_find ( & p -> p_vmspace -> vm_map , NULL , 0 , & addr , FASTTRAP_SCRBLOCK_SIZE , 0 , VMFS_ANY_SPACE , VM_PROT_ALL , VM_PROT_ALL , 0 ) ; if ( error != KERN_SUCCESS ) goto done ; scrblk = malloc ( sizeof ( * scrblk ) , M_SOLARIS , M_WAITOK ) ; scrblk -> ftsb_addr = addr ; LIST_INSERT_HEAD ( & fprc -> ftpc_scrblks , scrblk , ftsb_next ) ; for ( i = 0 ; i < FASTTRAP_SCRBLOCK_SIZE / FASTTRAP_SCRSPACE_SIZE ; i ++ ) { scrspc = malloc ( sizeof ( * scrspc ) , M_SOLARIS , M_WAITOK ) ; scrspc -> ftss_addr = addr + i * FASTTRAP_SCRSPACE_SIZE ; LIST_INSERT_HEAD ( & fprc -> ftpc_fscr , scrspc , ftss_next ) ; } } scrspc = LIST_FIRST ( & fprc -> ftpc_fscr ) ; LIST_REMOVE ( scrspc , ftss_next ) ; LIST_INSERT_HEAD ( & fprc -> ftpc_ascr , scrspc , ftss_next ) ; td -> t_dtrace_sscr = scrspc ; done : mutex_exit ( & fprc -> ftpc_mtx ) ; return ( scrspc ) ; }
Obtain a chunk of scratch space in the address space of the target process.
Obtain a chunk of scratch space in the address space of the target process .
/* If the thread already has scratch space, we're done. */ /*
		 * No scratch space is available, so we'll map a new scratch
		 * space block into the traced process' address space.
		 */ /*
		 * Carve the block up into chunks and put them on the free list.
		 */ /*
	 * Take the first scratch chunk off the free list, put it on the
	 * allocated list, and return its address.
	 */ /*
	 * This scratch space is reserved for use by td until the thread exits.
	 */