Exemplo n.º 1
0
int setup_mmap_aux(int which_fd, int which_mmap) {

	int i,flags,prot,size;

	i=find_empty_mmap();
	if (i<0) return -1;

	size=mmap_random_size(0);
	prot=mmap_random_prot();
	flags=mmap_random_flags();

	/* need locking? */
	mmaps[i].addr=MAP_FAILED;

	mmaps[i].prot=prot;
	mmaps[i].flags=flags;
	mmaps[i].size=size;
	mmaps[i].aux=1;
	mmaps[i].parent_mmap=which_mmap;

	if (!ignore_but_dont_skip.mmap) {

		stats.mmap_aux_attempts++;

		/* Hook into existing mmap */
		struct perf_event_mmap_page *mmap_control;

		mmap_control = (struct perf_event_mmap_page *)
				mmaps[which_mmap].addr;

		if ((mmap_control!=NULL) &&
			(mmaps[which_mmap].prot&PROT_WRITE)) {
			mmap_control->aux_offset=mmaps[which_mmap].size;
			mmap_control->aux_size=mmaps[i].size;
		}

		mmaps[i].addr=mmap(NULL, size,
			prot, flags,
			event_data[which_fd].fd, mmaps[which_mmap].size);

		if (mmaps[i].addr==MAP_FAILED) {
			mmaps[i].addr=MAP_FAILED;
#if LOG_FAILURES
			if (logging&TYPE_MMAP) {
				if (trigger_failure_logging) {
					sprintf(log_buffer,"# M %d %d %p\n",
						mmaps[i].size,
						event_data[which_fd].fd,
						mmaps[i].addr);
					write(log_fd,log_buffer,
						strlen(log_buffer));
				}
			}
#endif
			return -1;
		}

		else {
			active_mmaps++;
			event_data[which_fd].mmap=i;
			mmaps[i].fd=event_data[which_fd].fd;

			if (logging&TYPE_MMAP) {
				sprintf(log_buffer,"M %d %d %p\n",
					mmaps[i].size,
					event_data[which_fd].fd,
					mmaps[i].addr);
				write(log_fd,log_buffer,strlen(log_buffer));
			}

			stats.mmap_aux_successful++;
		}
	}

	mmaps[i].active=1;
//	if (mmaps[i].addr==NULL) printf("b%d.active=1 %p\n",i,mmaps[i].addr);

	return 0;
}
Exemplo n.º 2
0
int setup_mmap_aux(int which_fd, int which_mmap) {

	int i,flags,prot;

	i=find_empty_mmap();
	if (i<0) return -1;

	/* need locking? */
	mmaps[i].active=1;

	/* to be valid we really want to be 2^x pages */
	switch(rand()%3) {
		case 0: mmaps[i].size=(rand()%64)*getpagesize();
			break;
		case 1: mmaps[i].size=
				((1<<rand()%10) )*getpagesize();
			break;
		default: mmaps[i].size=rand()%65535;
	}

	mmaps[i].addr=NULL;

	prot=mmap_random_prot();
	flags=mmap_random_flags();
	mmaps[i].prot=prot;
	mmaps[i].flags=flags;
	mmaps[i].aux=1;
	mmaps[i].parent_mmap=which_mmap;

	if (!ignore_but_dont_skip.mmap) {

		stats.mmap_aux_attempts++;

		/* Hook into existing mmap */
		struct perf_event_mmap_page *mmap_control;

		mmap_control = (struct perf_event_mmap_page *)
				mmaps[which_mmap].addr;

		if ((mmap_control!=NULL) &&
			(mmaps[which_mmap].prot&PROT_WRITE)) {
			mmap_control->aux_offset=mmaps[which_mmap].size;
			mmap_control->aux_size=mmaps[i].size;
		}

		mmaps[i].addr=mmap(NULL, mmaps[i].size,
			prot, flags,
			event_data[which_fd].fd, mmaps[which_mmap].size);

		if (mmaps[i].addr==MAP_FAILED) {
			mmaps[i].addr=NULL;
			mmaps[i].active=0;
#if LOG_FAILURES
			if (logging&TYPE_MMAP) {
				if (trigger_failure_logging) {
					sprintf(log_buffer,"# M %d %d %p\n",
						mmaps[i].size,
						event_data[which_fd].fd,
						mmaps[i].addr);
					write(log_fd,log_buffer,
						strlen(log_buffer));
				}
			}
#endif
		}

		else {
			active_mmaps++;
			event_data[which_fd].mmap=i;
			mmaps[i].fd=event_data[which_fd].fd;

			if (logging&TYPE_MMAP) {
				sprintf(log_buffer,"M %d %d %p\n",
					mmaps[i].size,
					event_data[which_fd].fd,
					mmaps[i].addr);
				write(log_fd,log_buffer,strlen(log_buffer));
			}

			stats.mmap_aux_successful++;
		}
	}
	return 0;
}
Exemplo n.º 3
0
/* active is set to 1 but addr is not valid.			*/
int setup_mmap(int which) {

	int i,prot,flags,size;

	i=find_empty_mmap();
	if (i<0) return -1;

	size=mmap_random_size(1);
	prot=mmap_random_prot();
	flags=mmap_random_flags();

	/* need locking? */
//	mmaps[i].active=1;
	mmaps[i].addr=MAP_FAILED;
	mmaps[i].prot=prot;
	mmaps[i].flags=flags;
	mmaps[i].size=size;
	mmaps[i].aux=0;

	if (!ignore_but_dont_skip.mmap) {

		stats.mmap_attempts++;
		mmaps[i].addr=mmap(NULL, size,
			prot, flags,
			event_data[which].fd, 0);

		/* If running as root, with MAP_FIXED, NULL is a valid addr */
//		if (mmaps[i].addr==NULL) {
//			printf("This can't happen???\n");
//		}

		if (mmaps[i].addr==MAP_FAILED) {
			mmaps[i].addr=MAP_FAILED;
#if LOG_FAILURES
			if (logging&TYPE_MMAP) {
				if (trigger_failure_logging) {
					sprintf(log_buffer,"# M %d %d %p\n",
						mmaps[i].size,
						event_data[which].fd,
						mmaps[i].addr);
					write(log_fd,log_buffer,
						strlen(log_buffer));
				}
			}
#endif
			return -1;
		}

		else {
			active_mmaps++;
			event_data[which].mmap=i;
			mmaps[i].fd=event_data[which].fd;
			mmaps[i].which_event=which;

			if (logging&TYPE_MMAP) {
				sprintf(log_buffer,"M %d %d %p\n",
					mmaps[i].size,
					event_data[which].fd,
					mmaps[i].addr);
				write(log_fd,log_buffer,strlen(log_buffer));
			}

			stats.mmap_successful++;
		}
	}

	mmaps[i].active=1;
//	if (mmaps[i].addr==NULL) printf("%d.active=1 %p\n",i,mmaps[i].addr);

	/* Randomly try to set up an aux mmap too */
	if (rand()%4==0) {
		setup_mmap_aux(which,i);
	}



	return 0;
}
Exemplo n.º 4
0
int setup_mmap(int which) {

	int i,prot,flags;

	i=find_empty_mmap();
	if (i<0) return -1;

	/* need locking? */
	mmaps[i].active=1;

	/* to be valid we really want to be 1+2^x pages */
	switch(rand()%3) {
		case 0: mmaps[i].size=(rand()%64)*getpagesize();
			break;
		case 1: mmaps[i].size=
				(1 + (1<<rand()%10) )*getpagesize();
			break;
		default: mmaps[i].size=rand()%65535;
	}

	mmaps[i].addr=NULL;

	prot=mmap_random_prot();
	flags=mmap_random_flags();
	mmaps[i].prot=prot;
	mmaps[i].flags=flags;
	mmaps[i].aux=0;

	if (!ignore_but_dont_skip.mmap) {

		stats.mmap_attempts++;
		mmaps[i].addr=mmap(NULL, mmaps[i].size,
			prot, flags,
			event_data[which].fd, 0);

		if (mmaps[i].addr==MAP_FAILED) {
			mmaps[i].addr=NULL;
			mmaps[i].active=0;
#if LOG_FAILURES
			if (logging&TYPE_MMAP) {
				if (trigger_failure_logging) {
					sprintf(log_buffer,"# M %d %d %p\n",
						mmaps[i].size,
						event_data[which].fd,
						mmaps[i].addr);
					write(log_fd,log_buffer,
						strlen(log_buffer));
				}
			}
#endif
		}

		else {
			active_mmaps++;
			event_data[which].mmap=i;
			mmaps[i].fd=event_data[which].fd;

			if (logging&TYPE_MMAP) {
				sprintf(log_buffer,"M %d %d %p\n",
					mmaps[i].size,
					event_data[which].fd,
					mmaps[i].addr);
				write(log_fd,log_buffer,strlen(log_buffer));
			}

			stats.mmap_successful++;
		}
	}

	/* Randomly try to set up an aux mmap too */
	if (rand()%4==0) {
		setup_mmap_aux(which,i);
	}

	return 0;
}