Пример #1
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;
}
Пример #2
0
/*===========================================================================*
 *				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;

	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 %d", who_e);
	c = CALLNUMBER(msg.m_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);
		pt_clearmapcache();
		/*
		 * 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);
}