示例#1
0
void
QmcMetric::setup(QmcGroup* group, pmMetricSpec *metricSpec)
{
    if (my.status >= 0)
	setupDesc(group, metricSpec);
    if (my.status >= 0)
	setupIndom(metricSpec);
    if (my.status < 0)
	return;
    if (pmDebug & DBG_TRACE_PMC)
	dumpAll();
}
示例#2
0
文件: main.c 项目: interfector/mcvm
int
main(int argc, char** argv)
{
	asm_env* env = malloc( sizeof(asm_env) );
	struct assembly opcode = { 0, 0, 0, NULL };
	unsigned char* args;
	int i;

	FILE* fp;
	struct stat st;

	for(i = 0;i < R_REGS;i++)
		env->regs[ i ] = 0;

	env->eflags =
	env->current_op = 
	env->current_args = 0;

	/*
	env->mem_size = sizeof( assembly_code );
	env->mem_base = malloc( env->mem_size );

	memset( env->mem_base, 0x00, env->mem_size );
	memcpy( env->mem_base, assembly_code, sizeof(assembly_code) );
	*/

	if(!argv[1])
	{
		printf("Usage: %s <file>\n", argv[0]);
		return 1;
	}

	if(!(fp = fopen(argv[1], "r")))
		pdie("fopen", 2);

	if(stat(argv[1], &st) < 0)
		pdie("stat", 3);

	env->mem_size = (int) st.st_size;
	env->mem_base = malloc( env->mem_size + STACKSTART );
	memset( env->mem_base, 0x00, env->mem_size + STACKSTART );

	env->regs[ R_EBP ] = env->regs[ R_ESP ] = (unsigned int)STACKSTART;
	env->regs[ R_ESP ] += 4; /* - */

	if(fread(env->mem_base, 1, env->mem_size, fp) != env->mem_size)
		pdie("fread", 4);

	fclose( fp );

	env->mem_size += (STACKSTART + STACKSIZE);

	if(getenv("LIBSYSCALL"))
		loadHandler();

	for(env->eip = 0;env->eip < env->mem_size;env->eip++)
	{
		env->current_op = env->mem_base[ env->eip ];
		opcode = getOpcode( env->mem_base[ env->eip ] );

		if( !opcode.function )
			die( env, "SIGILL" );

		if( opcode.bytes > 0 )
		{
			env->current_args = 0;
			args = malloc( opcode.bytes );
			memcpy( args, env->mem_base + env->eip + 1, opcode.bytes);

			for(i = 0;i < opcode.bytes;i++)
				env->current_args |= (args[i] << (i * 8));
		}

		opcode.function( env );

		env->eip += opcode.bytes;
	}

	env->eip -= (opcode.bytes + 1);

	dumpAll( env );

	free( env );

	return 0;
}
int checkpoint(int pid)
{

/*************************Initialization of variables******************************/
	struct task_struct *tsk,*st;
	int checkpoint_flag = 0;
	char filename[100];
	char msg[256];
	struct file *f;

/****************************End of initialization*********************************/

	//Get the task_struct of 1st process
	st=tsk=&init_task;
	
   	printk(KERN_INFO "Begin\n");
	//file where the task_struct will be dumped change address according to file system

	snprintf(filename, 100, "/home/ahzaz/checkpoint.%d",pid);

	//Get task_struct of process with pid passed to function
    	do
    	{
		if(tsk->pid==pid)
            	{
			checkpoint_flag = 1;
			break;
		}
		tsk=next_task(tsk);
    	}while(tsk!=st);
	
	//if task_struct is found
	if(checkpoint_flag == 1)
	{
		send_sig(SIGSTOP,tsk,0);

		snprintf(msg, 1024, "Found, I am  %s with PID %d and my parent is %s with PID %d \n",tsk->comm, tsk->pid, (tsk->parent)->comm, 																(tsk->parent)->pid);
	   	printk(KERN_INFO "%s", msg);
		//open file to for dumping		
		f=filp_open(filename,O_WRONLY|O_CREAT|O_TRUNC,0777);
		if(!f)
		{
			printk("file error\n");
			return -1;
		}
		else
		{
			//Dump All
			if(!dumpAll(f, tsk)) {
				printk("task struct error write error\n");
				checkpoint_flag = 0;
			}

		}
  		send_sig(SIGKILL,tsk,0);


	}
	//Some error Occured
	if(checkpoint_flag == 0)
		printk(KERN_INFO "Error\n");

	return checkpoint_flag;
}