コード例 #1
0
ファイル: main.c プロジェクト: michalwojciech/cs170s10proj2
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
PUBLIC int main(void)
{
  message msg;
  int result, who_e;

  /* SEF local startup. */
  sef_local_startup();

  /* This is VM's main loop. */
  while (TRUE) {
	int r, c;

	SANITYCHECK(SCL_TOP);
	if(missing_spares > 0) {
		pt_cycle();	/* pagetable code wants to be called */
	}
	SANITYCHECK(SCL_DETAIL);

  	if ((r=sef_receive(ANY, &msg)) != OK)
		vm_panic("sef_receive() error", r);

	SANITYCHECK(SCL_DETAIL);

	if(msg.m_type & NOTIFY_MESSAGE) {
		switch(msg.m_source) {
			case SYSTEM:
				/* Kernel wants to have memory ranges
				 * verified, and/or pagefaults handled.
				 */
				do_memory();
				break;
			case HARDWARE:
				do_pagefaults();
				break;
			case PM_PROC_NR:
				/* PM sends a notify() on shutdown, which
				 * is OK and we ignore.
				 */
				break;
			default:
				/* No-one else should send us notifies. */
				printf("VM: ignoring notify() from %d\n",
					msg.m_source);
				break;
		}
		continue;
	}
	who_e = msg.m_source;
	c = CALLNUMBER(msg.m_type);
	result = ENOSYS; /* Out of range or restricted calls return this. */
	if(c < 0 || !vm_calls[c].vmc_func) {
		printf("VM: out of range or missing callnr %d from %d\n",
			msg.m_type, who_e);
	} else if (vm_acl_ok(who_e, c) != OK) {
		printf("VM: unauthorized %s by %d\n",
			vm_calls[c].vmc_name, who_e);
	} else {
	SANITYCHECK(SCL_FUNCTIONS);
		result = vm_calls[c].vmc_func(&msg);
	SANITYCHECK(SCL_FUNCTIONS);
	}

	/* Send reply message, unless the return code is SUSPEND,
	 * which is a pseudo-result suppressing the reply message.
	 */
	if(result != SUSPEND) {
	SANITYCHECK(SCL_DETAIL);
		msg.m_type = result;
		if((r=send(who_e, &msg)) != OK) {
			printf("VM: couldn't send %d to %d (err %d)\n",
				msg.m_type, who_e, r);
			vm_panic("send() error", NO_NUM);
		}
	SANITYCHECK(SCL_DETAIL);
	}
	SANITYCHECK(SCL_DETAIL);
  }
  return(OK);
}
コード例 #2
0
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
int main(void)
{
    kipc_msg_t msg;
    int result, who_e;

#if SANITYCHECKS
    incheck = nocheck = 0;
    FIXME("VM SANITYCHECKS are on");
#endif

    vm_paged = 1;
    env_parse("vm_paged", "d", 0, &vm_paged, 0, 1);
#if SANITYCHECKS
    env_parse("vm_sanitychecklevel", "d", 0, &vm_sanitychecklevel, 0, SCL_MAX);
#endif

    vm_init();

    /* This is VM's main loop. */
    while (TRUE) {
        int r, c;

        SANITYCHECK(SCL_TOP);
        if(missing_spares > 0) {
            pt_cycle();	/* pagetable code wants to be called */
        }
        SANITYCHECK(SCL_DETAIL);

        if ((r=kipc_module_call(KIPC_RECEIVE, 0, ENDPT_ANY, &msg)) != 0)
            vm_panic("receive() error", r);

        SANITYCHECK(SCL_DETAIL);

        if(msg.m_type & NOTIFY_MESSAGE) {
            switch(msg.m_source) {
            case SYSTEM:
                /* Kernel wants to have memory ranges
                 * verified, and/or pagefaults handled.
                 */
                do_memory();
                break;
            case HARDWARE:
                do_pagefaults();
                break;
            case PM_PROC_NR:
                /* PM sends a notify() on shutdown, which
                 * is OK and we ignore.
                 */
                break;
            default:
                /* No-one else should send us notifies. */
                printk("VM: ignoring notify() from %d\n",
                       msg.m_source);
                break;
            }
            continue;
        }
        who_e = msg.m_source;
        c = CALLNUMBER(msg.m_type);
        result = -ENOSYS; /* Out of range or restricted calls return this. */
        if(c < 0 || !vm_calls[c].vmc_func) {
            printk("VM: out of range or missing callnr %d from %d\n",
                   msg.m_type, who_e);
        } else if (vm_acl_ok(who_e, c) != 0) {
            printk("VM: unauthorized %s by %d\n",
                   vm_calls[c].vmc_name, who_e);
        } else {
            SANITYCHECK(SCL_FUNCTIONS);
            result = vm_calls[c].vmc_func(&msg);
            SANITYCHECK(SCL_FUNCTIONS);
        }

        /* Send reply message, unless the return code is SUSPEND,
         * which is a pseudo-result suppressing the reply message.
         */
        if(result != SUSPEND) {
            SANITYCHECK(SCL_DETAIL);
            msg.m_type = result;
            if((r=kipc_module_call(KIPC_SEND, 0, who_e, &msg)) != 0) {
                printk("VM: couldn't send %d to %d (err %d)\n",
                       msg.m_type, who_e, r);
                vm_panic("send() error", NO_NUM);
            }
            SANITYCHECK(SCL_DETAIL);
        }
        SANITYCHECK(SCL_DETAIL);
    }
    return 0;
}
コード例 #3
0
ファイル: main.c プロジェクト: junzhe/minix_pandaboard_es
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
int main(void)
{
  message msg;
  int result, who_e, rcv_sts;
  int caller_slot;

  /* Initialize system so that all processes are runnable */
  init_vm();

  /* Register init callbacks. */
  sef_setcb_init_restart(sef_cb_init_fail);
  sef_setcb_signal_handler(sef_cb_signal_handler);

  /* Let SEF perform startup. */
  sef_startup();

  SANITYCHECK(SCL_TOP);

  /* This is VM's main loop. */
  while (TRUE) {
	int r, c;
	u32_t type, param;

	SANITYCHECK(SCL_TOP);
	if(missing_spares > 0) {
		alloc_cycle();	/* mem alloc code wants to be called */
	}

  	if ((r=sef_receive_status(ANY, &msg, &rcv_sts)) != OK)
		panic("sef_receive_status() error: %d", r);

	if (is_ipc_notify(rcv_sts)) {
		/* Unexpected notify(). */
		printf("VM: ignoring notify() from %d\n", msg.m_source);
		continue;
	}
	who_e = msg.m_source;
	if(vm_isokendpt(who_e, &caller_slot) != OK)
		panic("invalid caller %d", who_e);

	type = param = msg.m_type;
	type &= 0x0000FFFF;
	param >>= 16;
	c = CALLNUMBER(type);
	result = ENOSYS; /* Out of range or restricted calls return this. */
	
	if(msg.m_type == RS_INIT && msg.m_source == RS_PROC_NR) {
		result = do_rs_init(&msg);
	} else if (msg.m_type == VM_PAGEFAULT) {
		if (!IPC_STATUS_FLAGS_TEST(rcv_sts, IPC_FLG_MSG_FROM_KERNEL)) {
			printf("VM: process %d faked VM_PAGEFAULT "
					"message!\n", msg.m_source);
		}
		do_pagefaults(&msg);
		/*
		 * do not reply to this call, the caller is unblocked by
		 * a sys_vmctl() call in do_pagefaults if success. VM panics
		 * otherwise
		 */
		continue;
	} else if(c < 0 || !vm_calls[c].vmc_func) {
		/* out of range or missing callnr */
	} else {
		if (acl_check(&vmproc[caller_slot], c) != OK) {
			printf("VM: unauthorized %s by %d\n",
					vm_calls[c].vmc_name, who_e);
		} else {
			SANITYCHECK(SCL_FUNCTIONS);
			result = vm_calls[c].vmc_func(&msg);
			SANITYCHECK(SCL_FUNCTIONS);
		}
	}

	/* Send reply message, unless the return code is SUSPEND,
	 * which is a pseudo-result suppressing the reply message.
	 */
	if(result != SUSPEND) {
		msg.m_type = result;
		if((r=send(who_e, &msg)) != OK) {
			printf("VM: couldn't send %d to %d (err %d)\n",
				msg.m_type, who_e, r);
			panic("send() error");
		}
	}
  }
  return(OK);
}
コード例 #4
0
ファイル: main.c プロジェクト: universe-long-zhuo/C-Example01
/*===========================================================================*
 *				main					     *
 *===========================================================================*/
PUBLIC int main(void)
{
  message msg;
  int result, who_e, rcv_sts;
  int caller_slot;
  struct vmproc *vmp_caller;

  /* SEF local startup. */
  sef_local_startup();

  SANITYCHECK(SCL_TOP);

  /* This is VM's main loop. */
  while (TRUE) {
	int r, c;

	SANITYCHECK(SCL_TOP);
	if(missing_spares > 0) {
		pt_cycle();	/* pagetable code wants to be called */
	}

  	if ((r=sef_receive_status(ANY, &msg, &rcv_sts)) != OK)
		panic("sef_receive_status() error: %d", r);

	if (is_ipc_notify(rcv_sts)) {
		/* Unexpected notify(). */
		printf("VM: ignoring notify() from %d\n", msg.m_source);
		continue;
	}
	who_e = msg.m_source;
	if(vm_isokendpt(who_e, &caller_slot) != OK)
		panic("invalid caller", who_e);
	vmp_caller = &vmproc[caller_slot];
	c = CALLNUMBER(msg.m_type);
	result = ENOSYS; /* Out of range or restricted calls return this. */
	if (msg.m_type == VM_PAGEFAULT) {
		if (!IPC_STATUS_FLAGS_TEST(rcv_sts, IPC_FLG_MSG_FROM_KERNEL)) {
			printf("VM: process %d faked VM_PAGEFAULT "
					"message!\n", msg.m_source);
		}
		do_pagefaults(&msg);
		/*
		 * do not reply to this call, the caller is unblocked by
		 * a sys_vmctl() call in do_pagefaults if success. VM panics
		 * otherwise
		 */
		continue;
	} else if(c < 0 || !vm_calls[c].vmc_func) {
		/* out of range or missing callnr */
	} else {
		if (vm_acl_ok(who_e, c) != OK) {
			printf("VM: unauthorized %s by %d\n",
					vm_calls[c].vmc_name, who_e);
		} else {
			SANITYCHECK(SCL_FUNCTIONS);
			result = vm_calls[c].vmc_func(&msg);
			SANITYCHECK(SCL_FUNCTIONS);
		}
	}

	/* Send reply message, unless the return code is SUSPEND,
	 * which is a pseudo-result suppressing the reply message.
	 */
	if(result != SUSPEND) {
		msg.m_type = result;
		if((r=send(who_e, &msg)) != OK) {
			printf("VM: couldn't send %d to %d (err %d)\n",
				msg.m_type, who_e, r);
			panic("send() error");
		}
	}
  }
  return(OK);
}